mirror of
https://github.com/vsariola/sointu.git
synced 2025-06-04 01:28:45 -04:00
feat(tracker): ctrl + number change the current pattern in sequencer
This commit is contained in:
parent
33bd91764c
commit
5e76fabf21
@ -57,10 +57,10 @@ func (t *Tracker) KeyEvent(e key.Event) bool {
|
||||
return true
|
||||
}
|
||||
case "A":
|
||||
t.setCurrent(0)
|
||||
t.SetCurrentNote(0)
|
||||
return true
|
||||
case key.NameDeleteForward:
|
||||
t.setCurrent(1)
|
||||
t.SetCurrentNote(1)
|
||||
return true
|
||||
case key.NameEscape:
|
||||
os.Exit(0)
|
||||
@ -113,15 +113,22 @@ func (t *Tracker) KeyEvent(e key.Event) bool {
|
||||
t.CursorColumn = 0
|
||||
return true
|
||||
}
|
||||
if t.CursorColumn == 0 {
|
||||
if val, ok := noteMap[e.Name]; ok {
|
||||
t.NotePressed(val)
|
||||
if e.Modifiers.Contain(key.ModCtrl) {
|
||||
if iv, err := strconv.ParseInt(e.Name, 16, 8); err == nil {
|
||||
t.SetCurrentPattern(byte(iv))
|
||||
return true
|
||||
}
|
||||
} else {
|
||||
if iv, err := strconv.ParseInt(e.Name, 16, 8); err == nil {
|
||||
t.NumberPressed(byte(iv))
|
||||
return true
|
||||
if t.CursorColumn == 0 {
|
||||
if val, ok := noteMap[e.Name]; ok {
|
||||
t.NotePressed(val)
|
||||
return true
|
||||
}
|
||||
} else {
|
||||
if iv, err := strconv.ParseInt(e.Name, 16, 8); err == nil {
|
||||
t.NumberPressed(byte(iv))
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -143,12 +150,6 @@ func (t *Tracker) moveCursor(delta int) {
|
||||
}
|
||||
}
|
||||
|
||||
// setCurrent sets the (note) value in current pattern under cursor to iv
|
||||
func (t *Tracker) setCurrent(iv byte) {
|
||||
t.SaveUndo()
|
||||
t.song.Tracks[t.ActiveTrack].Patterns[t.song.Tracks[t.ActiveTrack].Sequence[t.DisplayPattern]][t.CursorRow] = iv
|
||||
}
|
||||
|
||||
// getCurrent returns the current (note) value in current pattern under the cursor
|
||||
func (t *Tracker) getCurrent() byte {
|
||||
return t.song.Tracks[t.ActiveTrack].Patterns[t.song.Tracks[t.ActiveTrack].Sequence[t.DisplayPattern]][t.CursorRow]
|
||||
@ -156,7 +157,7 @@ func (t *Tracker) getCurrent() byte {
|
||||
|
||||
// NotePressed handles incoming key presses while in the note column
|
||||
func (t *Tracker) NotePressed(val int) {
|
||||
t.setCurrent(getNoteValue(int(t.CurrentOctave), val))
|
||||
t.SetCurrentNote(getNoteValue(int(t.CurrentOctave), val))
|
||||
}
|
||||
|
||||
// NumberPressed handles incoming presses while in either of the hex number columns
|
||||
@ -167,5 +168,5 @@ func (t *Tracker) NumberPressed(iv byte) {
|
||||
} else if t.CursorColumn == 2 {
|
||||
val = (val & 0xF0) | (iv & 0xF)
|
||||
}
|
||||
t.setCurrent(val)
|
||||
t.SetCurrentNote(val)
|
||||
}
|
||||
|
@ -232,6 +232,25 @@ func (t *Tracker) AddInstrument() {
|
||||
}
|
||||
}
|
||||
|
||||
// SetCurrentNote sets the (note) value in current pattern under cursor to iv
|
||||
func (t *Tracker) SetCurrentNote(iv byte) {
|
||||
t.SaveUndo()
|
||||
t.song.Tracks[t.ActiveTrack].Patterns[t.song.Tracks[t.ActiveTrack].Sequence[t.DisplayPattern]][t.CursorRow] = iv
|
||||
}
|
||||
|
||||
func (t *Tracker) SetCurrentPattern(pat byte) {
|
||||
t.SaveUndo()
|
||||
length := len(t.song.Tracks[t.ActiveTrack].Patterns)
|
||||
if int(pat) >= length {
|
||||
tail := make([][]byte, int(pat)-length+1)
|
||||
for i := range tail {
|
||||
tail[i] = make([]byte, t.song.PatternRows())
|
||||
}
|
||||
t.song.Tracks[t.ActiveTrack].Patterns = append(t.song.Tracks[t.ActiveTrack].Patterns, tail...)
|
||||
}
|
||||
t.song.Tracks[t.ActiveTrack].Sequence[t.DisplayPattern] = pat
|
||||
}
|
||||
|
||||
func New(audioContext sointu.AudioContext) *Tracker {
|
||||
t := &Tracker{
|
||||
Theme: material.NewTheme(gofont.Collection()),
|
||||
|
Loading…
x
Reference in New Issue
Block a user