-
Notifications
You must be signed in to change notification settings - Fork 0
/
MELODY.ELPC
1545 lines (1267 loc) · 34.8 KB
/
MELODY.ELPC
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
#output playmaker
' Keys:
' ----
' Up arrow = Move to previous voice
' Down arrow = Move to next voice
' Left arrow = Move left within currrent voice string
' Right arrow = Move right within current voice string
' INST/DEL = Delete char in current voice string
' ESC,J = Move to start of current voice string
' ESC,K = Move to end of current voice string
' CTRL+W = Move forward one word in current voice string
' CTRL+U = Move back one word in current voice string
' < = Show previous song chunk
' > = Show next song chunk
' - = Decrease tempo
' + = Increase tempo
' MEGA+Q = Quit program / Exit Env Editor
' F1 = Load
' F3 = Save
' F7 = Envelope editor
' F8 = Filter editor
' F9/CTRL-P = Chunk sequencer
trap runstop_trapper
.declarations
'------------
#declare chunk_idx = 0
#declare chunk_cnt = 0
#define chunk_max = 50
#declare vidx, idx
#declare cursor_x = 0
#declare cursor_y = 0
#declare v$(5,chunk_max)
#declare key$
#declare valid$="cdefgab0123456789 #$.hiqrswotuxmpl"
#declare val$
#declare tmpo% = 12
#declare esc_flag% = 0
#struct ENVTYPE name$, attack, decay, sustain, release, waveform, pw
ENVTYPE envs(9) = [ {x5F}
[ "Piano", 0, 9, 0, 0, 2, 1536 ], {x5F}
[ "Accordion", 12, 0, 12, 0, 1, 0 ], {x5F}
[ "Calliope", 0, 0, 15, 0, 0, 0 ], {x5F}
[ "Drum", 0, 5, 5, 0, 3, 0 ], {x5F}
[ "Flute", 9, 4, 4, 0, 0, 0 ], {x5F}
[ "Guitar", 0, 9, 2, 1, 1, 0 ], {x5F}
[ "Harpsicrd", 0, 9, 0, 0, 2, 512 ], {x5F}
[ "Organ", 0, 9, 9, 0, 2, 2048 ], {x5F}
[ "Trumpet", 8, 9, 4, 1, 2, 512 ], {x5F}
[ "Xylophone", 0, 9, 0, 0, 0, 0 ] {x5F}
]
#define DIR_NONE = 0
#define DIR_UP = 1
#define DIR_DOWN = 2
#define DIR_OSC = 3
#declare dir_name$(3)
dir_name$(0) = "NONE"
dir_name$(1) = "UP"
dir_name$(2) = "DOWN"
dir_name$(3) = "OSC"
#define F_OFF = 0
#define F_ON = 1
#struct FILTTYPE name$, freq, lp, bp, hp, res, dir, min, sweep
FILTTYPE filt(10) = [ {x5F}
[ "lowp_up", 1000, F_ON, F_OFF, F_OFF, 15, DIR_UP, 100, 10 ], {x5F}
[ "lowp_down", 1000, F_ON, F_OFF, F_OFF, 15, DIR_DOWN, 100, 10 ], {x5F}
[ "lowp_osc", 1000, F_ON, F_OFF, F_OFF, 15, DIR_OSC, 100, 10 ], {x5F}
{x5F}
[ "bandp_up", 1000, F_OFF, F_ON, F_OFF, 15, DIR_UP, 100, 10 ], {x5F}
[ "bandp_down", 1000, F_OFF, F_ON, F_OFF, 15, DIR_DOWN, 100, 10 ], {x5F}
[ "bandp_osc", 1000, F_OFF, F_ON, F_OFF, 15, DIR_OSC, 100, 10 ], {x5F}
{x5F}
[ "highp_up", 1000, F_OFF, F_OFF, F_ON, 15, DIR_UP, 100, 10 ], {x5F}
[ "highp_down", 1000, F_OFF, F_OFF, F_ON, 15, DIR_DOWN, 100, 10 ], {x5F}
[ "highp_osc", 1000, F_OFF, F_OFF, F_ON, 15, DIR_OSC, 100, 10 ], {x5F}
{x5F}
[ "spare_1", 0, F_OFF, F_OFF, F_OFF, 0, DIR_NONE, 0, 0 ], {x5F}
[ "spare_2", 0, F_OFF, F_OFF, F_OFF, 0, DIR_NONE, 0, 0 ], {x5F}
{x5F}
]
#declare seq_chunk(200), seq_extra(200)
#declare echo_m, echo_b, echo_sz = .05, chunk_rpt, echo_delay
#declare v1$, v2$, v3$, v4$, v5$, v6$
#declare tmp
#declare sscol, s, seq_offs
#define OP_COPY = 0
#define OP_MIX = 1
#define OP_SWAP = 2
#define OP_FILL = 3
#define SCRNPTRLSB = $d060
#define SCRNPTRMSB = $d061
#define SCRNPTRBNK = $d062
.cmds
#define CMD_TEMPO = -1
#define CMD_FILTER = -2
#define CMD_LOOP = -3
#define CMD_ECHO_M1 = -4 ' echo melody: voice 1 on voice 4
#define CMD_ECHO_M2 = -5 ' echo melody: voice 1 on voice 2 + 4 + 5
#define CMD_ECHO_B = -6 ' echo bass: voice 3 on voice 6
#define CMD_ECHO_OFF = -7
#define CMD_ECHO_SZ = -8
#define CMD_VOL = -9
#define CMD_DELAY = -10
#define CMD_MAX = 11
#declare seq_cmdname$(10)
seq_cmdname$(1) = "TEMPO"
seq_cmdname$(2) = "FILTER"
seq_cmdname$(3) = "LOOP"
seq_cmdname$(4) = "ECHO_M1"
seq_cmdname$(5) = "ECHO_M2"
seq_cmdname$(6) = "ECHO_B"
seq_cmdname$(7) = "ECHO_OFF"
seq_cmdname$(8) = "ECHO_SZ"
seq_cmdname$(9) = "VOL"
seq_cmdname$(10) = "DELAY"
#declare seqcnt, seqptr
#declare row, col, srow, scol, a$, v, maxv, v$
#struct KEY_TYPE in$, out$
KEY_TYPE keys(11) = [ {x5F}
[ "a", "c", ], {x5F}
[ "w", "#c", ], {x5F}
[ "s", "d", ], {x5F}
[ "e", "#d", ], {x5F}
[ "d", "e", ], {x5F}
[ "f", "f", ], {x5F}
[ "t", "#f", ], {x5F}
[ "g", "g", ], {x5F}
[ "y", "#g", ], {x5F}
[ "h", "a", ], {x5F}
[ "u", "#a", ], {x5F}
[ "j", "b", ] {x5F}
]
#declare pstr$, k, delta
#declare wname$(4)
wname$(0) = "TRI"
wname$(1) = "SAW"
wname$(2) = "PULSE"
wname$(3) = "NOISE"
wname$(4) = "RING"
#declare filt_state_name$(2)
filt_state_name$(0) = "OFF"
filt_state_name$(1) = "ON"
#declare fpreset = 1
#declare fscol = 0, fsrow = 0, ffocus = 0, fsel = -1
#declare oct = 5
#declare curr_freq, curr_dir
#declare handled
#declare plyptr = -1, plyflag
.duration
'--------
#define DNAME = 0
#define DCHAR = 1
#define DKEY = 2
#define D_WHOLE = 0
#define D_HALF = 1
#define D_QUARTER = 2
#define D_EIGHTH = 3
#define D_SIXTEENTH = 4
#declare sdur = 2
#declare dur$(5,2)
dur$(D_WHOLE, DNAME) = "whole"
dur$(D_WHOLE, DCHAR) = "w"
dur$(D_WHOLE, DKEY) = "1"
dur$(D_HALF, DNAME) = "half"
dur$(D_HALF, DCHAR) = "h"
dur$(D_HALF, DKEY) = "2"
dur$(D_QUARTER, DNAME) = "quarter"
dur$(D_QUARTER, DCHAR) = "q"
dur$(D_QUARTER, DKEY) = "3"
dur$(D_EIGHTH, DNAME) = "eighth"
dur$(D_EIGHTH, DCHAR) = "i"
dur$(D_EIGHTH, DKEY) = "4"
dur$(D_SIXTEENTH, DNAME) = "sixteenth"
dur$(D_SIXTEENTH, DCHAR) = "s"
dur$(D_SIXTEENTH, DKEY) = "5"
#declare clip$, alt_key, limit, ret%, y, cp$(6)
.keys
'----
#define KEY_UP = "{x91}"
#define KEY_DOWN = "{x11}"
#define KEY_LEFT = "{x9D}"
#define KEY_RIGHT = "{x1D}"
#define KEY_SPACE = " "
#define KEY_DEL = "{x14}"
#define KEY_CTRL_W = "{x17}"
#define KEY_CTRL_U = "{x15}"
#define KEY_MEGA_Q = "«"
#define KEY_F1 = "{x85}"
#define KEY_F3 = "{x86}"
#define KEY_F4 = "{x8A}"
#define KEY_F7 = "{x88}"
#define KEY_F8 = "{x8C}"
#define KEY_F9 = chr$(16)
#define KEY_RETURN = chr$(13)
#define KEY_ESCAPE = chr$(27)
#define KEY_SHIFT_RETURN = chr$(141)
#define KEY_SHIFT_PLUS = "Û"
#define KEY_SHIFT_MINUS = "Ý"
#define KEY_REV_ON = "{x12}"
#define KEY_REV_OFF = "{x92}"
#define KEY_TAB = chr$(9)
#define KEY_HOME = "{x13}"
#define KEY_CLR = "{x93}"
#define KEY_LOWERCASE = chr$(14)
#define KEY_UPPERCASE = chr$(142)
#define KEY_BEEP = chr$(7)
#define KEY_INST = "{x94}"
#define KEY_DEL = "{x14}"
.init
'----
print "{x93}";KEY_LOWERCASE;KEY_ESCAPE;"5";
play : play ""
background 0 : border 0
color 5
.main
'----
key off
gosub draw_editor_screen
gosub user_input
goto main
.draw_editor_screen
'------------------
cursor 0,0:print "{x93}playmaker v0.5 - by gurce isikyildiz"
print "---------"
print "<: prev chunk, >: next chunk, -/+ tempo, F7=env editor, F9/CTRL-P=seq editor"
print "RTN: play curr voice, SHFT+RTN: play all voice, F1=load, F3=save, MEGA+Q=quit"
print "ALT-X/C/V: row cut/copy/paste, ESC-ESC: stop music, ALT-RTN: play from cursor"
print
gosub draw_current_chunk
return
.draw_current_chunk
'------------------
print "tempo: "; tmpo%
print "chunk_idx: "; chunk_idx
for vidx=0 to 5
if cursor_y <> vidx then begin
cursor 0,9+vidx*2:print chr$(27);"q";"v";vidx+1;": ";v$(vidx,chunk_idx);
bend:else begin
cursor 0,9+vidx*2:print chr$(27);"q";"v";vidx+1;": ";
for idx=1 to len(v$(vidx,chunk_idx))
if cursor_x = idx-1 then begin
print "{x12}";mid$(v$(vidx,chunk_idx),idx,1);"{x92}";
bend:else begin
print mid$(v$(vidx,chunk_idx),idx,1);
bend
next idx
if len(v$(vidx,chunk_idx)) = 0 or cursor_x=len(v$(vidx,chunk_idx)) then print "{x12} {x92}";
bend
next vidx
return
.check_valid_key
'---------------
for idx=1 to len(valid$)
val$=mid$(valid$,idx,1)
if key$= val$ then begin
if cursor_x < len(v$(cursor_y,chunk_idx)) then begin
v$(cursor_y,chunk_idx) = left$(v$(cursor_y,chunk_idx),cursor_x) {x5F}
+ val$ + mid$(v$(cursor_y,chunk_idx),cursor_x+1)
cursor_x=cursor_x+1
return
bend
v$(cursor_y,chunk_idx)=v$(cursor_y,chunk_idx)+val$
cursor_x=cursor_x+1
return
bend
next idx
return
.forward_word
'------------
if cursor_x = len(v$(cursor_y,chunk_idx)) then return
do while mid$(v$(cursor_y,chunk_idx),cursor_x+1,1) <> " "
cursor_x=cursor_x+1
if cursor_x = len(v$(cursor_y,chunk_idx)) then return
loop
do while mid$(v$(cursor_y,chunk_idx),cursor_x+1,1) = " "
cursor_x=cursor_x+1
if cursor_x = len(v$(cursor_y,chunk_idx)) then return
loop
return
.previous_word
'-------------
if cursor_x = 0 then return
if cursor_x = 1 then cursor_x = 0: return
cursor_x = cursor_x - 1
do while mid$(v$(cursor_y,chunk_idx),cursor_x+1,1) = " "
cursor_x=cursor_x-1
if cursor_x = 0 then return
loop
do while mid$(v$(cursor_y,chunk_idx),cursor_x+1,1) <> " "
cursor_x=cursor_x-1
if cursor_x = 0 then return
loop
cursor_x=cursor_x+1
return
.set_all_env
'-----------
for row = 0 to 9
gosub set_env
next row
return
.load
'----
input "load name: ";key$
if key$="" then return
dopen #2,(key$),r,u8
' load melody chunks
' ------------------
input #2, chunk_cnt
for chunk_idx = 0 to chunk_cnt - 1
for vidx=0 to 5
input #2,v$(vidx, chunk_idx)
next vidx
next chunk_idx
input #2,tmpo%
' load envelopes
' --------------
for row = 0 to 9
input #2, envs_name$(row)
input #2, envs_attack(row)
input #2, envs_decay(row)
input #2, envs_sustain(row)
input #2, envs_release(row)
input #2, envs_waveform(row)
input #2, envs_pw(row)
gosub set_env
next row
print
' load filter presets
' -------------------
for row = 0 to 10
input #2, filt_name$(row)
input #2, filt_freq(row)
input #2, filt_lp(row)
input #2, filt_bp(row)
input #2, filt_hp(row)
input #2, filt_res(row)
input #2, filt_dir(row)
input #2, filt_min(row)
input #2, filt_sweep(row)
next row
' load sequence
' -------------
seqcnt = 0
input #2, seqcnt
row = 0
do while row < seqcnt
input #2, seq_chunk(row)
input #2, seq_extra(row)
row = row + 1
loop
dclose #2
chunk_idx = 0
return
.get_chunk_cnt
'-------------
chunk_cnt = 0
for k = 0 to chunk_max
if v$(0,k)<>"" or v$(1,k)<>"" or v$(2,k)<>"" or v$(3,k)<>"" or v$(4,k)<>"" or v$(5,k)<>"" then begin
chunk_cnt = k + 1
bend
next k
return
.save
'----
input "save name: ";key$
if key$="" then return
delete (key$)
dopen #2,(key$),w,u8
tmp = chunk_idx
' save melody chunks
' ------------------
gosub get_chunk_cnt
print #2, chunk_cnt
for chunk_idx = 0 to chunk_cnt - 1
for vidx=0 to 5
print #2,v$(vidx, chunk_idx)
next vidx
next chunk_idx
print #2,tmpo%
' save envelopes
' --------------
for row = 0 to 9
print #2, envs_name$(row)
print #2, envs_attack(row)
print #2, envs_decay(row)
print #2, envs_sustain(row)
print #2, envs_release(row)
print #2, envs_waveform(row)
print #2, envs_pw(row)
next row
' save filter presets
' -------------------
for row = 0 to 10
print #2, filt_name$(row)
print #2, filt_freq(row)
print #2, filt_lp(row)
print #2, filt_bp(row)
print #2, filt_hp(row)
print #2, filt_res(row)
print #2, filt_dir(row)
print #2, filt_min(row)
print #2, filt_sweep(row)
next row
' save sequence
' -------------
print #2, seqcnt
row = 0
do while row < seqcnt
print #2, seq_chunk(row)
print #2, seq_extra(row)
row = row + 1
loop
dclose #2
chunk_idx = tmp
return
.save_as_text
'------------
input "save (as text) name: ";key$
if key$="" then return
delete (key$)
dopen #2,(key$),w,u8
for chunk_idx = 0 to chunk_max
for vidx=0 to 5
print #2, "v";chr$(49+vidx);"$(";str$(chunk_idx);")=";
print #2, chr$(34);v$(vidx, chunk_idx);chr$(34)
next vidx
print #2, ""
next chunk_idx
dclose #2
chunk_idx = 0
return
.user_input
'----------
' getkey key$
gosub read_key_loop
key$ = a$
gosub check_alt_key_inputs
' down arrow?
if key$ = KEY_DOWN and cursor_y<5 then begin
cursor_y = cursor_y + 1
if cursor_x > len(v$(cursor_y,chunk_idx)) then cursor_x = {x5F}
len(v$(cursor_y,chunk_idx))
bend
' up arrow?
if key$ = KEY_UP and cursor_y>0 then begin
cursor_y = cursor_y - 1
if cursor_x > len(v$(cursor_y,chunk_idx)) then {x5F}
cursor_x = len(v$(cursor_y,chunk_idx))
bend
' right arrow?
if key$ = KEY_RIGHT and cursor_x < len(v$(cursor_y,chunk_idx)) then begin
cursor_x=cursor_x+1
bend
' left arrow?
if key$ = KEY_LEFT and cursor_x > 0 then cursor_x=cursor_x-1
' backspace (inst/del)?
if key$ = KEY_DEL and cursor_x > 0 then begin
v$(cursor_y,chunk_idx)=left$(v$(cursor_y,chunk_idx),cursor_x-1) {x5F}
+ mid$(v$(cursor_y,chunk_idx),cursor_x+1)
cursor_x=cursor_x-1
bend
if esc_flag% then begin
esc_flag%=0
if key$ = "j" then begin:cursor_x=0:bend
if key$ = "k" then begin:cursor_x=len(v$(cursor_y,chunk_idx)):bend
if key$=KEY_ESCAPE then gosub stop_all_music
key$=""
bend
if key$ = KEY_ESCAPE then esc_flag%=abs(esc_flag%-1)
' ctrl-w = forward one word
if key$ = KEY_CTRL_W then gosub forward_word
' ctrl-u = back one word
if key$ = KEY_CTRL_U then gosub previous_word
' < / > = previous/next chunk
if key$ = "<" and chunk_idx>0 then begin
chunk_idx=chunk_idx-1
cursor_x=0
bend
if key$ = ">" and chunk_idx<chunk_max then begin
chunk_idx=chunk_idx+1
cursor_x=0
bend
' +/- = tempo change
if key$="-" then tmpo%=tmpo%-1
if key$="+" then tmpo%=tmpo%+1
' mega-q = exit
if key$ = KEY_MEGA_Q then begin
print "are you sure? (y/n)"
get key a$
if a$="y" then key on:end
bend
if key$ = KEY_F1 then gosub load
if key$ = KEY_F3 then gosub save
if key$ = KEY_F7 then gosub envelope_editor
if key$ = KEY_F9 then gosub chunk_sequencer
' F4 = save as text
if key$ = KEY_F4 then gosub save_as_text
' return=play row
if key$ = KEY_RETURN then tempo tmpo% : play v$(cursor_y,chunk_idx)
' shift+return=play all channels
if key$ = KEY_SHIFT_RETURN then begin
tempo tmpo%
gosub play_chunk_idx
bend
if key$ = KEY_INST then begin
v1$ = v$(cursor_y, chunk_idx)
v1$ = left$(v1$,cursor_x) + mid$(v1$,cursor_x+2)
v$(cursor_y, chunk_idx) = v1$
bend
gosub check_valid_key
return
.check_alt_key_inputs
'--------------------
alt_key = peek($d611) and 16
if alt_key = 0 then return
if key$="x" then clip$=v$(cursor_y, chunk_idx) : v$(cursor_y, chunk_idx) = ""
if key$="c" then clip$=v$(cursor_y, chunk_idx)
if key$="v" then v$(cursor_y, chunk_idx) = clip$
if key$="C" then gosub copy_all_voices_to_clipboard
if key$="V" then gosub paste_all_voices_from_clipboard
if key$=KEY_RETURN then begin
v1$ = mid$(v$(cursor_y, chunk_idx), cursor_x + 1)
tempo tmpo% : play v1$
bend
if key$="," then delta = -1 : gosub transpose_octave
if key$="." then delta = 1 : gosub transpose_octave
if key$="i" then gosub insert_chunk
key$ = ""
return
.copy_all_voices_to_clipboard
'----------------------------
for y = 0 to 5
cp$(y) = v$(y, chunk_idx)
next y
return
.paste_all_voices_from_clipboard
'-------------------------------
for y = 0 to 5
v$(y, chunk_idx) = cp$(y)
next y
return
.insert_chunk
'------------
for k = chunk_max-1 to chunk_idx + 1 step -1
for y = 0 to 5
v$(y, k) = v$(y, k-1)
next y
next k
for y = 0 to 5
v$(y, chunk_idx) = ""
next y
' repair items in the sequence that are affected
for k = 0 to 100
if seq_chunk(k) >= chunk_idx then seq_chunk(k) = seq_chunk(k) + 1
next k
return
.transpose_octave
'----------------
v1$ = v$(cursor_y, chunk_idx)
limit = 0
if delta = 1 then limit = 6
ret% = 0
gosub can_transpose_octave
if ret% = 0 then print KEY_BEEP; : return
k = 0
do while k < len(v1$)
v2$ = mid$(v1$,k+1,1)
if v2$ = "o" and (k + 1) < len(v1$) then begin
v2$ = str$(val(mid$(v1$,k+2,1)) + delta)
v2$ = mid$(v2$,2)
v1$ = left$(v1$,k+1) + v2$ + mid$(v1$, k+3)
bend
k = k + 1
loop
v$(cursor_y, chunk_idx) = v1$
return
.can_transpose_octave
'--------------------
ret% = 1
k = 0
do while k < len(v1$)
v2$ = mid$(v1$,k+1,1)
if v2$ = "o" and (k+1) < len(v1$) then begin
v2$ = mid$(v1$,k+2,1)
if val(v2$) = limit then ret% = 0 : return
bend
k = k + 1
loop
return
.play_chunk_idx
'--------------
v1$ = v$(0,chunk_idx)
v2$ = v$(1,chunk_idx)
v3$ = v$(2,chunk_idx)
v4$ = v$(3,chunk_idx)
v5$ = v$(4,chunk_idx)
v6$ = v$(5,chunk_idx)
if echo_delay = 1 then begin
play v1$
sleep (echo_sz)
play ,v2$
sleep (echo_sz)
play ,,v3$
sleep (echo_sz)
play ,,,v4$
sleep (echo_sz)
play ,,,,v5$
sleep (echo_sz)
play ,,,,,v6$
sleep (echo_sz)
return
bend
if echo_m = 0 and echo_b = 0 then begin
play v1$, v2$, v3$, v4$, v5$, v6$
return
bend
if echo_m = 1 and echo_b = 0 then begin
play v1$, v2$, v3$, , v5$, v6$
sleep (echo_sz)
play , , , v1$
bend
if echo_m = 1 and echo_b = 1 then begin
play v1$, v2$, v3$, , v5$
sleep (echo_sz)
play , , , v1$, , v3$
bend
if echo_m = 2 and echo_b = 0 then begin
play v1$, , v3$, , , v6$
sleep (echo_sz)
play , , , v1$
sleep (echo_sz)
play , v1$
sleep (echo_sz)
play , , , , v1$
bend
if echo_m = 2 and echo_b = 1 then begin
play v1$, , v3$
sleep (echo_sz)
play , , , v1$
sleep (echo_sz)
play , v1$, , , , v3$
sleep (echo_sz)
play , , , , v1$
bend
return
.envelope_editor
'---------------
do while 1
gosub draw_table
gosub get_user_input_for_table
' alt+q to exit
if a$ = KEY_MEGA_Q then exit
loop
return
.draw_table
'----------
print "{x93}env editor";KEY_TAB;dur$(sdur, DNAME);KEY_TAB;"octave";oct
print "----------"
print "-/+: decr/incr, </>: octave, RTN: edit, TAB: focus env/filter, MEGA+Q: exit"
print
print " NAME";KEY_TAB;KEY_TAB;"ATTACK";KEY_TAB;"DECAY";KEY_TAB;"SUSTAIN";KEY_TAB;"RELEASE";KEY_TAB;
print "WAVEFRM";KEY_TAB;"PULSEWIDTH"
for row = 0 to 9
if srow = row then print ">";:else print " ";
print row;": ";
col = 0 : v$ = envs_name$(row)
gosub show_cell
col = 1 : v = envs_attack(row)
gosub show_cell
col = 2 : v = envs_decay(row)
gosub show_cell
col = 3 : v = envs_sustain(row)
gosub show_cell
col = 4 : v = envs_release(row)
gosub show_cell
col = 5 : v = envs_waveform(row)
gosub show_cell
col = 6 : v = envs_pw(row)
gosub show_cell
print
next row
print
print "filter editor"
print "-------------";
print KEY_TAB;"freq";KEY_TAB;"lp";KEY_TAB;"bp";KEY_TAB;"hp";KEY_TAB;"res";
print KEY_TAB;"dir";KEY_TAB;"min";KEY_TAB;"sweep"
for fpreset = 0 to 10
gosub show_filter
next fpreset
return
.show_filter
'-----------
if fsel = fpreset then print ">";:else print " ";
k = 0 : gosub check_show_filter_highlight
print filt_name$(fpreset);" ";KEY_TAB;
k = 1 : gosub check_show_filter_highlight
print filt_freq(fpreset);KEY_TAB;
k = 2 : gosub check_show_filter_highlight
print filt_state_name$(filt_lp(fpreset));KEY_TAB;
k = 3 : gosub check_show_filter_highlight
print filt_state_name$(filt_bp(fpreset));KEY_TAB;
k = 4 : gosub check_show_filter_highlight
print filt_state_name$(filt_hp(fpreset));KEY_TAB;
k = 5 : gosub check_show_filter_highlight
print filt_res(fpreset);KEY_TAB;
k = 6 : gosub check_show_filter_highlight
print dir_name$(filt_dir(fpreset));KEY_TAB;
k = 7 : gosub check_show_filter_highlight
print filt_min(fpreset);KEY_TAB;
k = 8 : gosub check_show_filter_highlight
print filt_sweep(fpreset);
print KEY_REV_OFF
return
.check_show_filter_highlight
'---------------------------
if fsrow = fpreset and ffocus = 1 and fscol = k then {x5F}
print KEY_REV_ON; : else print KEY_REV_OFF;
return
.get_val
'-------
if scol = 0 then v$ = envs_name$(srow)
if scol = 1 then v = envs_attack(srow)
if scol = 2 then v = envs_decay(srow)
if scol = 3 then v = envs_sustain(srow)
if scol = 4 then v = envs_release(srow)
if scol = 5 then v = envs_waveform(srow)
if scol = 6 then v = envs_pw(srow)
return
.show_cell
'---------
if srow=row and scol = col and ffocus=0 then print KEY_REV_ON;:else print KEY_REV_OFF;
if col = 0 then begin
print v$;KEY_TAB;"{x92}";
return
bend
if col = 5 then begin
print wname$(v);KEY_TAB;KEY_REV_OFF;
return
bend
' else
print v;KEY_TAB;KEY_REV_OFF;
return
.get_user_input_for_table
'------------------------
' get key a$
gosub read_key_loop
if a$ = KEY_LEFT and scol > 0 then scol = scol - 1
if a$ = KEY_RIGHT and scol < 6 then scol = scol + 1
if a$ = KEY_UP and srow > 0 then srow = srow - 1
if a$ = KEY_DOWN and srow < 9 then srow = srow + 1
if a$ = "+" or a$="=" then delta=1 : gosub incr_val
if a$ = "-" then delta=1 : gosub decr_val
if a$ = KEY_SHIFT_PLUS then delta=100 : gosub incr_val
if a$ = KEY_SHIFT_MINUS then delta=100 : gosub decr_val
if a$ = KEY_RETURN then a$ = "+" : gosub edit_env_field
if a$ = KEY_SHIFT_RETURN then a$ = "-" : gosub edit_env_field
if a$ = KEY_TAB then ffocus = 1 : gosub get_user_input_for_filters
gosub check_duration_change
gosub check_piano_keys
return
.get_user_input_for_filters
'--------------------------
do while 1
gosub draw_table
' get key a$
gosub read_key_loop
if a$ = KEY_LEFT and fscol > 0 then fscol = fscol - 1
if a$ = KEY_RIGHT and fscol < 8 then fscol = fscol + 1
if a$ = KEY_UP and fsrow > 0 then fsrow = fsrow - 1
if a$ = KEY_DOWN and fsrow < 10 then fsrow = fsrow + 1
if a$ = "+" or a$="=" then delta=1 : gosub incr_fval
if a$ = "-" then delta=1 : gosub decr_fval
if a$ = KEY_SHIFT_PLUS then delta = 100 : gosub incr_fval
if a$ = KEY_SHIFT_MINUS then delta = 100 : gosub decr_fval
if a$ = " " then begin
if fsel = fsrow then fsel = -1:else fsel = fsrow
gosub apply_selected_filter
bend
if a$ = KEY_RETURN then gosub edit_filter_field:gosub apply_selected_filter
if a$ = KEY_TAB or a$ = KEY_MEGA_Q then exit
gosub check_duration_change
gosub check_piano_keys
loop
ffocus = 0
return
.read_key_loop
'-------------
a$ = ""
do while a$=""
get a$
if fsel <> -1 then begin
gosub update_selected_filter
bend
if plyflag = 1 then begin
if rplay(1) = 0 then gosub parse_current_seqptr
bend
loop
return
.parse_current_seqptr
'--------------------
k = seq_chunk(plyptr)
if k >= 0 then begin
chunk_idx = k
if chunk_rpt <= 0 then chunk_rpt = seq_extra(plyptr)
gosub play_chunk_idx
sleep .1
gosub draw_sequence
bend
if k = CMD_TEMPO then begin
k = seq_extra(plyptr)
tempo (k)
tmpo% = k
bend
if k = CMD_FILTER then begin
k = seq_extra(plyptr)
fsrow = k
fsel = k
gosub apply_selected_filter
bend
if k = CMD_ECHO_M1 then echo_m = 1 : echo_delay = 0
if k = CMD_ECHO_M2 then echo_m = 2 : echo_delay = 0
if k = CMD_ECHO_B then echo_b = 1 : echo_delay = 0
if k = CMD_ECHO_OFF then echo_m = 0 : echo_b = 0
if k = CMD_ECHO_SZ then echo_sz = seq_extra(plyptr)
if k = CMD_DELAY then echo_delay = 1 : echo_m = 0 : echo_b = 0
if k = CMD_VOL then v = seq_extra(plyptr) : vol v, v