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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
|
import pygtk
pygtk.require('2.0')
import gtk
from Util.Profiler import TP
import gobject
import time
import shelve
from gettext import gettext as _
import os
from sugar.graphics.toolcombobox import ToolComboBox
from Util.ThemeWidgets import BigComboBox
import Config
from Util.ThemeWidgets import *
from Util.CSoundClient import new_csound_client
from SynthLab.SynthObjectsParameters import SynthObjectsParameters
from SynthLab.SynthLabConstants import SynthLabConstants
from SynthLab.SynthLabToolbars import mainToolbar
from SynthLab.SynthLabToolbars import presetToolbar
from Util.Trackpad import Trackpad
from SubActivity import SubActivity
Tooltips = Config.Tooltips
as_window = False
class SynthLabWindow(SubActivity):
def __init__( self, activity, set_mode, dummy_to_change_signature ):
SubActivity.__init__(self, set_mode)
if as_window:
color = gtk.gdk.color_parse(Config.PANEL_BCK_COLOR)
self.modify_bg(gtk.STATE_NORMAL, color)
self.set_border_width(Config.MAIN_WINDOW_PADDING)
self.set_keep_above(False)
self.set_decorated(False)
self.activity = activity
self.csnd = new_csound_client()
self.trackpad = Trackpad( self )
self.synthObjectsParameters = SynthObjectsParameters()
self.resetLocations()
self.objectCount = len(self.locations)
self.connections = []
self.initializeConnections()
self.bounds = []
for i in range(self.objectCount):
self.bounds.append([0,0,0,0])
self.updateBounds(i)
self.instanceOpen = 0
self.recordWait = 0
self.recCount = 0
self.duration = 2
self.new = True
self.viewType = ''
self.viewParam = ''
self.curSlider = 1
self.durString = '%.2f' % self.duration
self.playingPitch = []
self.journalCalled = True
#Toolbars
self.activity.activity_toolbar.keep.show()
self._mainToolbar = mainToolbar(self.activity.toolbox, self)
self._presetToolbar = presetToolbar(self.activity.toolbox, self)
self.activity.toolbox.add_toolbar(_('Main'), self._mainToolbar)
self.activity.toolbox.add_toolbar(_('Presets'), self._presetToolbar)
self.activity.toolbox.set_current_toolbar(1)
self._mainToolbar.show()
self._presetToolbar.show()
loopPointsTable = []
sample_names = [name for i in range( len( Config.INSTRUMENTS ) ) for name in Config.INSTRUMENTS.keys() if Config.INSTRUMENTS[ name ].instrumentId == i ]
for inst in sample_names:
loopStart = Config.INSTRUMENTS[ inst ].loopStart
loopEnd = Config.INSTRUMENTS[ inst ].loopEnd
crossDur = Config.INSTRUMENTS[ inst ].crossDur
loopPointsTable.extend( [ loopStart, loopEnd, crossDur ] )
mess = "f5755 0 512 -2 " + " " .join([str(n) for n in loopPointsTable])
self.csnd.inputMessage( mess )
self.lineWidth = 3
self.lineWidthMUL2 = self.lineWidth*2
self.lineWidthMUL4 = self.lineWidth*4
self.lineWidthMUL4SQ = self.lineWidthMUL4*self.lineWidthMUL4
self.clockStart = 0
self.sample_names = [name for i in range( len( Config.INSTRUMENTS ) ) for name in Config.INSTRUMENTS.keys() if Config.INSTRUMENTS[ name ].instrumentId == i ]
self.tooltips = gtk.Tooltips()
if as_window:
self.add_events(gtk.gdk.KEY_PRESS_MASK|gtk.gdk.KEY_RELEASE_MASK)
self.action = None
self.dragObject = None
self.overWire = None
self.overGate = None
self.overGateObj = None
self.overGateReject = False
self.overGateSize = 32
self.overGateSizeDIV2 = self.overGateSize//2
self.overLineWidth = self.lineWidth*2
self.overLineWidthMUL2 = self.overLineWidth*2
self.gatePoint = SynthLabConstants.GATE_POINT
self.gateMap = SynthLabConstants.GATE_MAP
# look up gate type to find the matching gate type
self.gateMatch = [ SynthLabConstants.GT_CONTROL_INPUT,
SynthLabConstants.GT_CONTROL_OUTPUT,
SynthLabConstants.GT_SOUND_INPUT,
SynthLabConstants.GT_SOUND_OUTPUT ]
# set up window
if as_window:
self.set_position( gtk.WIN_POS_CENTER_ON_PARENT )
self.set_title("Synth Lab")
self.mainBox = gtk.HBox()
self.subBox = gtk.HBox()
self.drawingBox = RoundVBox( 10, Config.PANEL_COLOR, Config.PANEL_COLOR )
self.drawingBox.set_border_width(Config.PANEL_SPACING)
self.infoBox = RoundVBox( 10, Config.TOOLBAR_BCK_COLOR, Config.TOOLBAR_BCK_COLOR )
self.infoBox.set_border_width(Config.PANEL_SPACING)
self.infoBox.set_size_request(300, 750)
self.subBox.pack_start(self.drawingBox, True, True)
self.subBox.pack_start(self.infoBox, True, True)
self.mainBox.pack_start(self.subBox)
menuBox = gtk.HBox()
self.objComboBox = BigComboBox()
self.objComboBox.append_item(0, 'adsr', Config.IMAGE_ROOT + '/adsr.png')
self.objComboBox.set_active(0)
self.objComboBox.connect('changed', self.changeObject)
comboMenu = ToolComboBox(self.objComboBox)
menuBox.pack_start(comboMenu)
self.infoBox.pack_start(menuBox, False, False, 5)
slidersBox = gtk.HBox()
#fake values
self.instanceID = 12 # object number
self.objectType = self.instanceID / 4 #(control, source, fx, output)
self.choosenType = 0 # self.synthObjectsParameters.types[self.instanceID] module as an index
selectedType = SynthLabConstants.CHOOSE_TYPE[self.objectType][self.choosenType] #module as a string
slider1Min = SynthLabConstants.TYPES[selectedType][4]
slider1Max = SynthLabConstants.TYPES[selectedType][5]
slider2Min = SynthLabConstants.TYPES[selectedType][6]
slider2Max = SynthLabConstants.TYPES[selectedType][7]
slider3Min = SynthLabConstants.TYPES[selectedType][8]
slider3Max = SynthLabConstants.TYPES[selectedType][9]
slider4Min = SynthLabConstants.TYPES[selectedType][10]
slider4Max = SynthLabConstants.TYPES[selectedType][11]
slider1Step = SynthLabConstants.TYPES[selectedType][12][0]
slider1Snap = SynthLabConstants.TYPES[selectedType][12][1]
slider2Step = SynthLabConstants.TYPES[selectedType][13][0]
slider2Snap = SynthLabConstants.TYPES[selectedType][13][1]
slider3Step = SynthLabConstants.TYPES[selectedType][14][0]
slider3Snap = SynthLabConstants.TYPES[selectedType][14][1]
parametersTable = self.synthObjectsParameters.choiceParamsSet[self.objectType]
tablePos = (self.instanceID % 4)*4
slider1Init = parametersTable[tablePos]
slider2Init = parametersTable[tablePos+1]
slider3Init = parametersTable[tablePos+2]
slider4Init = parametersTable[tablePos+3]
sliderTextColor = gtk.gdk.color_parse(Config.WHITE_COLOR)
sliderHeight = 268
self.p1Adjust = gtk.Adjustment(slider1Init, slider1Min, slider1Max, slider1Step, slider1Step, 0)
self.p1Adjust.connect("value-changed", self.sendTables, 1)
self.slider1 = gtk.VScale(self.p1Adjust)
self.slider1.connect("button-release-event", self.handleSliderRelease)
self.slider1.connect("enter-notify-event", self.handleSliderEnter, 1)
self.slider1.set_digits(slider1Snap)
self.slider1.set_inverted(True)
self.slider1.set_size_request(55, sliderHeight)
self.slider1.modify_fg(gtk.STATE_NORMAL, sliderTextColor)
slidersBox.pack_start(self.slider1, True, False)
self.p2Adjust = gtk.Adjustment(slider2Init, slider2Min, slider2Max, slider2Step, slider2Step, 0)
self.p2Adjust.connect("value-changed", self.sendTables, 2)
self.slider2 = gtk.VScale(self.p2Adjust)
self.slider2.connect("button-release-event", self.handleSliderRelease)
self.slider2.connect("enter-notify-event", self.handleSliderEnter, 2)
self.slider2.set_digits(slider2Snap)
self.slider2.set_inverted(True)
self.slider2.set_size_request(55, sliderHeight)
self.slider2.modify_fg(gtk.STATE_NORMAL, sliderTextColor)
slidersBox.pack_start(self.slider2, True, False)
self.p3Adjust = gtk.Adjustment(slider3Init, slider3Min, slider3Max, slider3Step, slider3Step, 0)
self.p3Adjust.connect("value-changed", self.sendTables, 3)
self.slider3 = gtk.VScale(self.p3Adjust)
self.slider3.connect("button-release-event", self.handleSliderRelease)
self.slider3.connect("enter-notify-event", self.handleSliderEnter, 3)
self.slider3.set_digits(slider3Snap)
self.slider3.set_inverted(True)
self.slider3.set_size_request(55, sliderHeight)
self.slider3.modify_fg(gtk.STATE_NORMAL, sliderTextColor)
slidersBox.pack_start(self.slider3, True, False)
self.p4Adjust = gtk.Adjustment(slider4Init, slider4Min, slider4Max, .01, .01, 0)
self.p4Adjust.connect("value-changed", self.sendTables, 4)
self.slider4 = gtk.VScale(self.p4Adjust)
self.slider4.connect("button-release-event", self.handleSliderRelease)
self.slider4.connect("enter-notify-event", self.handleSliderEnter, 4)
self.slider4.set_digits(2)
self.slider4.set_inverted(True)
self.slider4.set_size_request(55, sliderHeight)
self.slider4.modify_fg(gtk.STATE_NORMAL, sliderTextColor)
slidersBox.pack_start(self.slider4, True, False)
self.infoBox.pack_start(slidersBox, False, False, 5)
self.infoText = 'ADSR envelope apply on the overall signal'
textBox = gtk.HBox()
textScroller = gtk.ScrolledWindow()
textScroller.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
textScroller.set_size_request(270, 310)
self.textBuf = gtk.TextBuffer(None)
self.textBuf.set_text(self.infoText)
self.textViewer = gtk.TextView(self.textBuf)
self.textViewer.set_wrap_mode(gtk.WRAP_WORD)
self.textViewer.set_editable(False)
self.textViewer.set_overwrite(True)
self.textViewer.set_cursor_visible(False)
self.textViewer.set_left_margin(10)
self.textViewer.set_right_margin(10)
self.textViewer.set_justification(gtk.JUSTIFY_LEFT)
textScroller.add(self.textViewer)
textBox.pack_start(textScroller, False, False, 10)
self.infoBox.pack_start(textBox, False, False, 5)
self.infoLabel = gtk.Label()
self.infoBox.pack_end(self.infoLabel, False, False, 20)
textColor = gtk.gdk.color_parse(Config.WHITE_COLOR)
self.infoLabel.modify_fg(gtk.STATE_NORMAL, textColor)
self.drawingAreaWidth = 900
self.drawingAreaHeight = 750
self.separatorY = 660
self.clearMask = gtk.gdk.Rectangle(0,0,self.drawingAreaWidth,self.drawingAreaHeight)
win = gtk.gdk.get_default_root_window()
self.gc = gtk.gdk.GC( win )
self.gc.set_line_attributes( self.lineWidth, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_BUTT, gtk.gdk.JOIN_MITER )
self.dirtyRectToAdd = gtk.gdk.Rectangle()
self.dirty = False
self.screenBuf = gtk.gdk.Pixmap( win, self.drawingAreaWidth, self.drawingAreaHeight )
self.screenBufDirtyRect = gtk.gdk.Rectangle()
self.screenBufDirty = False
self.drawingArea = gtk.DrawingArea()
self.drawingArea.set_size_request( self.drawingAreaWidth, self.drawingAreaHeight )
self.col = gtk.gdk.color_parse(Config.PANEL_COLOR)
colormap = self.drawingArea.get_colormap()
self.bgColor = colormap.alloc_color( Config.PANEL_COLOR, True, True )
self.lineColor = colormap.alloc_color( Config.SL_LINE_COLOR, True, True )
self.highlightColor = colormap.alloc_color( Config.SL_HIGHLIGHT_COLOR, True, True )
self.overWireColor = colormap.alloc_color( Config.SL_OVER_WIRE_COLOR, True, True )
self.overGateColor = colormap.alloc_color( Config.SL_OVER_GATE_COLOR, True, True )
self.overGateRejectColor = colormap.alloc_color( Config.SL_OVER_GATE_REJECT_COLOR, True, True )
self.drawingArea.modify_bg(gtk.STATE_NORMAL, self.col)
self.drawingArea.add_events( gtk.gdk.BUTTON_PRESS_MASK
| gtk.gdk.BUTTON_RELEASE_MASK
| gtk.gdk.POINTER_MOTION_MASK
| gtk.gdk.POINTER_MOTION_HINT_MASK )
self.drawingArea.connect( "button-press-event", self.handleButtonPress )
self.drawingArea.connect( "button-release-event", self.handleButtonRelease )
self.drawingArea.connect( "motion-notify-event", self.handleMotion )
self.drawingArea.connect("expose-event", self.draw)
self.drawingBox.pack_start(self.drawingArea, False, False, 5)
tempFile = 'synthTemp'
if tempFile in os.listdir(Config.PREF_DIR):
self.handleLoadTemp()
else:
self.presetCallback(None,1)
self.add(self.mainBox)
self.show_all()
def onDestroy(self):
pass
def select(self, i):
if i == self.instanceID:
return
self.new = False
if self.instanceID > 0:
self.invalidate_rect( self.bounds[self.instanceID][0], self.bounds[self.instanceID][1]-2, SynthLabConstants.PIC_SIZE, SynthLabConstants.PIC_SIZE_HIGHLIGHT )
self.instanceID = i
self.invalidate_rect( self.bounds[i][0], self.bounds[i][1]-2, SynthLabConstants.PIC_SIZE, SynthLabConstants.PIC_SIZE_HIGHLIGHT )
if self.instanceID / 4 != self.objectType:
self.objectType = self.instanceID / 4
self.objComboBox.remove_all()
for obj in SynthLabConstants.CHOOSE_TYPE[self.objectType]:
self.objComboBox.append_item(SynthLabConstants.CHOOSE_TYPE[self.objectType].index(obj), obj, Config.IMAGE_ROOT + '/' + obj + '.png')
oldChoosen = self.choosenType
if self.instanceID != 12:
self.choosenType = self.synthObjectsParameters.types[self.instanceID]
else:
self.choosenType = 0
self.objComboBox.set_active(self.choosenType)
if self.choosenType == oldChoosen:
self.changeObject(self.objComboBox)
else:
self.updateViewer()
#Not sure about this
self.slider1.grab_focus()
self.sendTables(self.slider1, 1)
def changeObject(self, widget):
self.choosenType = widget.props.value
self.resize()
self.synthObjectsParameters.setType(self.instanceID, self.choosenType)
self.writeTables( self.synthObjectsParameters.types, self.synthObjectsParameters.controlsParameters,
self.synthObjectsParameters.sourcesParameters, self.synthObjectsParameters.fxsParameters )
self.updateViewer()
def updateViewer(self):
self.viewType = Tooltips.SYNTHTYPES[self.objectType][self.choosenType]
selectedType = SynthLabConstants.CHOOSE_TYPE[self.objectType][self.choosenType]
self.viewParam = Tooltips.SYNTHPARA[selectedType][self.curSlider-1] + ': ' + self.recallSliderValue(self.curSlider)
self.infoText = self.viewType + '\n\n' + self.viewParam
self.textBuf.set_text(self.infoText)
def recallSliderValue( self, num ):
if num == 1:
if Tooltips.SYNTHTYPES[self.objectType][self.choosenType] == Tooltips.NOISE:
return Tooltips.NOISE_TYPES[int(self.slider1Val)]
else:
return '%.2f' % self.slider1Val
if num == 2:
if Tooltips.SYNTHTYPES[self.objectType][self.choosenType] == Tooltips.VCO:
return Tooltips.VCO_WAVEFORMS[int(self.slider2Val)]
elif Tooltips.SYNTHTYPES[self.objectType][self.choosenType] == Tooltips.SAMPLE or Tooltips.SYNTHTYPES[self.objectType][self.choosenType] == Tooltips.GRAIN:
return self.sample_names[int(self.slider2Val)]
elif Tooltips.SYNTHTYPES[self.objectType][self.choosenType] == Tooltips.VOICE:
return Tooltips.VOWEL_TYPES[int(self.slider2Val)]
else:
return '%.2f' % self.slider2Val
if num == 3:
if Tooltips.SYNTHTYPES[self.objectType][self.choosenType] == Tooltips.LFO:
return Tooltips.LFO_WAVEFORMS[int(self.slider3Val)]
elif Tooltips.SYNTHTYPES[self.objectType][self.choosenType] == Tooltips.TRACKPADX:
return Tooltips.SCALING_TYPES[int(self.slider3Val)]
elif Tooltips.SYNTHTYPES[self.objectType][self.choosenType] == Tooltips.TRACKPADY:
return Tooltips.SCALING_TYPES[int(self.slider3Val)]
elif Tooltips.SYNTHTYPES[self.objectType][self.choosenType] == Tooltips.FILTER:
return Tooltips.FILTER_TYPES[int(self.slider3Val)]
elif Tooltips.SYNTHTYPES[self.objectType][self.choosenType] == Tooltips.RINGMOD:
return Tooltips.LFO_WAVEFORMS[int(self.slider3Val)]
else:
return '%.2f' % self.slider3Val
if num == 4: return '%.2f' % self.slider4Val
def resize( self ):
selectedType = SynthLabConstants.CHOOSE_TYPE[self.objectType][self.choosenType]
if self.new:
slider1Init = SynthLabConstants.TYPES[selectedType][0]
slider2Init = SynthLabConstants.TYPES[selectedType][1]
slider3Init = SynthLabConstants.TYPES[selectedType][2]
slider4Init = SynthLabConstants.TYPES[selectedType][3]
else:
parametersTable = self.synthObjectsParameters.choiceParamsSet[self.objectType]
tablePos = (self.instanceID % 4)*4
slider1Init = parametersTable[tablePos]
slider2Init = parametersTable[tablePos+1]
slider3Init = parametersTable[tablePos+2]
slider4Init = parametersTable[tablePos+3]
slider1Min = SynthLabConstants.TYPES[selectedType][4]
slider1Max = SynthLabConstants.TYPES[selectedType][5]
slider2Min = SynthLabConstants.TYPES[selectedType][6]
slider2Max = SynthLabConstants.TYPES[selectedType][7]
slider3Min = SynthLabConstants.TYPES[selectedType][8]
slider3Max = SynthLabConstants.TYPES[selectedType][9]
slider4Min = SynthLabConstants.TYPES[selectedType][10]
slider4Max = SynthLabConstants.TYPES[selectedType][11]
slider1Step = SynthLabConstants.TYPES[selectedType][12][0]
slider1Snap = SynthLabConstants.TYPES[selectedType][12][1]
slider2Step = SynthLabConstants.TYPES[selectedType][13][0]
slider2Snap = SynthLabConstants.TYPES[selectedType][13][1]
slider3Step = SynthLabConstants.TYPES[selectedType][14][0]
slider3Snap = SynthLabConstants.TYPES[selectedType][14][1]
self.p1Adjust.set_all(slider1Init, slider1Min, slider1Max, slider1Step, slider1Step, 0)
self.p2Adjust.set_all(slider2Init, slider2Min, slider2Max, slider2Step, slider2Step, 0)
self.p3Adjust.set_all(slider3Init, slider3Min, slider3Max, slider3Step, slider3Step, 0)
self.p4Adjust.set_all(slider4Init, slider4Min, slider4Max, 0.01, 0.01, 0)
self.slider1.set_digits(slider1Snap)
self.slider2.set_digits(slider2Snap)
self.slider3.set_digits(slider3Snap)
self.new = True
def sendTables( self, widget, data ):
self.curSlider = data
self.slider1Val = self.p1Adjust.value
self.slider2Val = self.p2Adjust.value
self.slider3Val = self.p3Adjust.value
self.slider4Val = self.p4Adjust.value
if self.instanceID != 12:
self.synthObjectsParameters.setType(self.instanceID, self.choosenType)
sliderListValue = [ self.p1Adjust.value, self.p2Adjust.value, self.p3Adjust.value, self.p4Adjust.value ]
if self.objectType == 0:
for i in range(4):
self.synthObjectsParameters.setControlParameter((self.instanceID % 4)*4+i, sliderListValue[i])
elif self.objectType == 1:
for i in range(4):
self.synthObjectsParameters.setSourceParameter((self.instanceID % 4)*4+i, sliderListValue[i])
elif self.objectType == 2:
for i in range(4):
self.synthObjectsParameters.setFxParameter((self.instanceID % 4)*4+i, sliderListValue[i])
else:
for i in range(4):
self.synthObjectsParameters.setOutputParameter(i, sliderListValue[i])
self.updateViewer()
def handleSliderRelease(self, widget, data=None):
if self.instanceID != 12:
self.writeTables( self.synthObjectsParameters.types, self.synthObjectsParameters.controlsParameters,
self.synthObjectsParameters.sourcesParameters, self.synthObjectsParameters.fxsParameters )
def handleSliderEnter(self, widget, data, slider):
widget.grab_focus()
self.sendTables(widget, slider)
def onKeyPress(self,widget,event):
key = event.hardware_keycode
#temporary binding for saving preset
if key == 50:
self.handleSave(None, None)
if key not in Config.KEY_MAP:
return
midiPitch = Config.KEY_MAP[key]
if midiPitch not in self.playingPitch:
if self.recordWait == 0:
self.playingPitch.append( midiPitch )
self.playNote( midiPitch, 0 )
else:
self.recordWait = 0
self.playingPitch.append( midiPitch )
self.playNote( midiPitch, self.table )
self.waitRecording()
def resetRecord( self ):
gobject.source_remove( self.wait )
self.recordButton.set_active(False)
inst = 'lab' + str(self.table-85)
self.csnd.load_synth_instrument(inst)
self.table = 0
return True
def waitRecording(self):
self.wait = gobject.timeout_add(int(self.duration*1000) , self.resetRecord )
def onKeyRelease( self, widget, event ):
key = event.hardware_keycode
if key not in Config.KEY_MAP:
return
midiPitch = Config.KEY_MAP[key]
if midiPitch in self.playingPitch:
self.playingPitch.remove( midiPitch )
def handleDuration( self, adjustment ):
self.duration = adjustment.value
def parameterUpdate( self, string ):
self.infoLabel.set_text(string)
def playNote( self, midiPitch, table ):
cpsPitch = 261.626*pow(1.0594633, midiPitch-36)
self.recCount += 1
mess = "i5203." + str(self.recCount) + " 0 " + str(self.duration) + " " + str(cpsPitch) + " " + str(table) + " " + " " .join([str(n) for n in self.synthObjectsParameters.getOutputParameters()])
self.csnd.inputMessage( mess )
if self.recCount >= 9: self.recCount = 0
def handleClose( self, widget, data ):
if self.journalCalled:
self.activity.close()
return
self.set_mode('welcome')
if as_window:
self.set_keep_above(False)
self.hide()
def resetLocations( self ):
# deep copy the list
self.locations = [ loc[:] for loc in SynthLabConstants.INIT_LOCATIONS ]
def handleReset( self, widget, data = None):
self.resetLocations()
self.objectCount = len(self.locations)
for i in range(self.objectCount):
self.updateBounds( i )
self.duration = 2
self._mainToolbar.durationSliderAdj.set_value(self.duration)
self.connections = []
self.synthObjectsParameters.__init__()
self.writeTables( self.synthObjectsParameters.types, self.synthObjectsParameters.controlsParameters, self.synthObjectsParameters.sourcesParameters, self.synthObjectsParameters.fxsParameters )
self.synthObjectsParameters.update()
self.initializeConnections()
self.invalidate_rect( 0, 0, self.drawingAreaWidth, self.drawingAreaHeight )
time.sleep(.01)
self.controlToSrcConnections()
time.sleep(.01)
self.controlToFxConnections()
time.sleep(.01)
self.audioConnections()
time.sleep(.01)
def setAction( self, action ):
self.action = action
def doneAction( self ):
if self.action == "drag-object": self.doneDragObject()
self.action = None
def handleButtonRelease( self, widget, event ):
self.highlightWire( None )
self.highlightGate( None )
if self.action == "drag-object":
self.doneAction()
elif self.action == "draw-wire":
for i in range(self.objectCount):
if self.bounds[i][0] < event.x < self.bounds[i][2] and self.bounds[i][1] < event.y < self.bounds[i][3]:
if i == self.wireObj:
break
gate = self.testGates( i, event.x-self.locations[i][0], event.y-self.locations[i][1] )
if gate:
self.connectWire( i, gate )
break
# if we don't connect the wire here they can try to click it somewhere, so don't end the action
def handleButtonPress( self, widget, event):
self.clickLoc = (int(event.x),int(event.y))
self.highlightWire( None )
self.highlightGate( None )
if event.button == 1:
for i in range(self.objectCount-1,-1,-1):
if self.bounds[i][0] < event.x < self.bounds[i][2] and self.bounds[i][1] < event.y < self.bounds[i][3]:
gate = self.testGates( i, event.x-self.locations[i][0], event.y-self.locations[i][1] )
if gate:
if self.action == "draw-wire":
self.connectWire( i, gate )
else:
self.startWire( i, gate )
else:
if self.action == "draw-wire":
self.doneWire()
if i != self.objectCount-1:
#self.select( i )
self.startDragObject( i )
else:
self.select( i )
return
if self.action == "draw-wire": # didn't hit anything
self.doneWire()
else:
# check if we clicked a wire
i = self.wireUnderLoc( event.x, event.y )
if i >= 0: self.deleteWire( i )
def handleMotion( self, widget, event ):
if event.is_hint:
x, y, state = widget.window.get_pointer()
event.x = float(x)
event.y = float(y)
event.state = state
if self.action == "drag-object":
self.updateDragObject( int(event.x), int(event.y) )
elif self.action == "draw-wire":
self.updateWire( int(event.x), int(event.y) )
for i in range(self.objectCount):
if self.locations[i] == SynthLabConstants.INIT_LOCATIONS[i] \
and i != self.objectCount-1: continue
if self.bounds[i][0] < event.x < self.bounds[i][2] and self.bounds[i][1] < event.y < self.bounds[i][3]:
gate = self.testGates( i, event.x-self.locations[i][0], event.y-self.locations[i][1] )
if gate and gate != self.wireGate:
if gate[0] == SynthLabConstants.GT_CONTROL_OUTPUT or gate[0] == SynthLabConstants.GT_SOUND_OUTPUT:
ok = self.testConnection( i, gate, self.wireObj, self.wireGate )
else:
ok = self.testConnection( self.wireObj, self.wireGate, i, gate )
self.highlightGate( i, gate, not ok )
else: self.highlightGate( None )
return
self.highlightGate( None )
else: # check for mouse overs
for i in range(self.objectCount):
if self.locations[i] == SynthLabConstants.INIT_LOCATIONS[i] \
and i != self.objectCount-1: continue
if self.bounds[i][0] < event.x < self.bounds[i][2] and self.bounds[i][1] < event.y < self.bounds[i][3]:
gate = self.testGates( i, event.x-self.locations[i][0], event.y-self.locations[i][1] )
if gate:
self.highlightGate( i, gate )
else:
self.highlightGate( None )
self.highlightWire( None )
return
# didn't find a gate
self.highlightGate( None )
# check for wires
i = self.wireUnderLoc( event.x, event.y )
if i >= 0: self.highlightWire( i )
else: self.highlightWire( None )
def testGates( self, i, x, y ):
oT = i >> 2
for gT in range(len(self.gateMap[oT])):
for n in range(len(self.gateMap[oT][gT])):
if self.gateMap[oT][gT][n][0] <= x <= self.gateMap[oT][gT][n][2] \
and self.gateMap[oT][gT][n][1] <= y <= self.gateMap[oT][gT][n][3]:
return ( gT, n, self.gateMap[oT][gT][n][4], self.gatePoint[oT][gT][n] ) # type, index, wire loc, center loc
return False
def startWire( self, obj, gate ):
self.wireObj = obj
self.wireGate = gate
x = gate[2][0] + self.locations[obj][0]
y = gate[2][1] + self.locations[obj][1]
self.wirePoint = [ [ x, y ], [ x, y ] ]
self.wireRect = [ 0, 0, 0, 0 ]
self.setAction( "draw-wire" )
def updateWire( self, x, y ):
if x < 0: x = 0
elif x > self.drawingAreaWidth: x = self.drawingAreaWidth
if y < 0: y = 0
elif y > self.separatorY: y = self.separatorY
self.invalidate_rect( self.wireRect[0], self.wireRect[1], self.wireRect[2], self.wireRect[3], False )
if x < self.wirePoint[0][0]: self.wireRect[0], self.wireRect[2] = x-self.lineWidth, self.wirePoint[0][0]-x+self.lineWidthMUL2
else: self.wireRect[0], self.wireRect[2] = self.wirePoint[0][0]-self.lineWidth, x-self.wirePoint[0][0]+self.lineWidthMUL2
if y < self.wirePoint[0][1]: self.wireRect[1], self.wireRect[3] = y-self.lineWidth, self.wirePoint[0][1]-y+self.lineWidthMUL2
else: self.wireRect[1], self.wireRect[3] = self.wirePoint[0][1]-self.lineWidth, y-self.wirePoint[0][1]+self.lineWidthMUL2
self.wirePoint[1][0] = x
self.wirePoint[1][1] = y
self.invalidate_rect( self.wireRect[0], self.wireRect[1], self.wireRect[2], self.wireRect[3], False )
def connectWire( self, obj, gate ):
if gate[0] == SynthLabConstants.GT_CONTROL_OUTPUT or gate[0] == SynthLabConstants.GT_SOUND_OUTPUT:
bObj, eObj = obj, self.wireObj
bGate, eGate = gate, self.wireGate
else:
bObj, eObj = self.wireObj, obj
bGate, eGate = self.wireGate, gate
i = self.newConnection( bObj, bGate, eObj, eGate )
if i >= 0: # successful connection
self.invalidate_rect( self.cBounds[i][0], self.cBounds[i][1], self.cBounds[i][2], self.cBounds[i][3] )
self.doneWire()
def deleteWire( self, i ):
self.invalidate_rect( self.cBounds[i][0], self.cBounds[i][1], self.cBounds[i][2], self.cBounds[i][3] )
self.delConnection( i )
def doneWire( self ):
self.invalidate_rect( self.wireRect[0], self.wireRect[1], self.wireRect[2], self.wireRect[3] )
self.doneAction()
def wireUnderLoc( self, x, y ):
for i in range(len(self.connections)):
if x < self.cBounds[i][0] or x > self.cBounds[i][4]: continue
if y < self.cBounds[i][1] or y > self.cBounds[i][5]: continue
if self.cPoints[i][0] == self.cPoints[i][2]: # vertical line
if abs(x-self.cPoints[i][0]) < self.lineWidthMUL4:
return i
else:
slope = (self.cPoints[i][3]-self.cPoints[i][1])/float(self.cPoints[i][2]-self.cPoints[i][0])
if abs(slope) < 1:
yy = self.cPoints[i][1] + (x-self.cPoints[i][0])*slope
if abs(y-yy) < self.lineWidthMUL4:
return i
else:
xx = self.cPoints[i][0] + (y-self.cPoints[i][1])/slope
if abs(x-xx) < self.lineWidthMUL4:
return i
return -1 # nothing found
# pass in i = None to clear
def highlightWire( self, i ):
if self.overWire != i:
if self.overWire != None:
self.invalidate_rect( self.cBounds[self.overWire][0], self.cBounds[self.overWire][1], self.cBounds[self.overWire][2], self.cBounds[self.overWire][3] )
self.overWire = i
if self.overWire != None:
self.invalidate_rect( self.cBounds[self.overWire][0], self.cBounds[self.overWire][1], self.cBounds[self.overWire][2], self.cBounds[self.overWire][3] )
# pass in obj = None to clear
def highlightGate( self, obj, gate = None, reject = False ):
if obj == None:
self.parameterUpdate('')
if self.overGateObj != obj or self.overGate != gate or self.overGateReject != reject:
if self.overGate != None:
self.invalidate_rect( self.overGateLoc[0], self.overGateLoc[1], self.overGateSize, self.overGateSize )
self.overGateObj = obj
self.overGate = gate
self.overGateReject = reject
if self.overGate != None:
oT = self.overGateObj//4
x = self.locations[self.overGateObj][0] + self.overGate[3][0] - self.overGateSizeDIV2
y = self.locations[self.overGateObj][1] + self.overGate[3][1] - self.overGateSizeDIV2
self.overGateLoc = ( x, y )
self.invalidate_rect( self.overGateLoc[0], self.overGateLoc[1], self.overGateSize, self.overGateSize )
if obj != 12:
choosen = SynthLabConstants.CHOOSE_TYPE[obj/4][self.typesTable[obj]]
_str = Tooltips.SYNTHTYPES[obj/4][self.typesTable[obj]] + ': ' + Tooltips.SYNTHPARA[choosen][gate[1]]
if gate[0] == 1:
if True:
gateNum = self.overGate[1]+1
exec 'self.slider%s.grab_focus()' % str(gateNum)
exec 'self.sendTables(self.slider%s, %d)' % (str(gateNum), gateNum)
self.parameterUpdate( _str )
def startDragObject( self, i ):
self.dragObject = i
self.dragInitialLoc = (self.locations[i][0],self.locations[i][1])
self.potentialDisconnect = False
self.invalidate_rect( self.bounds[i][0], self.bounds[i][1]-2, SynthLabConstants.PIC_SIZE, SynthLabConstants.PIC_SIZE_HIGHLIGHT )
for i in self.outputMap[self.dragObject]:
self.invalidate_rect( self.cBounds[i][0], self.cBounds[i][1], self.cBounds[i][2], self.cBounds[i][3] )
for i in self.inputMap[self.dragObject]:
self.invalidate_rect( self.cBounds[i][0], self.cBounds[i][1], self.cBounds[i][2], self.cBounds[i][3] )
self.setAction( "drag-object" )
def updateDragObject( self, x, y ):
delta = [ x-self.clickLoc[0], y-self.clickLoc[1] ]
x = self.dragInitialLoc[0]+delta[0]
if x-SynthLabConstants.HALF_SIZE < 0: x = SynthLabConstants.HALF_SIZE
elif x+SynthLabConstants.HALF_SIZE > self.drawingAreaWidth: x = self.drawingAreaWidth - SynthLabConstants.HALF_SIZE
y = self.dragInitialLoc[1]+delta[1]
if y-SynthLabConstants.HALF_SIZE < 0: y = SynthLabConstants.HALF_SIZE
elif y+SynthLabConstants.HALF_SIZE > self.drawingAreaHeight: y = self.drawingAreaHeight - SynthLabConstants.HALF_SIZE
self.invalidate_rect(self.bounds[self.dragObject][0], self.bounds[self.dragObject][1]-2, SynthLabConstants.PIC_SIZE, SynthLabConstants.PIC_SIZE_HIGHLIGHT, False )
if not self.potentialDisconnect:
for i in self.outputMap[self.dragObject]:
self.invalidate_rect( self.cBounds[i][0], self.cBounds[i][1], self.cBounds[i][2], self.cBounds[i][3], False )
for i in self.inputMap[self.dragObject]:
self.invalidate_rect( self.cBounds[i][0], self.cBounds[i][1], self.cBounds[i][2], self.cBounds[i][3], False )
if y > self.separatorY: self.potentialDisconnect = True
else: self.potentialDisconnect = False
self.locations[self.dragObject][0] = int( x )
self.locations[self.dragObject][1] = int( y )
self.updateBounds(self.dragObject)
self.invalidate_rect(self.bounds[self.dragObject][0], self.bounds[self.dragObject][1]-2, SynthLabConstants.PIC_SIZE, SynthLabConstants.PIC_SIZE_HIGHLIGHT, False )
if not self.potentialDisconnect:
for i in self.outputMap[self.dragObject]:
self.invalidate_rect( self.cBounds[i][0], self.cBounds[i][1], self.cBounds[i][2], self.cBounds[i][3], False )
for i in self.inputMap[self.dragObject]:
self.invalidate_rect( self.cBounds[i][0], self.cBounds[i][1], self.cBounds[i][2], self.cBounds[i][3], False )
def doneDragObject( self ):
if self.potentialDisconnect:
self.invalidate_rect( self.bounds[self.dragObject][0], self.bounds[self.dragObject][1]-2, SynthLabConstants.PIC_SIZE, SynthLabConstants.PIC_SIZE_HIGHLIGHT, False )
m = self.outputMap[self.dragObject][:]
m.sort(reverse=True)
for i in m: self.delConnection( i )
m = self.inputMap[self.dragObject][:]
m.sort(reverse=True)
for i in m: self.delConnection( i )
self.locations[self.dragObject][0] = SynthLabConstants.INIT_LOCATIONS[self.dragObject][0]
self.locations[self.dragObject][1] = SynthLabConstants.INIT_LOCATIONS[self.dragObject][1]
self.updateBounds( self.dragObject )
#self.invalidate_rect(self.bounds[self.dragObject][0], self.bounds[self.dragObject][1]-2, SynthLabConstants.PIC_SIZE, SynthLabConstants.PIC_SIZE_HIGHLIGHT )
else:
#self.invalidate_rect( self.bounds[self.dragObject][0], self.bounds[self.dragObject][1]-2, SynthLabConstants.PIC_SIZE, SynthLabConstants.PIC_SIZE_HIGHLIGHT )
for i in self.outputMap[self.dragObject]:
self.invalidate_rect( self.cBounds[i][0], self.cBounds[i][1], self.cBounds[i][2], self.cBounds[i][3] )
for i in self.inputMap[self.dragObject]:
self.invalidate_rect( self.cBounds[i][0], self.cBounds[i][1], self.cBounds[i][2], self.cBounds[i][3] )
# NOTE: select function invalidates the rect so no need to do it above
self.select( self.dragObject )
self.dragObject = None
self.handleSaveTemp()
def updateBounds( self, i ):
self.bounds[i][0] = self.locations[i][0]-SynthLabConstants.HALF_SIZE
self.bounds[i][1] = self.locations[i][1]-SynthLabConstants.HALF_SIZE
self.bounds[i][2] = self.locations[i][0]+SynthLabConstants.HALF_SIZE
self.bounds[i][3] = self.locations[i][1]+SynthLabConstants.HALF_SIZE
for c in self.outputMap[i]:
self.updateConnection( c )
for c in self.inputMap[i]:
self.updateConnection( c )
def updateConnection( self, i ):
c = self.connections[i]
oT = c[0][0]//4
x1 = self.locations[c[0][0]][0] + self.gateMap[oT][c[0][1]][c[0][2]][4][0]
y1 = self.locations[c[0][0]][1] + self.gateMap[oT][c[0][1]][c[0][2]][4][1]
oT = c[1][0]//4
x2 = self.locations[c[1][0]][0] + self.gateMap[oT][c[1][1]][c[1][2]][4][0]
y2 = self.locations[c[1][0]][1] + self.gateMap[oT][c[1][1]][c[1][2]][4][1]
self.cPoints[i][0], self.cPoints[i][1], self.cPoints[i][2], self.cPoints[i][3] = ( x1, y1, x2, y2 )
if x1 > x2: x1, x2 = ( x2, x1 )
if y1 > y2: y1, y2 = ( y2, y1 )
self.cBounds[i][0], self.cBounds[i][1], self.cBounds[i][2], self.cBounds[i][3], self.cBounds[i][4], self.cBounds[i][5] = ( x1-self.lineWidth, y1-self.lineWidth, x2-x1+self.lineWidthMUL2, y2-y1+self.lineWidthMUL2, x2+self.lineWidth, y2+self.lineWidth )
def findRecursive( self, obj, target ):
if obj == target: return True
for c in self.outputMap[obj]:
if self.findRecursive( self.straightConnections[c][1], target ):
return True
return False
def testConnection( self, bObj, bGate, eObj, eGate ):
if self.gateMatch[bGate[0]] != eGate[0]:
return False # type mismatch
for c in self.inputMap[eObj]:
if self.connections[c][1][1] == eGate[0] \
and self.connections[c][1][2] == eGate[1] : # same type and port
if self.connections[c][0][0] == bObj:
return False # connections already exists
if self.findRecursive( eObj, bObj ):
return False # loop
return True
def newConnection( self, bObj, bGate, eObj, eGate ):
if not self.testConnection( bObj, bGate, eObj, eGate ):
return -1 # connection failed
ind = len(self.connections)
# connection format: [ ( outputObject, gate type, gate num ), ( inputObject, gate type, gate num ) ]
self.connections.append ( [ ( bObj, bGate[0], bGate[1] ),
( eObj, eGate[0], eGate[1] ) ] )
self.straightConnections.append( ( bObj, eObj ) )
self.outputMap[bObj].append(ind)
self.inputMap[eObj].append(ind)
self.outputs.append( bObj )
self.cPoints.append( [ 0, 0, 0, 0 ] )
self.cBounds.append( [ 0, 0, 0, 0, 0, 0 ] )
self.updateConnection( ind )
self.updateSound()
self.handleSaveTemp()
return ind
def delConnection( self, i ):
b = self.straightConnections[i][0]
e = self.straightConnections[i][1]
self.straightConnections.pop(i)
self.outputMap[b].remove(i)
self.inputMap[e].remove(i)
self.outputs.pop(i)
self.cPoints.pop(i)
self.cBounds.pop(i)
self.connections.pop(i)
for o in range(self.objectCount):
for m in range(len(self.outputMap[o])):
if self.outputMap[o][m] > i: self.outputMap[o][m] -= 1
for m in range(len(self.inputMap[o])):
if self.inputMap[o][m] > i: self.inputMap[o][m] -= 1
self.updateSound()
self.handleSaveTemp()
def initializeConnections( self ):
self.straightConnections = []
self.outputMap = [ [] for i in self.locations ]
self.inputMap = [ [] for i in self.locations ]
self.outputs = []
self.cPoints = []
self.cBounds = []
for i in range(len(self.connections)):
c = self.connections[i]
first = c[0][0]
second = c[1][0]
self.straightConnections.append([first, second])
self.outputMap[first].append(i)
self.inputMap[second].append(i)
self.outputs.append(first)
self.cPoints.append( [ 0, 0, 0, 0 ] )
self.cBounds.append( [ 0, 0, 0, 0, 0, 0 ] )
self.updateConnection( i )
self.updateSound()
def predraw( self, buf ):
startX = self.screenBufDirtyRect.x
startY = self.screenBufDirtyRect.y
stopX = self.screenBufDirtyRect.x + self.screenBufDirtyRect.width
stopY = self.screenBufDirtyRect.y + self.screenBufDirtyRect.height
# draw bg
self.gc.foreground = self.bgColor
buf.draw_rectangle( self.gc, True, startX, startY, self.screenBufDirtyRect.width, self.screenBufDirtyRect.height )
# draw separator
self.gc.foreground = self.lineColor
buf.draw_line( self.gc, startX, self.separatorY, stopX, self.separatorY )
# draw objects
self.gc.set_clip_mask( self.clipMask )
for i in range(self.objectCount):
if i == self.dragObject or i == self.instanceID:
continue
if startX > self.bounds[i][2] or stopX < self.bounds[i][0] or startY > self.bounds[i][3] or stopY < self.bounds[i][1]:
continue
type = i >> 2
self.gc.set_clip_origin( self.bounds[i][0]-SynthLabConstants.PIC_SIZE*type, self.bounds[i][1] )
buf.draw_drawable( self.gc, self.pixmap[i], 0, 0, self.bounds[i][0], self.bounds[i][1], SynthLabConstants.PIC_SIZE, SynthLabConstants.PIC_SIZE )
if self.dragObject != self.instanceID:
i = self.instanceID
type = i >> 2
#draw object
self.gc.set_clip_origin( self.bounds[i][0]-SynthLabConstants.PIC_SIZE*type, self.bounds[i][1] )
buf.draw_drawable( self.gc, self.pixmap[i], 0, 0, self.bounds[i][0], self.bounds[i][1], SynthLabConstants.PIC_SIZE, SynthLabConstants.PIC_SIZE )
# draw selectionHighlight
self.gc.set_clip_origin( self.bounds[i][0]-SynthLabConstants.PIC_SIZE*type, self.bounds[i][1]-82 )
self.gc.foreground = self.highlightColor
buf.draw_rectangle( self.gc, True, self.bounds[i][0], self.bounds[i][1]-2, SynthLabConstants.PIC_SIZE, SynthLabConstants.PIC_SIZE_HIGHLIGHT )
self.gc.foreground = self.lineColor
self.gc.set_clip_rectangle( self.clearMask )
# draw wires
for c in range(len(self.connections)):
if self.straightConnections[c][0] == self.dragObject or self.straightConnections[c][1] == self.dragObject:
continue
if startX > self.cBounds[c][4] or stopX < self.cBounds[c][0] or startY > self.cBounds[c][5] or stopY < self.cBounds[c][1]:
continue
buf.draw_line( self.gc, self.cPoints[c][0], self.cPoints[c][1],
self.cPoints[c][2], self.cPoints[c][3] )
self.screenBufDirty = False
def draw( self, widget, event ):
#TP.ProfileBegin("SL::draw")
startX = event.area.x
startY = event.area.y
stopX = event.area.x + event.area.width
stopY = event.area.y + event.area.height
if self.screenBufDirty:
self.predraw( self.screenBuf )
# draw base
widget.window.draw_drawable( self.gc, self.screenBuf, startX, startY, startX, startY, event.area.width, event.area.height )
if self.action == "drag-object":
# draw dragObject
self.gc.set_clip_mask( self.clipMask )
type = self.dragObject >> 2
self.gc.set_clip_origin( self.bounds[self.dragObject][0]-SynthLabConstants.PIC_SIZE*type, self.bounds[self.dragObject][1] )
widget.window.draw_drawable( self.gc, self.pixmap[self.dragObject], 0, 0, self.bounds[self.dragObject][0], self.bounds[self.dragObject][1], SynthLabConstants.PIC_SIZE, SynthLabConstants.PIC_SIZE )
if self.instanceID == self.dragObject:
# draw selectionHighlight
self.gc.set_clip_origin( self.bounds[self.dragObject][0]-SynthLabConstants.PIC_SIZE*type, self.bounds[self.dragObject][1]-82 )
self.gc.foreground = self.highlightColor
widget.window.draw_rectangle( self.gc, True, self.bounds[self.dragObject][0], self.bounds[self.dragObject][1]-2, SynthLabConstants.PIC_SIZE, SynthLabConstants.PIC_SIZE_HIGHLIGHT )
self.gc.set_clip_rectangle( self.clearMask )
# draw wires
if not self.potentialDisconnect:
self.gc.foreground = self.lineColor
for c in self.outputMap[self.dragObject]:
if startX > self.cBounds[c][4] or stopX < self.cBounds[c][0] or startY > self.cBounds[c][5] or stopY < self.cBounds[c][1]:
continue
widget.window.draw_line( self.gc, self.cPoints[c][0], self.cPoints[c][1],
self.cPoints[c][2], self.cPoints[c][3] )
for c in self.inputMap[self.dragObject]:
if startX > self.cBounds[c][4] or stopX < self.cBounds[c][0] or startY > self.cBounds[c][5] or stopY < self.cBounds[c][1]:
continue
widget.window.draw_line( self.gc, self.cPoints[c][0], self.cPoints[c][1],
self.cPoints[c][2], self.cPoints[c][3] )
elif self.action == "draw-wire":
# draw the wire
self.gc.foreground = self.lineColor
widget.window.draw_line( self.gc, self.wirePoint[0][0], self.wirePoint[0][1],
self.wirePoint[1][0], self.wirePoint[1][1] )
# draw highlights
if self.overWire != None:
self.gc.foreground = self.overWireColor
widget.window.draw_line( self.gc, self.cPoints[self.overWire][0], self.cPoints[self.overWire][1],
self.cPoints[self.overWire][2], self.cPoints[self.overWire][3] )
elif self.overGate != None:
self.gc.set_line_attributes( self.overLineWidth, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_BUTT, gtk.gdk.JOIN_MITER )
if self.overGateReject:
self.gc.foreground = self.overGateRejectColor
widget.window.draw_line( self.gc, self.overGateLoc[0]+self.overLineWidth, self.overGateLoc[1]+self.overLineWidth, self.overGateLoc[0]+self.overGateSize-self.overLineWidth, self.overGateLoc[1]+self.overGateSize-self.overLineWidth )
widget.window.draw_line( self.gc, self.overGateLoc[0]+self.overLineWidth, self.overGateLoc[1]+self.overGateSize-self.overLineWidth, self.overGateLoc[0]+self.overGateSize-self.overLineWidth, self.overGateLoc[1]+self.overLineWidth )
else:
self.gc.foreground = self.overGateColor
widget.window.draw_arc( self.gc, False, self.overGateLoc[0]+self.overLineWidth, self.overGateLoc[1]+self.overLineWidth, self.overGateSize-self.overLineWidthMUL2, self.overGateSize-self.overLineWidthMUL2, 0, 23040 )
self.gc.set_line_attributes( self.lineWidth, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_BUTT, gtk.gdk.JOIN_MITER )
#print TP.ProfileEndAndPrint("SL::draw")
return True
def invalidate_rect( self, x, y, w, h, dirtyScreenBuf = True ):
self.dirtyRectToAdd.x = x
self.dirtyRectToAdd.y = y
self.dirtyRectToAdd.width = w
self.dirtyRectToAdd.height = h
if dirtyScreenBuf:
if self.screenBufDirty:
self.screenBufDirtyRect = self.screenBufDirtyRect.union(self.dirtyRectToAdd)
else:
self.screenBufDirtyRect.x = x
self.screenBufDirtyRect.y = y
self.screenBufDirtyRect.width = w
self.screenBufDirtyRect.height = h
self.screenBufDirty = True
if self.drawingArea.window != None:
self.drawingArea.window.invalidate_rect( self.dirtyRectToAdd, True )
self.dirty = True
def writeTables( self, typesTable, controlParametersTable, sourceParametersTable, fxParametersTable ):
mess = 'f5200 0 16 -2 ' + " ".join([str(n) for n in controlParametersTable])
self.csnd.inputMessage( mess )
time.sleep(0.005)
mess = "f5201 0 16 -2 " + " " .join([str(n) for n in sourceParametersTable])
self.csnd.inputMessage( mess )
time.sleep(.005)
mess = "f5202 0 16 -2 " + " " .join([str(n) for n in fxParametersTable])
self.csnd.inputMessage( mess )
time.sleep(.005)
self.typesTable = typesTable
lastTable = [0]*12
for i in range(12):
if i in self.outputs:
lastTable[i] = (typesTable[i]+1)
mess = "f5203 0 16 -2 " + " " .join([str(n) for n in lastTable]) + " 0 0 0 0"
self.csnd.inputMessage( mess )
time.sleep(.005)
if lastTable[4] == 8:
snd = Config.SOUNDS_DIR + '/' + self.sample_names[int(sourceParametersTable[1])]
mess = "f5501 0 32768 -1 " + "\"%s\" 0 0 0" % snd
self.csnd.inputMessage( mess )
if lastTable[5] == 8:
snd = Config.SOUNDS_DIR + '/' + self.sample_names[int(sourceParametersTable[5])]
mess = "f5502 0 32768 -1 " + "\"%s\" 0 0 0" % snd
self.csnd.inputMessage( mess )
if lastTable[6] == 8:
snd = Config.SOUNDS_DIR + '/' + self.sample_names[int(sourceParametersTable[9])]
mess = "f5503 0 32768 -1 " + "\"%s\" 0 0 0" % snd
self.csnd.inputMessage( mess )
if lastTable[7] == 8:
snd = Config.SOUNDS_DIR + '/' + self.sample_names[int(sourceParametersTable[13])]
mess = "f5504 0 32768 -1 " + "\"%s\" 0 0 0" % snd
self.csnd.inputMessage( mess )
time.sleep(.005)
self.loadPixmaps(typesTable)
self.invalidate_rect( 0, 0, self.drawingAreaWidth, self.drawingAreaHeight )
def recordSound( self, widget, data ):
if widget.get_active() == True:
self.recordButton = widget
self.recordWait = 1
os.system('rm ' + Config.SNDS_DIR + '/lab' + str(data))
self.table = 85 + data
else:
self.recordWait = 0
def updateSound( self ):
self.controlToSrcConnections()
time.sleep(.01)
self.controlToFxConnections()
time.sleep(.01)
self.audioConnections()
time.sleep(.01)
lastTable = [0]*12
for i in range(12):
if i in self.outputs:
lastTable[i] = (self.synthObjectsParameters.types[i]+1)
mess = "f5203 0 16 -2 " + " " .join([str(n) for n in lastTable]) + " 0 0 0 0"
self.csnd.inputMessage( mess )
time.sleep(.01)
def updateTables( self ):
self.writeTables( self.synthObjectsParameters.types, self.synthObjectsParameters.controlsParameters, self.synthObjectsParameters.sourcesParameters, self.synthObjectsParameters.fxsParameters )
def controlToSrcConnections( self ):
self.contSrcConnections = []
for i in self.connections:
if i[0][0] < 4 and 3 < i[1][0] < 8:
offset = i[1][2]
self.contSrcConnections.append([i[0][0], i[1][0], offset])
table = [0 for i in range(16)]
sources = [source for source in range(4,8) if source in self.outputs]
for source in sources:
for entre in range(4):
value = sum([2**(li[0]+1) for li in self.contSrcConnections if li[1] == source and li[2] == entre], 1)
table[(source % 4) * 4 + entre] = value
mess = "f5204 0 16 -2 " + " " .join([str(n) for n in table])
self.csnd.inputMessage( mess )
def controlToFxConnections( self ):
self.contFxConnections = []
for i in self.connections:
if i[0][0] < 4 and 7 < i[1][0] < 12:
offset = i[1][2]
self.contFxConnections.append([i[0][0], i[1][0], offset])
table = [0 for i in range(16)]
fxs = [fx for fx in range(8,12) if fx in self.outputs]
for fx in fxs:
for entre in range(4):
value = sum([2**(li[0]+1) for li in self.contFxConnections if li[1] == fx and li[2] == entre], 1)
table[(fx % 4) * 4 + entre] = value
mess = "f5205 0 16 -2 " + " " .join([str(n) for n in table])
self.csnd.inputMessage( mess )
def audioConnections( self ):
self.srcFxConnections = [i for i in self.straightConnections if 3 < i[0] < 8 and 7 < i[1] < 12]
self.fxConnections = [i for i in self.straightConnections if 7 < i[0] < 12 and 7 < i[1] < 12]
self.outConnections = [i[0] for i in self.straightConnections if i[1] == 12]
table = []
for fx in range(8, 12):
value = 0
for li in self.srcFxConnections:
if li[1] == fx:
value += pow(2, li[0]-4)
table.append(value)
for fx in range(8, 12):
value = 0
for li in self.fxConnections:
if li[1] == fx:
value += pow(2, li[0]-8)
table.append(value)
for sig in range(4, 12):
value = 0
if sig in self.outConnections:
value = 1
table.append(value)
mess = "f5206 0 16 -2 " + " " .join([str(n) for n in table])
self.csnd.inputMessage( mess )
def loadPixmaps( self, typesList ):
win = gtk.gdk.get_default_root_window()
gc = gtk.gdk.GC( win )
gc.foreground = self.bgColor
self.pixmap = []
for i in range(13):
if i < 4: img = SynthLabConstants.CHOOSE_TYPE_PLUS[0][typesList[i]]
elif i < 8: img = SynthLabConstants.CHOOSE_TYPE_PLUS[1][typesList[i]]
elif i < 12: img = SynthLabConstants.CHOOSE_TYPE_PLUS[2][typesList[i]]
else: img = "speaker"
pix = gtk.gdk.pixbuf_new_from_file(Config.IMAGE_ROOT + img + '.png')
map = gtk.gdk.Pixmap( win, pix.get_width(), pix.get_height() )
map.draw_rectangle( gc, True, 0, 0, pix.get_width(), pix.get_height() )
map.draw_pixbuf( gc, pix, 0, 0, 0, 0, pix.get_width(), pix.get_height(), gtk.gdk.RGB_DITHER_NONE )
self.pixmap.append(map)
pix = gtk.gdk.pixbuf_new_from_file(Config.IMAGE_ROOT+'synthlabMask.png')
pixels = pix.get_pixels()
stride = pix.get_rowstride()
channels = pix.get_n_channels()
bitmap = ""
byte = 0
shift = 0
for j in range(pix.get_height()):
offset = stride*j
for i in range(pix.get_width()):
r = pixels[i*channels+offset]
if r != "\0": byte += 1 << shift
shift += 1
if shift > 7:
bitmap += "%c" % byte
byte = 0
shift = 0
bitmap += "%c" % byte
self.clipMask = gtk.gdk.bitmap_create_from_data( None, bitmap, pix.get_width(), pix.get_height() )
def handleSave(self, widget, data):
chooser = gtk.FileChooserDialog(title='Save SynthLab Preset',action=gtk.FILE_CHOOSER_ACTION_SAVE, buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_SAVE,gtk.RESPONSE_OK))
filter = gtk.FileFilter()
filter.add_pattern('*.syn')
chooser.set_filter(filter)
chooser.set_current_folder(Config.SYNTH_DIR)
for f in chooser.list_shortcut_folder_uris():
chooser.remove_shortcut_folder_uri(f)
if chooser.run() == gtk.RESPONSE_OK:
ofilename = chooser.get_filename()
if ofilename[-4:] != '.syn':
ofilename += '.syn'
try:
print 'INFO: save SynthLab file %s' % chooser.get_filename()
f = shelve.open(ofilename, 'n')
self.saveState(f)
f.close()
except IOError:
print 'ERROR: failed to save SynthLab to file %s' % chooser.get_filename()
chooser.destroy()
def handleJournalSave(self, file_path):
f = shelve.open(file_path, 'n')
self.saveState(f)
f.close()
def handleLoad(self, widget, data):
chooser = gtk.FileChooserDialog(title='Load SynthLab Preset',action=gtk.FILE_CHOOSER_ACTION_OPEN, buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))
filter = gtk.FileFilter()
filter.add_pattern('*.syn')
chooser.set_filter(filter)
chooser.set_current_folder(Config.SYNTH_DIR)
for f in chooser.list_shortcut_folder_uris():
chooser.remove_shortcut_folder_uri(f)
if chooser.run() == gtk.RESPONSE_OK:
try:
print 'INFO: load SynthLab state from file %s' % chooser.get_filename()
f = shelve.open( chooser.get_filename(), 'r')
self.loadState(f)
f.close()
except IOError:
print 'ERROR: failed to load SynthLab state from file %s' % chooser.get_filename()
chooser.destroy()
def handleJournalLoad(self, file_path):
f = shelve.open( file_path, 'r')
self.loadState(f)
f.close()
def handleSaveTemp( self ):
file = Config.PREF_DIR + '/synthTemp'
f = shelve.open(file, 'n')
self.saveState(f)
f.close()
def handleLoadTemp( self ):
file = Config.PREF_DIR + '/synthTemp'
f = shelve.open(file, 'r')
self.loadState(f)
f.close()
def saveState( self, state ):
state['types'] = self.synthObjectsParameters.types
state['controls'] = self.synthObjectsParameters.controlsParameters
state['sources'] = self.synthObjectsParameters.sourcesParameters
state['fxs'] = self.synthObjectsParameters.fxsParameters
state['envelope'] = self.synthObjectsParameters.outputParameters
state['locations'] = self.locations
state['connections'] = self.connections
state['duration'] = self.duration
def tempVerifyLocations(self):
for l in self.locations:
l[0] = int(l[0])
l[1] = int(l[1])
def tempVerifyConnectionFormat(self):
for c in self.connections:
if c[0][1] > 3 or c[0][2] > 3 \
or c[1][1] > 3 or c[1][2] > 3:
print "old format"
print c
i = c[0]
if i[1] == 0 and i[2] == 40:
if i[0] < 4: t,n = 0,0 # control output
else: t,n = 2,0 # sound output
else:
print "unhandled loc"
t,n = i[1],i[2]
c[0] = ( c[0][0], t, n )
i = c[1]
if i[1] == 0 and i[2] == -40: t,n = 3,0
elif i[1] == 40 and i[2] == -19: t,n = 1,0
elif i[1] == -25 and i[2] == -40: t,n = 1,0
elif i[1] == -9 and i[2] == -40: t,n = 1,1
elif i[1] == 8 and i[2] == -40: t,n = 1,2
elif i[1] == 25 and i[2] == -40: t,n = 1,3
else:
print "unhandled loc"
t,n = i[1],i[2]
c[1] = ( c[1][0], t, n )
def loadState( self, state ):
self.synthObjectsParameters.types = state['types']
self.synthObjectsParameters.controlsParameters = state['controls']
self.synthObjectsParameters.sourcesParameters = state['sources']
self.synthObjectsParameters.fxsParameters = state['fxs']
self.synthObjectsParameters.outputParameters = state['envelope']
self.locations = state['locations']
#self.tempVerifyLocations()
self.objectCount = len(self.locations)
for i in range(self.objectCount):
self.updateBounds( i )
self.connections = state['connections']
#self.tempVerifyConnectionFormat()
self.duration = state['duration']
self._mainToolbar.durationSliderAdj.set_value(self.duration)
self.initializeConnections()
self.controlToSrcConnections()
time.sleep(.01)
self.controlToFxConnections()
time.sleep(.01)
self.audioConnections()
time.sleep(.01)
self.synthObjectsParameters.update()
self.writeTables( self.synthObjectsParameters.types, self.synthObjectsParameters.controlsParameters, self.synthObjectsParameters.sourcesParameters, self.synthObjectsParameters.fxsParameters )
time.sleep(.01)
self.invalidate_rect( 0, 0, self.drawingAreaWidth, self.drawingAreaHeight )
def presetCallback( self, widget, data ):
preset = 'synthFile' + str(data)
f = shelve.open( Config.TAM_TAM_ROOT + '/Resources/SynthFiles/' + preset, 'r')
self.loadState(f)
f.close()
self.handleSaveTemp()
def initRadioButton( self, labelList, methodCallback, box ):
for i in range( len( labelList ) ):
label = labelList[i]
if i == 0:
button = ImageRadioButton( group = None, mainImg_path = Config.IMAGE_ROOT + label + '.png', altImg_path = Config.IMAGE_ROOT + label + 'sel.png' )
else:
button = ImageRadioButton( group = button, mainImg_path = Config.IMAGE_ROOT + label + '.png', altImg_path = Config.IMAGE_ROOT + label + 'sel.png' )
button.connect( "toggled", methodCallback, i )
box.pack_start( button, True, True )
|