# Printing into a Score using MuseScore

MuseScore is a wonderful and open source professional music score editor with a huge amount of capabilities. MusicManipulations provides a convenient interface that can instantly print any Notes or MIDIFile structure via MuseScore.

MusicVisualizations.musescoreFunction
musescore(file, notes | midi; keywords...)

Use the open source software "MuseScore" to create a score and save the given notes (or an entire midi file) to file, which can be either a .pdf or a .png.If given a .png the actual file name will end with -1, -2 etc. for each page of the score.

MuseScore must be accessible from the command line for this to work (add the path to MuseScore.exe to your PATH environment variable (ask Google)).

The keyword display = true will also display the created file. Keyword rmmidi = true deletes the MIDI file that has to be created inbetween score convertion (use false to keep it). MuseScore is run by default with commands -n -T 10 -r 1200, but you can change the keyword c to be whatever command (enclosed in backticks) you want, see the command line options of MuseScore for details.

Keep in mind that the score creation capabilities of MuseScore rely upon having well-defined notes. This means that you should use the function quantize to quantize both the position and duration of your notes!

## Creating a Score out of some Notes

using FileIO # used for loading the midi files
using MusicManipulations # tools for manipulating notes in Julia
using MusicVisualizations # tools for visualizing these notes

We first load the test MIDI file "Doxy". The third track has the notes of the Bass:

midi = load(testmidi()) # read the "test" Doxy MIDI recording.
bass = getnotes(midi, 3)
basstrim = bass[1:50]

Because the notes of the Bass are already quantized we can already print them into a staff using MuseScore:

musescore("bass.png", basstrim)

Amazingly MuseScore deduces automatically the clef and even the key of the piece!

## Creating a full Score out of a MIDI file

You can also pass a full MIDI file to musescore.

piano = getnotes(midi, 4)

However, MuseScore has decent results only with quantized notes. Let's quantize on a triplet grid using quantize.

qpiano = quantize(piano, [0, 1//3, 2//3, 1])

and save both tracks into a midi file:

ptrack = MIDITrack()
smidi = MIDIFile(1, 960, [midi.tracks[3], ptrack])

and then save the full thing as .pdf or .png:

musescore("doxy.pdf", smidi)

The first page looks like this:

When given multiple tracks MuseScore displays the name of the track (trackname), as well as the instrument it automatically chose to represent it.

## Drum Notation

It is also possible to use MuseScore to create drum notation. The process for this is almost identical with the above, with two differences. Firstly, the pitch of each note must have a specific value that maps the the actual drum instrument, and secondly all notes must be written on channel 9.

The function DrumNote simplifies this process:

MIDI.DrumNoteFunction
DrumNote(pitch, position, duration = 960; velocity = 100)

Shorthand constructor for a Note that is always on channel 9. It is possible to specify pitch as a String (e.g. "Acoustic Snare"), which will be converted to actual pitch using DRUMKEY.

And this is the drum key we use:

DRUMKEY

Here is an example where we create the "basic rock groove" in drum notation:

tpq = 960; e = 960÷2 # eigth note = quarter note ÷ 2
bass = "Acoustic Bass Drum"
snare = "Acoustic Snare"
hihat = "Closed Hi-Hat"
"Closed Hi-Hat"

We make the 8 hihat notes

rock = [DrumNote(hihat, i*e, e) for i in 0:7]

push!(rock, DrumNote(bass, 0, e), DrumNote(bass, 4e, e))

push!(rock, DrumNote(snare, 2e, e), DrumNote(snare, 6e, e))
rock = Notes(rock, tpq)
musescore("rock.png", rock)