[Extension] arcade-mml

Hey folks!

I’ve gone ahead and made another extension! This one is super simple, it allows you to play songs written using MML. For more info on the syntax of MML, check out the README of this repo, where I’ve written up an explainer:

MML was used back in the old days for authoring chiptunes on systems like the NES! Some videogames still use it today. Anyways, have fun!

18 Likes

wow, this is awesome!
is there a way to set custom instruments? such as something like a square wave?

1 Like

@Jedi the computer is a square wave

2 Likes

it is, but it has some sort of effect applied to it, i just want simple waves such as the ones you can use for sfxs

1 Like

Thank you so much @richard ! You just opened up a huge door for music making possibilities!

Here’s something awesome I found really quick:

4 Likes

@Jedi the computer should just be a square wave, though i’ve never tested it to see how square it is. maybe i should hook it up to my oscilloscope…

in any case, you can make a custom instrument like this:

const myInstrument = new music.sequencer.Instrument();

// The waveform. See the table on this page: https://arcade.makecode.com/developer/sound
myInstrument.waveform = 15

// Controls the volume over time
myInstrument.ampEnvelope.attack = 0;
myInstrument.ampEnvelope.decay = 0;
myInstrument.ampEnvelope.sustain = 1024;
myInstrument.ampEnvelope.release = 0;
myInstrument.ampEnvelope.amplitude = 1204;

// Controls the pitch over time. Set the amplitude to 0 to ignore
myInstrument.pitchEnvelope.attack = 0;
myInstrument.pitchEnvelope.decay = 0;
myInstrument.pitchEnvelope.sustain = 0;
myInstrument.pitchEnvelope.release = 0;
myInstrument.pitchEnvelope.amplitude = 0;

// Varies the volume over time with a triangle wave. Set the amplitude to 0 to ignore
myInstrument.ampLFO.frequency = 1;
myInstrument.ampLFO.amplitude = 0;

// Varies the pitch over time with a triangle wave. Set the amplitude to 0 to ignore
myInstrument.pitchLFO.frequency = 1;
myInstrument.pitchLFO.amplitude = 0;

const mmlInstrument = new mml.MMLInstrument(myInstrument.buf);

music.play(
    mml.playable(
        mml.track(mmlInstrument, "CDEFGAB>C")
    ),
    music.PlaybackMode.UntilDone
);

for more info on how envelopes work, here’s the wikipedia page though i’m sure there are many helpful youtube videos on the subject as well.

3 Likes

@Jedi here, I made a template project you can use to make custom instruments:

Just edit the code in this and reshare it. Then you can add the share link to a project as an extension and your custom instrument will appear in the dropdown of options next to the default ones.

If you do edit this, make sure you change the name of the exported variable to something descriptive so that you don’t accidentally collide with other folks. Also, this example makes the icon for the instrument pizza; change the //% jres="" comment to change the icon. You can use the qualified name for any of the builtin gallery sprites as icons; just hover over the sprite you want in the gallery and the hover text will be what you need to put in that jres comment

3 Likes

ok. thank you!

dang this is so awesome!

2 Likes

ok. thank you so much for this! it was a bit tedious trying to make a waveform over and over.

this is what i did before i saw this XD

3 Likes

2 Parts:


Invalid:

This extension looky real SHINY to use over here


Using this extension, is it possible to port music into makecode? Already possible in SCRATCH, but can we do it here?

1 Like
1 Like

@peli wrote an extension back in the early days of MakeCode to play melodies written in RTTTL. Link to the thread below.

If the melody is written as text, then between these two extensions, you probably can play it in MakeCode.

1 Like

UnsignedArduino has a midi-to-song converter, pretty much the best way to convert music right now.

2 Likes