-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGridMidi.cpp
88 lines (82 loc) · 3 KB
/
GridMidi.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
// ======================================================================
// WinGridStrument - a Windows touchscreen musical instrument
// Copyright(C) 2020 Roger Allen
//
// This program is free software : you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// ======================================================================
#include "GridMidi.h"
#include "GridUtils.h"
#include <iostream>
// Not just a midi device any longer. A Midi or Synth output
GridMidi::GridMidi(HMIDIOUT midiDevice, GridSynth *gridSynth)
{
midi_device_ = midiDevice;
grid_synth_ = gridSynth;
play_midi_ = false;
play_synth_ = false;
}
void checkAlertExit(MMRESULT rc) {
if (rc != MMSYSERR_NOERROR) {
wchar_t* error = new wchar_t[MAXERRORLENGTH]();
midiOutGetErrorText(rc, error, MAXERRORLENGTH);
std::wostringstream text;
text << "Unable to midiOutShortMsg: " << error;
delete[] error;
AlertExit(NULL, text.str().c_str());
}
}
void GridMidi::noteOn(int channel, int note, int midi_pressure)
{
if (play_synth_) {
grid_synth_->noteOn(channel, note, midi_pressure); // FIXME
}
if (play_midi_) {
MidiMessage message(MIDI::NOTE_ON + channel, note, midi_pressure);
MMRESULT rc = midiOutShortMsg(midi_device_, message.data());
checkAlertExit(rc);
}
}
void GridMidi::pitchBend(int channel, int mod_pitch)
{
if (play_synth_) {
grid_synth_->pitchBend(channel, mod_pitch); // FIXME
}
if (play_midi_) {
MidiMessage message(MIDI::PITCH_BEND + channel, mod_pitch & 0x7f, (mod_pitch >> 7) & 0x7f);
MMRESULT rc = midiOutShortMsg(midi_device_, message.data());
checkAlertExit(rc);
}
}
void GridMidi::controlChange(int channel, int controller, int mod_modulation)
{
if (play_synth_) {
grid_synth_->controlChange(channel, controller, mod_modulation); // FIXME
}
if (play_midi_) {
MidiMessage message(MIDI::CONTROL_CHANGE + channel, controller, mod_modulation);
MMRESULT rc = midiOutShortMsg(midi_device_, message.data());
checkAlertExit(rc);
}
}
void GridMidi::polyKeyPressure(int channel, int key, int pressure)
{
if (play_synth_) {
grid_synth_->polyKeyPressure(channel, key, pressure); // FIXME
}
if (play_midi_) {
MidiMessage message(MIDI::POLY_KEY_PRESSURE + channel, key, pressure);
MMRESULT rc = midiOutShortMsg(midi_device_, message.data());
checkAlertExit(rc);
}
}