# \[Extension\] arcade-mml

**URL:** <https://forum.makecode.com/t/extension-arcade-mml/31351>\
**Category:** Arcade\
**Tags:** extension\
**Created:** [October 25, 2024, 6:31pm UTC](https://forum.makecode.com/t/extension-arcade-mml/31351 "2024-10-25T18:31:23Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [October 25, 2024, 6:31pm UTC](https://forum.makecode.com/t/extension-arcade-mml/31351/1 "2024-10-25T18:31:23Z")

</div>

Hey folks!

I’ve gone ahead and made another extension! This one is super simple, it allows you to play songs written using [MML](https://en.wikipedia.org/wiki/Music_Macro_Language). For more info on the syntax of MML, check out the README of this repo, where I’ve written up an explainer:

> **[GitHub - riknoll/arcade-mml: A MakeCode extension for playing songs authored...](https://github.com/riknoll/arcade-mml)**
>
> A MakeCode extension for playing songs authored with Music Macro Language

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!

---

<div class="post-metadata">

**Author:** ![Jedi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jedi/32/14307_2.png) [@Jedi](https://forum.makecode.com/u/Jedi)\
**Post date:** [October 25, 2024, 6:50pm UTC](https://forum.makecode.com/t/extension-arcade-mml/31351/2 "2024-10-25T18:50:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [October 25, 2024, 6:52pm UTC](https://forum.makecode.com/t/extension-arcade-mml/31351/3 "2024-10-25T18:52:48Z")

</div>

@Jedi the computer is a square wave

---

<div class="post-metadata">

**Author:** ![Jedi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jedi/32/14307_2.png) [@Jedi](https://forum.makecode.com/u/Jedi)\
**Post date:** [October 25, 2024, 7:00pm UTC](https://forum.makecode.com/t/extension-arcade-mml/31351/4 "2024-10-25T19:00:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![JtSpeedRun](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jtspeedrun/32/33167_2.png) [@JtSpeedRun](https://forum.makecode.com/u/JtSpeedRun)\
**Post date:** [October 25, 2024, 7:52pm UTC](https://forum.makecode.com/t/extension-arcade-mml/31351/5 "2024-10-25T19:52:05Z")

</div>

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

Here’s something awesome I found really quick:

> **[WackyWork Bench-SonicCD(JP)](https://arcade.makecode.com/76988-23105-04115-24680)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [October 25, 2024, 9:50pm UTC](https://forum.makecode.com/t/extension-arcade-mml/31351/6 "2024-10-25T21:50:32Z")

</div>

@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:

```ts
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](https://en.wikipedia.org/wiki/Envelope_(music)) though i’m sure there are many helpful youtube videos on the subject as well.

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [October 25, 2024, 10:00pm UTC](https://forum.makecode.com/t/extension-arcade-mml/31351/7 "2024-10-25T22:00:46Z")

</div>

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

> **[my-custom-instrument](https://arcade.makecode.com/06362-42233-65355-63861)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

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

---

<div class="post-metadata">

**Author:** ![Jedi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jedi/32/14307_2.png) [@Jedi](https://forum.makecode.com/u/Jedi)\
**Post date:** [October 25, 2024, 10:01pm UTC](https://forum.makecode.com/t/extension-arcade-mml/31351/8 "2024-10-25T22:01:18Z")

</div>

ok. thank you!

---

<div class="post-metadata">

**Author:** ![Jedi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jedi/32/14307_2.png) [@Jedi](https://forum.makecode.com/u/Jedi)\
**Post date:** [October 25, 2024, 10:01pm UTC](https://forum.makecode.com/t/extension-arcade-mml/31351/9 "2024-10-25T22:01:48Z")

</div>

> **[SMB 1 song](https://arcade.makecode.com/42969-41420-02935-97637)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

dang this is so awesome!

---

<div class="post-metadata">

**Author:** ![Jedi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jedi/32/14307_2.png) [@Jedi](https://forum.makecode.com/u/Jedi)\
**Post date:** [October 25, 2024, 10:08pm UTC](https://forum.makecode.com/t/extension-arcade-mml/31351/10 "2024-10-25T22:08:03Z")

</div>

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

> **[Test 2](https://arcade.makecode.com/86520-96086-86656-24191)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

this is what i did before i saw this XD

---

<div class="post-metadata">

**Author:** ![redSprite](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/redsprite/32/34262_2.png) [@redSprite](https://forum.makecode.com/u/redSprite)\
**Post date:** [October 26, 2024, 7:54pm UTC](https://forum.makecode.com/t/extension-arcade-mml/31351/11 "2024-10-26T19:54:29Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![kaleb3335](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/kaleb3335/32/16382_2.png) [@kaleb3335](https://forum.makecode.com/u/kaleb3335)\
**Post date:** [October 26, 2024, 7:55pm UTC](https://forum.makecode.com/t/extension-arcade-mml/31351/12 "2024-10-26T19:55:13Z")

</div>

> **[Megalovania](https://arcade.makecode.com/S64626-65730-54283-21816)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

**Author:** ![AlexK](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/alexk/32/33339_2.png) [@AlexK](https://forum.makecode.com/u/AlexK)\
**Post date:** [October 26, 2024, 8:10pm UTC](https://forum.makecode.com/t/extension-arcade-mml/31351/13 "2024-10-26T20:10:49Z")

</div>

@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.

> [@RTTTL tunes extension](https://forum.makecode.com/t/rtttl-tunes-extension/4193):
>
> Ring Tone Transfer Language… is a popular format for tunes. With this library, you can play existing RTTL tunes in Arcade. RTTL [https://en.wikipedia.org/wiki/Ring\_Tone\_Transfer\_Language](https://en.wikipedia.org/wiki/Ring_Tone_Transfer_Language)

---

<div class="post-metadata">

**Author:** ![Brohann](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/brohann/32/17380_2.png) [@Brohann](https://forum.makecode.com/u/Brohann)\
**Post date:** [October 31, 2024, 2:09am UTC](https://forum.makecode.com/t/extension-arcade-mml/31351/14 "2024-10-31T02:09:32Z")

</div>

> [@redSprite](#):
>
> Using this extension, is it possible to port music into makecode?

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