File: patch.cpp

package info (click to toggle)
giada 0.15.2%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,700 kB
  • sloc: cpp: 30,043; sh: 1,056; makefile: 422; ansic: 1
file content (231 lines) | stat: -rw-r--r-- 7,417 bytes parent folder | download
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#include "../src/core/patch.h"
#include "../src/core/const.h"
#include "../src/core/types.h"
#include <catch.hpp>


using std::string;
using std::vector;
using namespace giada;
using namespace giada::m;


TEST_CASE("patch")
{
	string filename = "./test-patch.json";

	SECTION("test write")
	{
		patch::action_t  action0;
		patch::action_t  action1;
		patch::channel_t channel1;
		patch::column_t  column;
#ifdef WITH_VST
		patch::plugin_t  plugin1;
		patch::plugin_t  plugin2;
		patch::plugin_t  plugin3;
#endif

		action0.type   = 0;
		action0.frame  = 50000;
		action0.fValue = 0.3f;
		action0.iValue = 1000;
		action1.type   = 2;
		action1.frame  = 589;
		action1.fValue = 1.0f;
		action1.iValue = 130;
		channel1.actions.push_back(action0);
		channel1.actions.push_back(action1);

#ifdef WITH_VST
		plugin1.path   = "/path/to/plugin1";
		plugin1.bypass = false;
		plugin1.params.push_back(0.0f);
		plugin1.params.push_back(0.1f);
		plugin1.params.push_back(0.2f);
		channel1.plugins.push_back(plugin1);

		plugin2.path   = "/another/path/to/plugin2";
		plugin2.bypass = true;
		plugin2.params.push_back(0.6f);
		plugin2.params.push_back(0.6f);
		plugin2.params.push_back(0.6f);
		plugin2.params.push_back(0.0f);
		plugin2.params.push_back(1.0f);
		plugin2.params.push_back(1.0f);
		plugin2.params.push_back(0.333f);
		channel1.plugins.push_back(plugin2);
#endif

		channel1.type              = static_cast<int>(ChannelType::SAMPLE);
		channel1.index             = 666;
		channel1.size              = G_GUI_CHANNEL_H_1;
		channel1.column            = 0;
		channel1.mute              = 0;
		channel1.solo              = 0;
		channel1.volume            = 1.0f;
		channel1.pan               = 0.5f;
		channel1.midiIn            = true;
		channel1.midiInKeyPress    = UINT32_MAX;  // check maximum value
		channel1.midiInKeyRel      = 1;
		channel1.midiInKill        = 2;
		channel1.midiInArm         = 11;
		channel1.midiInVolume      = 3;
		channel1.midiInMute        = 4;
		channel1.midiInSolo        = 5;
		channel1.midiOutL          = true;
		channel1.midiOutLplaying   = 7;
		channel1.midiOutLmute      = 8;
		channel1.midiOutLsolo      = 9;
		channel1.samplePath        = "/tmp/test.wav";
		channel1.key               = 666;
		channel1.mode              = 0;
		channel1.begin             = 0;
		channel1.end               = 0;
		channel1.boost             = 0;
		channel1.recActive         = 0;
		channel1.pitch             = 1.2f;
		channel1.midiInReadActions = 0;
		channel1.midiInPitch       = 0;
		channel1.midiOut           = 0;
		channel1.midiOutChan       = 5;
		patch::channels.push_back(channel1);

		column.index = 0;
		column.width = 500;
		patch::columns.push_back(column);

		patch::header       = "GPTCH";
		patch::version      = "1.0";
		patch::versionMajor = 6;
		patch::versionMinor = 6;
		patch::versionPatch = 6;
		patch::name         = "test patch";
		patch::bpm          = 100.0f;
		patch::bars         = 4;
		patch::beats        = 23;
		patch::quantize     = 1;
		patch::masterVolIn  = 1.0f;
		patch::masterVolOut = 0.7f;
		patch::metronome    = 0;
		patch::lastTakeId   = 0;
		patch::samplerate   = 44100;

#ifdef WITH_VST

		patch::masterInPlugins.push_back(plugin1);
		patch::masterOutPlugins.push_back(plugin2);

#endif

		REQUIRE(patch::write(filename) == 1);
	}

	SECTION("test read")
	{
		REQUIRE(patch::read(filename) == PATCH_READ_OK);
		REQUIRE(patch::header == "GPTCH");
		REQUIRE(patch::version == "1.0");
		REQUIRE(patch::versionMajor == 6);
		REQUIRE(patch::versionMinor == 6);
		REQUIRE(patch::versionPatch == 6);
		REQUIRE(patch::name == "test patch");
		REQUIRE(patch::bpm == Approx(100.0f));
		REQUIRE(patch::bars == 4);
		REQUIRE(patch::beats == 23);
		REQUIRE(patch::quantize == 1);
		REQUIRE(patch::masterVolIn == Approx(1.0f));
		REQUIRE(patch::masterVolOut == Approx(0.7f));
		REQUIRE(patch::metronome == 0);
		REQUIRE(patch::lastTakeId == 0);
		REQUIRE(patch::samplerate == 44100);

		patch::column_t column0 = patch::columns.at(0);
		REQUIRE(column0.index == 0);
		REQUIRE(column0.width == 500);

		patch::channel_t channel0 = patch::channels.at(0);
		REQUIRE(channel0.type == static_cast<int>(ChannelType::SAMPLE));
		REQUIRE(channel0.index == 666);
		REQUIRE(channel0.size == G_GUI_CHANNEL_H_1);
		REQUIRE(channel0.column == 0);
		REQUIRE(channel0.mute == 0);
		REQUIRE(channel0.solo == 0);
		REQUIRE(channel0.volume == Approx(1.0f));
		REQUIRE(channel0.pan == Approx(0.5f));
		REQUIRE(channel0.midiIn == true);
		REQUIRE(channel0.midiInKeyPress == UINT32_MAX);
		REQUIRE(channel0.midiInKeyRel == 1);
		REQUIRE(channel0.midiInKill == 2);
		REQUIRE(channel0.midiInArm == 11);
		REQUIRE(channel0.midiInVolume == 3);
		REQUIRE(channel0.midiInMute == 4);
		REQUIRE(channel0.midiInSolo == 5);
		REQUIRE(channel0.midiOutL == true);
		REQUIRE(channel0.midiOutLplaying == 7);
		REQUIRE(channel0.midiOutLmute == 8);
		REQUIRE(channel0.midiOutLsolo == 9);
		REQUIRE(channel0.samplePath == "/tmp/test.wav");
		REQUIRE(channel0.key == 666);
		REQUIRE(channel0.mode == 0);
		REQUIRE(channel0.begin == 0);
		REQUIRE(channel0.end == 0);
		REQUIRE(channel0.boost == 1.0f);
		REQUIRE(channel0.recActive == 0);
		REQUIRE(channel0.pitch == Approx(1.2f));
		REQUIRE(channel0.midiInReadActions == 0);
		REQUIRE(channel0.midiInPitch == 0);
		REQUIRE(channel0.midiOut == 0);
		REQUIRE(channel0.midiOutChan == 5);

		patch::action_t action0 = channel0.actions.at(0);
		REQUIRE(action0.type == 0);
		REQUIRE(action0.frame == 50000);
		REQUIRE(action0.fValue == Approx(0.3f));
		REQUIRE(action0.iValue == 1000);

		patch::action_t action1 = channel0.actions.at(1);
		REQUIRE(action1.type == 2);
		REQUIRE(action1.frame == 589);
		REQUIRE(action1.fValue == Approx(1.0f));
		REQUIRE(action1.iValue == 130);

#ifdef WITH_VST
		patch::plugin_t plugin0 = channel0.plugins.at(0);
		REQUIRE(plugin0.path   == "/path/to/plugin1");
		REQUIRE(plugin0.bypass == false);
		REQUIRE(plugin0.params.at(0) == Approx(0.0f));
		REQUIRE(plugin0.params.at(1) == Approx(0.1f));
		REQUIRE(plugin0.params.at(2) == Approx(0.2f));

		patch::plugin_t plugin1 = channel0.plugins.at(1);
		REQUIRE(plugin1.path == "/another/path/to/plugin2");
		REQUIRE(plugin1.bypass == true);
		REQUIRE(plugin1.params.at(0) == Approx(0.6f));
		REQUIRE(plugin1.params.at(1) == Approx(0.6f));
		REQUIRE(plugin1.params.at(2) == Approx(0.6f));
		REQUIRE(plugin1.params.at(3) == Approx(0.0f));
		REQUIRE(plugin1.params.at(4) == Approx(1.0f));
		REQUIRE(plugin1.params.at(5) == Approx(1.0f));
		REQUIRE(plugin1.params.at(6) == Approx(0.333f));

		patch::plugin_t masterPlugin0 = patch::masterInPlugins.at(0);
		REQUIRE(masterPlugin0.path   == "/path/to/plugin1");
		REQUIRE(masterPlugin0.bypass == false);
		REQUIRE(masterPlugin0.params.at(0) == Approx(0.0f));
		REQUIRE(masterPlugin0.params.at(1) == Approx(0.1f));
		REQUIRE(masterPlugin0.params.at(2) == Approx(0.2f));

		patch::plugin_t masterPlugin1 = patch::masterOutPlugins.at(0);
		REQUIRE(masterPlugin1.path == "/another/path/to/plugin2");
		REQUIRE(masterPlugin1.bypass == true);
		REQUIRE(masterPlugin1.params.at(0) == Approx(0.6f));
		REQUIRE(masterPlugin1.params.at(1) == Approx(0.6f));
		REQUIRE(masterPlugin1.params.at(2) == Approx(0.6f));
		REQUIRE(masterPlugin1.params.at(3) == Approx(0.0f));
		REQUIRE(masterPlugin1.params.at(4) == Approx(1.0f));
		REQUIRE(masterPlugin1.params.at(5) == Approx(1.0f));
		REQUIRE(masterPlugin1.params.at(6) == Approx(0.333f));
#endif
	}
}