-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.cpp
More file actions
86 lines (71 loc) · 2.22 KB
/
main.cpp
File metadata and controls
86 lines (71 loc) · 2.22 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
#include <tracktion_engine/tracktion_engine.h>
namespace te = tracktion;
using namespace std::literals;
using namespace te::literals;
static void addNoteToClip(
te::MidiClip *midiClip,
int noteNumber,
int velocity,
te::BeatPosition start,
te::BeatDuration duration)
{
midiClip->getSequence().addNote(
noteNumber,
start,
duration,
velocity,
0,
nullptr);
}
int main()
{
// Create the engine
te::Engine engine{"Tracktion Hello World"};
// Create an edit
te::Edit edit{
engine,
te::createEmptyEdit(engine),
te::Edit::forEditing,
nullptr,
0};
// Create a track
edit.ensureNumberOfAudioTracks(1);
auto track = te::getAudioTracks(edit)[0];
// Get length of 1 bar
const tracktion::TimeRange oneBarTimeRange(
0s,
edit.tempoSequence.toTime({1, tracktion::BeatDuration()}));
// Insert a 1 bar long Midi clip
auto clip = track->insertNewClip(
te::TrackItem::Type::midi,
"Midi Clip",
oneBarTimeRange,
nullptr);
auto midiClip = static_cast<te::MidiClip *>(clip);
// Add a 4-note C-E-G-C sequence to the clip
// Note the use of Tracktion's beat position/duration literals
addNoteToClip(midiClip, 60, 100, 0_bp, 0.5_bd);
addNoteToClip(midiClip, 64, 100, 1_bp, 0.5_bd);
addNoteToClip(midiClip, 67, 100, 2_bp, 0.5_bd);
addNoteToClip(midiClip, 72, 100, 3_bp, 0.5_bd);
// Create a built-in synth plugin instance to play the sequence on
auto plugin = edit.getPluginCache()
.createNewPlugin(te::FourOscPlugin::xmlTypeName, {})
.get();
auto fourOscPlugin = static_cast<te::FourOscPlugin *>(plugin);
// Insert the plugin to the track
track->pluginList.insertPlugin(*fourOscPlugin, 0, nullptr);
// Get the transport & set it to the start of the edit
auto &transport = edit.getTransport();
transport.setPosition(0s);
// Set the transport to loop our clip
transport.setLoopRange(clip->getEditTimeRange());
transport.looping = true;
// Begin playback
transport.play(false);
// Dance while the record spins
while (true)
{
}
return 0;
}