feat(tracker): add keys to adjust current octave

This commit is contained in:
vsariola 2020-12-31 00:01:54 +02:00
parent 2e2b5261ae
commit 1d91603e36
3 changed files with 52 additions and 30 deletions

View File

@ -7,31 +7,39 @@ import (
"gioui.org/io/key" "gioui.org/io/key"
) )
var noteMap = map[string]byte{ var noteMap = map[string]int{
"Z": 0, "Z": -12,
"S": 1, "S": -11,
"X": 2, "X": -10,
"D": 3, "D": -9,
"C": 4, "C": -8,
"V": 5, "V": -7,
"G": 6, "G": -6,
"B": 7, "B": -5,
"H": 8, "H": -4,
"N": 9, "N": -3,
"J": 10, "J": -2,
"M": 11, "M": -1,
"Q": 12, ",": 0,
"2": 13, "L": 1,
"W": 14, ".": 2,
"3": 15, "Q": 0,
"E": 16, "2": 1,
"R": 17, "W": 2,
"5": 18, "3": 3,
"T": 19, "E": 4,
"6": 20, "R": 5,
"Y": 21, "5": 6,
"7": 22, "T": 7,
"U": 23, "6": 8,
"Y": 9,
"7": 10,
"U": 11,
"I": 12,
"9": 13,
"O": 14,
"0": 15,
"P": 16,
} }
// KeyEvent handles incoming key events and returns true if repaint is needed. // KeyEvent handles incoming key events and returns true if repaint is needed.
@ -58,6 +66,18 @@ func (t *Tracker) KeyEvent(e key.Event) bool {
case "Space": case "Space":
t.TogglePlay() t.TogglePlay()
return true return true
case `\`:
if e.Modifiers.Contain(key.ModShift) {
if t.CurrentOctave < 9 {
t.CurrentOctave++
return true
}
} else {
if t.CurrentOctave > 0 {
t.CurrentOctave--
return true
}
}
case key.NameUpArrow: case key.NameUpArrow:
t.CursorRow = (t.CursorRow + t.song.PatternRows() - 1) % t.song.PatternRows() t.CursorRow = (t.CursorRow + t.song.PatternRows() - 1) % t.song.PatternRows()
return true return true
@ -104,8 +124,8 @@ func (t *Tracker) getCurrent() byte {
} }
// NotePressed handles incoming key presses while in the note column // NotePressed handles incoming key presses while in the note column
func (t *Tracker) NotePressed(val byte) { func (t *Tracker) NotePressed(val int) {
t.setCurrent(getNoteValue(t.CurrentOctave, val)) t.setCurrent(getNoteValue(int(t.CurrentOctave), val))
} }
// NumberPressed handles incoming presses while in either of the hex number columns // NumberPressed handles incoming presses while in either of the hex number columns

View File

@ -1,6 +1,8 @@
package tracker package tracker
import ( import (
"fmt"
"gioui.org/layout" "gioui.org/layout"
) )
@ -34,6 +36,6 @@ func (t *Tracker) layoutControls(gtx layout.Context) layout.Dimensions {
gtx.Constraints.Max.Y = 400 gtx.Constraints.Max.Y = 400
return layout.Stack{Alignment: layout.NW}.Layout(gtx, return layout.Stack{Alignment: layout.NW}.Layout(gtx,
layout.Expanded(t.QuitButton.Layout), layout.Expanded(t.QuitButton.Layout),
layout.Stacked(Raised(Label("Hello", white))), layout.Stacked(Raised(Label(fmt.Sprintf("Current octave: %v", t.CurrentOctave), white))),
) )
} }

View File

@ -36,6 +36,6 @@ func valueAsNote(val byte) string {
} }
// noteValue return the note value for a particular note and octave combination // noteValue return the note value for a particular note and octave combination
func getNoteValue(octave, note byte) byte { func getNoteValue(octave, note int) byte {
return baseNote + (octave * 12) + note return byte(baseNote + (octave * 12) + note)
} }