-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmid2coco.bas
2606 lines (2519 loc) · 106 KB
/
mid2coco.bas
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
' MIDI file to CoCo MOD converter V 1.00 by Glen Hewlett
' Do whatever you want with it :)
'--------------------------------------------------------
'Key Signature data
DATA "C","D","E","F","G","A","B"
'Note Data
DATA "C","C#","D","D#","E","F","F#","G","G#","A","A#","B"
'Event names
DATA "Header","Start_track","Note_off_c","Note_on_c","Poly_aftertouch_c","Control_c","Program_c","Channel_aftertouch_c","Pitch_bend_c"
DATA "System_exclusive","Sequence_number","Text_t","Copyright_t","Title_t","Instrument_name_t","Lyric_t","Marker_t","Cue_point_t","Channel_prefix"
DATA "MIDI_port","End_track","Tempo","SMPTE_offset","Time_signature","Key_signature","Sequencer_specific","Unknown_event"
'General MIDI Instrument Patch Map
DATA "Acoustic Grand Piano","Bright Acoustic Piano","Electric Grand Piano","Honky-tonk Piano","Electric Piano 1 (Rhodes Piano)","Electric Piano 2 (Chorused Piano)"
DATA "Harpsichord","Clavinet","Celesta","Glockenspiel","Music Box","Vibraphone","Marimba","Xylophone","Tubular Bells","Dulcimer (Santur)","Drawbar Organ (Hammond)"
DATA "Percussive Organ","Rock Organ","Church Organ","Reed Organ","Accordion (French)","Harmonica","Tango Accordion (Band neon)","Acoustic Guitar (nylon)"
DATA "Acoustic Guitar (steel)","Electric Guitar (jazz)","Electric Guitar (clean)","Electric Guitar (muted)","Overdriven Guitar","Distortion Guitar"
DATA "Guitar harmonics","Acoustic Bass","Electric Bass (fingered)","Electric Bass (picked)","Fretless Bass","Slap Bass 1","Slap Bass 2","Synth Bass 1","Synth Bass 2"
DATA "Violin","Viola","Cello","Contrabass","Tremolo Strings","Pizzicato Strings","Orchestral Harp","Timpani","String Ensemble 1 (strings)","String Ensemble 2 (slow strings)"
DATA "SynthStrings 1","SynthStrings 2","Choir Aahs","Voice Oohs","Synth Voice","Orchestra Hit","Trumpet","Trombone","Tuba","Muted Trumpet","French Horn","Brass Section"
DATA "SynthBrass 1","SynthBrass 2","Soprano Sax","Alto Sax","Tenor Sax","Baritone Sax","Oboe","English Horn","Bassoon","Clarinet","Piccolo","Flute","Recorder"
DATA "Pan Flute","Blown Bottle","Shakuhachi","Whistle","Ocarina","Lead 1 (square wave)","Lead 2 (sawtooth wave)","Lead 3 (calliope)","Lead 4 (chiffer)","Lead 5 (charang)"
DATA "Lead 6 (voice solo)","Lead 7 (fifths)","Lead 8 (bass + lead)","Pad 1 (new age Fantasia)","Pad 2 (warm)","Pad 3 (polysynth)","Pad 4 (choir space voice)"
DATA "Pad 5 (bowed glass)","Pad 6 (metallic pro)","Pad 7 (halo)","Pad 8 (sweep)","FX 1 (rain)","FX 2 (soundtrack)","FX 3 (crystal)","FX 4 (atmosphere)","FX 5 (brightness)"
DATA "FX 6 (goblins)","FX 7 (echoes, drops)","FX 8 (sci-fi, star theme)","Sitar","Banjo","Shamisen","Koto","Kalimba","Bag pipe","Fiddle","Shanai","Tinkle Bell","Agogo"
DATA "Steel Drums","Woodblock","Taiko Drum","Melodic Tom","Synth Drum","Reverse Cymbal","Guitar Fret Noise","Breath Noise","Seashore","Bird Tweet","Telephone Ring"
DATA "Helicopter","Applause","Gunshot"
'Game Master Cartridge Frequency values Can't play notes below B2
' Frequency
DATA EE,F: 'C-1 0
DATA EE,F: 'C#-1/Db-1
DATA EE,F: 'D-1
DATA EE,F: 'D#-1/Eb-1
DATA EE,F: 'E-1
DATA EE,F: 'F-1
DATA EE,F: 'F#-1/Gb-1
DATA EE,F: 'G-1
DATA EE,F: 'G#-1/Ab-1
DATA EE,F: 'A-1
DATA EE,F: 'A#-1/Bb-1
DATA EE,F: 'B-1
DATA EE,F: 'C0 16.35 12
DATA EE,F: 'C#0/Db0 17.32
DATA EE,F: 'D0 18.35
DATA EE,F: 'D#0/Eb0 19.45
DATA EE,F: 'E0 20.6
DATA EE,F: 'F0 21.83
DATA EE,F: 'F#0/Gb0 23.12
DATA EE,F: 'G0 24.5
DATA EE,F: 'G#0/Ab0 25.96
DATA EE,F: 'A0 27.5
DATA EE,F: 'A#0/Bb0 29.14
DATA EE,F: 'B0 30.87
DATA EE,F: 'C1 32.7 24
DATA E1,8: 'C#1/Db1 34.65
DATA D4,D: 'D1 36.71
DATA C8,E: 'D#1/Eb1 38.89
DATA BD,A: 'E1 41.2
DATA B3,0: 'F1 43.65
DATA A8,F: 'F#1/Gb1 46.25
DATA 9F,7: 'G1 49
DATA 96,8: 'G#1/Ab1 51.91
DATA 8E,1: 'A1 55
DATA 86,1: 'A#1/Bb1 58.27
DATA 7E,9: 'B1 61.74
DATA 77,7: 'C2 65.41 36
DATA 70,C: 'C#2/Db2 69.3
DATA 6A,7: 'D2 73.42
DATA 64,7: 'D#2/Eb2 77.78
DATA 5E,D: 'E2 82.41
DATA 59,8: 'F2 87.31
DATA 54,7: 'F#2/Gb2 92.5
DATA 4F,C: 'G2 98
DATA 4B,4: 'G#2/Ab2 103.83
DATA 47,0: 'A2 110
DATA 43,1: 'A#2/Bb2 116.54
DATA 3F,4: 'B2 123.47 *** Lowest Note GMC can play unless you use a different clock chip in the cartridge
DATA 3B,C: 'C3 130.81 48
DATA 38,6: 'C#3/Db3 138.59
DATA 35,3: 'D3 146.83
DATA 32,4: 'D#3/Eb3 155.56
DATA 2F,6: 'E3 164.81
DATA 2C,C: 'F3 174.61
DATA 2A,4: 'F#3/Gb3 185
DATA 27,E: 'G3 196
DATA 25,A: 'G#3/Ab3 207.65
DATA 23,8: 'A3 220
DATA 21,8: 'A#3/Bb3 233.08
DATA 1F,A: 'B3 246.94
DATA 1D,E: 'C4 261.63 60 - MIDI programs use C4=72
DATA 1C,3: 'C#4/Db4 277.18
DATA 1A,A: 'D4 293.66
DATA 19,2: 'D#4/Eb4 311.13
DATA 17,B: 'E4 329.63
DATA 16,6: 'F4 349.23
DATA 15,2: 'F#4/Gb4 369.99
DATA 13,F: 'G4 392
DATA 12,D: 'G#4/Ab4 415.3
DATA 11,C: 'A4 440
DATA 10,C: 'A#4/Bb4 466.16
DATA F,D: 'B4 493.88
DATA E,F: 'C5 523.25 72
DATA E,1: 'C#5/Db5 554.37
DATA D,5: 'D5 587.33
DATA C,9: 'D#5/Eb5 622.25
DATA B,E: 'E5 659.25
DATA B,3: 'F5 698.46
DATA A,9: 'F#5/Gb5 739.99
DATA 9,F: 'G5 783.99
DATA 9,6: 'G#5/Ab5 830.61
DATA 8,E: 'A5 880
DATA 8,6: 'A#5/Bb5 932.33
DATA 7,F: 'B5 987.77
DATA 7,7: 'C6 1046.5 84
DATA 7,1: 'C#6/Db6 1108.73
DATA 6,A: 'D6 1174.66
DATA 6,4: 'D#6/Eb6 1244.51
DATA 5,F: 'E6 1318.51
DATA 5,9: 'F6 1396.91
DATA 5,4: 'F#6/Gb6 1479.98
DATA 5,0: 'G6 1567.98
DATA 4,B: 'G#6/Ab6 1661.22
DATA 4,7: 'A6 1760
DATA 4,3: 'A#6/Bb6 1864.66
DATA 3,F: 'B6 1975.53
DATA 3,C: 'C7 2093 96
DATA 3,8: 'C#7/Db7 2217.46
DATA 3,5: 'D7 2349.32
DATA 3,2: 'D#7/Eb7 2489.02
DATA 2,F: 'E7 2637.02
DATA 2,D: 'F7 2793.83
DATA 2,A: 'F#7/Gb7 2959.96
DATA 2,8: 'G7 3135.96
DATA 2,6: 'G#7/Ab7 3322.44
DATA 2,4: 'A7 3520
DATA 2,2: 'A#7/Bb7 3729.31
DATA 2,0: 'B7 3951.07
DATA 1,E: 'C8 4186.01 108
DATA 1,C: 'C#8/Db8 4434.92
DATA 1,B: 'D8 4698.63
DATA 1,9: 'D#8/Eb8 4978.03
DATA 1,8: 'E8 5274.04
DATA 1,6: 'F8 5587.65
DATA 1,5: 'F#8/Gb8 5919.91
DATA 1,4: 'G8 6271.93
DATA 1,3: 'G#8/Ab8 6644.88
DATA 1,2: 'A8 7040
DATA 1,1: 'A#8/Bb8 7458.62
DATA 1,0: 'B8 7902.13
DATA 0,E: 'C9 8,372.02 120
DATA 0,E: 'C#9/Db9 8,869.84
DATA 0,D: 'D9 9,397.27
DATA 0,C: 'D#9/Eb9 9,956.06
DATA 0,B: 'E9 10,548.08
DATA 0,B: 'F9 11,175.30
DATA 0,A: 'F#9/Gb9 11,839.82
DATA 0,9: 'G9 12,543.85
'CoCo PSG Frequency values Can't play notes below B0 value with clock at 2Mhz
' Frequency
DATA F,D1: 'C-1 0
DATA F,D1: 'C#-1/Db-1
DATA F,D1: 'D-1
DATA F,D1: 'D#-1/Eb-1
DATA F,D1: 'E-1
DATA F,D1: 'F-1
DATA F,D1: 'F#-1/Gb-1
DATA F,D1: 'G-1
DATA F,D1: 'G#-1/Ab-1
DATA F,D1: 'A-1
DATA F,D1: 'A#-1/Bb-1
DATA F,D1: 'B-1
DATA F,D1: 'C0 16.35 12
DATA F,D1: 'C#0/Db0 17.32
DATA F,D1: 'D0 18.35
DATA F,D1: 'D#0/Eb0 19.45
DATA F,D1: 'E0 20.6
DATA F,D1: 'F0 21.83
DATA F,D1: 'F#0/Gb0 23.12
DATA F,D1: 'G0 24.5
DATA F,D1: 'G#0/Ab0 25.96
DATA F,D1: 'A0 27.5
DATA F,D1: 'A#0/Bb0 29.14
DATA F,D1: 'B0 30.87 *** Lowest note @ 2Mhz
DATA E,EE: 'C1 32.7 24
DATA E,17: 'C#1/Db1 34.65
DATA D,4D: 'D1 36.71
DATA C,8E: 'D#1/Eb1 38.89
DATA B,D9: 'E1 41.2
DATA B,2F: 'F1 43.65
DATA A,8E: 'F#1/Gb1 46.25
DATA 9,F7: 'G1 49
DATA 9,67: 'G#1/Ab1 51.91
DATA 8,E0: 'A1 55
DATA 8,61: 'A#1/Bb1 58.27
DATA 7,E8: 'B1 61.74
DATA 7,77: 'C2 65.41 36
DATA 7,0B: 'C#2/Db2 69.3
DATA 6,A6: 'D2 73.42
DATA 6,47: 'D#2/Eb2 77.78
DATA 5,EC: 'E2 82.41
DATA 5,97: 'F2 87.31
DATA 5,47: 'F#2/Gb2 92.5
DATA 4,FB: 'G2 98
DATA 4,B3: 'G#2/Ab2 103.83
DATA 4,70: 'A2 110
DATA 4,30: 'A#2/Bb2 116.54
DATA 3,F4: 'B2 123.47
DATA 3,BB: 'C3 130.81 48
DATA 3,85: 'C#3/Db3 138.59
DATA 3,53: 'D3 146.83
DATA 3,23: 'D#3/Eb3 155.56
DATA 2,F6: 'E3 164.81
DATA 2,CB: 'F3 174.61
DATA 2,A3: 'F#3/Gb3 185
DATA 2,7D: 'G3 196
DATA 2,59: 'G#3/Ab3 207.65
DATA 2,38: 'A3 220
DATA 2,18: 'A#3/Bb3 233.08
DATA 1,FA: 'B3 246.94
DATA 1,DD: 'C4 261.63 60
DATA 1,C2: 'C#4/Db4 277.18
DATA 1,A9: 'D4 293.66
DATA 1,91: 'D#4/Eb4 311.13
DATA 1,7B: 'E4 329.63
DATA 1,65: 'F4 349.23
DATA 1,51: 'F#4/Gb4 369.99
DATA 1,3E: 'G4 392
DATA 1,2C: 'G#4/Ab4 415.3
DATA 1,1C: 'A4 440
DATA 1,0C: 'A#4/Bb4 466.16
DATA 0,FD: 'B4 493.88
DATA 0,EE: 'C5 523.25 72
DATA 0,E1: 'C#5/Db5 554.37
DATA 0,D4: 'D5 587.33
DATA 0,C8: 'D#5/Eb5 622.25
DATA 0,BD: 'E5 659.25
DATA 0,B2: 'F5 698.46
DATA 0,A8: 'F#5/Gb5 739.99
DATA 0,9F: 'G5 783.99
DATA 0,96: 'G#5/Ab5 830.61
DATA 0,8E: 'A5 880
DATA 0,86: 'A#5/Bb5 932.33
DATA 0,7E: 'B5 987.77
DATA 0,77: 'C6 1046.5 84
DATA 0,70: 'C#6/Db6 1108.73
DATA 0,6A: 'D6 1174.66
DATA 0,64: 'D#6/Eb6 1244.51
DATA 0,5E: 'E6 1318.51
DATA 0,59: 'F6 1396.91
DATA 0,54: 'F#6/Gb6 1479.98
DATA 0,4F: 'G6 1567.98
DATA 0,4B: 'G#6/Ab6 1661.22
DATA 0,47: 'A6 1760
DATA 0,43: 'A#6/Bb6 1864.66
DATA 0,3F: 'B6 1975.53
DATA 0,3B: 'C7 2093 96
DATA 0,38: 'C#7/Db7 2217.46
DATA 0,35: 'D7 2349.32
DATA 0,32: 'D#7/Eb7 2489.02
DATA 0,2F: 'E7 2637.02
DATA 0,2C: 'F7 2793.83
DATA 0,2A: 'F#7/Gb7 2959.96
DATA 0,27: 'G7 3135.96
DATA 0,25: 'G#7/Ab7 3322.44
DATA 0,23: 'A7 3520
DATA 0,21: 'A#7/Bb7 3729.31
DATA 0,1F: 'B7 3951.07
DATA 0,1D: 'C8 4186.01 108
DATA 0,1C: 'C#8/Db8 4434.92
DATA 0,1A: 'D8 4698.63
DATA 0,19: 'D#8/Eb8 4978.03
DATA 0,17: 'E8 5274.04
DATA 0,16: 'F8 5587.65
DATA 0,15: 'F#8/Gb8 5919.91
DATA 0,13: 'G8 6271.93
DATA 0,12: 'G#8/Ab8 6644.88
DATA 0,11: 'A8 7040
DATA 0,10: 'A#8/Bb8 7458.62
DATA 0,F: 'B8 7902.13
DATA 0,E: 'C9 8,372.02 120
DATA 0,E: 'C#9/Db9 8,869.84
DATA 0,D: 'D9 9,397.27
DATA 0,C: 'D#9/Eb9 9,956.06
DATA 0,B: 'E9 10,548.08
DATA 0,B: 'F9 11,175.30
DATA 0,A: 'F#9/Gb9 11,839.82
DATA 0,9: 'G9 12,543.85
'PSG loader CoCo 6809 machine code which loads the PSG music into the 512k of RAM in the PSG, I think this might even work on a 4k CoCo with CoCo PSG and cassette :)
'See the source code "PSG_L1.ASM" which explains how it works
DATA "00","00","34","13","1A","50","B6","FF","7F","34","02","C6","FC","F7","FF","7F","34","04","CC","06","FF","FD","FF","5E","4A","2A","FA","86","06","8E","00","00","B7"
DATA "FF","5E","F6","FF","5F","3A","4A","2A","F6","35","04","8C","03","49","27","07","C1","FF","27","05","5C","20","D5","C4","03","35","02","B7","FF","7F","35","93","34"
DATA "56","8D","BD","C1","FF","26","2C","CE","04","00","8D","1A","45","52","52","4F","52","7A","4E","4F","60","43","4F","43","4F","50","53","47","60","46","4F","55","4E"
DATA "44","00","35","56","39","AE","E4","20","02","A7","C0","A6","80","26","FA","AF","E4","39","BE","FF","FE","8C","8C","1B","27","08","86","DE","B7","0E","CD","B7","0E"
DATA "F3","F7","0E","02","B6","FF","7F","B7","0E","06","84","FC","BA","0E","02","B7","FF","7F","B6","FF","5D","8A","10","B7","FF","5D","B6","FF","7F","58","58","58","58"
DATA "FA","0E","02","F7","0E","02","84","CC","BA","0E","02","B7","0E","07","B7","FF","7F","86","80","B7","FF","5A","F6","0E","03","5C","F7","0E","03","BE","0E","04","7F"
DATA "FF","DF","CE","C0","00","86","10","B7","FF","5D","B6","0E","06","B7","FF","7F","BD","A1","76","1A","50","7F","FF","DE","F6","0E","07","F7","FF","7F","C6","18","F7"
DATA "FF","5D","A7","C0","7F","FF","DF","1C","57","30","1F","26","05","7A","0E","03","27","0B","11","83","E0","00","25","CC","7C","FF","5A","20","C4","86","10","B7","FF"
DATA "5D","B6","0E","06","B7","FF","7F","FC","0E","00","FD","01","77","35","56","7E","01","76","00","00","02","01","77","0E","47","FF","00","00","0E","47"
SCREEN _NEWIMAGE(1280, 752, 256)
DIM array(5000000) AS _UNSIGNED _BYTE, TrackTitle$(100), InstrumentName$(100), EventName$(30), UsedTrack(100)
DIM Track(500000) AS _BYTE, Tick(500000), Event(500000) AS _BYTE, Channel(500000) AS _BYTE, Keynum(500000) AS _BYTE, Velocity(500000) AS _BYTE
DIM Track2(500000) AS _BYTE, Tick2(500000), Event2(500000) AS _BYTE, Channel2(500000) AS _BYTE, Keynum2(500000) AS _BYTE, Velocity2(500000) AS _BYTE
DIM BPM(10000), BPMChange(10000), tname$(16)
DIM note$(7), NoteName$(132), MIDIDev$(128)
DIM TrackInfo(100000, 128), noteTime(500000), noteOnOff(500000), note1(100000), note2(100000), note3(100000), note4(100000)
DIM vel1(100000) AS _UNSIGNED _BYTE, vel2(100000) AS _UNSIGNED _BYTE, vel3(100000) AS _UNSIGNED _BYTE, vel4(100000) AS _UNSIGNED _BYTE
DIM FI(200), GoodStart(200), ST(200), GoodEnd(200)
DIM CombineTracks(200) AS _BYTE, TempTrack(100000) AS _BYTE, TempTrackVel(100000) AS _BYTE
DIM GMC$(127, 1), PSG$(127, 1), TempOut(100000, 10) AS _UNSIGNED _BYTE, ramsize AS LONG
DIM DrumTrack(128) AS _UNSIGNED _BYTE, A AS _UNSIGNED _BYTE, velcon(15) AS _UNSIGNED _BYTE
'Read in Array data
FOR x = 1 TO 7: READ note$(x): NEXT x
FOR x = 0 TO 11: READ NoteName$(x): NEXT x
FOR x = 1 TO 27: READ EventName$(x): NEXT x
FOR y = 12 TO 120 STEP 12
FOR x = 0 TO 11
NoteName$(y + x) = NoteName$(x)
NEXT x
NEXT y
FOR x = 1 TO 128: READ MIDIDev$(x): NEXT x
'Read in Game Master Controller Frequency values
FOR x = 0 TO 127
FOR y = 1 TO 0 STEP -1
READ GMC$(x, y)
NEXT y
NEXT x
'Read in CoCo PSG Frequency values
FOR x = 0 TO 127
FOR y = 0 TO 1
READ PSG$(x, y)
NEXT y
NEXT x
' Fix values for velocity for PSG as it is logarithmic
velcon(0) = 0
velcon(1) = 4
velcon(2) = 9
velcon(3) = 11
velcon(4) = 11
velcon(5) = 12
velcon(6) = 12
velcon(7) = 13
velcon(8) = 13
velcon(9) = 13
velcon(10) = 14
velcon(11) = 14
velcon(12) = 14
velcon(13) = 15
velcon(14) = 15
velcon(15) = 15
'MIDI Events
' 1=Header
' 2=Start_track
' 3=Note_off_c
' 4=Note_on_c
' 5=Poly_aftertouch_c
' 6=Control_c
' 7=Program_c
' 8=Channel_aftertouch_c
' 9=Pitch_bend_c
'10=System_exclusive=
'11=Sequence_number
'12=Text_t
'13=Copyright_t
'14=Title_t
'15=Instrument_name_t
'16=Lyric_t
'17=Marker_t
'18=Cue_point_t
'19=Channel_prefix
'20=MIDI_port
'21=End_track
'22=Tempo
'23=SMPTE_offset
'24=Time_signature
'25=Key_signature
'26=Sequencer_specific
'27=Unknown_event
GOTO 11
10 Track(L) = Trk: Tick(L) = Tik: Event(L) = Evnt: Channel(L) = Chan: Keynum(L) = Keyn: Velocity(L) = Vel: L = L + 1: RETURN
11
PRINT "MIDI format to CoCo converter V 1.0:"
PRINT "By: Glen Hewlett"
PRINT
PRINT "Converts MIDI files to a CoCo audio file format"
PRINT
'GOTO 12
count = _COMMANDCOUNT
IF count < 1 THEN
PRINT "Usage: mid2cc MIDIfile"
PRINT "Where: MIDIfile is the source MIDI file."
PRINT
PRINT "The program will allow the user to convert MIDI files into a format that can be played back in the background"
PRINT "On a TRS-80 Color Computer. It can output the music in one of three formats"
PRINT "- Simon Jonassen's Dipole - two voice software player"
PRINT "- John Linveille's Game Master Cartridge - three voice plus one noise channel, hardware player"
PRINT "- Ed Snider's CoCo Programable Sound Generator - three voice, any voice could also play noise, hardware player"
END
END IF
FI = 0: nt = 0: newp = 0: endp = 0
FOR check = 1 TO count
N$ = COMMAND$(check)
' check if we have a file name yet if so then the next filename will be output
IF FI > 0 THEN Fname$ = N$: GOTO 100
FI = 1
Fname$ = N$
OPEN Fname$ FOR APPEND AS #1
length = LOF(1)
CLOSE #1
IF length < 1 THEN PRINT "Error file: "; Fname$; " is 0 bytes. Or doesn't exits.": KILL Fname$: END
PRINT "Length of Input file "; Fname$; " is:"; length
OPEN Fname$ FOR BINARY AS #1
GET #1, , array()
CLOSE #1
100 NEXT check
GOTO 12
'12
'N$ = "MISSION.MID"
'N$ = "Dreams.mid"
N$ = "fod.mid"
N$ = "FOD_Half.mid"
'N$ = "FOD_Full.mid"
'N$ = "HALLOWEE.MID"
'N$ = "Halloween2.mid"
N$ = "The_Doors_-_Riders_on_the_Storm.mid"
'N$ = "PEANUTS.MID"
'N$ = "C_Scale_C4_to_C8.mid"
'N$ = "ChromaticScale_C2_to_B7.mid"
'N$ = "X_FILES4.MID"
'N$ = "BLADERUN.MID"
'N$ = "DRWHO.MID"
'N$ = "LLDOB.MID"
'N$ = "Axelf.mid"
'N$ = "FOD_Fav.mid"
'N$ = "ESCAPENY.MID"
'N$ = "Shine_On_You_Crazy_Diamond.mid"
'N$ = "Sheep.mid"
'N$ = "CLOUDBUS.MID"
'N$ = "PETERGUN.MID"
'N$ = "FollowYouFollowMe.mid"
'N$ = "GaryJules_-_MadWorld.mid"
'N$ = "Tears_For_Fears_-_Head_Over_Heels.mid"
'N$ = "Yodas_Theme.mid"
'N$ = "Requiem_For_A_Dream.mid"
'N$ = "Bass_Drum_Hit.mid"
'N$ = "Bass_Hi-Hat.mid"
'N$ = "Hi-Hat.mid"
'N$ = "snare.mid"
'N$ = "VolumeTest.mid"
12
Fname$ = N$: OPEN Fname$ FOR BINARY AS #1: GET #1, , array(): CLOSE #1
t$ = "": cp = 0: L = 0: 't$=temp text, cp=current pointer to MIDI file array, L is the MIDI instruction described as a row
'read the header chunk of the MIDI file
FOR x = 0 TO 3
t$ = t$ + CHR$(array(cp)): cp = cp + 1
NEXT x
'load mv with a 4 byte value
GOSUB 340
IF t$ <> "MThd" OR mv <> 6 THEN PRINT "File "; Fname$; " is not a valid MIDI file": END
PRINT " Input file: "; Fname$
outname$ = Fname$ + ".asm"
OPEN outname$ FOR OUTPUT AS #2
'OPEN "test.asm" FOR OUTPUT AS #2
PRINT "Output file: "; outname$
'load mv with a 2 byte value to get the MIDI Type #
GOSUB 320: MF = mv
PRINT "MIDI Format is Type"; MF
'load mv with a 2 byte value to get the # of tracks in this MIDI file
'Type 0 MIDI file will only have one Track Chunk, Type 1 and Type 2 can have many...
GOSUB 320: TrackChunks = mv
PRINT "Number of MIDI Track Chunks"; TrackChunks
'get the Delta Time Info and figure out the TimeDivision
DT = array(cp)
IF DT AND 128 THEN ' DT = SMPTE standards
DT = 255 - DT + 1 ' convert from 2's compliment
IF DT = 29 THEN DT = 29.97
DTU = array(cp + 1) ' delta time units
PRINT "MIDI uses SMPTE time"; DT; "Frames per second and"; DTU; "'divisions per frame - Untested time format!!!"
PRINT "Code to handle this MIDI time format has been added as per the spec but it"
PRINT "hasn't been tested."
TimeDivision = DT * DTU
ELSE
TimeDivision = DT * 256 + array(cp + 1)
END IF
PRINT "MIDI delta-time increments (TimeDivision)"; TimeDivision; "each millisecond."
cp = cp + 2
Trk = 0: Tik = 0: Evnt = 1: Chan = MF: Keyn = TrackChunks: Vel = TimeDivision: GOSUB 10
'Initialize settings
BPM(0) = 120: 'default for MIDI if no BMP info given in the MIDI file
BPMCount = 0: BeatCount = 0: BPM = BPM(0)
'Main track input loop starts here
200
Trk = Trk + 1: Tik = 0: Evnt = 2: Chan = 0: Keyn = 0: Vel = 0: GOSUB 10: Event = 1 = Start_track
'Initialize the Total time for this track and the message/name of the track
Total = 0: mess$ = ""
t$ = "": RealTime = 0
FOR x = 1 TO 4
t$ = t$ + CHR$(array(cp)): cp = cp + 1
NEXT x
'Make sure the start of the new Track header is correct
IF t$ <> "MTrk" THEN 230: 'got to the end of the file (read all the tracks)
'Get 4 byte value in mv to get the size of the Trac kChunk
GOSUB 340: cs = mv
'PRINT #2, "Size of this track Chunk is"; cs
checksize = cp + cs
'Track Reading Loop
210
'Always get the time from last event in ticks, mv is a Variable Length Quantity
GOSUB 300: ticks = mv: Total = Total + ticks: Tik = Total
'Handle Tempo change, at the BPMChange() point add a note on and note off with 0 time difference
'This should ensure all Tempo changes are made on each channel at the same point in the score
tempoflag = 0
Event = array(cp): cp = cp + 1
'Check for System Exclusive Event
IF Event = &HF0 OR Event = &HF7 THEN
Evnt = 10: GOSUB 10
'Load mv with the Variable Length Quantity where cp is pointing in the array
GOSUB 300:
'ignore the Sys Exclusive info...
cp = cp + mv
GOTO 220
END IF
'Check for a Meta Event
IF Event = &HFF THEN
'PRINT #2, "Meta Event"
GOSUB 500: GOTO 220
END IF
IF Event < &H80 THEN
'Running status is used, same event as last time, so this event is actually data for the same type of event as last time
'PRINT #2, "Midi uses Running Status"
Event = lastevent
cp = cp - 1: ' move pointer back so it points to the data for this same event type as the last one
' PRINT HEX$(event), HEX$(array(cp)), HEX$(array(cp + 1)): SLEEP: END
END IF
'MIDI Messages
'turn event into lnibble,rnibble
GOSUB 350:
'PRINT #2, HEX$(lnibble), HEX$(rnibble), HEX$(array(cp - 1)), HEX$(array(cp)), HEX$(array(cp + 1))
'Remember the event so we can handle running status MIDI file event data
lastevent = Event
'Check for a Mode Message
IF lnibble = &HB AND array(cp) > &H77 THEN
'PRINT #2, "Channel Mode Messages"
GOSUB 700: GOTO 220
END IF
'If we get here then it is a Channel Voice Message
'PRINT #2, "Channel Voice Messages ";
GOSUB 600
220
'See if we are at the end of this track yet, loop if not
IF cp < checksize THEN 210
'Try to get name of track from MIDI message or device number
tname$(Midichan) = tname$(Midichan) + " - " + mess$: 'trackname$
IF LEN(tname$(Midichan)) > 72 THEN tname$(Midichan) = LEFT$(tname$(Midichan), 72)
'Loop to get another Track's data
GOTO 200
'We now have all the note info from the MIDI file
230
'Skip if MIDI format is Type 1, otherwise arange it so it's similar to a Type 1 MIDI file
IF MF = 1 THEN 239
x = 1
232
IF Channel(x) = 0 THEN
Track2(x) = Track(x)
Tick2(x) = Tick(x)
Event2(x) = Event(x)
Channel2(x) = Channel(x)
Keynum2(x) = Keynum(x)
Velocity2(x) = Velocity(x)
x = x + 1: GOTO 232
END IF
x = x + 1
Track2(x) = Track(x - 1)
Tick2(x) = Tick(x - 1)
Event2(x) = 21
Channel2(x) = Channel(x - 1)
Keynum2(x) = Keynum(x - 1)
Velocity2(x) = Velocity(x - 1)
x = x + 1
Track2(x) = Track(x - 2)
Tick2(x) = Tick(x - 2)
Event2(x) = 2
Channel2(x) = Channel(x - 2)
Keynum2(x) = Keynum(x - 2)
Velocity2(x) = Velocity(x - 2)
Chan = 0: st = x - 2: moveto = x + 1: movefrom = st: ad = 2
234
IF Channel(movefrom) = Chan THEN
Track2(moveto) = Track(movefrom)
Tick2(moveto) = Tick(movefrom)
Event2(moveto) = Event(movefrom)
Channel2(moveto) = Channel(movefrom)
Keynum2(moveto) = Keynum(movefrom)
Velocity2(moveto) = Velocity(movefrom)
moveto = moveto + 1
movefromLast = movefrom
END IF
movefrom = movefrom + 1
IF movefrom <= L THEN 234
Chan = Chan + 1
IF moveto <> movetoLast THEN
Track2(moveto) = Track(movefromLast)
Tick2(moveto) = Tick(movefromLast)
Event2(moveto) = 21
Channel2(moveto) = Channel(movefromLast)
Keynum2(moveto) = Keynum(movefromLast)
Velocity2(moveto) = Velocity(movefromLast)
moveto = moveto + 1
Track2(moveto) = Track(movefromLast)
Tick2(moveto) = 0
Event2(moveto) = 2
Channel2(moveto) = 0
Keynum2(moveto) = 0
Velocity2(moveto) = 0
moveto = moveto + 1
ad = ad + 2
movetoLast = moveto
END IF
movefrom = st
IF Chan < 16 THEN 234
238
L = L + ad - 2
' move data back
FOR x = 1 TO moveto - 1
Track(x) = Track2(x)
Tick(x) = Tick2(x)
Event(x) = Event2(x)
Channel(x) = Channel2(x)
Keynum(x) = Keynum2(x)
Velocity(x) = Velocity2(x)
NEXT x
239
'figure out the tracks that are empty and where the good ones start
C = 0
FOR x = 0 TO L
IF Event(x) = 7 OR Event(x) = 2 THEN 'Event 7 = Instrument change, Event 2 = Start track
'PRINT "Start Track or New Instrument"
ST(C) = x: C = C + 1
END IF
NEXT x
ST(C) = L
BC = 0: LT = 0: RTBPMC = 1: TickDiff = 0: RealTime = 0: UT = 1
FOR x = 0 TO L
noteOnOff(x) = 0
PRINT #2, Track(x); ","; Tick(x); ",Event #"; Event(x); EventName$(Event(x)); ","; Channel(x); ","; Keynum(x); ","; Velocity(x);
IF Event(x) = 7 THEN UT = UT + 1: 'Event 7 = Instrument Change
IF Event(x) = 22 THEN ' Event 22 = Tempo Change
PRINT #2, "="; INT(BPM(BC) + .5); "BPM": BC = BC + 1
ELSE
' track start
IF Event(x) = 2 THEN ' Event 2 = Start New Track
UT = UT + 1
flag = 1
RTBPMC = 1
TickDiff = 0
RealTime = 0
noteTime(x) = 0
PRINT #2,
ELSE
IF x > 0 AND Event(x) <> 21 THEN ' Event 21 = End Track
IF RTBPMC <= BPMCount AND Tick(x) >= BPMChange(RTBPMC) THEN
LastTick = Tick(x - 1)
WHILE RTBPMC <= BPMCount AND Tick(x) > BPMChange(RTBPMC)
'PRINT "found Time to update tempo and time."
TickDiff = BPMChange(RTBPMC) - LastTick
RealTime = RealTime + (TickDiff / TimeDivision) * (60000 / BPM(RTBPMC - 1))
TickDiff = Tick(x) - BPMChange(RTBPMC)
LastTick = BPMChange(RTBPMC)
RTBPMC = RTBPMC + 1
WEND
ELSE
TickDiff = Tick(x) - Tick(x - 1)
END IF
RealTime = RealTime + (TickDiff / TimeDivision) * (60000 / BPM(RTBPMC - 1))
tminutes = INT(RealTime / 60000)
tseconds = (RealTime / 60000 - tminutes) * 60
tps = (tseconds - INT(tseconds)) * 25: 'TScc
tps = INT(tps * 100) / 100
tps2 = (tps - INT(tps)) * 80: 'TScc
tps2 = INT(tps2 + .5)
tps = INT(tps)
Ti$ = STR$(tminutes) + ":" + STR$(INT(tseconds)) + ":" + STR$(tps) + "." + STR$(tps2)
PRINT #2, Ti$, RealTime, RTBPMC; BPMChange(RTBPMC); BPM(RTBPMC - 1); BPMCount;
IF Event(x) = 4 THEN ' Event 4 = Note On
IF Velocity(x) < 128 THEN
IF Velocity(x) > 0 THEN noteOnOff(x) = 1: 'If velocity = 0 then it is the same as a note off (usually used with running status)
END IF
END IF
PRINT #2, x, noteOnOff(x)
noteTime(x) = RealTime
ELSE
PRINT #2,
END IF
END IF
END IF
'figure out the longest track
IF RealTime > LT THEN LT = RealTime
NEXT x
FOR y = 0 TO C - 1
FI(y) = 0
FOR x = ST(y) TO ST(y + 1)
IF Event(x) = 3 OR Event(x) = 4 THEN FI(y) = 1: EXIT FOR
NEXT x
NEXT y
C = 0: T = 0
FOR x = 0 TO L
IF x = ST(C) THEN
C = C + 1
IF FI(C - 1) = 1 THEN
GoodStart(T) = ST(C - 1): GoodEnd(T) = ST(C) - 1
T = T + 1
END IF
END IF
NEXT x
OctaveAdd = 0
13
PRINT "Number of Tracks/Channels with note data is: "; T
PRINT
PRINT "In the next screen you will be able to select the tracks to be used with the converter."
PRINT "You can select multiple tracks for each voice. Keep in mind each voice can only play one note at a time."
PRINT
PRINT "What output format do you want to create:"
PRINT "Simon's dipole.asm format can playback 1 or 2 channels"
PRINT "1) - Simon Jonasson's dipole.asm software music player - FCB data format with Simon Jonesson's dipole.asm player ready for your own ML program"
PRINT "2) - Simon Jonasson's dipole.asm software music player - RAW FCB data format to be used with Simon Jonesson's dipole.asm player"
PRINT
PRINT "John Linville's Game Master Cartridge can play 1, 2 or 3 channels and a 4th noise channel can be used for a drum track"
PRINT "3) - John Linville's GMC - FCB data format with Glen Hewlett's GMC player - ready to be assembled and tested using MAME"
PRINT "4) - John Linville's GMC - RAW FCB data format for Glen Hewlett's GMC player"
PRINT
PRINT "Ed Snider's CoCo Programable Sound Generator can play 1,2 or 3 channels, channel 3 will play noise if it is used for a drum track"
PRINT "5) - Ed Snider's CoCo PSG - Converts to a PSGLOADR file ready to be played with Glen Hewlett's PSG Player used from BASIC with a CoCo PSG"
PRINT "6) - Ed Snider's CoCo PSG - Converts to a PSGLOADR file and FCB data and used with Glen Hewlett's PSGPLAYER.ASM and your own ML program"
PRINT
PRINT "If you want to playback the music on a PAL CoCo put the letter p after the number 1-6 below, or the program will default to NTSC timing"
INPUT "Format"; q$
OutputFormat = VAL(LEFT$(q$, 1))
IF OutputFormat < 1 OR OutputFormat > 6 THEN CLS: GOTO 13
IF OutputFormat = 1 OR OutputFormat = 2 THEN TimeInc = 0.03250794
IF OutputFormat = 3 OR OutputFormat = 4 THEN TimeInc = 0.033333333333
IF OutputFormat = 5 OR OutputFormat = 6 THEN TimeInc = 0.033333333333
IF RIGHT$(q$, 1) = "p" OR RIGHT$(q$, 1) = "P" THEN TimeInc = TimeInc * 60 / 50: PRINT "Using PAL timing, this will playback faster then normal on an NTSC CoCo"
PRINT
INPUT "Some older MIDI files are an octave too low - Convert the song an octave higher (y or [n])"; q$
IF q$ = "Y" OR q$ = "y" THEN OctaveAdd = 1
20
CLS
'If 2,4 or 6 then we don't need to ask the user more questions
IF OutputFormat = 1 OR OutputFormat = 3 OR OutputFormat = 5 THEN
PRINT "Going to output the Music data and player so that it can be used in the background of a BASIC program on the CoCo"
PRINT
PRINT "How much RAM does the target CoCo have:"
PRINT "1) - CoCo 1 or 2 with 16k"
PRINT "2) - CoCo 1 or 2 with 32k"
PRINT "3) - CoCo 1 or 2 with 64k"
PRINT "4) - CoCo 3 with 128k or more RAM"
INPUT "1,2,3,[4]"; RAM
IF RAM = 0 THEN RAM = 4
IF RAM > 4 THEN 20
IF RAM = 1 THEN ramsize = 16384 ' &H4000
IF RAM > 1 THEN ramsize = 32768 ' &H8000
END IF
CLS
ScaleX = 1080 / LT
ScaleY = 700 / T
ScaleY2 = -ScaleY / 128
LINE (200, 0)-(1280, 700), 2, BF
FOR x = 0 TO T - 1
LINE (200, x * ScaleY)-(1280, (x + 1) * ScaleY), 0, B
NEXT x
FOR C = 1 TO T
InstrCount = 0: InstrFlag = 0: BC = 0: LT = 0: RTBPMC = 1: TickDiff = 0: RealTime = 0
InstrumentFlag = 0
FOR x = GoodStart(C - 1) TO GoodEnd(C - 1)
IF Event(x) = 7 THEN
InstrumentFlag = 1
IF Channel(x) = 10 THEN
_PRINTSTRING (0, (C - 1) * ScaleY), "Drums"
IF OutputFormat > 2 THEN
_PRINTSTRING (125, (C - 1) * ScaleY + 13), "4"
LINE (135, (C - 1) * ScaleY + 14)-(160, (C - 1) * ScaleY + 25), 15, B
END IF
DrumTrack(C) = 1
ELSE
_PRINTSTRING (0, (C - 1) * ScaleY), LEFT$(MIDIDev$(Keynum(x)), 25)
_PRINTSTRING (5, (C - 1) * ScaleY + 13), "1"
LINE (15, (C - 1) * ScaleY + 14)-(40, (C - 1) * ScaleY + 25), 15, B
_PRINTSTRING (45, (C - 1) * ScaleY + 13), "2"
LINE (55, (C - 1) * ScaleY + 14)-(80, (C - 1) * ScaleY + 25), 15, B
IF OutputFormat > 2 THEN
_PRINTSTRING (85, (C - 1) * ScaleY + 13), "3"
LINE (95, (C - 1) * ScaleY + 14)-(120, (C - 1) * ScaleY + 25), 15, B
END IF
END IF
END IF
IF Event(x) <> 22 THEN
' track start
IF Event(x) = 2 OR Event(x) = 1 THEN
flag = 1
RTBPMC = 1
TickDiff = 0
RealTime = 0
ELSE
IF Tick(x) > 0 AND Event(x) <> 21 THEN ' Event 21 = End Track
IF RTBPMC <= BPMCount AND Tick(x) > BPMChange(RTBPMC) THEN
LastTick = Tick(x - 1)
WHILE RTBPMC <= BPMCount AND Tick(x) >= BPMChange(RTBPMC)
TickDiff = BPMChange(RTBPMC) - LastTick
RealTime = RealTime + (TickDiff / TimeDivision) * (60000 / BPM(RTBPMC - 1))
TickDiff = Tick(x) - BPMChange(RTBPMC)
LastTick = BPMChange(RTBPMC)
RTBPMC = RTBPMC + 1
WEND
ELSE
TickDiff = Tick(x) - Tick(x - 1)
END IF
RealTime = RealTime + (TickDiff / TimeDivision) * (60000 / BPM(RTBPMC - 1))
END IF
END IF
END IF
IF Event(x) = 4 AND Velocity(x) > 0 THEN
StartX = 200 + RealTime * ScaleX
tRealtime = RealTime
tRTBPMC = RTBPMC
tTickDiff = TickDiff
FOR R = x + 1 TO L
IF Tick(R) > 0 AND Event(R) <> 21 THEN
IF tRTBPMC <= BPMCount AND Tick(R) > BPMChange(tRTBPMC) THEN
tTickDiff = BPMChange(tRTBPMC) - Tick(R - 1)
tRealtime = tRealtime + (tTickDiff / TimeDivision) * (60000 / BPM(tRTBPMC - 1))
tTickDiff = Tick(R) - BPMChange(tRTBPMC)
tRTBPMC = tRTBPMC + 1
ELSE
tTickDiff = Tick(R) - Tick(R - 1)
END IF
tRealtime = tRealtime + (tTickDiff / TimeDivision) * (60000 / BPM(tRTBPMC - 1))
END IF
IF Event(R) = 7 THEN GOTO 290
IF Keynum(x) = Keynum(R) THEN
IF Event(R) = 4 AND Velocity(R) = 0 THEN GOTO 290: 'PRINT "trealtime"; tRealtime, RealTime: GOTO 290
IF Event(R) = 3 THEN GOTO 290
END IF
NEXT R
PRINT "didn't find an off key, for "; Channel(x), x: SLEEP: SYSTEM
290
EndX = 200 + tRealtime * ScaleX
StartY = C * ScaleY + Keynum(x) * ScaleY2
EndY = StartY
LINE (StartX, StartY)-(EndX, EndY), 14
END IF
NEXT x
IF InstrumentFlag = 0 THEN
_PRINTSTRING (0, (C - 1) * ScaleY), "??? Instrument or Drums"
_PRINTSTRING (5, (C - 1) * ScaleY + 13), "1"
LINE (15, (C - 1) * ScaleY + 14)-(40, (C - 1) * ScaleY + 25), 15, B
_PRINTSTRING (45, (C - 1) * ScaleY + 13), "2"
LINE (55, (C - 1) * ScaleY + 14)-(80, (C - 1) * ScaleY + 25), 15, B
IF OutputFormat > 2 THEN
_PRINTSTRING (85, (C - 1) * ScaleY + 13), "3"
LINE (95, (C - 1) * ScaleY + 14)-(120, (C - 1) * ScaleY + 25), 15, B
END IF
IF OutputFormat = 3 OR OutputFormat = 4 THEN
_PRINTSTRING (125, (C - 1) * ScaleY + 13), "4"
LINE (135, (C - 1) * ScaleY + 14)-(160, (C - 1) * ScaleY + 25), 15, B
END IF
END IF
NEXT C
_PRINTSTRING (0, 700), " Left Click on the Voice you want to add, Right Click to remove a selection. Press <Space Bar> or <Enter> when you have finished selecting the tracks"
_PRINTSTRING (0, 724), "- If Voice 1 and 2 are selected for the same track Voice 1 will be the high note and voice 2 will be the low note of a chord"
_PRINTSTRING (0, 737), "- If Voice 1,2 and 3 are used in the same track Voice 1 will be the high note, voice 2 will be the low note, voice 3 will be 2nd highest note of the chord"
DO: k$ = INKEY$
DO WHILE _MOUSEINPUT
x = _MOUSEX: y = _MOUSEY
IF _MOUSEBUTTON(1) = -1 THEN
PT = INT(y / ScaleY) + 1
IF x < 41 THEN
IF (CombineTracks(PT) AND 1) = 0 THEN
LINE (15, (PT - 1) * ScaleY + 14)-(40, (PT - 1) * ScaleY + 25), 12, BF
CombineTracks(PT) = CombineTracks(PT) + 1
END IF
END IF
IF x > 40 AND x < 81 THEN
IF (CombineTracks(PT) AND 2) = 0 THEN
LINE (55, (PT - 1) * ScaleY + 14)-(80, (PT - 1) * ScaleY + 25), 10, BF
CombineTracks(PT) = CombineTracks(PT) + 2
END IF
END IF
IF x > 80 AND x < 121 THEN
IF (CombineTracks(PT) AND 4) = 0 THEN
LINE (95, (PT - 1) * ScaleY + 14)-(120, (PT - 1) * ScaleY + 25), 14, BF
CombineTracks(PT) = CombineTracks(PT) + 4
END IF
END IF
IF x > 120 AND x < 161 THEN
IF (CombineTracks(PT) AND 8) = 0 THEN
LINE (135, (PT - 1) * ScaleY + 14)-(160, (PT - 1) * ScaleY + 25), 15, BF
CombineTracks(PT) = CombineTracks(PT) + 8
END IF
END IF
END IF
IF _MOUSEBUTTON(2) = -1 THEN
PT = INT(y / ScaleY) + 1
IF x < 41 THEN
IF (CombineTracks(PT) AND 1) = 1 THEN
LINE (15, (PT - 1) * ScaleY + 14)-(40, (PT - 1) * ScaleY + 25), 0, BF
LINE (15, (PT - 1) * ScaleY + 14)-(40, (PT - 1) * ScaleY + 25), 15, B
CombineTracks(PT) = CombineTracks(PT) - 1
END IF
END IF
IF x > 40 AND x < 81 THEN
IF (CombineTracks(PT) AND 2) = 2 THEN
LINE (55, (PT - 1) * ScaleY + 14)-(80, (PT - 1) * ScaleY + 25), 0, BF
LINE (55, (PT - 1) * ScaleY + 14)-(80, (PT - 1) * ScaleY + 25), 15, B
CombineTracks(PT) = CombineTracks(PT) - 2
END IF
END IF
IF x > 80 AND x < 121 THEN
IF (CombineTracks(PT) AND 4) = 4 THEN
LINE (95, (PT - 1) * ScaleY + 14)-(120, (PT - 1) * ScaleY + 25), 0, BF
LINE (95, (PT - 1) * ScaleY + 14)-(120, (PT - 1) * ScaleY + 25), 15, B
CombineTracks(PT) = CombineTracks(PT) - 4
END IF
END IF
IF x > 120 AND x < 161 THEN
IF (CombineTracks(PT) AND 8) = 8 THEN
LINE (135, (PT - 1) * ScaleY + 14)-(160, (PT - 1) * ScaleY + 25), 0, BF
LINE (135, (PT - 1) * ScaleY + 14)-(160, (PT - 1) * ScaleY + 25), 15, B
CombineTracks(PT) = CombineTracks(PT) - 8
END IF
END IF
END IF
LOOP
LOOP UNTIL k$ = CHR$(32) OR k$ = CHR$(13)
240
notecount = L
CLOSE #2
OPEN "temp.asm" FOR OUTPUT AS #2
PRINT #2, "********************************************"
PRINT #2, "* Music data for song: "; Fname$
PRINT #2, "* Voice 1 tracks are:"
FOR p = 0 TO T
IF CombineTracks(p) AND 1 THEN
PRINT #2, "* Track #"; p
END IF
NEXT p
PRINT #2, "* Voice 2 tracks are:"
FOR p = 0 TO T
IF CombineTracks(p) AND 2 THEN
PRINT #2, "* Track #"; p
END IF
NEXT p
IF OutputFormat > 2 THEN
PRINT #2, "* Voice 3 tracks are:"
FOR p = 0 TO T
IF CombineTracks(p) AND 4 THEN
PRINT #2, "* Track #"; p
END IF
NEXT p
IF OutputFormat = 3 OR OutputFormat = 4 THEN
PRINT #2, "* Voice 4 tracks are:"
FOR p = 0 TO T
IF CombineTracks(p) AND 8 THEN
PRINT #2, "* Track #"; p
END IF
NEXT p
END IF
END IF
' Playback will be updated every 1/30th of a second = 0.033333333
' This means it can playback 1/64th notes at 112.5 bpm max speed or 1/32 note at 225 bpm
' I don't think anyone will notice if 1/32 note is missed playing back at 225 bpm!
' This value could be changed so that slower songs would be even less CPU intensive, the the playback code would need to be tweaked based on this info
' two channels to convert to John Lynville's Game Master Cartridge format (Texas Instruments SN76489 sound chip)