Skip to content

Commit

Permalink
fix crashes on pattern change when number of track does ot match (fix #…
Browse files Browse the repository at this point in the history
  • Loading branch information
xaviergodart committed Aug 12, 2024
1 parent ce1ef84 commit f940a3e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ func (m mainModel) Init() tea.Cmd {
}

func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.resetPatternState()

switch msg := msg.(type) {

case tea.WindowSizeMsg:
Expand Down Expand Up @@ -359,6 +361,16 @@ func (m mainModel) View() string {
)
}

// resetPattern ensures that we reset active track and step state
// after a pattern chain if needed
func (m *mainModel) resetPatternState() {
if m.activeTrack >= len(m.seq.Tracks()) || m.activeStep >= len(m.seq.Tracks()[m.activeTrack].Steps()) {
m.activeTrack = 0
m.activeTrackPage = 0
m.activeStep = 0
}
}

func (m *mainModel) getActiveTrack() sequencer.Track {
return m.seq.Tracks()[m.activeTrack]
}
Expand Down

0 comments on commit f940a3e

Please sign in to comment.