-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmidi_module.cpp
96 lines (75 loc) · 1.84 KB
/
midi_module.cpp
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
#define MIDI_STATUS_DISCONNECTED 0
#define MIDI_STATUS_CONNECTED 1
class MidiModule
{
public:
int status;
void draw();
void handle_input();
int get_status();
void midi_connect();
void send(u8 message, u8 data1, u8 data2);
void send_note_on(int channel, int note, int velocity);
void send_note_off(int channel, int note);
MidiModule();
// ~MidiModule();
};
void MidiModule::draw()
{
PA_Clear8bitBg(BOTTOM_SCREEN);
PA_8bitText(BOTTOM_SCREEN, 2, 2, 255, 40,(char*)"Midi Settings",WHITE,1,1,130);
if (this->status == MIDI_STATUS_DISCONNECTED)
{
PA_8bitText(BOTTOM_SCREEN, 2, 15, 255, 40,(char*)"Press [A] to connect to MIDI...",WHITE,1,1,130);
}
else
{
PA_8bitText(BOTTOM_SCREEN, 2, 15, 255, 40,(char*)"Status: -- Connected --",WHITE,1,1,130);
}
}
void MidiModule::handle_input()
{
if (Pad.Newpress.A && (this->status == MIDI_STATUS_DISCONNECTED))
{
this->midi_connect();
}
}
int MidiModule::get_status()
{
return(this->status);
}
void MidiModule::midi_connect()
{
PA_Clear8bitBg(BOTTOM_SCREEN);
PA_8bitText(BOTTOM_SCREEN, 3, 3, 255, 40,"Searching for WIFI-MIDI...",1,1,0,100);
dsmi_setup_wifi_support();
int res = dsmi_connect();
if (res == 0)
{
PA_8bitText(BOTTOM_SCREEN, 3, 15, 255, 40,"No WIFI-MIDI detected.",1,1,0,100);
this->status = MIDI_STATUS_DISCONNECTED;
}
else
{
PA_8bitText(0, 3, 15, 255, 40,"Connected to WIFI-MIDI!",1,1,0,100);
this->status = MIDI_STATUS_CONNECTED;
}
}
void MidiModule::send(u8 message, u8 data1, u8 data2)
{
dsmi_write(message,data1,data2);
}
void MidiModule::send_note_on(int channel, int note, int velocity)
{
channel--;
dsmi_write(0x90 | channel, note, velocity);
}
void MidiModule::send_note_off(int channel, int note)
{
channel--;
dsmi_write(0x80 | channel, note, 0);
}
MidiModule::MidiModule()
{
this->status = MIDI_STATUS_DISCONNECTED;
}