mirror of
https://github.com/vsariola/sointu.git
synced 2025-06-04 01:28:45 -04:00
feat(tracker, gioui): add ability & button to delete tracks.
Refer #46.
This commit is contained in:
parent
87f373370e
commit
01226a2910
@ -32,6 +32,10 @@ func (t *Tracker) layoutTracker(gtx layout.Context) layout.Dimensions {
|
|||||||
t.AddTrack(true)
|
t.AddTrack(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for t.DeleteTrackBtn.Clicked() {
|
||||||
|
t.DeleteTrack(false)
|
||||||
|
}
|
||||||
|
|
||||||
//t.TrackHexCheckBoxes[i2].Value = t.TrackShowHex[i2]
|
//t.TrackHexCheckBoxes[i2].Value = t.TrackShowHex[i2]
|
||||||
//cbStyle := material.CheckBox(t.Theme, t.TrackHexCheckBoxes[i2], "hex")
|
//cbStyle := material.CheckBox(t.Theme, t.TrackHexCheckBoxes[i2], "hex")
|
||||||
//cbStyle.Color = white
|
//cbStyle.Color = white
|
||||||
@ -70,6 +74,14 @@ func (t *Tracker) layoutTracker(gtx layout.Context) layout.Dimensions {
|
|||||||
subtractOctaveBtnStyle.Color = primaryColor
|
subtractOctaveBtnStyle.Color = primaryColor
|
||||||
subtractOctaveBtnStyle.Background = transparent
|
subtractOctaveBtnStyle.Background = transparent
|
||||||
subtractOctaveBtnStyle.Inset = layout.UniformInset(unit.Dp(6))
|
subtractOctaveBtnStyle.Inset = layout.UniformInset(unit.Dp(6))
|
||||||
|
deleteTrackBtnStyle := material.IconButton(t.Theme, t.DeleteTrackBtn, widgetForIcon(icons.ActionDelete))
|
||||||
|
deleteTrackBtnStyle.Background = transparent
|
||||||
|
deleteTrackBtnStyle.Inset = layout.UniformInset(unit.Dp(6))
|
||||||
|
if t.CanDeleteTrack() {
|
||||||
|
deleteTrackBtnStyle.Color = primaryColor
|
||||||
|
} else {
|
||||||
|
deleteTrackBtnStyle.Color = disabledTextColor
|
||||||
|
}
|
||||||
newTrackBtnStyle := material.IconButton(t.Theme, t.NewTrackBtn, widgetForIcon(icons.ContentAdd))
|
newTrackBtnStyle := material.IconButton(t.Theme, t.NewTrackBtn, widgetForIcon(icons.ContentAdd))
|
||||||
newTrackBtnStyle.Background = transparent
|
newTrackBtnStyle.Background = transparent
|
||||||
newTrackBtnStyle.Inset = layout.UniformInset(unit.Dp(6))
|
newTrackBtnStyle.Inset = layout.UniformInset(unit.Dp(6))
|
||||||
@ -110,6 +122,7 @@ func (t *Tracker) layoutTracker(gtx layout.Context) layout.Dimensions {
|
|||||||
layout.Rigid(Label(" Voices:", white)),
|
layout.Rigid(Label(" Voices:", white)),
|
||||||
layout.Rigid(voiceUpDown),
|
layout.Rigid(voiceUpDown),
|
||||||
layout.Flexed(1, func(gtx C) D { return layout.Dimensions{Size: gtx.Constraints.Min} }),
|
layout.Flexed(1, func(gtx C) D { return layout.Dimensions{Size: gtx.Constraints.Min} }),
|
||||||
|
layout.Rigid(deleteTrackBtnStyle.Layout),
|
||||||
layout.Rigid(newTrackBtnStyle.Layout))
|
layout.Rigid(newTrackBtnStyle.Layout))
|
||||||
t.Song().Score.Tracks[t.Cursor().Track].Effect = t.TrackHexCheckBox.Value // TODO: we should not modify the model, but how should this be done
|
t.Song().Score.Tracks[t.Cursor().Track].Effect = t.TrackHexCheckBox.Value // TODO: we should not modify the model, but how should this be done
|
||||||
t.SetTrackVoices(t.TrackVoices.Value)
|
t.SetTrackVoices(t.TrackVoices.Value)
|
||||||
|
@ -28,6 +28,7 @@ type Tracker struct {
|
|||||||
TrackVoices *NumberInput
|
TrackVoices *NumberInput
|
||||||
InstrumentNameEditor *widget.Editor
|
InstrumentNameEditor *widget.Editor
|
||||||
NewTrackBtn *widget.Clickable
|
NewTrackBtn *widget.Clickable
|
||||||
|
DeleteTrackBtn *widget.Clickable
|
||||||
NewInstrumentBtn *widget.Clickable
|
NewInstrumentBtn *widget.Clickable
|
||||||
DeleteInstrumentBtn *widget.Clickable
|
DeleteInstrumentBtn *widget.Clickable
|
||||||
AddSemitoneBtn *widget.Clickable
|
AddSemitoneBtn *widget.Clickable
|
||||||
@ -113,6 +114,7 @@ func New(audioContext sointu.AudioContext, synthService sointu.SynthService, syn
|
|||||||
TrackVoices: new(NumberInput),
|
TrackVoices: new(NumberInput),
|
||||||
InstrumentNameEditor: &widget.Editor{SingleLine: true, Submit: true, Alignment: text.Middle},
|
InstrumentNameEditor: &widget.Editor{SingleLine: true, Submit: true, Alignment: text.Middle},
|
||||||
NewTrackBtn: new(widget.Clickable),
|
NewTrackBtn: new(widget.Clickable),
|
||||||
|
DeleteTrackBtn: new(widget.Clickable),
|
||||||
NewInstrumentBtn: new(widget.Clickable),
|
NewInstrumentBtn: new(widget.Clickable),
|
||||||
DeleteInstrumentBtn: new(widget.Clickable),
|
DeleteInstrumentBtn: new(widget.Clickable),
|
||||||
AddSemitoneBtn: new(widget.Clickable),
|
AddSemitoneBtn: new(widget.Clickable),
|
||||||
|
@ -203,6 +203,27 @@ func (m *Model) CanAddTrack() bool {
|
|||||||
return m.song.Score.NumVoices() < 32
|
return m.song.Score.NumVoices() < 32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Model) DeleteTrack(forward bool) {
|
||||||
|
if !m.CanDeleteTrack() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
m.saveUndo("DeleteTrack", 0)
|
||||||
|
newTracks := make([]sointu.Track, len(m.song.Score.Tracks)-1)
|
||||||
|
copy(newTracks, m.song.Score.Tracks[:m.cursor.Track])
|
||||||
|
copy(newTracks[m.cursor.Track:], m.song.Score.Tracks[m.cursor.Track+1:])
|
||||||
|
m.song.Score.Tracks = newTracks
|
||||||
|
if !forward {
|
||||||
|
m.cursor.Track--
|
||||||
|
}
|
||||||
|
m.selectionCorner = m.cursor
|
||||||
|
m.clampPositions()
|
||||||
|
m.notifyScoreChange()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Model) CanDeleteTrack() bool {
|
||||||
|
return len(m.song.Score.Tracks) > 1
|
||||||
|
}
|
||||||
|
|
||||||
func (m *Model) SetTrackVoices(value int) {
|
func (m *Model) SetTrackVoices(value int) {
|
||||||
if value < 1 {
|
if value < 1 {
|
||||||
value = 1
|
value = 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user