Skip to content

Commit e4f44ef

Browse files
committed
vs1053 Example for midi library
1 parent 1f7eb91 commit e4f44ef

File tree

4 files changed

+84
-1
lines changed

4 files changed

+84
-1
lines changed

examples/examples-vs1053/streams-midi-vs1053/streams-midi-vs1053.ino

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @file streams-midi-vs1053.ino
33
* @author Phil Schatzmann
4-
* @brief Demo that shows how to send midi commands to the vs1053
4+
* @brief Demo that shows how to send streaming midi commands to the vs1053
55
* @version 0.1
66
* @date 2022-08-23
77
*
@@ -16,6 +16,7 @@ VS1053Stream vs1053; // final output
1616
uint16_t note = 65; // 0 to 128
1717
uint16_t amplitude = 128; // 0 to 128
1818
int channel = 0;
19+
uint8_t instrument = 0;
1920

2021
//Send a MIDI note-on message. Like pressing a piano key
2122
void noteOn(uint8_t channel, uint8_t note, uint8_t attack_velocity=100) {
@@ -27,6 +28,15 @@ void noteOff(uint8_t channel, uint8_t note, uint8_t release_velocity=100) {
2728
vs1053.sendMidiMessage( (0x80 | channel), note, release_velocity);
2829
}
2930

31+
void selectInstrument(uint8_t channel, uint8_t instrument ){
32+
// Continuous controller 0, bank select: 0 gives you the default bank depending on the channel
33+
// 0x78 (percussion) for Channel 10, i.e. channel = 9 , 0x79 (melodic) for other channels
34+
vs1053.sendMidiMessage(0xB0| channel, 0, 0x00); //0x00 default bank
35+
36+
// Patch change, select instrument
37+
vs1053.sendMidiMessage(0xC0| channel, instrument, 0);
38+
}
39+
3040

3141
void setup() {
3242
Serial.begin(115200);
@@ -41,6 +51,7 @@ void setup() {
4151
//cfg.dreq_pin = VS1053_DREQ;
4252
//cfg.reset_pin = VS1053_RESET;
4353
vs1053.begin(cfg);
54+
vs1053.setVolume(1.0);
4455

4556
}
4657

@@ -55,5 +66,9 @@ void loop() {
5566
delay(200);
5667
if (note>=90) {
5768
note = 64;
69+
Serial.println();
70+
Serial.print("selecting Instrument ");
71+
Serial.println(++instrument);
72+
selectInstrument(channel, instrument);
5873
}
5974
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* @file streams-midi-vs1053.ino
3+
* @author Phil Schatzmann
4+
* @brief Demo that shows how to send streaming midi commands to the vs1053
5+
* This example using my https://github.com/pschatzmann/arduino-midi.git library
6+
* @version 0.1
7+
* @date 2022-08-23
8+
*
9+
* @copyright Copyright (c) 2022
10+
*
11+
*/
12+
13+
#include "AudioTools.h"
14+
#include "AudioLibs/VS1053Stream.h"
15+
#include "Midi.h"
16+
17+
18+
VS1053Stream vs1053; // final output
19+
MidiStreamOut midi_out(vs1053);
20+
uint8_t note = 65; // 0 to 128
21+
uint8_t amplitude = 128; // 0 to 128
22+
uint8_t instrument = 0;
23+
24+
void selectInstrument(uint8_t instrument, uint8_t bank=0x00){
25+
// Continuous controller 0, bank select: 0 gives you the default bank depending on the channel
26+
// 0x78 (percussion) for Channel 10, i.e. channel = 9 , 0x79 (melodic) for other channels
27+
//vs1053.sendMidiMessage(0xB0| channel, 0, 0x00); //0x00 default bank
28+
midi_out.controlChange(BANK_SELECT, bank);
29+
30+
// Patch change, select instrument
31+
midi_out.programChange(instrument);
32+
}
33+
34+
35+
void setup() {
36+
Serial.begin(115200);
37+
AudioLogger::instance().begin(Serial, AudioLogger::Info);
38+
39+
// setup vs1053
40+
auto cfg = vs1053.defaultConfig();
41+
cfg.is_midi = true; // vs1053 is accepting streaming midi data
42+
// Use your custom pins or define in AudioCodnfig.h
43+
//cfg.cs_pin = VS1053_CS;
44+
//cfg.dcs_pin = VS1053_DCS;
45+
//cfg.dreq_pin = VS1053_DREQ;
46+
//cfg.reset_pin = VS1053_RESET;
47+
vs1053.begin(cfg);
48+
vs1053.setVolume(1.0);
49+
50+
}
51+
52+
void loop() {
53+
Serial.println();
54+
Serial.print("playing ");
55+
Serial.println(++note);
56+
57+
midi_out.noteOn(note, amplitude );
58+
delay(900);
59+
midi_out.noteOff(note, 20 );
60+
delay(200);
61+
if (note>=90) {
62+
note = 64;
63+
Serial.println();
64+
Serial.print("selecting Instrument ");
65+
Serial.println(++instrument);
66+
selectInstrument(instrument);
67+
}
68+
}

0 commit comments

Comments
 (0)