mirror of
https://github.com/vsariola/sointu.git
synced 2025-07-18 04:54:27 -04:00
feat(sointu, tracker, gioui): add a comment field to the instrument
This commit is contained in:
@ -3,6 +3,7 @@ package sointu
|
|||||||
// Instrument includes a list of units consisting of the instrument, and the number of polyphonic voices for this instrument
|
// Instrument includes a list of units consisting of the instrument, and the number of polyphonic voices for this instrument
|
||||||
type Instrument struct {
|
type Instrument struct {
|
||||||
Name string `yaml:",omitempty"`
|
Name string `yaml:",omitempty"`
|
||||||
|
Comment string `yaml:",omitempty"`
|
||||||
NumVoices int
|
NumVoices int
|
||||||
Units []Unit
|
Units []Unit
|
||||||
}
|
}
|
||||||
@ -12,5 +13,5 @@ func (instr *Instrument) Copy() Instrument {
|
|||||||
for i, u := range instr.Units {
|
for i, u := range instr.Units {
|
||||||
units[i] = u.Copy()
|
units[i] = u.Copy()
|
||||||
}
|
}
|
||||||
return Instrument{Name: instr.Name, NumVoices: instr.NumVoices, Units: units}
|
return Instrument{Name: instr.Name, Comment: instr.Comment, NumVoices: instr.NumVoices, Units: units}
|
||||||
}
|
}
|
||||||
|
@ -174,5 +174,8 @@ func (t *Tracker) loadInstrument(filename string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
t.SetInstrument(instrument)
|
t.SetInstrument(instrument)
|
||||||
|
if t.Instrument().Comment != "" {
|
||||||
|
t.InstrumentExpanded = true
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gioui.org/io/clipboard"
|
"gioui.org/io/clipboard"
|
||||||
|
"gioui.org/io/key"
|
||||||
"gioui.org/io/pointer"
|
"gioui.org/io/pointer"
|
||||||
"gioui.org/layout"
|
"gioui.org/layout"
|
||||||
"gioui.org/op"
|
"gioui.org/op"
|
||||||
@ -72,6 +73,16 @@ func (t *Tracker) layoutInstruments(gtx C) D {
|
|||||||
|
|
||||||
func (t *Tracker) layoutInstrumentHeader(gtx C) D {
|
func (t *Tracker) layoutInstrumentHeader(gtx C) D {
|
||||||
header := func(gtx C) D {
|
header := func(gtx C) D {
|
||||||
|
collapseIcon := icons.NavigationExpandLess
|
||||||
|
if t.InstrumentExpanded {
|
||||||
|
collapseIcon = icons.NavigationExpandMore
|
||||||
|
}
|
||||||
|
|
||||||
|
instrumentExpandBtnStyle := material.IconButton(t.Theme, t.InstrumentExpandBtn, widgetForIcon(collapseIcon))
|
||||||
|
instrumentExpandBtnStyle.Background = transparent
|
||||||
|
instrumentExpandBtnStyle.Inset = layout.UniformInset(unit.Dp(6))
|
||||||
|
instrumentExpandBtnStyle.Color = primaryColor
|
||||||
|
|
||||||
copyInstrumentBtnStyle := material.IconButton(t.Theme, t.CopyInstrumentBtn, widgetForIcon(icons.ContentContentCopy))
|
copyInstrumentBtnStyle := material.IconButton(t.Theme, t.CopyInstrumentBtn, widgetForIcon(icons.ContentContentCopy))
|
||||||
copyInstrumentBtnStyle.Background = transparent
|
copyInstrumentBtnStyle.Background = transparent
|
||||||
copyInstrumentBtnStyle.Inset = layout.UniformInset(unit.Dp(6))
|
copyInstrumentBtnStyle.Inset = layout.UniformInset(unit.Dp(6))
|
||||||
@ -96,6 +107,7 @@ func (t *Tracker) layoutInstrumentHeader(gtx C) D {
|
|||||||
deleteInstrumentBtnStyle.Color = disabledTextColor
|
deleteInstrumentBtnStyle.Color = disabledTextColor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
header := func(gtx C) D {
|
||||||
return layout.Flex{Axis: layout.Horizontal, Alignment: layout.Middle}.Layout(gtx,
|
return layout.Flex{Axis: layout.Horizontal, Alignment: layout.Middle}.Layout(gtx,
|
||||||
layout.Rigid(Label("Voices: ", white)),
|
layout.Rigid(Label("Voices: ", white)),
|
||||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||||
@ -109,11 +121,35 @@ func (t *Tracker) layoutInstrumentHeader(gtx C) D {
|
|||||||
return dims
|
return dims
|
||||||
}),
|
}),
|
||||||
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(instrumentExpandBtnStyle.Layout),
|
||||||
layout.Rigid(saveInstrumentBtnStyle.Layout),
|
layout.Rigid(saveInstrumentBtnStyle.Layout),
|
||||||
layout.Rigid(loadInstrumentBtnStyle.Layout),
|
layout.Rigid(loadInstrumentBtnStyle.Layout),
|
||||||
layout.Rigid(copyInstrumentBtnStyle.Layout),
|
layout.Rigid(copyInstrumentBtnStyle.Layout),
|
||||||
layout.Rigid(deleteInstrumentBtnStyle.Layout))
|
layout.Rigid(deleteInstrumentBtnStyle.Layout))
|
||||||
}
|
}
|
||||||
|
for t.InstrumentExpandBtn.Clicked() {
|
||||||
|
t.InstrumentExpanded = !t.InstrumentExpanded
|
||||||
|
if !t.InstrumentExpanded {
|
||||||
|
key.FocusOp{Tag: nil}.Add(gtx.Ops) // clear focus
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if t.InstrumentExpanded || t.InstrumentCommentEditor.Focused() { // we draw once the widget after it manages to lose focus
|
||||||
|
if t.InstrumentCommentEditor.Text() != t.Instrument().Comment {
|
||||||
|
t.InstrumentCommentEditor.SetText(t.Instrument().Comment)
|
||||||
|
}
|
||||||
|
editorStyle := material.Editor(t.Theme, t.InstrumentCommentEditor, "Comment")
|
||||||
|
editorStyle.Color = highEmphasisTextColor
|
||||||
|
ret := layout.Flex{Axis: layout.Vertical}.Layout(gtx,
|
||||||
|
layout.Rigid(header),
|
||||||
|
layout.Rigid(func(gtx C) D {
|
||||||
|
return layout.UniformInset(unit.Dp(6)).Layout(gtx, editorStyle.Layout)
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
t.SetInstrumentComment(t.InstrumentCommentEditor.Text())
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
return header(gtx)
|
||||||
|
}
|
||||||
for t.CopyInstrumentBtn.Clicked() {
|
for t.CopyInstrumentBtn.Clicked() {
|
||||||
contents, err := yaml.Marshal(t.Instrument())
|
contents, err := yaml.Marshal(t.Instrument())
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -82,6 +82,7 @@ var unitKeyMap = map[string]string{
|
|||||||
func (t *Tracker) KeyEvent(w *app.Window, e key.Event) bool {
|
func (t *Tracker) KeyEvent(w *app.Window, e key.Event) bool {
|
||||||
if e.State == key.Press {
|
if e.State == key.Press {
|
||||||
if t.InstrumentNameEditor.Focused() ||
|
if t.InstrumentNameEditor.Focused() ||
|
||||||
|
t.InstrumentCommentEditor.Focused() ||
|
||||||
t.OpenSongDialog.Visible ||
|
t.OpenSongDialog.Visible ||
|
||||||
t.SaveSongDialog.Visible ||
|
t.SaveSongDialog.Visible ||
|
||||||
t.SaveInstrumentDialog.Visible ||
|
t.SaveInstrumentDialog.Visible ||
|
||||||
|
@ -78,6 +78,9 @@ type Tracker struct {
|
|||||||
OpenInstrumentDialog *FileDialog
|
OpenInstrumentDialog *FileDialog
|
||||||
SaveInstrumentDialog *FileDialog
|
SaveInstrumentDialog *FileDialog
|
||||||
ExportWavDialog *FileDialog
|
ExportWavDialog *FileDialog
|
||||||
|
InstrumentCommentEditor *widget.Editor
|
||||||
|
InstrumentExpandBtn *widget.Clickable
|
||||||
|
InstrumentExpanded bool
|
||||||
ConfirmSongActionType int
|
ConfirmSongActionType int
|
||||||
window *app.Window
|
window *app.Window
|
||||||
|
|
||||||
@ -182,6 +185,8 @@ func New(audioContext sointu.AudioContext, synthService sointu.SynthService, syn
|
|||||||
SaveSongDialog: NewFileDialog(),
|
SaveSongDialog: NewFileDialog(),
|
||||||
OpenInstrumentDialog: NewFileDialog(),
|
OpenInstrumentDialog: NewFileDialog(),
|
||||||
SaveInstrumentDialog: NewFileDialog(),
|
SaveInstrumentDialog: NewFileDialog(),
|
||||||
|
InstrumentCommentEditor: new(widget.Editor),
|
||||||
|
InstrumentExpandBtn: new(widget.Clickable),
|
||||||
|
|
||||||
ExportWavDialog: NewFileDialog(),
|
ExportWavDialog: NewFileDialog(),
|
||||||
errorChannel: make(chan error, 32),
|
errorChannel: make(chan error, 32),
|
||||||
|
@ -171,6 +171,14 @@ func (m *Model) SetInstrumentName(name string) {
|
|||||||
m.song.Patch[m.instrIndex].Name = name
|
m.song.Patch[m.instrIndex].Name = name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Model) SetInstrumentComment(comment string) {
|
||||||
|
if m.Instrument().Comment == comment {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
m.saveUndo("SetInstrumentComment", 10)
|
||||||
|
m.song.Patch[m.instrIndex].Comment = comment
|
||||||
|
}
|
||||||
|
|
||||||
func (m *Model) SetBPM(value int) {
|
func (m *Model) SetBPM(value int) {
|
||||||
if value < 1 {
|
if value < 1 {
|
||||||
value = 1
|
value = 1
|
||||||
|
Reference in New Issue
Block a user