-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSFMusicalShield.cpp
More file actions
95 lines (70 loc) · 2.28 KB
/
SFMusicalShield.cpp
File metadata and controls
95 lines (70 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "SFMusicalShield.h"
void SFMusicalShield::begin(){
SoftwareSerial s(2,3);
s.begin(31250);
mySerial = &s;
resetMIDI(4);
}
//begin method for overriding default resetMIDIPin
void SFMusicalShield::begin(int resetMIDIPin){
SoftwareSerial s(2,3);
s.begin(31250);
mySerial = &s;
resetMIDI(resetMIDIPin);
}
// begin method for overriding default Stream
void SFMusicalShield::begin(Stream &s){
mySerial = &s;
resetMIDI(4);
}
// begin method for overriding default resetMIDIPin and default stream
void SFMusicalShield::begin(int resetMIDIPin, Stream &s){
//Setup software serial for MIDI
//SoftwareSerial softSerial(2,3);
mySerial = &s;
resetMIDI(resetMIDIPin);
}
void SFMusicalShield::resetMIDI(int resetMIDIPin){
//Reset the VS1053
pinMode(resetMIDIPin, HIGH);
digitalWrite(resetMIDIPin, LOW);
delay(100);
digitalWrite(resetMIDIPin, HIGH);
delay(100);
setVolume(0, 125);
}
void SFMusicalShield::talkMIDI(byte cmd, byte data1, byte data2){
mySerial->write(cmd);
mySerial->write(data1);
if( (cmd & 0xF0) <= 0xB0) {
mySerial->write(data2);
}
}
void SFMusicalShield::noteOn(byte channel, byte note, byte attack_velocity) {
talkMIDI( (0x90 | channel), note, attack_velocity);
}
void SFMusicalShield::noteOff(byte channel, byte note, byte release_velocity) {
talkMIDI( (0x80 | channel), note, release_velocity);
}
void SFMusicalShield::allOff(byte channel) {
talkMIDI( (0xB0 | channel), 0x78, 0);
}
void SFMusicalShield::setBank(byte channel, byte bank) {
talkMIDI( (0xB0 | channel), 0, bank);
}
void SFMusicalShield::setInstrument(byte channel, byte instrument) {
instrument--; //Instruments are listed from 1-128 instead of 0-127 in datasheet
talkMIDI( (0xC0 | channel), instrument, 0);
}
void SFMusicalShield::setVolume(byte channel, byte volume) {
talkMIDI( (0xB0 | channel), 0x07, volume);
}
/*
void SFMusicalShield::setReverbLevel(byte channel, byte level){
talkMIDI( (0xB0 | channel), 0x5b, level);
}
void SFMusicalShield::setReverbDecay(byte channel, byte level){
talkMIDI( (0xB0 | channel), 0xC0, level);
}
*/
SFMusicalShield Musical;