Miditones and ATMlib Problem

When using miditones to convert midi files over to an Arduboy Playtune readable format, some notes don’t play.

When using ATMlib, it breaks my game.

Please help!

ArduboyPlaytune can only play 2 notes at a time. If the MIDI file you’re converting with midi2tones plays more that 2 notes at a time, some of the notes won’t sound.

ATMLib uses its own unique score format. I don’t know of any program that can convert MIDI to ATMLib format.

Well, for the ATMLib song, I wrote it by hand but when I import and use ATMLib functions, it breaks the game. For example, when I import ATMLib, the arduboy.print function stops working.

Can you post some code that exhibits this problem?

#include <Arduboy2.h>
#include <ATMlib.h>
 
Arduboy2 arduboy;
ATMsynth ATM;

const uint8_t song[] PROGMEM = {
  0x10,      // Number of tracks
0x00, 0x00,   // Address of track 0
0x1d, 0x00,   // Address of track 1
0x1e, 0x00,   // Address of track 2
0x1f, 0x00,   // Address of track 3
0x20, 0x00,   // Address of track 4
0x33, 0x00,   // Address of track 5
0x48, 0x00,   // Address of track 6
0x57, 0x00,   // Address of track 7
0x66, 0x00,   // Address of track 8
0x7b, 0x00,   // Address of track 9
0x8a, 0x00,   // Address of track 10
0x93, 0x00,   // Address of track 11
0x9c, 0x00,   // Address of track 12
0xa7, 0x00,   // Address of track 13
0xb0, 0x00,   // Address of track 14
0xbb, 0x00,   // Address of track 15
0x00,     // Channel 0 entry track
0x01,     // Channel 1 entry track
0x02,     // Channel 2 entry track
0x03,     // Channel 3 entry track
//"Track channel 0"
0x40, 100,    // FX: SET VOLUME: volume = 100
0x9D, 26,   // FX: SET TEMPO: tempo = 26
0xFC, 4,    // GOTO track 4
0xFC, 5,    // GOTO track 5
0xFC, 6,    // GOTO track 6
0xFC, 7,    // GOTO track 7
0xFC, 8,    // GOTO track 8
0xFC, 9,    // GOTO track 9
0xFC, 10,   // GOTO track 10
0xFC, 11,   // GOTO track 11
0xFC, 12,   // GOTO track 12
0xFC, 13,   // GOTO track 13
0xFC, 14,   // GOTO track 14
0xFC, 15,   // GOTO track 15
0x9F,     // FX: STOP CURRENT CHANNEL
//"Track channel 1"
0x9F,     // FX: STOP CURRENT CHANNEL
//"Track channel 2"
0x9F,     // FX: STOP CURRENT CHANNEL
//"Track channel 3"
0x9F,     // FX: STOP CURRENT CHANNEL
//"Track Track 1"
0x00 + 29,    // NOTE ON: note = 29
0x9F + 12,    // DELAY: ticks = 12
0x00 + 24,    // NOTE ON: note = 24
0x9F + 6,   // DELAY: ticks = 6
0x00 + 25,    // NOTE ON: note = 25
0x9F + 6,   // DELAY: ticks = 6
0x00 + 27,    // NOTE ON: note = 27
0x9F + 12,    // DELAY: ticks = 12
0x00 + 25,    // NOTE ON: note = 25
0x9F + 6,   // DELAY: ticks = 6
0x00 + 24,    // NOTE ON: note = 24
0x9F + 6,   // DELAY: ticks = 6
0x00 + 22,    // NOTE ON: note = 22
0x9F + 6,   // DELAY: ticks = 6
0x00 + 0,   // NOTE ON: note = 0
0x9F + 6,   // DELAY: ticks = 6
0x00 + 22,    // NOTE ON: note = 22
0x9F + 4,   // DELAY: ticks = 4
0xFE,     // RETURN
//"Track Track 2"
0x00 + 22,    // NOTE ON: note = 22
0x9F + 2,   // DELAY: ticks = 2
0x00 + 25,    // NOTE ON: note = 25
0x9F + 6,   // DELAY: ticks = 6
0x00 + 29,    // NOTE ON: note = 29
0x9F + 12,    // DELAY: ticks = 12
0x00 + 27,    // NOTE ON: note = 27
0x9F + 6,   // DELAY: ticks = 6
0x00 + 25,    // NOTE ON: note = 25
0x9F + 6,   // DELAY: ticks = 6
0x00 + 24,    // NOTE ON: note = 24
0x9F + 6,   // DELAY: ticks = 6
0x00 + 0,   // NOTE ON: note = 0
0x9F + 6,   // DELAY: ticks = 6
0x00 + 24,    // NOTE ON: note = 24
0x9F + 6,   // DELAY: ticks = 6
0x00 + 25,    // NOTE ON: note = 25
0x9F + 6,   // DELAY: ticks = 6
0x00 + 27,    // NOTE ON: note = 27
0x9F + 8,   // DELAY: ticks = 8
0xFE,     // RETURN
//"Track Track 3"
0x00 + 27,    // NOTE ON: note = 27
0x9F + 5,   // DELAY: ticks = 5
0x00 + 29,    // NOTE ON: note = 29
0x9F + 12,    // DELAY: ticks = 12
0x00 + 25,    // NOTE ON: note = 25
0x9F + 12,    // DELAY: ticks = 12
0x00 + 22,    // NOTE ON: note = 22
0x9F + 6,   // DELAY: ticks = 6
0x00 + 0,   // NOTE ON: note = 0
0x9F + 6,   // DELAY: ticks = 6
0x00 + 22,    // NOTE ON: note = 22
0x9F + 12,    // DELAY: ticks = 12
0x00 + 0,   // NOTE ON: note = 0
0x9F + 11,    // DELAY: ticks = 11
0xFE,     // RETURN
//"Track Track 4"
0x00 + 0,   // NOTE ON: note = 0
0x9F + 13,    // DELAY: ticks = 13
0x00 + 27,    // NOTE ON: note = 27
0x9F + 12,    // DELAY: ticks = 12
0x00 + 30,    // NOTE ON: note = 30
0x9F + 6,   // DELAY: ticks = 6
0x00 + 34,    // NOTE ON: note = 34
0x9F + 12,    // DELAY: ticks = 12
0x00 + 32,    // NOTE ON: note = 32
0x9F + 6,   // DELAY: ticks = 6
0x00 + 30,    // NOTE ON: note = 30
0x9F + 6,   // DELAY: ticks = 6
0x00 + 29,    // NOTE ON: note = 29
0x9F + 9,   // DELAY: ticks = 9
0xFE,     // RETURN
//"Track Track 5"
0x00 + 29,    // NOTE ON: note = 29
0x9F + 9,   // DELAY: ticks = 9
0x00 + 25,    // NOTE ON: note = 25
0x9F + 6,   // DELAY: ticks = 6
0x00 + 29,    // NOTE ON: note = 29
0x9F + 12,    // DELAY: ticks = 12
0x00 + 27,    // NOTE ON: note = 27
0x9F + 6,   // DELAY: ticks = 6
0x00 + 25,    // NOTE ON: note = 25
0x9F + 6,   // DELAY: ticks = 6
0x00 + 24,    // NOTE ON: note = 24
0x9F + 6,   // DELAY: ticks = 6
0x00 + 0,   // NOTE ON: note = 0
0x9F + 6,   // DELAY: ticks = 6
0x00 + 24,    // NOTE ON: note = 24
0x9F + 6,   // DELAY: ticks = 6
0x00 + 25,    // NOTE ON: note = 25
0x9F + 6,   // DELAY: ticks = 6
0x00 + 27,    // NOTE ON: note = 27
0x9F + 1,   // DELAY: ticks = 1
0xFE,     // RETURN
//"Track Track 6"
0x00 + 27,    // NOTE ON: note = 27
0x9F + 11,    // DELAY: ticks = 11
0x00 + 29,    // NOTE ON: note = 29
0x9F + 12,    // DELAY: ticks = 12
0x00 + 25,    // NOTE ON: note = 25
0x9F + 12,    // DELAY: ticks = 12
0x00 + 22,    // NOTE ON: note = 22
0x9F + 6,   // DELAY: ticks = 6
0x00 + 0,   // NOTE ON: note = 0
0x9F + 6,   // DELAY: ticks = 6
0x00 + 22,    // NOTE ON: note = 22
0x9F + 6,   // DELAY: ticks = 6
0x00 + 0,   // NOTE ON: note = 0
0x9F + 11,    // DELAY: ticks = 11
0xFE,     // RETURN
//"Track Track 7"
0x00 + 0,   // NOTE ON: note = 0
0x9F + 7,   // DELAY: ticks = 7
0x00 + 29,    // NOTE ON: note = 29
0x9F + 24,    // DELAY: ticks = 24
0x00 + 25,    // NOTE ON: note = 25
0x9F + 24,    // DELAY: ticks = 24
0x00 + 27,    // NOTE ON: note = 27
0x9F + 9,   // DELAY: ticks = 9
0xFE,     // RETURN
//"Track Track 8"
0x00 + 27,    // NOTE ON: note = 27
0x9F + 15,    // DELAY: ticks = 15
0x00 + 24,    // NOTE ON: note = 24
0x9F + 24,    // DELAY: ticks = 24
0x00 + 25,    // NOTE ON: note = 25
0x9F + 24,    // DELAY: ticks = 24
0x00 + 22,    // NOTE ON: note = 22
0x9F + 1,   // DELAY: ticks = 1
0xFE,     // RETURN
//"Track Track 9"
0x00 + 22,    // NOTE ON: note = 22
0x9F + 23,    // DELAY: ticks = 23
0x00 + 21,    // NOTE ON: note = 21
0x9F + 12,    // DELAY: ticks = 12
0x00 + 22,    // NOTE ON: note = 22
0x9F + 12,    // DELAY: ticks = 12
0x00 + 24,    // NOTE ON: note = 24
0x9F + 12,    // DELAY: ticks = 12
0x00 + 0,   // NOTE ON: note = 0
0x9F + 5,   // DELAY: ticks = 5
0xFE,     // RETURN
//"Track Track 10"
0x00 + 0,   // NOTE ON: note = 0
0x9F + 7,   // DELAY: ticks = 7
0x00 + 29,    // NOTE ON: note = 29
0x9F + 24,    // DELAY: ticks = 24
0x00 + 25,    // NOTE ON: note = 25
0x9F + 24,    // DELAY: ticks = 24
0x00 + 27,    // NOTE ON: note = 27
0x9F + 9,   // DELAY: ticks = 9
0xFE,     // RETURN
//"Track Track 11"
0x00 + 27,    // NOTE ON: note = 27
0x9F + 15,    // DELAY: ticks = 15
0x00 + 24,    // NOTE ON: note = 24
0x9F + 24,    // DELAY: ticks = 24
0x00 + 25,    // NOTE ON: note = 25
0x9F + 12,    // DELAY: ticks = 12
0x00 + 29,    // NOTE ON: note = 29
0x9F + 12,    // DELAY: ticks = 12
0x00 + 34,    // NOTE ON: note = 34
0x9F + 1,   // DELAY: ticks = 1
0xFE,     // RETURN
//"Track Track 12"
0x00 + 34,    // NOTE ON: note = 34
0x9F + 23,    // DELAY: ticks = 23
0x00 + 33,    // NOTE ON: note = 33
0x9F + 36,    // DELAY: ticks = 36
0xFC, 0    // RETURN

};


