@@ -19,23 +19,25 @@ const (
19
19
SAMPLES model = "Model:Samples"
20
20
)
21
21
22
- type voice int8
22
+ // Voice represents a track on the physical machine.
23
+ type Voice int8
23
24
24
25
// Voices/Tracks
25
26
const (
26
- T1 voice = iota
27
+ T1 Voice = iota
27
28
T2
28
29
T3
29
30
T4
30
31
T5
31
32
T6
32
33
)
33
34
34
- type notes int8
35
+ // Notes are all notes reproducible by the machines.
36
+ type Notes int8
35
37
36
38
// Keys/letter notes
37
39
const (
38
- A0 notes = iota + 21
40
+ A0 Notes = iota + 21
39
41
As0
40
42
B0
41
43
C1
@@ -135,54 +137,55 @@ const (
135
137
As8
136
138
B8
137
139
138
- Bf0 notes = As0
139
- Df1 notes = Cs1
140
- Ef1 notes = Ds1
141
- Gf1 notes = Fs1
142
- Af1 notes = Gs1
143
- Bf1 notes = As1
144
- Df2 notes = Cs2
145
- Ef2 notes = Ds2
146
- Gf2 notes = Fs2
147
- Af2 notes = Gs2
148
- Bf2 notes = As2
149
- Df3 notes = Cs3
150
- Ef3 notes = Ds3
151
- Gf3 notes = Fs3
152
- Af3 notes = Gs3
153
- Bf3 notes = As3
154
- Df4 notes = Cs4
155
- Ef4 notes = Ds4
156
- Gf4 notes = Fs4
157
- Af4 notes = Gs4
158
- Bf4 notes = As4
159
- Df5 notes = Cs5
160
- Ef5 notes = Ds5
161
- Gf5 notes = Fs5
162
- Af5 notes = Gs5
163
- Bf5 notes = As5
164
- Df6 notes = Cs6
165
- Ef6 notes = Ds6
166
- Gf6 notes = Fs6
167
- Af6 notes = Gs6
168
- Bf6 notes = As6
169
- Df7 notes = Cs7
170
- Ef7 notes = Ds7
171
- Gf7 notes = Fs7
172
- Af7 notes = Gs7
173
- Bf7 notes = As7
174
- Df8 notes = Cs8
175
- Ef8 notes = Ds8
176
- Gf8 notes = Fs8
177
- Af8 notes = Gs8
178
- Bf8 notes = As8
140
+ Bf0 Notes = As0
141
+ Df1 Notes = Cs1
142
+ Ef1 Notes = Ds1
143
+ Gf1 Notes = Fs1
144
+ Af1 Notes = Gs1
145
+ Bf1 Notes = As1
146
+ Df2 Notes = Cs2
147
+ Ef2 Notes = Ds2
148
+ Gf2 Notes = Fs2
149
+ Af2 Notes = Gs2
150
+ Bf2 Notes = As2
151
+ Df3 Notes = Cs3
152
+ Ef3 Notes = Ds3
153
+ Gf3 Notes = Fs3
154
+ Af3 Notes = Gs3
155
+ Bf3 Notes = As3
156
+ Df4 Notes = Cs4
157
+ Ef4 Notes = Ds4
158
+ Gf4 Notes = Fs4
159
+ Af4 Notes = Gs4
160
+ Bf4 Notes = As4
161
+ Df5 Notes = Cs5
162
+ Ef5 Notes = Ds5
163
+ Gf5 Notes = Fs5
164
+ Af5 Notes = Gs5
165
+ Bf5 Notes = As5
166
+ Df6 Notes = Cs6
167
+ Ef6 Notes = Ds6
168
+ Gf6 Notes = Fs6
169
+ Af6 Notes = Gs6
170
+ Bf6 Notes = As6
171
+ Df7 Notes = Cs7
172
+ Ef7 Notes = Ds7
173
+ Gf7 Notes = Fs7
174
+ Af7 Notes = Gs7
175
+ Bf7 Notes = As7
176
+ Df8 Notes = Cs8
177
+ Ef8 Notes = Ds8
178
+ Gf8 Notes = Fs8
179
+ Af8 Notes = Gs8
180
+ Bf8 Notes = As8
179
181
)
180
182
181
- type chords int8
183
+ // Chords are all chords supported by the machines mapped custom type.
184
+ type Chords int8
182
185
183
186
// Chords
184
187
const (
185
- Unisonx2 chords = iota
188
+ Unisonx2 Chords = iota
186
189
Unisonx3
187
190
Unisonx4
188
191
Minor
@@ -222,10 +225,12 @@ const (
222
225
Fifths
223
226
)
224
227
228
+ // Parameter is all track parameters of the physical machine.
229
+ // Sample has certain different key/values than Cycles.
225
230
type Parameter int8
226
231
227
232
const (
228
- // NOTE Parameter = 3
233
+ NOTE Parameter = 3
229
234
TRACKLEVEL Parameter = 17
230
235
MUTE Parameter = 94
231
236
PAN Parameter = 10
@@ -288,13 +293,6 @@ const (
288
293
CHORD
289
294
)
290
295
291
- type scaleMode bool
292
-
293
- const (
294
- PTN scaleMode = true
295
- TRK scaleMode = false
296
- )
297
-
298
296
// Project long description of the data structure, methods, behaviors and useage.
299
297
type Project struct {
300
298
model
@@ -307,7 +305,8 @@ type Project struct {
307
305
wr * writer.Writer
308
306
}
309
307
310
- type preset map [Parameter ]int8
308
+ // Preset represents a machine's preset.
309
+ type Preset map [Parameter ]int8
311
310
312
311
// NewProject initiates and returns a *Project struct.
313
312
func NewProject (m model ) (* Project , error ) {
@@ -363,66 +362,67 @@ func NewProject(m model) (*Project, error) {
363
362
}
364
363
365
364
// Preset immediately sets (CC) provided parameters.
366
- func (f * Project ) Preset (track voice , preset preset ) {
365
+ func (p * Project ) Preset (track Voice , preset Preset ) {
367
366
for parameter , value := range preset {
368
- f .cc (track , parameter , value )
367
+ p .cc (track , parameter , value )
369
368
}
370
369
}
371
370
372
371
// Note fires immediately a midi note on signal followed by a note off specified duration in milliseconds (ms).
373
372
// Optionally user can pass a preset too for convenience.
374
- func (f * Project ) Note (track voice , note notes , velocity int8 , duration float64 , pre ... preset ) {
373
+ func (p * Project ) Note (track Voice , note Notes , velocity int8 , duration float64 , pre ... Preset ) {
375
374
if len (pre ) != 0 {
376
- for i , _ := range pre {
377
- f .Preset (track , pre [i ])
375
+ for i := range pre {
376
+ p .Preset (track , pre [i ])
378
377
}
379
378
}
380
379
381
- f .noteon (track , note , velocity )
380
+ p .noteon (track , note , velocity )
382
381
go func () {
383
382
time .Sleep (time .Millisecond * time .Duration (duration ))
384
- f .noteoff (track , note )
383
+ p .noteoff (track , note )
385
384
}()
386
385
}
387
386
388
387
// CC control change.
389
- func (f * Project ) CC (track voice , parameter Parameter , value int8 ) {
390
- f .cc (track , parameter , value )
388
+ func (p * Project ) CC (track Voice , parameter Parameter , value int8 ) {
389
+ p .cc (track , parameter , value )
391
390
}
392
391
393
392
// PC Project control change.
394
- func (f * Project ) PC (t voice , pc int8 ) {
395
- f .pc (t , pc )
393
+ func (p * Project ) PC (t Voice , pc int8 ) {
394
+ p .pc (t , pc )
396
395
}
397
396
398
397
// Close midi connection. Use it with defer after creating a new project.
399
- func (s * Project ) Close () {
400
- s .in .Close ()
401
- s .out .Close ()
402
- s .drv .Close ()
398
+ func (p * Project ) Close () {
399
+ p .in .Close ()
400
+ p .out .Close ()
401
+ p .drv .Close ()
403
402
}
404
403
405
- func (s * Project ) noteon (t voice , n notes , vel int8 ) {
406
- s .wr .SetChannel (uint8 (t ))
407
- writer .NoteOn (s .wr , uint8 (n ), uint8 (vel ))
404
+ func (p * Project ) noteon (t Voice , n Notes , vel int8 ) {
405
+ p .wr .SetChannel (uint8 (t ))
406
+ writer .NoteOn (p .wr , uint8 (n ), uint8 (vel ))
408
407
}
409
408
410
- func (s * Project ) noteoff (t voice , n notes ) {
411
- s .wr .SetChannel (uint8 (t ))
412
- writer .NoteOff (s .wr , uint8 (n ))
409
+ func (p * Project ) noteoff (t Voice , n Notes ) {
410
+ p .wr .SetChannel (uint8 (t ))
411
+ writer .NoteOff (p .wr , uint8 (n ))
413
412
}
414
413
415
- func (s * Project ) cc (t voice , par Parameter , val int8 ) {
416
- s .wr .SetChannel (uint8 (t ))
417
- writer .ControlChange (s .wr , uint8 (par ), uint8 (val ))
414
+ func (p * Project ) cc (t Voice , par Parameter , val int8 ) {
415
+ p .wr .SetChannel (uint8 (t ))
416
+ writer .ControlChange (p .wr , uint8 (par ), uint8 (val ))
418
417
}
419
418
420
- func (s * Project ) pc (t voice , pc int8 ) {
421
- s .wr .SetChannel (uint8 (t ))
422
- writer .ProgramChange (s .wr , uint8 (pc ))
419
+ func (p * Project ) pc (t Voice , pc int8 ) {
420
+ p .wr .SetChannel (uint8 (t ))
421
+ writer .ProgramChange (p .wr , uint8 (pc ))
423
422
}
424
423
425
- func PT1 () preset {
424
+ // PT1 is the cycles preset for track 1.
425
+ func PT1 () Preset {
426
426
p := make (map [Parameter ]int8 )
427
427
p [MACHINE ] = int8 (KICK )
428
428
p [TRACKLEVEL ] = int8 (120 )
@@ -442,7 +442,8 @@ func PT1() preset {
442
442
return p
443
443
}
444
444
445
- func PT2 () preset {
445
+ // PT2 is the cycles preset for track 2.
446
+ func PT2 () Preset {
446
447
p := PT1 ()
447
448
p [MACHINE ] = int8 (SNARE )
448
449
p [SWEEP ] = int8 (8 )
@@ -453,7 +454,8 @@ func PT2() preset {
453
454
return p
454
455
}
455
456
456
- func PT3 () preset {
457
+ // PT3 is the cycles preset for track 3.
458
+ func PT3 () Preset {
457
459
p := PT1 ()
458
460
p [MACHINE ] = int8 (METAL )
459
461
p [SWEEP ] = int8 (48 )
@@ -464,7 +466,8 @@ func PT3() preset {
464
466
return p
465
467
}
466
468
467
- func PT4 () preset {
469
+ // PT4 is the cycles preset for track 4.
470
+ func PT4 () Preset {
468
471
p := PT1 ()
469
472
p [MACHINE ] = int8 (PERC )
470
473
p [SWEEP ] = int8 (100 )
@@ -475,7 +478,8 @@ func PT4() preset {
475
478
return p
476
479
}
477
480
478
- func PT5 () preset {
481
+ // PT5 is the cycles preset for track 5.
482
+ func PT5 () Preset {
479
483
p := PT1 ()
480
484
p [MACHINE ] = int8 (TONE )
481
485
p [SWEEP ] = int8 (38 )
@@ -486,7 +490,8 @@ func PT5() preset {
486
490
return p
487
491
}
488
492
489
- func PT6 () preset {
493
+ // PT6 is the cycles preset for track 6.
494
+ func PT6 () Preset {
490
495
p := PT1 ()
491
496
p [MACHINE ] = int8 (CHORD )
492
497
p [SWEEP ] = int8 (43 )
0 commit comments