Skip to content

Commit 27ac9f0

Browse files
committed
export types for easier usage
1 parent 361ffa0 commit 27ac9f0

File tree

2 files changed

+95
-91
lines changed

2 files changed

+95
-91
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,4 @@ dev
1515
mem.pb.gz
1616

1717
.vscode/*
18-
examples/record
19-
out.wav
18+
*.wav

models.go

Lines changed: 94 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,25 @@ const (
1919
SAMPLES model = "Model:Samples"
2020
)
2121

22-
type voice int8
22+
// Voice represents a track on the physical machine.
23+
type Voice int8
2324

2425
// Voices/Tracks
2526
const (
26-
T1 voice = iota
27+
T1 Voice = iota
2728
T2
2829
T3
2930
T4
3031
T5
3132
T6
3233
)
3334

34-
type notes int8
35+
// Notes are all notes reproducible by the machines.
36+
type Notes int8
3537

3638
// Keys/letter notes
3739
const (
38-
A0 notes = iota + 21
40+
A0 Notes = iota + 21
3941
As0
4042
B0
4143
C1
@@ -135,54 +137,55 @@ const (
135137
As8
136138
B8
137139

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
179181
)
180182

181-
type chords int8
183+
// Chords are all chords supported by the machines mapped custom type.
184+
type Chords int8
182185

183186
// Chords
184187
const (
185-
Unisonx2 chords = iota
188+
Unisonx2 Chords = iota
186189
Unisonx3
187190
Unisonx4
188191
Minor
@@ -222,10 +225,12 @@ const (
222225
Fifths
223226
)
224227

228+
// Parameter is all track parameters of the physical machine.
229+
// Sample has certain different key/values than Cycles.
225230
type Parameter int8
226231

227232
const (
228-
// NOTE Parameter = 3
233+
NOTE Parameter = 3
229234
TRACKLEVEL Parameter = 17
230235
MUTE Parameter = 94
231236
PAN Parameter = 10
@@ -288,13 +293,6 @@ const (
288293
CHORD
289294
)
290295

291-
type scaleMode bool
292-
293-
const (
294-
PTN scaleMode = true
295-
TRK scaleMode = false
296-
)
297-
298296
// Project long description of the data structure, methods, behaviors and useage.
299297
type Project struct {
300298
model
@@ -307,7 +305,8 @@ type Project struct {
307305
wr *writer.Writer
308306
}
309307

310-
type preset map[Parameter]int8
308+
// Preset represents a machine's preset.
309+
type Preset map[Parameter]int8
311310

312311
// NewProject initiates and returns a *Project struct.
313312
func NewProject(m model) (*Project, error) {
@@ -363,66 +362,67 @@ func NewProject(m model) (*Project, error) {
363362
}
364363

365364
// Preset immediately sets (CC) provided parameters.
366-
func (f *Project) Preset(track voice, preset preset) {
365+
func (p *Project) Preset(track Voice, preset Preset) {
367366
for parameter, value := range preset {
368-
f.cc(track, parameter, value)
367+
p.cc(track, parameter, value)
369368
}
370369
}
371370

372371
// Note fires immediately a midi note on signal followed by a note off specified duration in milliseconds (ms).
373372
// 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) {
375374
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])
378377
}
379378
}
380379

381-
f.noteon(track, note, velocity)
380+
p.noteon(track, note, velocity)
382381
go func() {
383382
time.Sleep(time.Millisecond * time.Duration(duration))
384-
f.noteoff(track, note)
383+
p.noteoff(track, note)
385384
}()
386385
}
387386

388387
// 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)
391390
}
392391

393392
// 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)
396395
}
397396

398397
// 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()
403402
}
404403

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))
408407
}
409408

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))
413412
}
414413

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))
418417
}
419418

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))
423422
}
424423

425-
func PT1() preset {
424+
// PT1 is the cycles preset for track 1.
425+
func PT1() Preset {
426426
p := make(map[Parameter]int8)
427427
p[MACHINE] = int8(KICK)
428428
p[TRACKLEVEL] = int8(120)
@@ -442,7 +442,8 @@ func PT1() preset {
442442
return p
443443
}
444444

445-
func PT2() preset {
445+
// PT2 is the cycles preset for track 2.
446+
func PT2() Preset {
446447
p := PT1()
447448
p[MACHINE] = int8(SNARE)
448449
p[SWEEP] = int8(8)
@@ -453,7 +454,8 @@ func PT2() preset {
453454
return p
454455
}
455456

456-
func PT3() preset {
457+
// PT3 is the cycles preset for track 3.
458+
func PT3() Preset {
457459
p := PT1()
458460
p[MACHINE] = int8(METAL)
459461
p[SWEEP] = int8(48)
@@ -464,7 +466,8 @@ func PT3() preset {
464466
return p
465467
}
466468

467-
func PT4() preset {
469+
// PT4 is the cycles preset for track 4.
470+
func PT4() Preset {
468471
p := PT1()
469472
p[MACHINE] = int8(PERC)
470473
p[SWEEP] = int8(100)
@@ -475,7 +478,8 @@ func PT4() preset {
475478
return p
476479
}
477480

478-
func PT5() preset {
481+
// PT5 is the cycles preset for track 5.
482+
func PT5() Preset {
479483
p := PT1()
480484
p[MACHINE] = int8(TONE)
481485
p[SWEEP] = int8(38)
@@ -486,7 +490,8 @@ func PT5() preset {
486490
return p
487491
}
488492

489-
func PT6() preset {
493+
// PT6 is the cycles preset for track 6.
494+
func PT6() Preset {
490495
p := PT1()
491496
p[MACHINE] = int8(CHORD)
492497
p[SWEEP] = int8(43)

0 commit comments

Comments
 (0)