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
|
<CsoundSynthesizer>
<CsOptions>
-odac
</CsOptions>
<CsInstruments>
/*
csound-opl example 1
Multiple channel chord sequence
Richard Knight 2021 : examples are licensed as public domain equivalent : http://unlicense.org/
*/
sr = 44100
kr = 4410
nchnls = 2
0dbfs = 1
giopl init 0
/*
Play notes with certain parameters:
kinstr : the instrument number to play
kduration : play duration
kbase : base MIDI note number
kintervals : intervals to form a chord with from kbase
ktimeinc : how much time to step with each interval
kreadmode : read intervals 0=forward, 1=reverse
*/
opcode playchord, 0, kkkk[]kk
kinstr, kduration, kbase, kintervals[], ktimeinc, kreadmode xin
ktime = 0
if (kreadmode == 0) then
kdx = 0
while (kdx < lenarray(kintervals)) do
event "i", kinstr, ktime, kduration, kbase+kintervals[kdx]
ktime += ktimeinc
kdx += 1
od
else
kdx = lenarray(kintervals) - 1
while (kdx > -1) do
event "i", kinstr, ktime, kduration, kbase+kintervals[kdx]
ktime += ktimeinc
kdx -= 1
od
endif
endop
; audio output, voice setting and sequencer invocation
instr main
; the synthesiser
giopl, aL, aR opl
outs aL, aR
; set the voices for four channels
oplpatchchange giopl, 0, 89
oplpatchchange giopl, 1, 12
oplpatchchange giopl, 2, 72
oplpatchchange giopl, 3, 96
oplpatchchange giopl, 4, 39
; start the sequencer
event_i "i", "sequencer", 0, p3
endin
; basic chord triggering pseudo-sequencer
instr sequencer
itempo = 120
ibeatduration = 60/itempo
; intervals for chords, and notes for progression
kintervalsall[][] init 4, 4
kintervalsall fillarray 0, 4, 5, 9, 4, 5, 7, 9, 0, 5, 7, 14, 0, 5, 7, 8
knotes[] fillarray 50, 54, 56, 54
knotedx init 0
kbeat metro itempo/60
kbar0 init 0
if (kbeat == 1) then
kintervals[] getrow kintervalsall, knotedx
if (kbar0 == 0) then
playchord 3, ibeatduration*4, knotes[knotedx], kintervals, 0, 0
elseif (kbar0 == 1) then
playchord 2, ibeatduration, knotes[knotedx], kintervals, ibeatduration/4, 0
elseif (kbar0 == 2) then
playchord 1, ibeatduration, knotes[knotedx]+12, kintervals, 0, 0
elseif (kbar0 == 3) then
playchord 4, ibeatduration, knotes[knotedx]+12, kintervals, ibeatduration/4, 1
endif
kbassnote = knotes[knotedx]
event "i", 5, 0, ibeatduration*0.2, kbassnote-24
event "i", 5, ibeatduration*0.5, ibeatduration*0.16, kbassnote-12
if (kbar0 < 3) then
kbar0 += 1
else
if (knotedx < 3) then
knotedx += 1
else
knotedx = 0
endif
kbar0 = 0
endif
endif
endin
; play note on channel 0
instr 1
oplnote giopl, 0, p4, 120
endin
; play note on channel 1
instr 2
oplnote giopl, 1, p4, 100
endin
; play note on channel 2
instr 3
oplnote giopl, 2, p4, 100
endin
; play note on channel 3
instr 4
oplnote giopl, 3, p4, 100
endin
; play note on channel 4
instr 5
oplnote giopl, 4, p4, 80
endin
</CsInstruments>
<CsScore>
i"main" 0 3600
</CsScore>
</CsoundSynthesizer>
|