-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsonifier.h
2269 lines (2094 loc) · 105 KB
/
sonifier.h
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include <unistd.h>
//***********************************
//data structure for global variables
//***********************************
typedef struct {
int nextnote[256]; //random note number
float nextpan[256]; //random panning value
float notelength; //note length
int testnote; //used to remove duplicate note numbers
int midi_note; //root note of the piece
int result; //used to share the randomly generated note numbers with other instruments in the cscore
int keychoice; //the choice of mode for the piece
float totalLength; //total length of the score
int printflag; //used for error handling
double length; //number of random note generations to be made
int numchanges; //number of changes that will occur in the score
int scorenum; //indicates which csound orchestra was picked
int blockFlag; //keeps track of when the score should process the new block's image data
char filename[100]; //filename
char commands[100]; //char array used to execute terminal commands (temporary)
int channel; //used to keep track of how many times blockAverages() runs
int redAvg[500]; //a variable to store our red pixel-block averages
int greenAvg[500]; //a variable to store our green pixel-block averages
int blueAvg[500]; //a variable to store our blue pixel-block averages
unsigned int blockSize; //a variable to store the number of pixels in each block that the image is divided into
int numBlocks; //a variable to store the number of pixel blocks the image is broken into
int brightness;
int mainColor;
int blockColor[100]; //some space to store the color average of every block of the image
int blockBrghtnss[100]; //some space to store the brightness average of every block of the image
unsigned int ravgs;
unsigned int rsum;
unsigned int gavgs;
unsigned int gsum;
unsigned int bavgs;
unsigned int bsum;
int saveFlag;
FILE *scorefile; //our scorefile for csound to use
FILE *red; //file for our red pixel values
FILE *green; //file for our green pixel values
FILE *blue; //file for our blue pixel values
} boxdata;
// **********
// prototypes
// **********
// ----------
//csound functions:
int init(boxdata *a);
int getarguments(boxdata *data);
void csdbuild(boxdata *data);
float randnum();
int scales(boxdata *data);
void scorebuild(boxdata *data);
int runscore(boxdata *b);
int cleanup(boxdata *c);
//----------------------------
//image sonification functions:
int setBlockSize(int color);
int blockAverages(FILE* color, boxdata *data);
int imageDataProcess(boxdata *data);
int colorFinder(boxdata *data, int tflag);
// *********
// functions
// *********
int init(boxdata *a){
a = malloc(sizeof(boxdata));
if(a == NULL){
fprintf(stderr, "Problem allocating memory for data structure\n");
return 1;
}
else{
printf("Initalization complete\n");
usleep(15);
system("clear");
}
srand(time(NULL));
return 0;
}
int getarguments(boxdata *data){
printf("Please enter the name for the csd file that will be made (exclude '.csd' file extension):\n");
scanf("%s", data->filename);
printf("Enter 1 to save the resulting file...\nEnter 2 if you'd like the file to play from the command line and delete itself\n");
scanf("%d", &data->saveFlag);
//append our filename with a .csd filetype
strcat(data->filename, ".csd");
system("clear");
return 0;
}
void csdbuild(boxdata *data){
double tmp;
double gainChange;
double panChange;
int waveChange;
int pluckChange;
if(data->scorefile == NULL) {
fprintf(stderr, "Problem opening file\n");
}
else{
if(data->numchanges <= 0){
data->numchanges = 1;
}
tmp = ((double)data->numchanges * 0.25) + 0.1;
fprintf(data->scorefile, "<CsoundSynthesizer>\n");
fprintf(data->scorefile, "<CsOptions>\n");
fprintf(data->scorefile, "</CsOptions>\n");
fprintf(data->scorefile, "<CsInstruments>\n");
fprintf(data->scorefile, "sr = 44100\n");
fprintf(data->scorefile, "ksmps = 32\n");
fprintf(data->scorefile, "nchnls = 2\n");
fprintf(data->scorefile, "0dbfs = 1\n");
//init statements for all scores
fprintf(data->scorefile, "gamixL init 0\ngamixR init 0\n");
fprintf(data->scorefile, "gamix2L init 0\n");
fprintf(data->scorefile, "gamix2R init 0\n");
fprintf(data->scorefile, "gadelay init 0\n");
fprintf(data->scorefile, "garvbL init 0\n");
fprintf(data->scorefile, "garvbR init 0\n");
fprintf(data->scorefile, "ganzrvbL init 0\n");
fprintf(data->scorefile, "ganzrvbR init 0\n");
//i100 brightscore's primary instrument
fprintf(data->scorefile, "instr 100\n");
fprintf(data->scorefile, "kamp = ampdb (p4)\n");
fprintf(data->scorefile, "ifrq = cpsmidinn (p5)\n");
fprintf(data->scorefile, "irise = p6\n");
fprintf(data->scorefile, "idec = p7\n");
fprintf(data->scorefile, "ifn = 6\n");
fprintf(data->scorefile, "ipanfrq = p8\n");
fprintf(data->scorefile, "ares linen p4, p6, p3, p7\n");
fprintf(data->scorefile, "kpan poscil .5, ipanfrq, -1\n");
fprintf(data->scorefile, "asig poscil ares, ifrq, ifn\n");
fprintf(data->scorefile, "kpanlfo = sqrt(kpan+.5)\n");
fprintf(data->scorefile, "outs asig*kpanlfo, asig*(1-kpanlfo)\n");
fprintf(data->scorefile, "gamixL = gamixL + asig\ngamixR = gamixR + asig\n");
fprintf(data->scorefile, "endin\n");
//i200 brightscore's bass instrument
fprintf(data->scorefile, "instr 200\n");
fprintf(data->scorefile, "kamp = p4\n");
fprintf(data->scorefile, "kcps = cpsmidinn (p5)\n");
fprintf(data->scorefile, "aenv linen p4, p6, p3, p7\n");
fprintf(data->scorefile, "asig oscili aenv, kcps\n");
fprintf(data->scorefile, "aLP butterlp asig, p8\n");
fprintf(data->scorefile, "outs aLP, aLP\n");
fprintf(data->scorefile, "endin\n");
//i300 filter mod instrument for brightscore
fprintf(data->scorefile, "instr 300\n");
fprintf(data->scorefile, "kcps = cpsmidinn(p5)\n");
fprintf(data->scorefile, "amod oscili p4, (kcps*1.5), 3\n");
fprintf(data->scorefile, "acar oscili p4, kcps, 4\n");
fprintf(data->scorefile, "amix1 = acar*amod\n");
if(data->mainColor == 3){
gainChange = 500;
panChange = 0.25;
}
else{
gainChange = 200;
panChange = 1;
}
fprintf(data->scorefile, "klfo poscil %.2f, p8, 1\n", gainChange);
fprintf(data->scorefile, "afilt zdf_ladder amix1, klfo+p9, 3\n");
fprintf(data->scorefile, "aenv linen afilt, p6, p3, p7\n");
fprintf(data->scorefile, "kpan poscil 1, 3, 3\n");
fprintf(data->scorefile, "apanL, apanR pan2 aenv, kpan*%.2f, 2\n", panChange);
fprintf(data->scorefile, "outs apanL, apanR\n");
fprintf(data->scorefile, "gamix2L = gamix2L+aenv\n");
fprintf(data->scorefile, "gamix2R = gamix2R+aenv\n");
fprintf(data->scorefile, "endin\n");
//i400 rhythmic instrument for brightscore
fprintf(data->scorefile, "instr 400\n");
fprintf(data->scorefile, "kcps = cpsmidinn(p5)\n");
fprintf(data->scorefile, "icps = cpsmidinn(p5)\n");
//if blue score or green score has been selected, make the waveform and pluck type different
if(data->mainColor == 7 || data->mainColor == 6){
if(data->mainColor == 7){
waveChange = 1;
pluckChange = 1;
gainChange = 0.6;
}
if(data->mainColor == 6){
waveChange = 2;
pluckChange = 1;
gainChange = 0.8;
}
}
else{
waveChange = 3;
pluckChange = 3;
gainChange = 1;
}
fprintf(data->scorefile, "asig pluck p4*%.2f, kcps, icps, %d, %d, 0.1\n", gainChange, waveChange, pluckChange);
fprintf(data->scorefile, "aenv linen asig, p6, p3, p7\n");
fprintf(data->scorefile, "klfo poscil 350, p8, 3\n");
fprintf(data->scorefile, "afilt zdf_ladder aenv, klfo+p9, 5\n");
fprintf(data->scorefile, "outs afilt, afilt\n");
fprintf(data->scorefile, "gadelay += afilt\n");
fprintf(data->scorefile, "gamix2L += (afilt*0.25)\n");
fprintf(data->scorefile, "gamix2R += (afilt*0.25)\n");
fprintf(data->scorefile, "endin\n");
//i500 main instrument in darkscore
fprintf(data->scorefile, "instr 500\n");
fprintf(data->scorefile, "kamp = ampdb(p4)\n");
fprintf(data->scorefile, "kcps = cpsmidinn(p5)\n");
fprintf(data->scorefile, "a1 poscil kamp, kcps*0.5, 1\n");
fprintf(data->scorefile, "aenv1 linen a1, p6, p3, p7\n");
fprintf(data->scorefile, "a2 poscil kamp, kcps*2.52, 1\n");
fprintf(data->scorefile, "aenv2 linen a2, p6, p3, p7\n");
fprintf(data->scorefile, "a3 poscil kamp, kcps*1.5, 1\n");
fprintf(data->scorefile, "amix = aenv1 * aenv2\n");
fprintf(data->scorefile, "amix2 = amix * a3 \n");
fprintf(data->scorefile, "krand linrand p8\n");
fprintf(data->scorefile, "afilt moogladder amix2, (krand+p9), 0.5\n");
fprintf(data->scorefile, "kpenv expseg 1, p3*0.5, 3, p3*0.5, 1\n");
fprintf(data->scorefile, "kpan poscil 1, kpenv, 1\n");
fprintf(data->scorefile, "aL, aR pan2 afilt, kpan, 0\n");
fprintf(data->scorefile, "outs aL, aR\n");
fprintf(data->scorefile, "endin\n");
//i600 darkscore's bass instrument
fprintf(data->scorefile, "instr 600\n");
fprintf(data->scorefile, "kamp = ampdb(p4)\n");
fprintf(data->scorefile, "kcps = cpsmidinn(p5)\n");
fprintf(data->scorefile, "a1 poscil kamp, kcps, 3\n");
fprintf(data->scorefile, "aenv1 linen a1, p6, p3, p7\n");
fprintf(data->scorefile, "a2 poscil kamp, kcps*0.5, 3\n");
fprintf(data->scorefile, "aenv2 linen a2, p6, p3, p7\n");
fprintf(data->scorefile, "amix = aenv1 * aenv2\n");
fprintf(data->scorefile, "kenv expseg 1, p3*0.5, p8, p3*0.5, 1\n");
fprintf(data->scorefile, "afilt butterlp amix, kenv+200\n");
fprintf(data->scorefile, "aclip clip afilt, 2, 0.5\n");
fprintf(data->scorefile, "outs aclip*0.2, aclip*0.2\n");
fprintf(data->scorefile, "garvbL += aclip*0.3\n");
fprintf(data->scorefile, "garvbR += aclip*0.3\n");
fprintf(data->scorefile, "endin\n");
//i700 wave terrain synth for darkscore
fprintf(data->scorefile, "instr 700\n");
fprintf(data->scorefile, "kdclk linseg 0.1, p3/2, 0.5, p3/2, 0.1\n");
fprintf(data->scorefile, "kcx line 0.1, p3, 1.9\n");
fprintf(data->scorefile, "krx linseg 0.1, p3/2, 0.5, p3/2, 0.1\n");
fprintf(data->scorefile, "kpch line cpsmidinn(p4), p3, p5 * cpsmidinn(p4)\n");
fprintf(data->scorefile, "a1 wterrain 0.18, kpch, kcx, kcx, -krx, krx, p6, p7\n");
fprintf(data->scorefile, "a1 dcblock a1\n");
fprintf(data->scorefile, "amix = a1*kdclk\n");
fprintf(data->scorefile, "outs amix, amix\n");
fprintf(data->scorefile, "endin\n");
//i800 pink noise, ring mod, and mild pitch modulation
fprintf(data->scorefile, "instr 800\n");
fprintf(data->scorefile, "kamp = ampdb(p4)\n");
fprintf(data->scorefile, "kcps = cpsmidinn(p5)\n");
fprintf(data->scorefile, "kmodfreq = p13\n");
fprintf(data->scorefile, "aosc pinker\n");
fprintf(data->scorefile, "aenv linen aosc, p6, (p3-0.5), p7\n");
fprintf(data->scorefile, "anflt moogladder2 aenv, p8, p9\n");
fprintf(data->scorefile, "ap1, ap2 pan2 anflt, p10, 1\n");
fprintf(data->scorefile, "kmod poscil kamp*0.025, kmodfreq, 1\n");
fprintf(data->scorefile, "asqr1 poscil kamp*0.6, kcps*.75, 3\n");
fprintf(data->scorefile, "asqr2 poscil kamp*0.6, kcps*kmod, 3\n");
fprintf(data->scorefile, "asqrmix = asqr1 * asqr2\n");
fprintf(data->scorefile, "aenv2 linen asqrmix, p6, (p3-0.5), p7\n");
fprintf(data->scorefile, "amflt moogladder2 aenv2, p11, p12\n");
fprintf(data->scorefile, "apanL, apanR pan2 amflt, p10, 1\n");
//if blue score has been detected, alter the volume of the noise oscillator in i800:
if(data->mainColor == 7 || data->mainColor == 2){
if(data->mainColor == 7){
gainChange = 0.5;
}
if(data->mainColor == 2){
gainChange = 0.25;
}
}
else{
gainChange = 0.95;
}
fprintf(data->scorefile, "aoscmixL = apanL + (ap1*%.2f)\n", gainChange);
fprintf(data->scorefile, "aoscmixR = apanR + (ap2*%.2f)\n", gainChange);
fprintf(data->scorefile, "outs aoscmixL, aoscmixR\n");
fprintf(data->scorefile, "ganzrvbL += aoscmixL * 0.15\n");
fprintf(data->scorefile, "ganzrvbR += aoscmixR * 0.15\n");
fprintf(data->scorefile, "endin \n");
//i1000 primary reverb for main instrument in brightscore
fprintf(data->scorefile, "instr 1000\n");
fprintf(data->scorefile, "aenvL linen gamixL, 12, p3, 10\n");
fprintf(data->scorefile, "aenvR linen gamixR, 12, p3, 10\n");
fprintf(data->scorefile, "aL, aR reverbsc aenvL, aenvR, 1, %d, sr, 0.5, 1\n", (data->brightness * 1300));
fprintf(data->scorefile, "outs aL, aR\n");
fprintf(data->scorefile, "clear gamixL\n");
fprintf(data->scorefile, "clear gamixR\n");
fprintf(data->scorefile, "endin\n");
//i2000 reverberation for i800
fprintf(data->scorefile, "instr 2000\n");
fprintf(data->scorefile, "ainL, ainR reverbsc ganzrvbL, ganzrvbR, 1, 11000, sr, 2\n");
fprintf(data->scorefile, "aenvL linen ainL, p4, p3, p5\n");
fprintf(data->scorefile, "aenvR linen ainR, p4, p3, p5\n");
fprintf(data->scorefile, "outs aenvL, aenvR\n");
fprintf(data->scorefile, "clear ganzrvbL\n");
fprintf(data->scorefile, "clear ganzrvbR\n");
fprintf(data->scorefile, "endin\n");
//i5000 global reverb for brightscore instruments
fprintf(data->scorefile, "instr 5000\n");
//allow for the pitch mod on revsc to be determined by art parameters
fprintf(data->scorefile, "aL, aR reverbsc gamix2L, gamix2R, 0.9, 12500, sr, %d\n", (data->numchanges / 2));
fprintf(data->scorefile, "outs (aL*0.5), (aR*0.5)\n");
fprintf(data->scorefile, "clear gamix2L\n");
fprintf(data->scorefile, "clear gamix2R\n");
fprintf(data->scorefile, " endin\n");
//i6000 delay for brightscore instruments
fprintf(data->scorefile, " instr 6000\n");
//allow for the variable delay times to be deteremined by an art parameter
fprintf(data->scorefile, "adel multitap gadelay, %.2f, 0.8, %.2f, 0.6, %.2f, 0.4, %.2f, 0.35, %.2f, 0.3, %.2f, 0.25, %.2f, 0.2, %.2f, 0.15, %.2f, 0.1, %.2f, 0.01\n"
, tmp, (tmp * 2), (tmp * 4), (tmp * 6), (tmp * 8), (tmp * 16), (tmp * 32), (tmp * 64), (tmp * 128), (tmp * 256));
fprintf(data->scorefile, "kpan poscil 1, 1, 3\n");
fprintf(data->scorefile, "apL, apR pan2 adel, kpan, 3\n");
fprintf(data->scorefile, "outs apL, apR\n");
fprintf(data->scorefile, "clear gadelay\n");
fprintf(data->scorefile, " endin\n");
//i7000 reverb for darkscore instruments
fprintf(data->scorefile, "instr 7000\n");
fprintf(data->scorefile, "aL, aR reverbsc garvbL, garvbR, 0.8, 12000, sr, 2\n");
fprintf(data->scorefile, "aenvL linen aL, p4, p3, p5\n");
fprintf(data->scorefile, "aenvR linen aR, p4, p3, p5\n");
fprintf(data->scorefile, "outs aenvL*0.8, aenvR*0.8\n");
fprintf(data->scorefile, "clear garvbL\n");
fprintf(data->scorefile, "clear garvbR\n");
fprintf(data->scorefile, "endin\n");
//beginning of score tags
fprintf(data->scorefile, "</CsInstruments>\n");
fprintf(data->scorefile, "<CsScore>\n");
fprintf(data->scorefile, "f6 0 16384 10 1 1 1 1 0.7 0.5 0.3 0.1\n");
fprintf(data->scorefile, "f1 0 16384 10 1\n");
fprintf(data->scorefile, "f2 0 16384 10 1 0.5 0.3 0.25 0.2 0.167 0.14 0.125 .111\n");
fprintf(data->scorefile, "f3 0 16384 10 1 0 0.3 0 0.2 0 0.14 0 .111\n");
fprintf(data->scorefile, "f4 0 16384 10 1 1 1 1 0.7 0.5 0.3 0.1\n");
}
}
float randnum(){
// Generate random panning values:
float scaler = 4.0;
float randresult;
randresult = (rand()/(double)(RAND_MAX)) * scaler;
return randresult;
}
int scales(boxdata *data){
// lydian key steps
int i, ii, iii, iv, v, vi, vii, viii;
i = data->midi_note;
ii = data->midi_note + 2;
iii = data->midi_note + 4;
iv = data->midi_note + 6;
v = data->midi_note + 7;
vi = data->midi_note + 9;
vii = data->midi_note + 11;
viii = data->midi_note + 12;
// major key steps
int doe, re, mi, fa, sol, la, ti, oct;
doe = data->midi_note;
re = data->midi_note + 2;
mi = data->midi_note + 4;
fa = data->midi_note + 5;
sol = data->midi_note + 7;
la = data->midi_note + 9;
ti = data->midi_note + 11;
oct = data->midi_note + 12;
//phrygian key steps
int I, II, III, IV, V, VI, VII, VIII;
I = data->midi_note;
II = data->midi_note + 1;
III = data->midi_note + 3;
IV = data->midi_note + 5;
V = data->midi_note + 7;
VI = data->midi_note + 8;
VII = data->midi_note + 10;
VIII = data->midi_note + 12;
//lydian
if(data->keychoice == 3) {
switch (rand() % (7 + 1 - 0) + 0) {
case 0:
data->result = i;
break;
case 1:
data->result = ii;
break;
case 2:
data->result = iii;
break;
case 3:
data->result = iv;
break;
case 4:
data->result = v;
break;
case 5:
data->result = vi;
break;
case 6:
data->result = vii;
break;
case 7:
data->result = viii;
break;
}
}
//major
if(data->keychoice == 2) {
switch (rand() % (7 + 1 - 0) + 0) {
case 0:
data->result = doe;
break;
case 1:
data->result = re;
break;
case 2:
data->result = mi;
break;
case 3:
data->result = fa;
break;
case 4:
data->result = sol;
break;
case 5:
data->result = la;
break;
case 6:
data->result = ti;
break;
case 7:
data->result = oct;
break;
}
}
//phrygian
if(data->keychoice == 1){
switch(rand() % (7 + 1 - 0) + 0){
case 0:
data->result = I;
break;
case 1:
data->result = II;
break;
case 2:
data->result = III;
break;
case 3:
data->result = IV;
break;
case 4:
data->result = V;
break;
case 5:
data->result = VI;
break;
case 6:
data->result = VII;
break;
case 7:
data->result = VIII;
break;
}
}
return data->result;
}
void scorebuild(boxdata *data){
if(data->scorefile == NULL) {
fprintf(stderr, "Problem opening file\n");
}
int a;
int b;
int c;
int lastBrghtnss;
int lastColor;
int deltaFlag;
int prevScore;
int count;
int rnd;
double nextpan;
double rmod;
double rate;
double colorLength;
float lengthtotal;
data->printflag = 0;
data->totalLength = 0;
data->scorenum = 0;
switch(data->mainColor){
case 1:
//switch for grey score - noise pad, rhythm instrument, and dark bass
switch(data->scorenum){
case 0:
for(a = 0; a < data->length; a++){
//randomly generate our values for pitch, panning, and notelength
data->nextnote[a] = scales(data);
data->nextpan[a] = randnum();
data->notelength = (double)randnum() + 3;
data->testnote = data->nextnote[a];
//checking for duplicate notes
while (data->nextnote[a] == data->testnote) {
data->nextnote[a] = scales(data);
}
}
data->scorenum += 1;
case 1:
data->printflag = 0;
c = 0;
for(a = 0; a < data->length; a++){
data->notelength = (double)randnum() + 4.5;
//note checking
if(data->nextnote[a] <= 60){
data->nextnote[a] += 12;
}
else if(data->nextnote[a] <= 55){
data->nextnote[a] += 24;
}
else if(data->nextnote[a] >= 85){
data->nextnote[a] -= 12;
}
else if((int)(data->nextnote[a]) >= 90){
data->nextnote[a] -= 24;
}
if((data->printflag % data->numBlocks) == 0){
if(data->printflag == 0){
fprintf(data->scorefile, "i800 0 3 0.7 %d 2 3 %d 0.6 0.5 %d 0.5 %d\n", data->nextnote[a], (data->blockBrghtnss[c] * 1000), (data->blockBrghtnss[c] * 1000), (data->blockColor[c] * 5));
}
else{
fprintf(data->scorefile, "i800 + %.2f 0.7 %d 2 %.2f %d . . %d . %d\n", data->notelength, data->nextnote[a], (data->notelength - 1), (data->blockBrghtnss[c] * 1000), (data->blockBrghtnss[c] * 1000), (data->blockColor[c] * 5));
}
lastBrghtnss = data->blockBrghtnss[c];
lastColor = data->blockColor[c];
c++;
if(c == 7){
c--;
}
}
else{
if(lastBrghtnss == data->blockBrghtnss[c]){
if(lastColor == data->blockColor[c]){
fprintf(data->scorefile, "i800 + %.2f 0.7 %d 2 %.2f . . . . . .\n", data->notelength, data->nextnote[a], (data->notelength - 1));
}
else{
fprintf(data->scorefile, "i800 + %.2f 0.7 %d 2 %.2f . . . . . <\n", data->notelength, data->nextnote[a], (data->notelength - 1));
}
}
else{
if(lastColor == data->blockBrghtnss[c]){
fprintf(data->scorefile, "i800 + %.2f 0.7 %d 2 %.2f < . . < . .\n", data->notelength, data->nextnote[a], (data->notelength - 1));
}
else{
fprintf(data->scorefile, "i800 + %.2f 0.7 %d 2 %.2f < . . < . <\n", data->notelength, data->nextnote[a], (data->notelength - 1));
}
}
}
data->totalLength += (data->notelength + 1);
data->printflag++;
}
data->scorenum += 1;
case 2:
lengthtotal = 0;
count = 0;
data->printflag = 0;
c = 0;
for(a = 0; a < data->length; a++){
data->notelength = (double)randnum() + 3;
rate = 2;
int pitch[3];
int z;
//fill up array indexes for the groups of pitches played by the rhythm instrument, then constrain them to their frequency range
for(z = 0; z < 3; z++){
pitch[z] = scales(data);
if(pitch[z] >= 65){
pitch[z] -= 12;
}
if(pitch[z] >= 70){
pitch[z] -= 24;
}
}
int rnd = ((rand() % 6) + 1);
count++;
//used to calculate the total amount of time taken up by the rhythm instrument, so that it doesn't play longer than the other instruments
lengthtotal += data->notelength;
//determine when to change the rate of the rhythm
if(count % rnd == 0){
rate = rate / 2;
}
if((data->printflag % data->numBlocks) == 0){
if(data->printflag == 0){
//print the first line of the score for the rhythm instrument
fprintf(data->scorefile, "i400 0 %.2f 0.5 %d 0 0.1 1 %d\n", rate, (data->midi_note + 12), (data->blockBrghtnss[0] * 500));
}
else{
fprintf(data->scorefile, "i400 + %.2f 0.5 %d . . . %d\n", rate, (data->midi_note + 12), (data->blockBrghtnss[c] * 500));
}
if(data->blockColor[c] >= 5){
rate = 2;
}
else{
rate = 1;
}
lastBrghtnss = data->blockBrghtnss[c];
c++;
if(c == 7){
c--;
}
}
else{
if(lastBrghtnss == data->blockBrghtnss[c]){
//additional lines for the rhythm instrument
fprintf(data->scorefile, "i400 + %.2f . %d . . . .\n", rate, (data->nextnote[a] + 12));
fprintf(data->scorefile, "i400 + %.2f . %d . . . .\n", rate, (pitch[0] + 12));
fprintf(data->scorefile, "i400 + %.2f . %d . . . .\n", rate, (pitch[1] + 12));
fprintf(data->scorefile, "i400 + %.2f . %d . . . .\n", rate, (pitch[2] + 12));
}
else{
//additional lines for the rhythm instrument
fprintf(data->scorefile, "i400 + %.2f . %d . . . <\n", rate, (data->nextnote[a] + 12));
fprintf(data->scorefile, "i400 + %.2f . %d . . . <\n", rate, (pitch[0] + 12));
fprintf(data->scorefile, "i400 + %.2f . %d . . . <\n", rate, (pitch[1] + 12));
fprintf(data->scorefile, "i400 + %.2f . %d . . . <\n", rate, (pitch[2] + 12));
}
}
data->totalLength += (data->notelength);
data->printflag++;
if((data-> printflag == data->length) && (lengthtotal <= (data->totalLength - 30))){
a--;
}
}
data->scorenum += 1;
case 3:
data->printflag = 0;
c = 0;
for(a = 0; a < data->length; a++){
data->notelength = (double)randnum() + 4.5;
//constraining the note numbers to their frequency ranges
if(data->nextnote[a] <= 35){
data->nextnote[a] += 12;
}
else if(data->nextnote[a] <= 25){
data->nextnote[a] += 24;
}
else if(data->nextnote[a] >= 60){
data->nextnote[a] -= 24;
}
else if((data->nextnote[a]) >= 71){
data->nextnote[a] -= 36;
}
if((data->printflag % data->numBlocks) == 0){
if(data->printflag == 0){
//print the first line of the score for the dark bass instrument
fprintf(data->scorefile, "i600 0 4 0.15 %d 1 3.8 %d\n", (data->midi_note), (data->blockBrghtnss[0] * 75));
}
else{
fprintf(data->scorefile, "i600 + %.2f . %d . %.2f %d\n", data->notelength, (data->nextnote[a]), (data->notelength - 0.5), (data->blockBrghtnss[0] * 75));
}
lastBrghtnss = data->blockBrghtnss[c];
c++;
if(c == 7){
c--;
}
}
else{
if(lastBrghtnss == data->blockBrghtnss[c]){
fprintf(data->scorefile, "i600 + %.2f . %d . %.2f .\n", data->notelength, (data->nextnote[a]), (data->notelength - 0.5));
}
else{
fprintf(data->scorefile, "i600 + %.2f . %d . %.2f <\n", data->notelength, (data->nextnote[a]), (data->notelength - 0.5));
}
}
data->totalLength += (data->notelength + 1);
data->printflag++;
}
data->scorenum += 1;
case 4:
fprintf(data->scorefile, "i1000 0 %.2f\n", ((data->totalLength / 3) + 10));
fprintf(data->scorefile, "i2000 0 %.2f 1 4\n", ((data->totalLength / 3) + 10));
fprintf(data->scorefile, "i5000 0 %.2f\n", ((data->totalLength / 3) + 10));
fprintf(data->scorefile, "i6000 0 %.2f\n", ((data->totalLength / 3) + 10));
fprintf(data->scorefile, "i7000 0 %.2f 2 3\n", ((data->totalLength / 3) + 10));
fprintf(data->scorefile, "e\n");
fprintf(data->scorefile, "</CsScore>\n</CsoundSynthesizer>\n");
break;
}
break;
case 2:
//switch for cyan score - bright score pad, bright score bass, and noise pad
switch(data->scorenum){
case 0:
for(a = 0; a < data->length; a++){
//randomly generate our values for pitch, panning, and notelength
data->nextnote[a] = scales(data);
data->nextpan[a] = randnum();
data->notelength = (double)randnum() + 3;
data->testnote = data->nextnote[a];
//checking for duplicate notes
while (data->nextnote[a] == data->testnote) {
data->nextnote[a] = scales(data);
}
}
data->scorenum += 1;
case 1:
data->printflag = 0;
c = 0;
//print the first line of the score for the pad instrument;
fprintf(data->scorefile, "i100 0 5 0.05 %d 2 3.5 %.2f\n", data->midi_note + 12, randnum());
for(a = 0; a < data->length; a++){
data->printflag++;
data->notelength = (double)randnum() + 4;
//constraining the note numbers to their frequency range
if(data->nextnote[a] <= 35){
data->nextnote[a] += 12;
}
if(data->nextnote[a] >= 85){
data->nextnote[a] -= 12;
}
//print the next line for the pad
fprintf(data->scorefile, "i100 + %.2f . %d . %.2f %.2f\n", data->notelength, data->nextnote[a], (data->notelength - 0.5), data->nextpan[a]);
//this is used to calculate the total length of the score, it is divided by 3 at the end because it counts for all three instruments
data->totalLength += (data->notelength + 1);
}
data->scorenum += 1;
case 2:
data->printflag = 0;
c = 0;
for(a = 0; a < (data->length); a++){
data->notelength = (double)randnum() + 4.5;
//constraining the note numbers to their frequency ranges
if(data->nextnote[a] <= 35){
data->nextnote[a] += 12;
}
else if(data->nextnote[a] <= 25){
data->nextnote[a] += 24;
}
else if(data->nextnote[a] >= 60){
data->nextnote[a] -= 24;
}
else if((int)(data->nextnote[a]) >= 71){
data->nextnote[a] -= 36;
}
if((data->printflag % data->numBlocks) == 0){
if(data->printflag == 0){
//print the first line of the score for the bass instrument
fprintf(data->scorefile, "i200 0 4 0.15 %d 1 3.8 %d\n", (data->midi_note - 12), (data->blockBrghtnss[c] * 90));
}
else{
fprintf(data->scorefile, "i200 + %.2f . %d . %.2f %d\n", data->notelength, (data->nextnote[a] - 12), (data->notelength - 0.5), (data->blockBrghtnss[c] * 80));
}
lastBrghtnss = data->blockBrghtnss[c];
lastColor = data->blockColor[c];
c++;
if(c == 7){
c--;
}
}
else{
if(lastBrghtnss == data->blockBrghtnss[c]){
fprintf(data->scorefile, "i200 + %.2f . %d . %.2f .\n", data->notelength, (data->nextnote[a] - 12), (data->notelength - 0.5));
}
else{
fprintf(data->scorefile, "i200 + %.2f . %d . %.2f <\n", data->notelength, (data->nextnote[a] - 12), (data->notelength - 0.5));
}
}
data->totalLength += (data->notelength + 1);
data->printflag++;
}
data->scorenum += 1;
case 3:
data->printflag = 0;
c = 0;
for(a = 0; a < data->length; a++){
data->notelength = (double)randnum() + 4.5;
//note checking
if(data->nextnote[a] <= 60){
data->nextnote[a] += 12;
}
else if(data->nextnote[a] <= 55){
data->nextnote[a] += 24;
}
else if(data->nextnote[a] >= 85){
data->nextnote[a] -= 12;
}
else if((int)(data->nextnote[a]) >= 90){
data->nextnote[a] -= 24;
}
if((data->printflag % data->numBlocks) == 0){
if(data->printflag == 0){
fprintf(data->scorefile, "i800 0 3 0.7 %d 2 3 %d 0.6 0.5 %d 0.5 %d\n", data->nextnote[a], (data->blockBrghtnss[c] * 1000), (data->blockBrghtnss[c] * 1000), (data->blockColor[c] * 5));
}
else{
fprintf(data->scorefile, "i800 + %.2f 0.7 %d 2 %.2f %d . . %d . %d\n", data->notelength, data->nextnote[a], (data->notelength - 1), (data->blockBrghtnss[c] * 1000), (data->blockBrghtnss[c] * 1000), (data->blockColor[c] * 5));
}
lastBrghtnss = data->blockBrghtnss[c];
lastColor = data->blockColor[c];
c++;
if(c == 7){
c--;
}
}
else{
if(lastBrghtnss == data->blockBrghtnss[c]){
if(lastColor == data->blockColor[c]){
fprintf(data->scorefile, "i800 + %.2f 0.7 %d 2 %.2f . . . . . .\n", data->notelength, data->nextnote[a], (data->notelength - 1));
}
else{
fprintf(data->scorefile, "i800 + %.2f 0.7 %d 2 %.2f . . . . . <\n", data->notelength, data->nextnote[a], (data->notelength - 1));
}
}
else{
if(lastColor == data->blockBrghtnss[c]){
fprintf(data->scorefile, "i800 + %.2f 0.7 %d 2 %.2f < . . < . .\n", data->notelength, data->nextnote[a], (data->notelength - 1));
}
else{
fprintf(data->scorefile, "i800 + %.2f 0.7 %d 2 %.2f < . . < . <\n", data->notelength, data->nextnote[a], (data->notelength - 1));
}
}
}
data->totalLength += (data->notelength + 1);
data->printflag++;
}
data->scorenum += 1;
case 4:
fprintf(data->scorefile, "i1000 0 %.2f\n", ((data->totalLength / 3) + 10));
fprintf(data->scorefile, "i2000 0 %.2f 1 4\n", ((data->totalLength / 3) + 10));
fprintf(data->scorefile, "i5000 0 %.2f\n", ((data->totalLength / 3) + 10));
fprintf(data->scorefile, "i6000 0 %.2f\n", ((data->totalLength / 3) + 10));
fprintf(data->scorefile, "i7000 0 %.2f 2 3\n", ((data->totalLength / 3) + 10));
fprintf(data->scorefile, "e\n");
fprintf(data->scorefile, "</CsScore>\n</CsoundSynthesizer>\n");
break;
}
break;
case 3:
//switch for magenta score - filter mod instrument, dark pad, wave terrain, and rhythm instrument
switch(data->scorenum){
case 0:
for(a = 0; a < data->length; a++){
//randomly generate our values for pitch, panning, and notelength
data->nextnote[a] = scales(data);
data->nextpan[a] = randnum();
data->notelength = (double)randnum() + 3;
data->testnote = data->nextnote[a];
//checking for duplicate notes
while (data->nextnote[a] == data->testnote) {
data->nextnote[a] = scales(data);
}
}
data->scorenum += 1;
case 1:
rnd = ((rand() % 7) + 1);
c = 0;
data->printflag = 0;
for(a = 0; a < data->length; a++){
data->notelength = (double)randnum() + 3;
rmod = 1;
count++;
//determine when to change the filter mod rate
if(count % rnd == 0){
rmod = 2;
}
//constraining the note numbers to their frequency range
if(data->nextnote[a] <= 35){
data->nextnote[a] += 12;
}
else if(data->nextnote[a] <= 25){
data->nextnote[a] += 24;
}
else if(data->nextnote[a] >= 60){
data->nextnote[a] -= 12;
}
else if(data->nextnote[a] >= 75){
data->nextnote[a] -= 24;
}
if((data->printflag % data->numBlocks) == 0){
if(data->printflag == 0){
//print the first line of the score for the filter mod instrument;
fprintf(data->scorefile, "i300 0 5 0.7 %d 0.02 5 1 %d\n", data->midi_note, (data->blockBrghtnss[0] * 1000));
}
else{
fprintf(data->scorefile, "i300 + %.2f . %d . %.1f %.1f %d\n", data->notelength, data->nextnote[a], (data->notelength - 1), rmod, data->blockBrghtnss[c] * 1000);
}
lastBrghtnss = data->blockBrghtnss[c];
c++;
if(c == 7){
c--;
}
}
else{
if(lastBrghtnss == data->blockBrghtnss[c]){
fprintf(data->scorefile, "i300 + %.2f . %d . %.1f %.1f .\n", data->notelength, data->nextnote[a], (data->notelength - 1), rmod);
}
else{
fprintf(data->scorefile, "i300 + %.2f . %d . %.1f %.1f <\n", data->notelength, data->nextnote[a], (data->notelength - 1), rmod);
}
}
data->totalLength += (data->notelength + 1);
data->printflag++;
}
data->scorenum += 1;
case 2:
data->printflag = 0;
c = 0;
for(a = 0; a < data->length; a++){
data->notelength = (double)randnum() + 4;
//constraining the note numbers to their frequency range
if(data->nextnote[a] <= 35){
data->nextnote[a] += 12;
}
if(data->nextnote[a] >= 85){
data->nextnote[a] -= 12;
}
if((data->printflag % data->numBlocks) == 0){
if(data->printflag == 0){
//print the first line of the score for the dark pad instrument;
fprintf(data->scorefile, "i500 0 5 0.5 %d 2 3.5 %d %d\n", data->midi_note + 12, (rand() % 100) + 100, (data->blockBrghtnss[0] * 175));
}
else{
fprintf(data->scorefile, "i500 + %.2f . %d . %.2f %d %d\n", data->notelength, data->nextnote[a] + 12, (data->notelength - 0.5), (rand() % 100) + 100, (data->blockBrghtnss[c] * 175));
}
lastBrghtnss = data->blockBrghtnss[c];
c++;
if(c == 7){
c--;
}
}
else{
if(lastBrghtnss == data->blockBrghtnss[c]){
fprintf(data->scorefile, "i500 + %.2f . %d . %.2f %d .\n", data->notelength, data->nextnote[a] + 12, (data->notelength - 0.5), (rand() % 100) + 100);
}
else{
fprintf(data->scorefile, "i500 + %.2f . %d . %.2f %d <\n", data->notelength, data->nextnote[a] + 12, (data->notelength - 0.5), (rand() % 100) + 100);
}
}
//this is used to calculate the total length of the score, it is divided by 3 at the end because it counts for all three instruments
data->totalLength += (data->notelength + 1);
data->printflag++;
}
data->scorenum += 1;
case 3: