How do I use midi2tones?

I want to add music to my programs, but I have no idea how to get midi2tones to work. I’ve tried running the .c file in atom and that didn’t do anything, also the arduino IDE doesn’t open any of the files included when i downloaded midi2score. Any help here would be appreciated.

I used midi2tones for Ravine Despoiler. If you look at

you’ll see the MIDI file I play. The output of miditones was put into

which I included into my game.h source file. Then, in my title screen code, I play it with this line

Thanks for the answer. I guess what I’m wondering is how do you convert the midi file to the needed code.

@unwiredben I think the issues is in the actual conversion of data from the midi file.

Do you have a midi file you want to use? When using ArduboyTones, your midi file can only have one channel. I use Aria Maestro to delete out all other channels.

I have compiled the program (and called it midiConverter, but you can call it whatever) and call it using the following:

% ./midiConverter -o2 {filename of midi file without extension}

yes I do have a single channel midi file I want to use, in what program do I enter that code to make it convert from midi to code?

I am using a Mac.

I compiled the C code to an executable and then run the program from a command line:

$ ./midi2tones -o2 {filename of midi file without extension}

However, if you are using windows I am guessing you can use the command line .exe that is already in the distribution. So something like this:

C:\midi2Tones>midi2Tones_64bit.exe -o2 {filename of midi file without extension}

This seems to get me closer to where i need to be, but all I get is this message C:\midi2Tones>midi2Tones_64bit.exe : The term ‘C:\midi2Tones>midi2Tones_64bit.exe’ is not recognized as the name of a
cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
At line:2 char:1

  • C:\midi2Tones>midi2Tones_64bit.exe -o2 {filename of midi file without …
  •   + CategoryInfo          : ObjectNotFound: (C:\midi2Tones>midi2Tones_64bit.exe:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException

Some simple questions:

What version of Windows are you on?
Did you download the midi2Tones package? (GitHub - MLXXXp/ArduboyTones: A library for playing tones and tone sequences, intended for the Arduboy game system)
Where did you put it?
Where is your midi file?
What command did you type from the command line?
What directory where you in when you ran that command? (maybe a screen shot of the whole window might help).

I’m on windows 11.
I did download the files as a zip and extracted them to my downloads folder, I also downloaded the ardrutones library in my arduino IDE.
My midi file is currently in my documents folder.
I simply pasted in the command you gave me and put the name of the midi file in the brackets.
For what directory I cannot answer that i’m afraid, I was in command prompt.

I’m terribly sorry if my questions are stupid or if i’m doing something obviously wrong. I’m pretty new to this.

No problem, we all must learn.

Mmmm … did you specify where the midi file is located? Did you substitute my folder name for yours?

Ok … lets try this.

  • In Windows explorer, create a directory such as C:\MidiConverter
  • Copy the files you extracted into that directory.
  • Copy the midi file into that directory too.
  • In Windows explorer, right-click on your new folder and select ‘Open in Terminal’.
  • Run the command midi2tones_64bit.exe -o2 {your file less the extension}

If the ‘Open in Terminal’ command doesn’t exist, open the command window and type in cd C:\MidiConverter (or whatever you chose to name it). then run the command Run the command midi2tones_64bit.exe -o2 {your file less the extension}

  • move the midi file into

Still not working I’m afraid. I’ll attach a screenshot.

Oh, its PowerShell. OK … can you append .\ in front of the command and remove the { } as these where to indicate what to replace :slight_smile:

.\midi2tones_64bit.exe -o2 Bassoon

Or alternatively open the command window (Win-R and then type cmd) and type in cd C:\MidiConverter (or whatever you chose to name it). then run the command Run the command midi2tones_64bit.exe -o2 Bassoon

Sorry, I am trying to help but are not in front of a Windows machine at the moment.

That worked. Thank you very much for your help.

No problem!

Glad it worked but … how does it sound?

Well, now comes the job of trying to get it to play in my program, when I get that done then I’ll come back to you.

OK … you have some sample code in Ben’s code.

Here is a stripped back set of isntructions (from MLXXXP’s site):

Setting up

Include the library using

#include <ArduboyTones.h>

You must then create an ArduboyTones object which specifies the callback function used for muting. The function is a required parameter. It must return a boolean (or bool ) value which will be true if sound should be played, or false if all sounds should be muted. In this document the ArduboyTones object will be named sound . The audio.enabled() function of the Arduboy library will be used for the mute callback. The Arduboy object will be named arduboy .

So, to set things up we can use:

#include <Arduboy2.h> 
#include <ArduboyTones.h> 
Arduboy2 arduboy; 

ArduboyTones sound(arduboy.audio.enabled);

To Play a Tone Sequence from Progmem

Play a tone sequence from frequency/duration pairs in an array in program memory:

void tones(arrayInProgram)

The array must end with a single value of either TONES_END , to end the sequence, or TONES_REPEAT to continuously repeat from beginning to end.

Example:

const uint16_t song1[] PROGMEM = { 220,1000, 0,250, 440,500, 880,2000, TONES_END }; 
sound.tones(song1);

It tells me that it expects a ) before a ; in context of the TONES_REPEAT }; part.

