mirror of
https://github.com/vsariola/sointu.git
synced 2025-05-28 03:10:24 -04:00
refactor(tracker): move NoteStr and NoteAsValue to gioui package
This commit is contained in:
parent
a60814bab7
commit
ff8e662857
@ -183,7 +183,7 @@ func (t *Tracker) NumberPressed(iv byte) {
|
|||||||
func (t *Tracker) JammingPressed(e key.Event) byte {
|
func (t *Tracker) JammingPressed(e key.Event) byte {
|
||||||
if val, ok := noteMap[e.Name]; ok {
|
if val, ok := noteMap[e.Name]; ok {
|
||||||
if _, ok := t.KeyPlaying[e.Name]; !ok {
|
if _, ok := t.KeyPlaying[e.Name]; !ok {
|
||||||
n := tracker.NoteAsValue(t.OctaveNumberInput.Value, val)
|
n := noteAsValue(t.OctaveNumberInput.Value, val)
|
||||||
instr := t.InstrIndex()
|
instr := t.InstrIndex()
|
||||||
noteID := tracker.NoteIDInstr(instr, n)
|
noteID := tracker.NoteIDInstr(instr, n)
|
||||||
t.NoteOn(noteID)
|
t.NoteOn(noteID)
|
||||||
|
@ -160,7 +160,7 @@ func (te *TrackEditor) Layout(gtx layout.Context, t *Tracker) layout.Dimensions
|
|||||||
} else {
|
} else {
|
||||||
if val, ok := noteMap[e.Name]; ok {
|
if val, ok := noteMap[e.Name]; ok {
|
||||||
if _, ok := t.KeyPlaying[e.Name]; !ok {
|
if _, ok := t.KeyPlaying[e.Name]; !ok {
|
||||||
n := tracker.NoteAsValue(t.OctaveNumberInput.Value, val)
|
n := noteAsValue(t.OctaveNumberInput.Value, val)
|
||||||
t.SetNote(n)
|
t.SetNote(n)
|
||||||
step = true
|
step = true
|
||||||
trk := t.Cursor().Track
|
trk := t.Cursor().Track
|
||||||
@ -289,6 +289,45 @@ func (te *TrackEditor) Layout(gtx layout.Context, t *Tracker) layout.Dimensions
|
|||||||
return dims
|
return dims
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const baseNote = 24
|
||||||
|
|
||||||
|
var notes = []string{
|
||||||
|
"C-",
|
||||||
|
"C#",
|
||||||
|
"D-",
|
||||||
|
"D#",
|
||||||
|
"E-",
|
||||||
|
"F-",
|
||||||
|
"F#",
|
||||||
|
"G-",
|
||||||
|
"G#",
|
||||||
|
"A-",
|
||||||
|
"A#",
|
||||||
|
"B-",
|
||||||
|
}
|
||||||
|
|
||||||
|
func noteStr(val byte) string {
|
||||||
|
if val == 1 {
|
||||||
|
return "..." // hold
|
||||||
|
}
|
||||||
|
if val == 0 {
|
||||||
|
return "---" // release
|
||||||
|
}
|
||||||
|
oNote := mod(int(val-baseNote), 12)
|
||||||
|
octave := (int(val) - oNote - baseNote) / 12
|
||||||
|
if octave < 0 {
|
||||||
|
return fmt.Sprintf("%s%s", notes[oNote], string(byte('Z'+1+octave)))
|
||||||
|
}
|
||||||
|
if octave >= 10 {
|
||||||
|
return fmt.Sprintf("%s%s", notes[oNote], string(byte('A'+octave-10)))
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%s%d", notes[oNote], octave)
|
||||||
|
}
|
||||||
|
|
||||||
|
func noteAsValue(octave, note int) byte {
|
||||||
|
return byte(baseNote + (octave * 12) + note)
|
||||||
|
}
|
||||||
|
|
||||||
func (te *TrackEditor) layoutTracks(gtx C, t *Tracker) D {
|
func (te *TrackEditor) layoutTracks(gtx C, t *Tracker) D {
|
||||||
defer op.Offset(image.Point{}).Push(gtx.Ops).Pop()
|
defer op.Offset(image.Point{}).Push(gtx.Ops).Pop()
|
||||||
defer clip.Rect{Max: gtx.Constraints.Max}.Push(gtx.Ops).Pop()
|
defer clip.Rect{Max: gtx.Constraints.Max}.Push(gtx.Ops).Pop()
|
||||||
@ -450,7 +489,7 @@ func (te *TrackEditor) layoutTracks(gtx C, t *Tracker) D {
|
|||||||
}
|
}
|
||||||
widget.Label{}.Layout(gtx, textShaper, trackerFont, trackerFontSize, strings.ToUpper(text), op.CallOp{})
|
widget.Label{}.Layout(gtx, textShaper, trackerFont, trackerFontSize, strings.ToUpper(text), op.CallOp{})
|
||||||
} else {
|
} else {
|
||||||
widget.Label{}.Layout(gtx, textShaper, trackerFont, trackerFontSize, tracker.NoteStr(c), op.CallOp{})
|
widget.Label{}.Layout(gtx, textShaper, trackerFont, trackerFontSize, noteStr(c), op.CallOp{})
|
||||||
}
|
}
|
||||||
op.Offset(image.Point{-patmarkWidth, trackRowHeight}).Add(gtx.Ops)
|
op.Offset(image.Point{-patmarkWidth, trackRowHeight}).Add(gtx.Ops)
|
||||||
}
|
}
|
||||||
|
@ -1,45 +0,0 @@
|
|||||||
package tracker
|
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
|
|
||||||
// note 81 = A4
|
|
||||||
// note 72 = C4
|
|
||||||
// note 24 = C0
|
|
||||||
const baseNote = 24
|
|
||||||
|
|
||||||
var notes = []string{
|
|
||||||
"C-",
|
|
||||||
"C#",
|
|
||||||
"D-",
|
|
||||||
"D#",
|
|
||||||
"E-",
|
|
||||||
"F-",
|
|
||||||
"F#",
|
|
||||||
"G-",
|
|
||||||
"G#",
|
|
||||||
"A-",
|
|
||||||
"A#",
|
|
||||||
"B-",
|
|
||||||
}
|
|
||||||
|
|
||||||
func NoteStr(val byte) string {
|
|
||||||
if val == 1 {
|
|
||||||
return "..." // hold
|
|
||||||
}
|
|
||||||
if val == 0 {
|
|
||||||
return "---" // release
|
|
||||||
}
|
|
||||||
oNote := mod(int(val-baseNote), 12)
|
|
||||||
octave := (int(val) - oNote - baseNote) / 12
|
|
||||||
if octave < 0 {
|
|
||||||
return fmt.Sprintf("%s%s", notes[oNote], string(byte('Z'+1+octave)))
|
|
||||||
}
|
|
||||||
if octave >= 10 {
|
|
||||||
return fmt.Sprintf("%s%s", notes[oNote], string(byte('A'+octave-10)))
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("%s%d", notes[oNote], octave)
|
|
||||||
}
|
|
||||||
|
|
||||||
func NoteAsValue(octave, note int) byte {
|
|
||||||
return byte(baseNote + (octave * 12) + note)
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user