int gameState = 0;

void setup() {
  arduboy.begin();
  arduboy.setFrameRate(60);
  arduboy.audio.on();
  ATM.play(song);
}

void loop() {
  if (!(arduboy.nextFrame())) {return;}
  arduboy.clear();
  if (gameState == 0) {
    if(arduboy.pressed(A_BUTTON)) {
      gameState = 1;
      //ATM.play(song);
    }
  }
  if (gameState == 1) {
    arduboy.print("Score:\n" + String(score) + "\n\nLevel:\n" + String(level));
  
  }
  if (gameState == 2) {
    arduboy.print("Game Over!\n\n\n\nScore: " + String(score) + "\n\nReset to continue...");
  }

  arduboy.display();
}

There’s a bit of an issue with posting Tetris code here.

oh, ok I will fix that

apparently, my program has started crashing while the music is playing

This is confusing, when I remove the majority of the code, it now works…

here is an example of a score that doesn’t work properly when converted from a midi file using miditones

const unsigned char PROGMEM score [] = {
0x90,64, 1,244, 0x91,59, 0x80, 0,250, 0x90,60, 0x81, 0,250, 0x91,62, 0x80, 1,244, 0x90,60, 0x81, 0,250, 0x91,59,
0x80, 0,250, 0x90,57, 0x81, 0,250, 0x80, 0,250, 0x90,57, 0x90,57, 0,250, 0x91,60, 0x80, 0,250, 0x90,64, 0x81, 1,244,
0x91,62, 0x80, 0,250, 0x90,60, 0x81, 0,250, 0x90,59, 0,250, 0x80, 0,250, 0x90,59, 0,250, 0x91,60, 0x80, 0,250,
0x90,62, 0x81, 1,244, 0x91,64, 0x80, 1,244, 0x90,60, 0x81, 1,244, 0x90,57, 0,250, 0x80, 0,250, 0x90,57, 0x91,57,
0,250, 0x80, 0x81, 3,232, 0x90,62, 1,244, 0x91,65, 0x80, 0,250, 0x90,69, 0x81, 1,244, 0x91,67, 0x80, 0,250, 0x90,65,
0x81, 0,250, 0x91,64, 0x80, 2,238, 0x90,60, 0x81, 0,250, 0x91,64, 0x80, 1,244, 0x90,62, 0x81, 0,250, 0x90,60, 0,250,
0x91,59, 0x80, 0,250, 0x81, 0,250, 0x90,59, 0,250, 0x91,60, 0x80, 0,250, 0x90,62, 0x81, 1,244, 0x91,64, 0x80, 1,244,
0x90,60, 0x81, 1,244, 0x91,57, 0x80, 0,250, 0x81, 0,250, 0x90,57, 0,250, 0x80, 2,238, 0x90,64, 1,244, 0x91,59,
0x80, 0,250, 0x90,60, 0x81, 0,250, 0x90,62, 1,244, 0x91,60, 0x80, 0,250, 0x90,59, 0x81, 0,250, 0x91,57, 0x80, 0,250,
0x81, 0,250, 0x90,57, 0x91,57, 0,250, 0x90,60, 0x81, 0,250, 0x91,64, 0x80, 1,244, 0x90,62, 0x81, 0,250, 0x91,60,
0x80, 0,250, 0x90,59, 0x81, 0,250, 0x80, 0,250, 0x90,59, 0,250, 0x91,60, 0x80, 0,250, 0x90,62, 0x81, 1,244, 0x91,64,
0x80, 1,244, 0x90,60, 0x81, 1,244, 0x91,57, 0x80, 0,250, 0x81, 0,250, 0x90,57, 0x90,57, 1,244, 0x80, 2,238, 0x90,62,
1,244, 0x91,65, 0x80, 0,250, 0x90,69, 0x81, 1,244, 0x91,67, 0x80, 0,250, 0x90,65, 0x81, 0,250, 0x91,64, 0x80, 2,238,
0x90,60, 0x81, 0,250, 0x91,64, 0x80, 1,244, 0x90,62, 0x81, 0,250, 0x91,60, 0x80, 0,250, 0x90,59, 0x81, 0,250, 0x80,
0,250, 0x90,59, 0,250, 0x91,60, 0x80, 0,250, 0x90,62, 0x81, 1,244, 0x91,64, 0x80, 1,244, 0x90,60, 0x81, 1,244,
0x91,57, 0x80, 0,250, 0x81, 0,250, 0x90,57, 0x91,57, 0,250, 0x80, 0x81, 2,238, 0x90,64, 3,232, 0x91,60, 0x80, 3,232,
0x90,62, 0x81, 3,232, 0x91,59, 0x80, 3,232, 0x90,60, 0x81, 3,232, 0x90,57, 3,232, 0x91,56, 0x80, 1,244, 0x90,57,
0x81, 1,244, 0x91,59, 0x80, 1,244, 0x81, 1,244, 0x90,64, 3,232, 0x91,60, 0x80, 3,232, 0x90,62, 0x81, 3,232, 0x91,59,
0x80, 3,232, 0x90,60, 0x81, 1,244, 0x91,64, 0x80, 1,244, 0x90,69, 0x81, 3,232, 0x91,68, 0x80, 5,220, 0x81, 0xe0};

You can’t concatenate quoted strings with the + operator.
You have no function named String.
You have no variables named score and level.

Are you using the original miditones or my fork, midi2tones?

I am using the original miditones.

I figured out my problem, there were notes in the midi file interfering with the playback.

1 Like