Repository navigation
Expand file tree
/
Copy pathLooper.cpp
More file actions
99 lines (85 loc) · 2.01 KB
/
Copy pathLooper.cpp
File metadata and controls
99 lines (85 loc) · 2.01 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
89
90
91
92
93
94
95
96
97
98
#include "Looper.h"
#include <iomanip>
MidiLooper::MidiLooper()
{
}
void MidiLooper::advancePlayback(double deltatime)
{
// advance scrubPosition
double newScrubPosition = scrubPosition + deltatime;
if (newScrubPosition >= recordingLength)
{
newScrubPosition -= recordingLength;
}
// find first timestamped event that falls into this range
for (int i=0; i<sequence.size(); ++i)
{
if (sequence[i].deltatime > newScrubPosition)
break;
if (sequence[i].deltatime >= scrubPosition)
{
midiOut[0]->sendMessage(&(sequence[i].message));
// output the MIDI message
std::cout << std::setprecision(10) << std::setw(8)
<< "SCRUB" << '\t'
<< std::setw(8) << deltatime << std::hex;
for (unsigned int i=0; i<sequence[i].message.size(); ++i)
{
std::cout << '\t' << (int)(sequence[i].message.at(i));
}
std::cout << std::dec << '\n';
}
}
scrubPosition = newScrubPosition;
}
void MidiLooper::consumeMidiMessage(double timestamp, std::vector<unsigned char> *message, void *userData)
{
if (recording)
{
sequence.push_back(MidiEvent(
timestamp-recordingStartedTimestamp,
*message));
}
}
int MidiLooper::getLengthInSamples() const
{
}
double MidiLooper::getLengthInSeconds() const
{
return recordingLength;
}
int MidiLooper::getScrubPositionInSamples() const
{
}
double MidiLooper::getScrubPositionInSeconds() const
{
return scrubPosition;
}
void MidiLooper::setRecording(bool recording)
{
if (recording)
{
sequence.empty();
recordingLength = 0;
this->recording = recording;
recordingStartedTimestamp = audio.getStreamTime();
scrubPosition = 0.0;
}
else
{
this->recording = recording;
recordingLength = audio.getStreamTime() - recordingStartedTimestamp;
scrubPosition = 0.0;
std::cout << "loop set: " << recordingLength << "s with " << sequence.size() << " MIDI events" << std::endl;
}
}
bool MidiLooper::getRecording()
{
return recording;
}
// return the state of recording _after_ toggling
bool MidiLooper::toggleRecording()
{
setRecording(!recording);
return recording;
}