Skip to content

Commit 6eec0a1

Browse files
committed
Examples
1 parent 49a12dc commit 6eec0a1

File tree

4 files changed

+72
-105
lines changed

4 files changed

+72
-105
lines changed

examples/midi-parse-multitrack/midi-parse-multitrack.ino

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
/**
2-
* We provide a midi file as hex array and parse it incrementally.
3-
*/
2+
* We provide a midi file as hex array and parse it incrementally.
3+
* This sketch has quite some complexity for reading the data.
4+
* This can be avoided when you use the MemoryStream and StreamCopy
5+
* from the AudioTools project.
6+
* @author Phil Schatzmann
7+
*/
48
#include "MidiFileParserMultiTrack.h"
59
#include "examples/example-midi.h"
610
#include <algorithm>
@@ -14,7 +18,7 @@ bool debug = false;
1418

1519
void setup() {
1620
#ifdef ARDUINO
17-
Serial.begin(19200);
21+
Serial.begin(115200);
1822
#endif
1923
mf.begin(debug, 256 * 5);
2024

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* We provide a midi file as hex array and parse it incrementally.
3+
* We use the MemoryStream and StreamCopy from the AudioTools project.
4+
* Please not that we need to use psram!
5+
* @author Phil Schatzmann
6+
*/
7+
#include "AudioTools.h" // https://github.com/pschatzmann/arduino-audio-tools
8+
#include "MidiFileParserMultiTrack.h"
9+
#include "examples/example-midi.h"
10+
#include "esp_heap_caps.h"
11+
12+
using namespace midi;
13+
14+
const int write_size = 256;
15+
MidiFileParserMultiTrack parser;
16+
MemoryStream midi_data(example_mid, example_mid_len);
17+
StreamCopy copy(parser, midi_data, write_size);
18+
bool debug = false;
19+
const int psram_limit = 8;
20+
21+
void setup() {
22+
Serial.begin(115200);
23+
parser.begin(debug, 256 * 5);
24+
25+
// use psram
26+
heap_caps_malloc_extmem_enable(psram_limit);
27+
28+
// load data to parser
29+
copy.copyAll();
30+
// data has been loaded
31+
printf("Number of events: %ld\n", (long)parser.size());
32+
}
33+
34+
void loop() {
35+
36+
// Parse midi
37+
auto state = parser.parseTimed(); // parseTimed() or parse();
38+
39+
// Process Result
40+
switch (state.status)
41+
case MIDI_PARSER_TRACK_MIDI: {
42+
// process midi
43+
char msg[100];
44+
sprintf(msg, "process time-cumulated ms: %ld status: %d [%s] channel: %d param1: %d param2: %d",
45+
(long)state.timeInMs(), state.midi.status,
46+
parser.midi_status_name(state.midi.status), state.midi.channel,
47+
state.midi.param1, state.midi.param2);
48+
Serial.println(msg);
49+
break;
50+
case MIDI_PARSER_ERROR:
51+
Serial.println("Error\n");
52+
case MIDI_PARSER_EOB:
53+
while (true)
54+
;
55+
break;
56+
default:
57+
break;
58+
}
59+
}

examples/midi-parse/midi-parse.ino

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
/**
22
* We provide a midi file as hex array and parse it incrementally.
3-
*/
3+
* This sketch has quite some complexity for reading the data.
4+
* This can be avoided when you use the MemoryStream and StreamCopy
5+
* from the AudioTools project.
6+
* @author Phil Schatzmann
7+
*/
48
#include "MidiFileParser.h"
59
#include "examples/example-midi.h"
610
#include <algorithm>
@@ -14,7 +18,7 @@ bool debug = false;
1418

1519
void setup() {
1620
#ifdef ARDUINO
17-
Serial.begin(19200);
21+
Serial.begin(115200);
1822
#endif
1923
mf.begin(debug, 256 * 5);
2024
}

examples/midi.ipynb

Lines changed: 0 additions & 100 deletions
This file was deleted.

0 commit comments

Comments
 (0)