This command was called Beep in build 226.

Makes the computer play written music from your script with voices (instruments) you program yourself.


Synth ( score )


Score is a melody with information about voices (instruments), speed, and other factors. See remarks below.


Here’s a hotkey that perforates somebody’s artery and plays the opening notes of Beethoven’s Fifth at the same time:

Hotkey ( Shift Ctrl C )
   Key ( Ctrl N )
   Synth ( Speed .9 "Key" Cm Just
   G4 200 G4 200 G4 200 Eb4 820
   R 300 F4 200 F4 200 F4 200 D4 820 )

The next hotkey plays the traditional Irish fiddle tune, The Rights of Man. Since it’s long and because the pieces of it would probably get reused, I’ll write it in three separate files and connect them with #Include.

First, in a file called “rights-of-man.score.txt”:
"key" Em speed 1.15 Just

|: G3 400 A3 240
B3 400 C4 240 A3 400 B3 240
G3 400 A3 240 F#3 400 G3 240
E3 400 F#3 240 G3 400 A3 240
B3 640 E4 400 F#4 240
G4 400 F#4 240 E4 400 D4 240
E4 400 D4 240 B3 400 D4 240
C4 400 B3 240 A3 400 G3 240
A3 640 G3 400 A3 240
B3 400 C4 240 A3 400 B3 240
G3 400 A3 240 F#3 400 G3 240
E3 400 F#3 240 G3 400 A3 240
B3 640 E4 400 F#4 240
G4 400 F#4 240 E4 400 D4 240 
B3 400 G4 240 F#4 400 G4 240  
E4 640 E3 640
E3 640 :|

|: G4 400 A4 240
B4 400 A4 240 B4 400 A4 240
E4 400 F#4 240 G4 400 A4 240
B4 400 A4 240 B4 400 A4 240
E4 400 G4 240 F#4 400 E4 240
D4 400 C#4 240 D4 400 E4 240
F#4 400 E4 240 F#4 400 G4 240
A4 400 F#4 240 D4 400 F#4 240
A4 640 G4 400 F#4 240
E4 400 D4 240 E4 400 F#4 240 
G4 400 F#4 240 G4 400 A4 240
B4 400 G4 240 A4 400 F#4 240
G4 400 F#4 240 E4 400 F#4 240
G4 400 F#4 240 E4 400 D4 240
B3 400 G4 240 F#4 400 G4 240
E4 640 E3 640
E3 640 :|

Second, in a file called “clarinet.voice.txt”:

fade .03 .2 wind .4
wave .1 .001
Wave 1 .25
Wave 2 .1
Wave 4 .1
wave 6 .08
Wave 8 .05
wave 10 .02
wave 3 .2
wave 5 .1
wave 7 .02
wave 9 .01
wave 11 .04

Third, finally, here’s the hotkey in a script:

Hotkey (f6)
  Synth (
    #include clarinet.voice.txt
    #include rights-of-man.score.txt  


This command can be used to provide audio feedback when you perform actions with hotkeys. For example, you could generate a cute little melody when you turn hotkeys on and a different cute little melody when you turn them off.

Mojo has two other commands that can be used in similar ways: PlaySound plays recorded wav files, and Beep does what its name suggests.

I got carried away when I wrote this command. It started when I wrote Beep, which used the standard beeping sound generated by the operating system. I thought the sound was unpleasant so I replaced it with a nicer tone that I generated with my own code. This turned out to be fun, so I made the tone-generation code a little more complex. That was even more fun. Long story short, over the next two days I ended up writing a full blown synthesizer. Then I changed the name to Synth and here it is.

As synthesizers go, it's pretty limited, but what do you expect for two days work. It lets you program your own voices (instruments) using as many sine waves as you want, and you can also adjust the attack (fade in and fade out). It is limited to one voice at a time (it can’t sing harmony) and it is strictly monophonic.

The basic syntax for a musical score is a series of notes each of which is written like this:

F#3 370

That means “play F# in the third octave for 370 milliseconds.”

For a flat sign, write lowercase b.

An R followed by a number indicates a rest. For example, here’s a rest that lasts 340 ms:

R 340

As shown in the example above, you can alter the speed by including a number. For example, here’s how you tell Mojo, “Play this melody at 80% of the speed at which it’s written.”

Speed 0.8

To repeat a section once, put it inside repeat symbols like this:

|: C4 300 E4 300 G600 :|

You can raise or lower the key by writing “Transpose” followed by a number which shows the number of half steps to go up or down.

Transpose +4
Transpose -2
Transpose 5
Transpose 7.469

Tempered tuning is used by default, but you can choose just intonation instead by including the word “Just” as shown in the example above. If you write “just” you must also write the key in the following format. Make sure you enclose the word “Key” in quotes. The quotes must be there so Mojo doesn’t think you’re writing the reserved keyword Key which is the name of one of its commands. For example, this means G major:

"Key" GM

This means G minor:

"Key" Gm

And this means C# minor:

"Key" C#m

Incidentally, this distinction between “m” and “M” for minor and major is the only situation in which Mojo is case-sensitive.


Mojo’s built-in synthesizer uses a simple form of additive synthesis to create voices (instruments). That means it combines sine waves. Therefore, to create a voice, you specify a bunch of sine waves. For each wave, you specify a frequency and a volume. The frequency is written in the form of a multiplier that expresses the ratio between the fundamental frequency and the sine wave that you're specifying. The volume is written as a number betweeen 0 (silence) and 1 (the maximum). For instance, to specify the tonic at half volume, you would write:

Wave 1 .5

To write the first harmonic (the octave) at one-quarter volume, you would write:

Wave 2 .25

To create a warbly effect, you can add a wave that’s very close in frequency to the fundamental or some other wave:

Wave .997 .3

You don’t have to specify waves. If you don’t specify any, Mojo uses its default voice. But if you specify at least one wave, Mojo won't play the fundamental unless you specify it.

Here's the first nice voice I managed to create in the first few hours after I started playing around with this stuff. It sounds a little like a marimba:

Fade 0 0 perc .65
wave 1 .2
wave .985 .12
wave .5 .03
wave .25 .02
wave .125 .01
wave 3 .05
wave 5 .03
wave 7 .02
wave 9 .01

Fade (attack profiles)

The keyword Fade specifies how a note fades in and fades out; in other words, how the volume of a note changes while it’s being held. You must always write four pieces of data after Fade even though they aren’t always all needed. When one of them isn’t needed, write zero for it or some random number.

  • Max Volume Start. How soon after the start of the note does the volume reach its maximum? Specified in seconds.

  • Fade Type. Does volume begin to drop off a fixed amount of time after the beginning of the note? Percussion and plucked instruments work this way. Or does volume begin to drop a fixed amount of time before the note ends? Wind and bowed instruments work this second way. Write Perc for the first option, Wind for the second. For an infinitely sustained note with no fade, write None.

  • Fade Start. The previous paragraph discussed a fixed amount of time, but how long is it? Here you specify the length in seconds. If Fade Type is None, this is ignored.

  • Fade Rate. How fast does the volume drop once the fade begins? This is specified as the number of seconds it would take to fade completely. An immediate abrupt fade is 0. A three-second fade is 3. If you want a note to be sustained infinitely with no fade at all, write None for Fade Type.

Here’s an example of an attack profile:

Fade .04 .2 perc .1




This page was first published on January 20, 2018 and last modified on January 21, 2018