@@ -90,15 +90,19 @@ int SequencePlayer::loopStart() const
90
90
SequencePlayer::SequencePlayer ()
91
91
: m_port(nullptr )
92
92
, m_songPositionTicks(0 )
93
+ , m_echoResolution(50 )
93
94
, m_loopEnabled(false )
94
95
, m_loopStart(0 )
95
96
, m_loopEnd(0 )
96
- , m_echoResolution(50 )
97
97
, m_pitchShift(0 )
98
98
, m_volumeFactor(100 )
99
99
, m_latestBeat(nullptr )
100
100
, m_firstBeat(nullptr )
101
101
{
102
+ #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
103
+ qRegisterMetaType<std::chrono::milliseconds>();
104
+ qRegisterMetaType<std::uint64_t >();
105
+ #endif
102
106
initChannels ();
103
107
}
104
108
@@ -131,12 +135,12 @@ void SequencePlayer::shutupSound()
131
135
132
136
void SequencePlayer::playEvent (MIDIEvent* ev)
133
137
{
134
- static const std::type_info& textId = typeid (TextEvent);
135
- static const std::type_info& tempoId = typeid (TempoEvent);
136
- static const std::type_info& timeSigId = typeid (TimeSignatureEvent);
137
- static const std::type_info& keySigId = typeid (KeySignatureEvent);
138
- static const std::type_info& beatId = typeid (BeatEvent);
139
- static const std::type_info& sysexId = typeid (SysExEvent);
138
+ static const std::type_info & textId = typeid (TextEvent);
139
+ static const std::type_info & tempoId = typeid (TempoEvent);
140
+ static const std::type_info & timeSigId = typeid (TimeSignatureEvent);
141
+ static const std::type_info & keySigId = typeid (KeySignatureEvent);
142
+ static const std::type_info & beatId = typeid (BeatEvent);
143
+ static const std::type_info & sysexId = typeid (SysExEvent);
140
144
141
145
if (m_port == nullptr )
142
146
return ;
@@ -274,10 +278,10 @@ void SequencePlayer::playerLoop()
274
278
using namespace std ::chrono;
275
279
using Clock = steady_clock;
276
280
using TimePoint = Clock::time_point;
277
- static const std::type_info& beatId = typeid (BeatEvent);
281
+ static const std::type_info & beatId = typeid (BeatEvent);
278
282
int currentBar{0 };
279
283
std::uint64_t echoTicks{0 };
280
- microseconds echoDelta{m_echoResolution }, eventTime{ 0 };
284
+ microseconds deltaTime{ microseconds::zero () }, echoDelta{m_echoResolution };
281
285
TimePoint currentTime{Clock::now ()}, nextTime{currentTime}, nextEcho{currentTime},
282
286
startTime{currentTime};
283
287
emit songStarted ();
@@ -300,9 +304,9 @@ void SequencePlayer::playerLoop()
300
304
}
301
305
}
302
306
if (ev->delta () > 0 ) {
303
- eventTime = m_song.timeOfEvent (ev);
307
+ deltaTime = m_song.deltaTimeOfEvent (ev);
304
308
echoDelta = m_song.timeOfTicks (m_echoResolution);
305
- nextTime = startTime + eventTime ;
309
+ nextTime = currentTime + deltaTime ;
306
310
nextEcho = currentTime + echoDelta;
307
311
while (nextEcho < nextTime) {
308
312
dispatcher->processEvents (eventFilter);
@@ -318,7 +322,8 @@ void SequencePlayer::playerLoop()
318
322
echoTicks = ev->tick ();
319
323
m_songPositionTicks = echoTicks;
320
324
currentTime = Clock::now ();
321
- emit songEchoTime (duration_cast<milliseconds>(eventTime), echoTicks);
325
+ emit songEchoTime (duration_cast<milliseconds>(m_song.timeOfTicks (echoTicks)),
326
+ echoTicks);
322
327
}
323
328
playEvent (ev);
324
329
}
@@ -333,7 +338,8 @@ void SequencePlayer::playerLoop()
333
338
334
339
emit songStopped ();
335
340
if (!m_song.hasMoreEvents ()) {
336
- // qDebug() << "Final Song Position:" << m_songPosition;
341
+ qDebug () << " Final Song Position:" << m_songPositionTicks
342
+ << (currentTime - startTime).count () / 1e9 ;
337
343
emit songFinished ();
338
344
}
339
345
dispatcher->processEvents (eventFilter);
0 commit comments