«Scale Listener» by Dindoléon

on 13 Feb'20 09:23 in guihelperscalepreviewdidactic

The Scale Listener is a simple GUI that previews every scale provided in SC, except Ascending/Descending ones. Can also serve as a template for a graphical scale selector, or for didactic purposes.

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
(

// Not refenrencing Ascending/descending scales
// See Scale.sc

var pentatonic_scales = [ \minorPentatonic, \majorPentatonic, \ritusen, \egyptian, \prometheus, \scriabin ];
var pentatonic_asian_scales = [ \kumoi, \hirajoshi, \iwato, \chinese, \indian, \pelog ];
var pentatonic_chinese_han_scales = [ \gong, \shang, \jiao, \zhi, \yu ];
var hexa_scales = [ \whole, \augmented, \augmented2 ];
var hexatonic_no_tritones_modes = [ \hexMajor7, \hexDorian, \hexPhrygian, \hexSus, \hexMajor6, \hexAeolian ];
var partch_otonalities = [ \partch_o1, \partch_o2, \partch_o3, \partch_o4, \partch_o5, \partch_o6 ];
var partch_utonalities = [ \partch_u1, \partch_u2, \partch_u3, \partch_u4, \partch_u5, \partch_u6 ];
var western_modes = [ \major, \dorian, \phrygian, \lydian, \mixolydian, \minor, \locrian ];
var western_harmo_melo_modes = [ \harmonicMinor, \harmonicMajor, \melodicMinor, \melodicMinorDesc, \melodicMajor ];
var hepta_other_modes = [ \hindu, \spanish, \bartok, \superLocrian, \romanianMinor, \hungarianMinor, \neapolitanMinor, \enigmatic ];
var raga_modes = [ \todi, \purvi, \marva, \bhairav, \ahirbhairav ];
var whole_tones_added = [ \leadingWhole, \lydianMinor, \neapolitanMajor, \locrianMajor ];
var eight_plus_scales = [ \diminished, \diminished2, \chromatic, \chromatic24 ];
var maqam_ajam = [ \ajam, \jiharkah, \shawqAfza ];
var maqam_sikah = [ \sikah, \sikahDesc, \huzam, \iraq, \bastanikar, \mustar ];
var maqam_bayati = [ \bayati, \karjighar, \husseini ];
var maqam_nahawand = [ \nahawand, \nahawandDesc, \farahfaza, \murassah, \ushaqMashri ];
var maqam_rast = [ \rast, \rastDesc, \suznak, \nairuz, \yakah, \yakahDesc, \mahur ];
var maqam_hijaz = [ \hijaz, \hijazDesc, \zanjaran, \hijazKar ];
var maqam_saba = [ \saba, \zamzam ];
var maqam_kurd = [ \kurd, \kijazKarKurd ];
var maqam_nawa_athar = [ \nawaAthar, \nikriz, \atharKurd ];

var all_groups = [ pentatonic_scales, pentatonic_asian_scales, pentatonic_chinese_han_scales, hexa_scales, hexatonic_no_tritones_modes, partch_otonalities, partch_utonalities, western_modes, western_harmo_melo_modes, hepta_other_modes, raga_modes, whole_tones_added, eight_plus_scales, maqam_ajam, maqam_sikah, maqam_bayati, maqam_nahawand, maqam_rast, maqam_hijaz, maqam_saba, maqam_kurd, maqam_nawa_athar ];

var group_names = [ "Pentatonic Scales", "Asian Pentatonic Scales", "Han Chinese Pentatonic Scales", "Six Notes Scales", "Hexatonic Modes With no Tritone", "Partch's Otonalities", "Partch's Utonalities", "Tonal modes", "Tonal harmonics and melodics modes", "Other heptatonic modes", "Raga modes", "Modes of whole tones with added note", "Eight, twelve and twenty-four notes modes", "Maqam Ajam", "Maqam Sikah", "Maqam Bayati", "Maqam Nahawand", "Maqam Rast", "Maqam Hijaz and HijazKar", "Maqam Saba", "Maqam Kurd", "Maqam Nawa Athar", "Maqam Bayati" ];

var view = Window.new( "Scale Listener", Rect.new( 0, 0, 1500, 700 ) );
var subview = UserView.new( view, Rect( 0, 0, view.bounds.width, view.bounds.height * 0.2 * all_groups.size ) );

var slider = Slider.new( view, Rect( view.bounds.width * 0.95, 0, view.bounds.width * 0.05, view.bounds.height ) );

var margin = 5;

var play_scale = { | symbol |
	Pbind(
		\instrument, \simple_sine,
		\dur, 0.333,
		\freq, Pseq( ( 440 * Scale.at( symbol ).ratios ++ [ 880 ] ) )
	).play
};

SynthDef(\simple_sine, {
	| out = 0, amp = 0.25, freq = 110 |
	var snd, env, envctl, envgen;
	env = Env.perc( 0.01, 0.666 );
	envgen = EnvGen.kr( env, doneAction: Done.freeSelf );
	snd = SinOsc.ar( [ freq, freq ], mul: 0.5 * amp * envgen );
	Out.ar( out, snd );
}).add;

all_groups.do( { | group, i |

	var group_title = StaticText.new( subview, Rect.new( 0, view.bounds.height * 0.2 * i, view.bounds.width, view.bounds.height * 0.1 ) ).string_( group_names[ i ] ).align_( \center );

	var button_width = view.bounds.width * 0.95 - ( margin + 1 * group.size ) / group.size;

	group.do( { | symbol, j |
		var b = Button.new( subview, Rect.new( margin + ( ( button_width + margin ) * j ), view.bounds.height * 0.2 * i + ( view.bounds.height * 0.1 ), button_width, view.bounds.height * 0.1 ) );
		b.states = [ [ Scale.at( symbol ).name, Color.white, Color.black ] ];
		b.action = { play_scale.value( symbol ) };
	} );

} );
slider.value = 1;
slider.step = ( 1 / ( all_groups.size - 5 ) );
slider.thumbSize = ( view.bounds.height / ( all_groups.size - 5 ) );
slider.action = {
	var value = slider.value.linlin( 0, 1, subview.bounds.height - view.bounds.height, 0 );
	subview.moveTo( 0, 0-value );
};

// Finally, bring the window to the front.
view.front;
CmdPeriod.doOnce({Window.closeAll}); // Kill GUI and server sounds on < Ctrl + ^ + . >, or on window closing .
view.onClose = {
	s.freeAll;
	Window.closeAll;
};

)
raw 4792 chars (focus & ctrl+a+c to copy)
reception
comments