Can you post a snippet of code?

If you post code, please wrap it in three back ticks ```

```
Like this

```

#include <Arduboy2.h>
#include <ArduboyTones.h>
Arduboy2 arduboy;
ArduboyTones sound(arduboy.audio.on);
void tones(const uint16_t score[] PROGMEM = {
// Bassoon?
 NOTE_REST,0, NOTE_A3,0, NOTE_D4,0, NOTE_F4,0, NOTE_A4,0, NOTE_REST,0, NOTE_E4,0, NOTE_E4,0,
 NOTE_REST,0, NOTE_REST,0, NOTE_D4,0, NOTE_F4,0, NOTE_A4,0, NOTE_D5,0, NOTE_REST,0, NOTE_A4,0,
 NOTE_A4,0, NOTE_REST,0, NOTE_G4,0, NOTE_A4,0, NOTE_AS4,0, NOTE_REST,0, NOTE_E4,0, NOTE_A4,0,
 NOTE_REST,0, NOTE_G4,0, NOTE_REST,0, NOTE_REST,0, NOTE_F4,0, NOTE_REST,0, NOTE_F4,0, NOTE_A4,0,
 NOTE_A4,0, NOTE_A4,0, NOTE_A4,0, NOTE_A4,0, NOTE_REST,0, NOTE_F4,0, NOTE_REST,0, NOTE_D4,0,
 NOTE_REST,0, NOTE_D4,0, NOTE_F4,0, NOTE_A4,0, NOTE_REST,0, NOTE_E4,0, NOTE_E4,0, NOTE_REST,0,
 NOTE_REST,0, NOTE_D4,0, NOTE_F4,0, NOTE_A4,0, NOTE_D5,0, NOTE_REST,0, NOTE_A4,0, NOTE_A4,0,
 NOTE_REST,0, NOTE_G4,0, NOTE_A4,0, NOTE_AS4,0, NOTE_REST,0, NOTE_E4,0, NOTE_A4,0, NOTE_REST,0,
 NOTE_G4,0, NOTE_REST,0, NOTE_REST,0, NOTE_F4,0, NOTE_REST,0, NOTE_F4,0, NOTE_A4,0, NOTE_A4,0,
 NOTE_A4,0, NOTE_A4,0, NOTE_A4,0, NOTE_REST,0, NOTE_F4,0, NOTE_REST,0, NOTE_D4,0, NOTE_REST,0,
 NOTE_D4,0, NOTE_F4,0, NOTE_A4,0, NOTE_REST,0, NOTE_E4,0, NOTE_E4,0, NOTE_REST,0, NOTE_REST,0,
 NOTE_D4,0, NOTE_F4,0, NOTE_A4,0, NOTE_D5,0, NOTE_REST,0, NOTE_A4,0, NOTE_A4,0, NOTE_REST,0,
 NOTE_G4,0, NOTE_A4,0, NOTE_AS4,0, NOTE_REST,0, NOTE_E4,0, NOTE_A4,0, NOTE_REST,0, NOTE_G4,0,
 NOTE_REST,0, NOTE_REST,0, NOTE_F4,0, NOTE_REST,0, NOTE_F4,0, NOTE_A4,0, NOTE_A4,0, NOTE_A4,0,
 NOTE_A4,0, NOTE_A4,0, NOTE_REST,0, NOTE_F4,0, NOTE_REST,0, NOTE_D4,0, NOTE_REST,0, NOTE_D5,0,
 TONES_REPEAT};
sound.tones(score);
)

i meant

Try this:

#include <Arduboy2.h>
#include <ArduboyTones.h>
Arduboy2 arduboy;

ArduboyTones sound(arduboy.audio.on);

const uint16_t score[] PROGMEM = {
// Bassoon?
NOTE_REST,0, NOTE_A3,0, NOTE_D4,0, NOTE_F4,0, NOTE_A4,0, NOTE_REST,0, NOTE_E4,0, NOTE_E4,0,
NOTE_REST,0, NOTE_REST,0, NOTE_D4,0, NOTE_F4,0, NOTE_A4,0, NOTE_D5,0, NOTE_REST,0, NOTE_A4,0,
NOTE_A4,0, NOTE_REST,0, NOTE_G4,0, NOTE_A4,0, NOTE_AS4,0, NOTE_REST,0, NOTE_E4,0, NOTE_A4,0,
NOTE_REST,0, NOTE_G4,0, NOTE_REST,0, NOTE_REST,0, NOTE_F4,0, NOTE_REST,0, NOTE_F4,0, NOTE_A4,0,
NOTE_A4,0, NOTE_A4,0, NOTE_A4,0, NOTE_A4,0, NOTE_REST,0, NOTE_F4,0, NOTE_REST,0, NOTE_D4,0,
NOTE_REST,0, NOTE_D4,0, NOTE_F4,0, NOTE_A4,0, NOTE_REST,0, NOTE_E4,0, NOTE_E4,0, NOTE_REST,0,
NOTE_REST,0, NOTE_D4,0, NOTE_F4,0, NOTE_A4,0, NOTE_D5,0, NOTE_REST,0, NOTE_A4,0, NOTE_A4,0,
NOTE_REST,0, NOTE_G4,0, NOTE_A4,0, NOTE_AS4,0, NOTE_REST,0, NOTE_E4,0, NOTE_A4,0, NOTE_REST,0,
NOTE_G4,0, NOTE_REST,0, NOTE_REST,0, NOTE_F4,0, NOTE_REST,0, NOTE_F4,0, NOTE_A4,0, NOTE_A4,0,
NOTE_A4,0, NOTE_A4,0, NOTE_A4,0, NOTE_REST,0, NOTE_F4,0, NOTE_REST,0, NOTE_D4,0, NOTE_REST,0,
NOTE_D4,0, NOTE_F4,0, NOTE_A4,0, NOTE_REST,0, NOTE_E4,0, NOTE_E4,0, NOTE_REST,0, NOTE_REST,0,
NOTE_D4,0, NOTE_F4,0, NOTE_A4,0, NOTE_D5,0, NOTE_REST,0, NOTE_A4,0, NOTE_A4,0, NOTE_REST,0,
NOTE_G4,0, NOTE_A4,0, NOTE_AS4,0, NOTE_REST,0, NOTE_E4,0, NOTE_A4,0, NOTE_REST,0, NOTE_G4,0,
NOTE_REST,0, NOTE_REST,0, NOTE_F4,0, NOTE_REST,0, NOTE_F4,0, NOTE_A4,0, NOTE_A4,0, NOTE_A4,0,
NOTE_A4,0, NOTE_A4,0, NOTE_REST,0, NOTE_F4,0, NOTE_REST,0, NOTE_D4,0, NOTE_REST,0, NOTE_D5,0,
TONES_REPEAT};

void setup() {
  arduboy.begin();
}

void loop() {
  sound.tones(score);
}

The score is declared first and then used later in the loop() or where ever you want it.