void CConductor::followPlaying() { if ( m_playMode == PB_PLAY_MODE_listen ) return; if (m_wantedChord.length() == 0) fetchNextChord(); if (m_wantedChord.length() == 0) return; if (seekingBarNumber()) { if (deltaAdjust(m_chordDeltaTime) > -m_stopPoint ) fetchNextChord(); } else if ( m_playMode == PB_PLAY_MODE_followYou) { if (deltaAdjust(m_chordDeltaTime) > -m_cfg_earlyNotesPoint ) m_followState = PB_FOLLOW_earlyNotes; if (deltaAdjust(m_chordDeltaTime) > -m_stopPoint ) { m_followState = PB_FOLLOW_waiting; // Throw away the time past the stop point (by adding a negative ticks) addDeltaTime( -m_stopPoint*SPEED_ADJUST_FACTOR - m_chordDeltaTime); } } else // m_playMode == PB_PLAY_MODE_playAlong { if (m_chordDeltaTime > m_cfg_playZoneLate ) { missedNotesColour(Cfg::playedStoppedColour()); fetchNextChord(); m_rating.lateNotes(m_wantedChord.length() - m_goodPlayedNotes.length()); setEventBits( EVENT_BITS_forceRatingRedraw); } } }
void CConductor::realTimeEngine(int mSecTicks) { int type; int ticks; // Midi ticks //mSecTicks = 2; // for debugging only ticks = m_tempo.mSecToTicks(mSecTicks); if (!m_followPlayingTimeOut) m_pianistTiming += ticks; while (checkMidiInput() > 0) expandPianistInput(readMidiInput()); if (getfollowState() == PB_FOLLOW_waiting ) { if (m_silenceTimeOut > 0) { m_silenceTimeOut -= mSecTicks; if (m_silenceTimeOut <= 0) { allSoundOff(); m_silenceTimeOut = 0; } } m_tempo.insertPlayingTicks(ticks); if (m_pianistTiming > m_cfg_playZoneLate) { if (m_followPlayingTimeOut == false) { m_followPlayingTimeOut = true; m_tempo.clearPlayingTicks(); m_rating.lateNotes(m_wantedChord.length() - m_goodPlayedNotes.length()); setEventBits( EVENT_BITS_forceRatingRedraw); missedNotesColour(Cfg::playedStoppedColour()); findImminentNotesOff(); // Don't keep any saved notes off if there are no notes down if (m_piano->pianistAllNotesDown() == 0) outputSavedNotesOff(); m_silenceTimeOut = Cfg::silenceTimeOut(); } } return; } m_silenceTimeOut = 0; if (m_playing == false) return; if (seekingBarNumber()) ticks = 0; m_tempo.adjustTempo(&ticks); ticks = m_bar.addDeltaTime(ticks); if (seekingBarNumber()) ticks = m_bar.goToBarNumer(); setEventBits( m_bar.readEventBits()); #if OPTION_DEBUG_CONDUCTOR if (m_realTimeEventBits | EVENT_BITS_newBarNumber) { ppDEBUG_CONDUCTOR(("m_savedNoteQueue %d m_playingDeltaTime %d",m_savedNoteQueue->space() , m_playingDeltaTime )); ppDEBUG_CONDUCTOR(("getfollowState() %d %d %d",getfollowState() , m_leadLagAdjust, m_songEventQueue->length() )); } #endif addDeltaTime(ticks); followPlaying(); while ( m_playingDeltaTime >= m_leadLagAdjust) { type = m_nextMidiEvent.type(); if (m_songEventQueue->length() == 0 && type == MIDI_PB_EOF) { ppLogInfo("The End of the song"); setEventBits(EVENT_BITS_playingStopped); m_playing = false; break; } if (type == MIDI_PB_tempo) { m_tempo.setMidiTempo(m_nextMidiEvent.data1()); m_leadLagAdjust = m_tempo.mSecToTicks( -getLatencyFix() ); } else if (type == MIDI_PB_timeSignature) { m_bar.setTimeSig(m_nextMidiEvent.data1(), m_nextMidiEvent.data2()); ppLogDebug("Midi Time Signature %d/%d", m_nextMidiEvent.data1(),m_nextMidiEvent.data2()); } else if ( type != MIDI_NONE ) // this marks the end of the piece of music { int channel = m_nextMidiEvent.channel(); // Is this this channel_muted if (!hasPianistKeyboardChannel(channel)) { if (getfollowState() >= PB_FOLLOW_earlyNotes && (m_playMode == PB_PLAY_MODE_followYou || m_playMode == PB_PLAY_MODE_rhythmTapping) && !seekingBarNumber() && m_followSkillAdvanced == false) { // Save up the notes until the pianist presses the right key if (m_savedNoteQueue->space()>0) m_savedNoteQueue->push(m_nextMidiEvent); else ppLogWarn("Warning the m_savedNoteQueue is full"); if (type == MIDI_NOTE_OFF) { if (m_savedNoteOffQueue->space()>0) m_savedNoteOffQueue->push(m_nextMidiEvent); else ppLogDebug("Warning the m_savedNoteOffQueue is full"); } } else { playTransposeEvent(m_nextMidiEvent); // Play the midi note or event ppDEBUG_CONDUCTOR(("playEvent() chan %d type %d note %d", m_nextMidiEvent.channel() , m_nextMidiEvent.type() , m_nextMidiEvent.note(), m_songEventQueue->length() )); } } } if (m_songEventQueue->length() > 0) m_nextMidiEvent = m_songEventQueue->pop(); else { ppDEBUG_CONDUCTOR(("no data in song queue")); m_nextMidiEvent.clear(); break; } m_playingDeltaTime -= m_nextMidiEvent.deltaTime() * SPEED_ADJUST_FACTOR; followPlaying(); } }