-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNoteHandler.h
More file actions
89 lines (74 loc) · 3.16 KB
/
NoteHandler.h
File metadata and controls
89 lines (74 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
Copyright (C) 2016 Mikko Tamminen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef NOTEHANDLER_H
#define NOTEHANDLER_H
#include "Note.h"
#include "IJackEngineCallbackProvider.h"
#include <string>
#include <map>
#include <vector>
typedef struct {
bool pass_through = true;
bool recording = true;
bool rolling = false;
bool wait_for_input = true;
double internal_frame = 0;
} NoteHandlerState;
class NoteHandler : public IJackEngineCallbackProvider{
public:
NoteHandler();
~NoteHandler() {};
void JackEngineTickHandler(int nframes);
void JackEngineNoteHandler(Note*, int offset);
void JackEngineTriggerHandler(Note*, int offset);
void JackEnginePlayFunctionHandler(std::function<void(Note*,int)> play_fn);
void JackEnginePostTickHandler();
void sendCommand(std::string command, double arg);
void TriggerLearn(std::string command, double arg);
void TriggerUnlearn(std::string command, double arg);
std::string learning_status() { return (trigger_learning.first.length() > 0) ? (trigger_learning.first + " " + std::to_string(trigger_learning.second)) : "none" ;}
void Save(std::string filename);
void Open(std::string filename);
bool isRolling() { return state.rolling; }
bool isRecording() { return state.recording; }
bool isPassingThrough() { return state.pass_through; }
bool isWaitingForInput() { return state.wait_for_input; }
double current_frame() { return state.internal_frame; }
int event_count() { return store.size();}
private:
int tick_size = 0;
NoteHandlerState state;
struct trigger{
std::string command;
double arg;
Note note;
};
std::map<double, std::vector<Note*>> store;
std::map<double, std::vector<Note*>> play_queue;
std::map<std::string, void(NoteHandler::*)(double arg)> commands;
std::vector<std::pair<std::string, double>> command_queue;
std::vector<trigger> triggers;
std::pair<std::string, double> trigger_learning;
std::pair<std::string, double> trigger_unlearning;
void seek(double where) {state.internal_frame = where;}
void stop(double arg) { state.rolling = false;}
void start(double arg) { state.rolling = true;}
void set_recording(double arg) { state.recording = (arg != 0);}
void set_rolling(double arg) { state.rolling = (arg != 0);}
void set_waiting(double arg) { state.wait_for_input = (arg != 0);}
void set_passthrough(double arg) { state.pass_through = (arg != 0);}
void clear_notes(double arg) { store.clear() ;}
};
#endif /* NOTEHANDLER_H */