16
16
#include " midi/GOMidiMap.h"
17
17
18
18
#include " GOEvent.h"
19
+ #include " GOMidi.h"
19
20
#include " GOOrganController.h"
20
21
21
22
enum {
@@ -38,24 +39,29 @@ const struct GOElementCreator::ButtonDefinitionEntry *GOMidiPlayer::
38
39
return m_element_types;
39
40
}
40
41
42
+ void GOMidiPlayer::ResetUI () {
43
+ m_buttons[ID_MIDI_PLAYER_PLAY]->Display (false );
44
+ m_buttons[ID_MIDI_PLAYER_PAUSE]->Display (false );
45
+ UpdateDisplay ();
46
+ }
47
+
41
48
GOMidiPlayer::GOMidiPlayer (GOOrganController *organController)
42
- : m_OrganController(organController),
49
+ : r_MidiMap(organController->GetSettings ().GetMidiMap()),
50
+ r_timer(*organController->GetTimer ()),
51
+ p_midi(nullptr ),
43
52
m_content(),
44
53
m_PlayingTime(organController),
45
54
m_Start(0 ),
46
55
m_PlayingSeconds(0 ),
47
56
m_Speed(1 ),
48
57
m_IsPlaying(false ),
49
58
m_Pause(false ) {
50
- CreateButtons (*m_OrganController);
51
- Clear ();
52
- m_DeviceID
53
- = m_OrganController->GetSettings ().GetMidiMap ().GetDeviceIdByLogicalName (
54
- _ (" GrandOrgue MIDI Player" ));
55
- UpdateDisplay ();
59
+ CreateButtons (*organController);
60
+ m_DeviceID = r_MidiMap.GetDeviceIdByLogicalName (_ (" GrandOrgue MIDI Player" ));
61
+ ResetUI ();
56
62
}
57
63
58
- GOMidiPlayer::~GOMidiPlayer () { StopPlaying (); }
64
+ GOMidiPlayer::~GOMidiPlayer () { Cleanup (); }
59
65
60
66
void GOMidiPlayer::Load (GOConfigReader &cfg) {
61
67
m_buttons[ID_MIDI_PLAYER_PLAY]->Init (cfg, wxT (" MidiPlayerPlay" ), _ (" PLAY" ));
@@ -81,15 +87,11 @@ void GOMidiPlayer::ButtonStateChanged(int id, bool newState) {
81
87
}
82
88
}
83
89
84
- void GOMidiPlayer::Clear () {
85
- StopPlaying ();
86
- m_content.Clear ();
87
- }
88
-
89
90
void GOMidiPlayer::LoadFile (
90
91
const wxString &filename, unsigned manuals, bool pedal) {
91
- Clear ();
92
- GOMidiFileReader reader (m_OrganController->GetSettings ().GetMidiMap ());
92
+ StopPlaying ();
93
+ m_content.Clear ();
94
+ GOMidiFileReader reader (r_MidiMap);
93
95
if (!reader.Open (filename)) {
94
96
GOMessageBox (
95
97
wxString::Format (_ (" Failed to load %s" ), filename.c_str ()),
@@ -98,11 +100,7 @@ void GOMidiPlayer::LoadFile(
98
100
NULL );
99
101
return ;
100
102
}
101
- if (!m_content.Load (
102
- reader,
103
- m_OrganController->GetSettings ().GetMidiMap (),
104
- manuals,
105
- pedal)) {
103
+ if (!m_content.Load (reader, r_MidiMap, manuals, pedal)) {
106
104
m_content.Clear ();
107
105
GOMessageBox (
108
106
wxString::Format (_ (" Failed to load %s" ), filename.c_str ()),
@@ -150,10 +148,17 @@ void GOMidiPlayer::Pause() {
150
148
m_Pause = true ;
151
149
m_buttons[ID_MIDI_PLAYER_PAUSE]->Display (m_Pause);
152
150
m_Start = wxGetLocalTimeMillis () - m_Start;
153
- m_OrganController-> GetTimer ()-> DeleteTimer (this );
151
+ r_timer. DeleteTimer (this );
154
152
}
155
153
}
156
154
155
+ void GOMidiPlayer::PlayMidiEvent (const GOMidiEvent &e) {
156
+ GOMidi *pMidi = p_midi;
157
+
158
+ if (pMidi)
159
+ pMidi->PlayEvent (e);
160
+ }
161
+
157
162
void GOMidiPlayer::StopPlaying () {
158
163
if (m_IsPlaying) {
159
164
for (unsigned i = 1 ; i < 16 ; i++) {
@@ -164,15 +169,14 @@ void GOMidiPlayer::StopPlaying() {
164
169
e.SetValue (0 );
165
170
e.SetDevice (m_DeviceID);
166
171
e.SetTime (wxGetLocalTimeMillis ());
167
- m_OrganController->ProcessMidi (e);
172
+ e.SetAllowedToReload (false );
173
+ PlayMidiEvent (e);
168
174
}
169
175
}
170
176
171
177
m_IsPlaying = false ;
172
- m_buttons[ID_MIDI_PLAYER_PLAY]->Display (false );
173
- m_buttons[ID_MIDI_PLAYER_PAUSE]->Display (false );
174
- UpdateDisplay ();
175
- m_OrganController->GetTimer ()->DeleteTimer (this );
178
+ ResetUI ();
179
+ r_timer.DeleteTimer (this );
176
180
}
177
181
178
182
bool GOMidiPlayer::IsPlaying () { return m_IsPlaying; }
@@ -207,12 +211,13 @@ void GOMidiPlayer::HandleTimer() {
207
211
}
208
212
e.SetDevice (m_DeviceID);
209
213
e.SetTime (wxGetLocalTimeMillis ());
210
- m_OrganController->ProcessMidi (e);
214
+ e.SetAllowedToReload (false );
215
+ PlayMidiEvent (e);
211
216
} else {
212
217
GOTime next = e.GetTime () * m_Speed + m_Start;
213
218
if (next > m_Start + m_Speed * (m_PlayingSeconds + 1 ) * 1000 )
214
219
next = m_Start + m_Speed * (m_PlayingSeconds + 1 ) * 1000 ;
215
- m_OrganController-> GetTimer ()-> SetTimer (next, this );
220
+ r_timer. SetTimer (next, this );
216
221
return ;
217
222
}
218
223
} while (true );
@@ -231,3 +236,8 @@ GOLabelControl *GOMidiPlayer::GetLabelControl(
231
236
return &m_PlayingTime;
232
237
return NULL ;
233
238
}
239
+
240
+ void GOMidiPlayer::Cleanup () {
241
+ StopPlaying ();
242
+ p_midi = nullptr ;
243
+ }
0 commit comments