annotate Source/TouchKeys/LogPlayback.h @ 56:b4a2d2ae43cf tip

merge
author Andrew McPherson <andrewm@eecs.qmul.ac.uk>
date Fri, 23 Nov 2018 15:48:14 +0000
parents 3580ffe87dc8
children
rev   line source
andrewm@0 1 /*
andrewm@0 2 TouchKeys: multi-touch musical keyboard control software
andrewm@0 3 Copyright (c) 2013 Andrew McPherson
andrewm@0 4
andrewm@0 5 This program is free software: you can redistribute it and/or modify
andrewm@0 6 it under the terms of the GNU General Public License as published by
andrewm@0 7 the Free Software Foundation, either version 3 of the License, or
andrewm@0 8 (at your option) any later version.
andrewm@0 9
andrewm@0 10 This program is distributed in the hope that it will be useful,
andrewm@0 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
andrewm@0 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
andrewm@0 13 GNU General Public License for more details.
andrewm@0 14
andrewm@0 15 You should have received a copy of the GNU General Public License
andrewm@0 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
andrewm@0 17
andrewm@0 18 =====================================================================
andrewm@0 19
andrewm@0 20 LogPlayback.h: basic functions for playing back a recorded TouchKeys log.
andrewm@0 21 */
andrewm@0 22
andrewm@0 23 #ifndef __touchkeys__LogPlayback__
andrewm@0 24 #define __touchkeys__LogPlayback__
andrewm@0 25
andrewm@0 26 #include <iostream>
andrewm@0 27 #include <fstream>
andrewm@0 28 #include <vector>
andrewm@0 29 #include <boost/bind.hpp>
andrewm@0 30 #include "MidiInputController.h"
andrewm@0 31 #include "KeyTouchFrame.h"
andrewm@0 32 #include "PianoKeyboard.h"
andrewm@0 33 #include "../Utility/Scheduler.h"
andrewm@0 34
andrewm@0 35 using namespace std;
andrewm@0 36
andrewm@0 37 class LogPlayback {
andrewm@0 38 public:
andrewm@0 39 // ***** Constructor and Destructor *****
andrewm@0 40 LogPlayback(PianoKeyboard& keyboard, MidiInputController& midi);
andrewm@0 41
andrewm@0 42 ~LogPlayback();
andrewm@0 43
andrewm@0 44 // ***** Log File Playback *****
andrewm@0 45 // File management
andrewm@0 46 bool openLogFiles(string const& touchPath, string const& midiPath);
andrewm@0 47 void closeLogFiles();
andrewm@0 48
andrewm@0 49 // Start, stop, pause, resume
andrewm@0 50 void startPlayback(timestamp_type startingTimestamp = 0);
andrewm@0 51 void stopPlayback();
andrewm@0 52 void pausePlayback();
andrewm@0 53 void resumePlayback();
andrewm@0 54
andrewm@0 55 // Seek to location and/or change the rate
andrewm@0 56 void seekPlayback(timestamp_type newTimestamp);
andrewm@0 57 void changePlaybackRate(float rate);
andrewm@0 58
andrewm@0 59 // Scheduler action functions
andrewm@0 60 timestamp_type nextTouchEvent();
andrewm@0 61 timestamp_type nextMidiEvent();
andrewm@0 62
andrewm@0 63 private:
andrewm@0 64 bool readNextTouchFrame();
andrewm@0 65 bool readNextMidiFrame();
andrewm@0 66
andrewm@0 67 PianoKeyboard& keyboard_; // Main keyboard controller
andrewm@0 68 MidiInputController& midiInputController_; // MIDI controller
andrewm@0 69 Scheduler playbackScheduler_; // Scheduler thread to send messages
andrewm@0 70 Scheduler::action touchAction_; // Scheduler action for playing next touch
andrewm@0 71 Scheduler::action midiAction_; // Scheduler action for playing next MIDI event
andrewm@0 72
andrewm@0 73 ifstream touchLog_; // Log file for key touches
andrewm@0 74 ifstream midiLog_; // Log file for MIDI data
andrewm@0 75
andrewm@0 76 bool open_; // Whether files are open
andrewm@0 77 bool playing_; // Whether playback is active
andrewm@0 78 bool paused_; // Whether playback is active, but paused
andrewm@0 79 bool usingTouch_, usingMidi_; // Whether touch and MIDI files are present
andrewm@0 80 float playbackRate_; // Current playback rate (default 1.0)
andrewm@0 81
andrewm@0 82 KeyTouchFrame nextTouch_; // Next touch frame to play
andrewm@0 83 int nextTouchMidiNote_; // MIDI note for next touch frame to play
andrewm@0 84 timestamp_type nextTouchTimestamp_; // When the next touch happens
andrewm@0 85 std::vector<unsigned char> nextMidi_; // Next MIDI event to play
andrewm@0 86 timestamp_type nextMidiTimestamp_; // When the next MIDI event happens
andrewm@0 87 timestamp_type lastMidiTimestamp_; // When the last MIDI event happened
andrewm@0 88 timestamp_type pauseTimestamp_; // When the playback was paused
andrewm@0 89 timestamp_diff_type timestampOffset_; // Difference between file and current playback time
andrewm@0 90 };
andrewm@0 91
andrewm@0 92 #endif /* defined(__touchkeys__LogPlayback__) */