«Makam_tester» by mahatGma

on 16 Dec'14 23:39 in maqam music trainer
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
(
//developed by Aykut Caglayan aykut_caglayan@yahoo.com//
//depends on turkish music database SymbTr http://compmusic.upf.edu/node/140//

//!! give the path for SymbTr txt database //
var myPath = PathName.new("~/SymbTr-2.0/txt/");

var file_array = Array.new(myPath.files.size);

var makam_list = Set.new;
var makam_window, sel_makam_set=Set(), sel_makam_w;
var ask_button;
var pick_a_makam, picked_makam_name;

var makam_name_slots = Set.new;

var makam_slots_dict = Dictionary.new();
var player_instance;
var user_answer_input;
var main_window_creator, makam_option_button_creator, selection_window_creator, ask_button_creator, answer_button_creator, answer_button_adder, answer_buttons_creator;
var explanation_text;
var make_pb_slider, playback_speed=1, pb_slider;

s.waitForBoot();


//the beginning of path//
//y = "~/".standardizePath ++ "database_txt/";
//y = myPath.fullPath ++ "/";
y = myPath.fullPath;


//list files in the folder//
myPath = myPath.files;


myPath.size.do{|i|
	file_array.insert(
		i,
		myPath[i].fullPath.asString;
)};





pick_a_makam = {
	while ( {})};


myPath.do({arg item;
	//item = item.fullPath.asString;
	var makam_name_pos;
	item = item.fullPath;
	makam_name_pos = item.find("--")-1; //end of the makam name in the path string//
	item = item.at((y.size..makam_name_pos)).collectAs({arg item; item}, String);

	makam_list.add(item);
});




//;converts Holdrian comma value to Hz//
~hc = {arg comma;
	var hc = (1200 / 53);
	((hc * comma.asInteger)/100).midicps;
};

//the most simple synth//
SynthDef("kal", {
	arg freq, dur;
	var sig, env;
	//dur = dur * playback_speed;
	env = EnvGen.kr(Env.perc(0.01, dur), doneAction:2);
	sig = SinOsc.ar(freq)*env;
	Out.ar(0, Pan2.ar(sig));
}).add;

//input the path as string//
~simple_read = {arg file;
	var a = TabFileReader.read(file, true);
	{a.size.do {arg i; var am, in, freq, dur;
		in = i+2;
		am = a[in][8];
		am = am.asInteger/1000;
		am = am*playback_speed;
		freq = a[in][5];
		freq=~hc.value(freq);
		Synth("kal", [\freq, freq, \dur, am]);
		am.wait;}
}.fork;};




//fills makam_slot_dictionary with makam names as keys//
makam_list.do({arg i;
	makam_slots_dict.put(i, List.new());
	//i.postln;
});


//in order to shorten the time for choosing a makam randomly from the optional pool//
//what program does is, index the makam files accordingly, and store them in the dictionary//
makam_list.do({arg name;
	name = name ++ "--";
	file_array.size.do({arg index2; var path, indexSet;
		path = file_array[index2].asString;
		if (
			path.containsStringAt(y.size, name),
			{
				//makam_slots_file.write([name, index2].asString ++ "\n");
				makam_slots_dict[(name.replace("--",""))].add(index2);
				makam_name_slots.add([name, index2]);},
			{});
	});


});



//main makam window creater//
main_window_creator = {
	makam_window = Window.new("makams", Rect(100, 100, 900, 600));
	makam_window.view.decorator = FlowLayout(makam_window.view.bounds);
	makam_window.front;

	makam_option_button_creator.value();
};


makam_option_button_creator = {
	makam_list.size.do{arg i;
		var makam_name, makam_name_o;
		makam_name = makam_list.asArray.sort[i];
		makam_name_o = makam_name;

		makam_name_o = Button(makam_window, Rect(10, i*22, 105, 20))

		.states_([
			[makam_name, Color.white, Color.grey],
			[makam_name, Color.black, Color.green]])
		.action_({ arg butt;
			if (butt.value == 1,
				{ sel_makam_set.add(makam_name_o.states[0][0]);
					player_instance.stop;
					sel_makam_set.postcs;
					answer_button_adder.value(makam_name_o.states[0][0]); //!!!
					sel_makam_w.front;
			},

				{ sel_makam_set.remove(makam_name_o.states[0][0]); //sel_button.close;
				sel_makam_set.postcs;
				sel_makam_w.close;
				selection_window_creator.value();
				ask_button_creator.value();
					//make_pb_slider.value();


				answer_buttons_creator.value();
			},

	)});
}};

selection_window_creator = {
	sel_makam_w = Window.new("selection", Rect(1200, 100, 120, 600));
	sel_makam_w.view.decorator = FlowLayout(sel_makam_w.view.bounds);
	make_pb_slider.value();

};

ask_button_creator = {
	var ask_button;
	ask_button = Button(sel_makam_w, Rect(10, 10, 50, 25))
	.states_([
		["Go", Color.black, Color.yellow],
		["Guess", Color.black, Color.green]])
	.action_({ arg butt;
		if (butt.value == 1,
			{ var sel;
				sel = sel_makam_set.asArray.choose;
				picked_makam_name = sel;

				sel = makam_slots_dict.at(sel).choose.postcs;
				player_instance = ~simple_read.value(file_array[sel])
			},
			{ player_instance.stop})
	});
};


answer_button_adder = {
	arg name;
	var makam_name_s = name, pos;
	pos = sel_makam_set.size-1;
	makam_name_s = Button(sel_makam_w, Rect(4, pos*22, 105, 20))
	.states_([
		[name, Color.white, Color.grey]])

	.mouseDownAction_({
		user_answer_input = makam_name_s.states[0][0];
		user_answer_input.postcs;
		if ( user_answer_input == picked_makam_name,
			{true.postln;
				makam_name_s.states = [[makam_name_s.states[0][0], Color.black, Color.green]]},
			{false.postln;
				makam_name_s.states = [[makam_name_s.states[0][0], Color.green, Color.red]]});

	})
	.mouseUpAction_({
		makam_name_s.states = [[makam_name_s.states[0][0], Color.white, Color.grey]]
	});


};


answer_buttons_creator = {
	//arg i, sel_button, button_name_org;
	sel_makam_set.size.do{arg i;
		var makam_name = sel_makam_set.asArray.sort[i];
		var makam_name_s = makam_name;
		makam_name_s = Button(sel_makam_w, Rect(4, 22*i, 105, 20)) //!!!//
		.states_([
			[makam_name, Color.white, Color.grey]])
		.mouseDownAction_({
			user_answer_input = makam_name_s.states[0][0];
			user_answer_input.postcs;
			if ( user_answer_input == picked_makam_name,
				{true.postln;
					makam_name_s.states = [[makam_name_s.states[0][0], Color.black, Color.green]]},
				{false.postln;
					makam_name_s.states = [[makam_name_s.states[0][0], Color.green, Color.red]]});

		})
		.mouseUpAction_({
			makam_name_s.states = [[makam_name_s.states[0][0], Color.white, Color.grey]]
		});
	};
	sel_makam_w.front;
};


//playback speed slider//
make_pb_slider = {
	pb_slider = Slider(sel_makam_w, Rect(60, 10, 100, 25))
	.value_(0.5)
	.action_({playback_speed = pb_slider.value.linlin(0, 1, 4, 0.25)});
};



//creates the ListView GUI//

main_window_creator.value();

selection_window_creator.value();
ask_button_creator.value();


)
raw 6566 chars (focus & ctrl+a+c to copy)
reception
comments
mahatGma user 16 Dec'14 23:41

In order to run this code, you should download turkish music datase SymbTr via https://github.com/MTG/SymbTr/archive/v2.0.0.zip and change the 6th line of code accroding to the path of SymbTr/txt/ folder