Submit
Browse
Anonymous
Login
RSS
SuperCollider Code
Fork Code: Makam_tester
name
code content
( //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(); )
code description
use markdown for formating
category tags
comma separated, i.g. "wild, siren" (do not enter default SC class names, please)
ancestor(s)
comma separated identificators, i.g. "1-C,1-1,1-4M,1-x"
Private?
the code will be accessible by direct url and not visible in public activity
signup to submit public code without captcha
comment of change