andrewm@0: /*
andrewm@0: TouchKeys: multi-touch musical keyboard control software
andrewm@0: Copyright (c) 2013 Andrew McPherson
andrewm@0:
andrewm@0: This program is free software: you can redistribute it and/or modify
andrewm@0: it under the terms of the GNU General Public License as published by
andrewm@0: the Free Software Foundation, either version 3 of the License, or
andrewm@0: (at your option) any later version.
andrewm@0:
andrewm@0: This program is distributed in the hope that it will be useful,
andrewm@0: but WITHOUT ANY WARRANTY; without even the implied warranty of
andrewm@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
andrewm@0: GNU General Public License for more details.
andrewm@0:
andrewm@0: You should have received a copy of the GNU General Public License
andrewm@0: along with this program. If not, see .
andrewm@0:
andrewm@0: =====================================================================
andrewm@0:
andrewm@0: LogPlayback.h: basic functions for playing back a recorded TouchKeys log.
andrewm@0: */
andrewm@0:
andrewm@0: #ifndef __touchkeys__LogPlayback__
andrewm@0: #define __touchkeys__LogPlayback__
andrewm@0:
andrewm@0: #include
andrewm@0: #include
andrewm@0: #include
andrewm@0: #include
andrewm@0: #include "MidiInputController.h"
andrewm@0: #include "KeyTouchFrame.h"
andrewm@0: #include "PianoKeyboard.h"
andrewm@0: #include "../Utility/Scheduler.h"
andrewm@0:
andrewm@0: using namespace std;
andrewm@0:
andrewm@0: class LogPlayback {
andrewm@0: public:
andrewm@0: // ***** Constructor and Destructor *****
andrewm@0: LogPlayback(PianoKeyboard& keyboard, MidiInputController& midi);
andrewm@0:
andrewm@0: ~LogPlayback();
andrewm@0:
andrewm@0: // ***** Log File Playback *****
andrewm@0: // File management
andrewm@0: bool openLogFiles(string const& touchPath, string const& midiPath);
andrewm@0: void closeLogFiles();
andrewm@0:
andrewm@0: // Start, stop, pause, resume
andrewm@0: void startPlayback(timestamp_type startingTimestamp = 0);
andrewm@0: void stopPlayback();
andrewm@0: void pausePlayback();
andrewm@0: void resumePlayback();
andrewm@0:
andrewm@0: // Seek to location and/or change the rate
andrewm@0: void seekPlayback(timestamp_type newTimestamp);
andrewm@0: void changePlaybackRate(float rate);
andrewm@0:
andrewm@0: // Scheduler action functions
andrewm@0: timestamp_type nextTouchEvent();
andrewm@0: timestamp_type nextMidiEvent();
andrewm@0:
andrewm@0: private:
andrewm@0: bool readNextTouchFrame();
andrewm@0: bool readNextMidiFrame();
andrewm@0:
andrewm@0: PianoKeyboard& keyboard_; // Main keyboard controller
andrewm@0: MidiInputController& midiInputController_; // MIDI controller
andrewm@0: Scheduler playbackScheduler_; // Scheduler thread to send messages
andrewm@0: Scheduler::action touchAction_; // Scheduler action for playing next touch
andrewm@0: Scheduler::action midiAction_; // Scheduler action for playing next MIDI event
andrewm@0:
andrewm@0: ifstream touchLog_; // Log file for key touches
andrewm@0: ifstream midiLog_; // Log file for MIDI data
andrewm@0:
andrewm@0: bool open_; // Whether files are open
andrewm@0: bool playing_; // Whether playback is active
andrewm@0: bool paused_; // Whether playback is active, but paused
andrewm@0: bool usingTouch_, usingMidi_; // Whether touch and MIDI files are present
andrewm@0: float playbackRate_; // Current playback rate (default 1.0)
andrewm@0:
andrewm@0: KeyTouchFrame nextTouch_; // Next touch frame to play
andrewm@0: int nextTouchMidiNote_; // MIDI note for next touch frame to play
andrewm@0: timestamp_type nextTouchTimestamp_; // When the next touch happens
andrewm@0: std::vector nextMidi_; // Next MIDI event to play
andrewm@0: timestamp_type nextMidiTimestamp_; // When the next MIDI event happens
andrewm@0: timestamp_type lastMidiTimestamp_; // When the last MIDI event happened
andrewm@0: timestamp_type pauseTimestamp_; // When the playback was paused
andrewm@0: timestamp_diff_type timestampOffset_; // Difference between file and current playback time
andrewm@0: };
andrewm@0:
andrewm@0: #endif /* defined(__touchkeys__LogPlayback__) */