mirror of
https://github.com/vsariola/sointu.git
synced 2025-07-19 21:44:38 -04:00
refactor(tracker/gioui): upgrade gio & store Tracker to gtx.Values
This commit is contained in:
parent
08c36ed462
commit
d78ef98e73
2
go.mod
2
go.mod
@ -5,7 +5,7 @@ go 1.23.8
|
|||||||
toolchain go1.24.0
|
toolchain go1.24.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
gioui.org v0.8.1-0.20250526181049-1a17e9ea3725
|
gioui.org v0.8.1-0.20250624114559-c3ce484b5e80
|
||||||
gioui.org/x v0.7.1
|
gioui.org/x v0.7.1
|
||||||
github.com/Masterminds/sprig v2.22.0+incompatible
|
github.com/Masterminds/sprig v2.22.0+incompatible
|
||||||
github.com/ebitengine/oto/v3 v3.3.0
|
github.com/ebitengine/oto/v3 v3.3.0
|
||||||
|
2
go.sum
2
go.sum
@ -2,6 +2,8 @@ eliasnaur.com/font v0.0.0-20230308162249-dd43949cb42d h1:ARo7NCVvN2NdhLlJE9xAbKw
|
|||||||
eliasnaur.com/font v0.0.0-20230308162249-dd43949cb42d/go.mod h1:OYVuxibdk9OSLX8vAqydtRPP87PyTFcT9uH3MlEGBQA=
|
eliasnaur.com/font v0.0.0-20230308162249-dd43949cb42d/go.mod h1:OYVuxibdk9OSLX8vAqydtRPP87PyTFcT9uH3MlEGBQA=
|
||||||
gioui.org v0.8.1-0.20250526181049-1a17e9ea3725 h1:8dzkqzvWLIwW6HEQv5CinK53vMeANmUEETzpcbtPRp0=
|
gioui.org v0.8.1-0.20250526181049-1a17e9ea3725 h1:8dzkqzvWLIwW6HEQv5CinK53vMeANmUEETzpcbtPRp0=
|
||||||
gioui.org v0.8.1-0.20250526181049-1a17e9ea3725/go.mod h1:CjNig0wAhLt9WZxOPAusgFD8x8IRvqt26LdDBa3Jvao=
|
gioui.org v0.8.1-0.20250526181049-1a17e9ea3725/go.mod h1:CjNig0wAhLt9WZxOPAusgFD8x8IRvqt26LdDBa3Jvao=
|
||||||
|
gioui.org v0.8.1-0.20250624114559-c3ce484b5e80 h1:cnimNlq1PEHY4z1Cy32n6In86VUF5/VLi7cWHAM1XcY=
|
||||||
|
gioui.org v0.8.1-0.20250624114559-c3ce484b5e80/go.mod h1:CjNig0wAhLt9WZxOPAusgFD8x8IRvqt26LdDBa3Jvao=
|
||||||
gioui.org/cpu v0.0.0-20210808092351-bfe733dd3334/go.mod h1:A8M0Cn5o+vY5LTMlnRoK3O5kG+rH0kWfJjeKd9QpBmQ=
|
gioui.org/cpu v0.0.0-20210808092351-bfe733dd3334/go.mod h1:A8M0Cn5o+vY5LTMlnRoK3O5kG+rH0kWfJjeKd9QpBmQ=
|
||||||
gioui.org/shader v1.0.8 h1:6ks0o/A+b0ne7RzEqRZK5f4Gboz2CfG+mVliciy6+qA=
|
gioui.org/shader v1.0.8 h1:6ks0o/A+b0ne7RzEqRZK5f4Gboz2CfG+mVliciy6+qA=
|
||||||
gioui.org/shader v1.0.8/go.mod h1:mWdiME581d/kV7/iEhLmUgUK5iZ09XR5XpduXzbePVM=
|
gioui.org/shader v1.0.8/go.mod h1:mWdiME581d/kV7/iEhLmUgUK5iZ09XR5XpduXzbePVM=
|
||||||
|
@ -117,7 +117,8 @@ func NewNoteEditor(model *tracker.Model) *NoteEditor {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func (te *NoteEditor) Layout(gtx layout.Context, t *Tracker) layout.Dimensions {
|
func (te *NoteEditor) Layout(gtx layout.Context) layout.Dimensions {
|
||||||
|
t := TrackerFromContext(gtx)
|
||||||
for {
|
for {
|
||||||
e, ok := gtx.Event(te.eventFilters...)
|
e, ok := gtx.Event(te.eventFilters...)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -48,7 +48,8 @@ func NewOrderEditor(m *tracker.Model) *OrderEditor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (oe *OrderEditor) Layout(gtx C, t *Tracker) D {
|
func (oe *OrderEditor) Layout(gtx C) D {
|
||||||
|
t := TrackerFromContext(gtx)
|
||||||
if oe.scrollTable.CursorMoved() {
|
if oe.scrollTable.CursorMoved() {
|
||||||
cursor := t.TrackEditor.scrollTable.Table.Cursor()
|
cursor := t.TrackEditor.scrollTable.Table.Cursor()
|
||||||
t.TrackEditor.scrollTable.ColTitleList.CenterOn(cursor.X)
|
t.TrackEditor.scrollTable.ColTitleList.CenterOn(cursor.X)
|
||||||
|
@ -90,14 +90,14 @@ func NewPatchPanel(model *tracker.Model) *PatchPanel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pp *PatchPanel) Layout(gtx C, t *Tracker) D {
|
func (pp *PatchPanel) Layout(gtx C) D {
|
||||||
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
|
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
|
||||||
layout.Rigid(func(gtx C) D { return pp.instrList.Layout(gtx, t) }),
|
layout.Rigid(pp.instrList.Layout),
|
||||||
layout.Rigid(func(gtx C) D { return pp.tools.Layout(gtx, t) }),
|
layout.Rigid(pp.tools.Layout),
|
||||||
layout.Flexed(1, func(gtx C) D {
|
layout.Flexed(1, func(gtx C) D {
|
||||||
return layout.Flex{Axis: layout.Horizontal}.Layout(gtx,
|
return layout.Flex{Axis: layout.Horizontal}.Layout(gtx,
|
||||||
layout.Rigid(func(gtx C) D { return pp.unitList.Layout(gtx, t) }),
|
layout.Rigid(pp.unitList.Layout),
|
||||||
layout.Flexed(1, func(gtx C) D { return pp.unitEditor.Layout(gtx, t) }),
|
layout.Flexed(1, pp.unitEditor.Layout),
|
||||||
)
|
)
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
@ -148,7 +148,8 @@ func MakeInstrumentTools(m *tracker.Model) InstrumentTools {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *InstrumentTools) Layout(gtx C, t *Tracker) D {
|
func (it *InstrumentTools) Layout(gtx C) D {
|
||||||
|
t := TrackerFromContext(gtx)
|
||||||
it.update(gtx, t)
|
it.update(gtx, t)
|
||||||
voicesLabel := Label(t.Theme, &t.Theme.InstrumentEditor.Voices, "Voices")
|
voicesLabel := Label(t.Theme, &t.Theme.InstrumentEditor.Voices, "Voices")
|
||||||
splitInstrumentBtn := ActionIconBtn(t.SplitInstrument(), t.Theme, it.splitInstrumentBtn, icons.CommunicationCallSplit, it.splitInstrumentHint)
|
splitInstrumentBtn := ActionIconBtn(t.SplitInstrument(), t.Theme, it.splitInstrumentBtn, icons.CommunicationCallSplit, it.splitInstrumentHint)
|
||||||
@ -256,7 +257,8 @@ func MakeInstrList(model *tracker.Model) InstrumentList {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (il *InstrumentList) Layout(gtx C, t *Tracker) D {
|
func (il *InstrumentList) Layout(gtx C) D {
|
||||||
|
t := TrackerFromContext(gtx)
|
||||||
il.update(gtx, t)
|
il.update(gtx, t)
|
||||||
octave := NumUpDown(t.Model.Octave(), t.Theme, t.OctaveNumberInput, "Octave")
|
octave := NumUpDown(t.Model.Octave(), t.Theme, t.OctaveNumberInput, "Octave")
|
||||||
linkInstrTrackBtn := ToggleIconBtn(t.Model.LinkInstrTrack(), t.Theme, il.linkInstrTrackBtn, icons.NotificationSyncDisabled, icons.NotificationSync, il.linkDisabledHint, il.linkEnabledHint)
|
linkInstrTrackBtn := ToggleIconBtn(t.Model.LinkInstrTrack(), t.Theme, il.linkInstrTrackBtn, icons.NotificationSyncDisabled, icons.NotificationSync, il.linkDisabledHint, il.linkEnabledHint)
|
||||||
@ -264,7 +266,7 @@ func (il *InstrumentList) Layout(gtx C, t *Tracker) D {
|
|||||||
addInstrumentBtn := ActionIconBtn(t.Model.AddInstrument(), t.Theme, il.newInstrumentBtn, icons.ContentAdd, il.addInstrumentHint)
|
addInstrumentBtn := ActionIconBtn(t.Model.AddInstrument(), t.Theme, il.newInstrumentBtn, icons.ContentAdd, il.addInstrumentHint)
|
||||||
return layout.Flex{Axis: layout.Horizontal, Alignment: layout.Middle}.Layout(
|
return layout.Flex{Axis: layout.Horizontal, Alignment: layout.Middle}.Layout(
|
||||||
gtx,
|
gtx,
|
||||||
layout.Flexed(1, func(gtx C) D { return il.actualLayout(gtx, t) }),
|
layout.Flexed(1, il.actualLayout),
|
||||||
layout.Rigid(layout.Spacer{Width: 10}.Layout),
|
layout.Rigid(layout.Spacer{Width: 10}.Layout),
|
||||||
layout.Rigid(Label(t.Theme, &t.Theme.InstrumentEditor.Octave, "Octave").Layout),
|
layout.Rigid(Label(t.Theme, &t.Theme.InstrumentEditor.Octave, "Octave").Layout),
|
||||||
layout.Rigid(layout.Spacer{Width: 4}.Layout),
|
layout.Rigid(layout.Spacer{Width: 4}.Layout),
|
||||||
@ -275,7 +277,8 @@ func (il *InstrumentList) Layout(gtx C, t *Tracker) D {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (il *InstrumentList) actualLayout(gtx C, t *Tracker) D {
|
func (il *InstrumentList) actualLayout(gtx C) D {
|
||||||
|
t := TrackerFromContext(gtx)
|
||||||
gtx.Constraints.Max.Y = gtx.Dp(36)
|
gtx.Constraints.Max.Y = gtx.Dp(36)
|
||||||
gtx.Constraints.Min.Y = gtx.Dp(36)
|
gtx.Constraints.Min.Y = gtx.Dp(36)
|
||||||
element := func(gtx C, i int) D {
|
element := func(gtx C, i int) D {
|
||||||
@ -365,7 +368,8 @@ func MakeUnitList(m *tracker.Model) UnitList {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ul *UnitList) Layout(gtx C, t *Tracker) D {
|
func (ul *UnitList) Layout(gtx C) D {
|
||||||
|
t := TrackerFromContext(gtx)
|
||||||
ul.update(gtx, t)
|
ul.update(gtx, t)
|
||||||
var units [256]tracker.UnitListItem
|
var units [256]tracker.UnitListItem
|
||||||
for i, item := range (*tracker.Units)(t.Model).Iterate {
|
for i, item := range (*tracker.Units)(t.Model).Iterate {
|
||||||
|
@ -68,22 +68,18 @@ func (s *SongPanel) Update(gtx C, t *Tracker) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SongPanel) Layout(gtx C, t *Tracker) D {
|
func (s *SongPanel) Layout(gtx C) D {
|
||||||
|
t := TrackerFromContext(gtx)
|
||||||
s.Update(gtx, t)
|
s.Update(gtx, t)
|
||||||
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
|
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
|
||||||
layout.Rigid(func(gtx C) D {
|
layout.Rigid(s.MenuBar.Layout),
|
||||||
return s.MenuBar.Layout(gtx, t)
|
layout.Rigid(s.PlayBar.Layout),
|
||||||
}),
|
layout.Rigid(s.layoutSongOptions),
|
||||||
layout.Rigid(func(gtx C) D {
|
|
||||||
return s.PlayBar.Layout(gtx, t)
|
|
||||||
}),
|
|
||||||
layout.Rigid(func(gtx C) D {
|
|
||||||
return s.layoutSongOptions(gtx, t)
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *SongPanel) layoutSongOptions(gtx C, tr *Tracker) D {
|
func (t *SongPanel) layoutSongOptions(gtx C) D {
|
||||||
|
tr := TrackerFromContext(gtx)
|
||||||
paint.FillShape(gtx.Ops, tr.Theme.SongPanel.Bg, clip.Rect(image.Rect(0, 0, gtx.Constraints.Max.X, gtx.Constraints.Max.Y)).Op())
|
paint.FillShape(gtx.Ops, tr.Theme.SongPanel.Bg, clip.Rect(image.Rect(0, 0, gtx.Constraints.Max.X, gtx.Constraints.Max.Y)).Op())
|
||||||
|
|
||||||
var weightingTxt string
|
var weightingTxt string
|
||||||
@ -324,7 +320,8 @@ func NewMenuBar(tr *Tracker) *MenuBar {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *MenuBar) Layout(gtx C, tr *Tracker) D {
|
func (t *MenuBar) Layout(gtx C) D {
|
||||||
|
tr := TrackerFromContext(gtx)
|
||||||
gtx.Constraints.Max.Y = gtx.Dp(unit.Dp(36))
|
gtx.Constraints.Max.Y = gtx.Dp(unit.Dp(36))
|
||||||
gtx.Constraints.Min.Y = gtx.Dp(unit.Dp(36))
|
gtx.Constraints.Min.Y = gtx.Dp(unit.Dp(36))
|
||||||
|
|
||||||
@ -409,7 +406,8 @@ func NewPlayBar() *PlayBar {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pb *PlayBar) Layout(gtx C, tr *Tracker) D {
|
func (pb *PlayBar) Layout(gtx C) D {
|
||||||
|
tr := TrackerFromContext(gtx)
|
||||||
playBtn := ToggleIconBtn(tr.Playing(), tr.Theme, pb.PlayingBtn, icons.AVPlayArrow, icons.AVStop, pb.playHint, pb.stopHint)
|
playBtn := ToggleIconBtn(tr.Playing(), tr.Theme, pb.PlayingBtn, icons.AVPlayArrow, icons.AVStop, pb.playHint, pb.stopHint)
|
||||||
rewindBtn := ActionIconBtn(tr.PlaySongStart(), tr.Theme, pb.RewindBtn, icons.AVFastRewind, pb.rewindHint)
|
rewindBtn := ActionIconBtn(tr.PlaySongStart(), tr.Theme, pb.RewindBtn, icons.AVFastRewind, pb.rewindHint)
|
||||||
recordBtn := ToggleIconBtn(tr.IsRecording(), tr.Theme, pb.RecordBtn, icons.AVFiberManualRecord, icons.AVFiberSmartRecord, pb.recordHint, pb.stopRecordHint)
|
recordBtn := ToggleIconBtn(tr.IsRecording(), tr.Theme, pb.RecordBtn, icons.AVFiberManualRecord, icons.AVFiberSmartRecord, pb.recordHint, pb.stopRecordHint)
|
||||||
|
@ -121,6 +121,8 @@ func (t *Tracker) Main() {
|
|||||||
recoveryTicker := time.NewTicker(time.Second * 30)
|
recoveryTicker := time.NewTicker(time.Second * 30)
|
||||||
var ops op.Ops
|
var ops op.Ops
|
||||||
titlePath := ""
|
titlePath := ""
|
||||||
|
globals := make(map[string]any, 1)
|
||||||
|
globals["Tracker"] = t
|
||||||
for !t.Quitted() {
|
for !t.Quitted() {
|
||||||
w := t.newWindow()
|
w := t.newWindow()
|
||||||
w.Option(app.Title(titleFromPath(titlePath)))
|
w.Option(app.Title(titleFromPath(titlePath)))
|
||||||
@ -173,6 +175,7 @@ func (t *Tracker) Main() {
|
|||||||
w.Option(app.Title(titleFromPath(titlePath)))
|
w.Option(app.Title(titleFromPath(titlePath)))
|
||||||
}
|
}
|
||||||
gtx := app.NewContext(&ops, e)
|
gtx := app.NewContext(&ops, e)
|
||||||
|
gtx.Values = globals
|
||||||
t.Layout(gtx, w)
|
t.Layout(gtx, w)
|
||||||
e.Frame(gtx.Ops)
|
e.Frame(gtx.Ops)
|
||||||
if t.Quitted() {
|
if t.Quitted() {
|
||||||
@ -190,6 +193,14 @@ func (t *Tracker) Main() {
|
|||||||
close(t.Broker().FinishedGUI)
|
close(t.Broker().FinishedGUI)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TrackerFromContext(gtx C) *Tracker {
|
||||||
|
t, ok := gtx.Values["Tracker"]
|
||||||
|
if !ok {
|
||||||
|
panic("Tracker not found in context values")
|
||||||
|
}
|
||||||
|
return t.(*Tracker)
|
||||||
|
}
|
||||||
|
|
||||||
func (t *Tracker) newWindow() *app.Window {
|
func (t *Tracker) newWindow() *app.Window {
|
||||||
w := new(app.Window)
|
w := new(app.Window)
|
||||||
w.Option(app.Size(t.preferences.WindowSize()))
|
w.Option(app.Size(t.preferences.WindowSize()))
|
||||||
@ -342,24 +353,16 @@ func (t *Tracker) explorerCreateFile(success func(io.WriteCloser), filename stri
|
|||||||
func (t *Tracker) layoutBottom(gtx layout.Context) layout.Dimensions {
|
func (t *Tracker) layoutBottom(gtx layout.Context) layout.Dimensions {
|
||||||
return t.BottomHorizontalSplit.Layout(gtx,
|
return t.BottomHorizontalSplit.Layout(gtx,
|
||||||
&t.Theme.Split,
|
&t.Theme.Split,
|
||||||
func(gtx C) D {
|
t.OrderEditor.Layout,
|
||||||
return t.OrderEditor.Layout(gtx, t)
|
t.TrackEditor.Layout,
|
||||||
},
|
|
||||||
func(gtx C) D {
|
|
||||||
return t.TrackEditor.Layout(gtx, t)
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tracker) layoutTop(gtx layout.Context) layout.Dimensions {
|
func (t *Tracker) layoutTop(gtx layout.Context) layout.Dimensions {
|
||||||
return t.TopHorizontalSplit.Layout(gtx,
|
return t.TopHorizontalSplit.Layout(gtx,
|
||||||
&t.Theme.Split,
|
&t.Theme.Split,
|
||||||
func(gtx C) D {
|
t.SongPanel.Layout,
|
||||||
return t.SongPanel.Layout(gtx, t)
|
t.PatchPanel.Layout,
|
||||||
},
|
|
||||||
func(gtx C) D {
|
|
||||||
return t.PatchPanel.Layout(gtx, t)
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,8 @@ func NewUnitEditor(m *tracker.Model) *UnitEditor {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pe *UnitEditor) Layout(gtx C, t *Tracker) D {
|
func (pe *UnitEditor) Layout(gtx C) D {
|
||||||
|
t := TrackerFromContext(gtx)
|
||||||
for {
|
for {
|
||||||
e, ok := gtx.Event(
|
e, ok := gtx.Event(
|
||||||
key.Filter{Focus: pe.sliderList, Name: key.NameLeftArrow, Optional: key.ModShift},
|
key.Filter{Focus: pe.sliderList, Name: key.NameLeftArrow, Optional: key.ModShift},
|
||||||
|
Reference in New Issue
Block a user