mirror of
https://github.com/vsariola/sointu.git
synced 2025-05-28 03:10:24 -04:00
The Model was getting unmaintanable mess. This is an attempt to refactor/rewrite the Model so that data of certain type is exposed in standardized way, offering certain standard manipulations for that data type, and on the GUI side, certain standard widgets to tied to that data. This rewrite closes #72, #106 and #120.
95 lines
2.4 KiB
Go
95 lines
2.4 KiB
Go
package tracker
|
|
|
|
type (
|
|
String struct {
|
|
StringData
|
|
}
|
|
|
|
StringData interface {
|
|
Value() string
|
|
setValue(string)
|
|
change(kind string) func()
|
|
}
|
|
|
|
FilePath Model
|
|
InstrumentName Model
|
|
InstrumentComment Model
|
|
UnitSearch Model
|
|
)
|
|
|
|
func (v String) Set(value string) {
|
|
if v.Value() != value {
|
|
defer v.change("Set")()
|
|
v.setValue(value)
|
|
}
|
|
}
|
|
|
|
// Model methods
|
|
|
|
func (m *Model) FilePath() *FilePath { return (*FilePath)(m) }
|
|
func (m *Model) InstrumentName() *InstrumentName { return (*InstrumentName)(m) }
|
|
func (m *Model) InstrumentComment() *InstrumentComment { return (*InstrumentComment)(m) }
|
|
func (m *Model) UnitSearch() *UnitSearch { return (*UnitSearch)(m) }
|
|
|
|
// FilePathString
|
|
|
|
func (v *FilePath) String() String { return String{v} }
|
|
func (v *FilePath) Value() string { return v.d.FilePath }
|
|
func (v *FilePath) setValue(value string) { v.d.FilePath = value }
|
|
func (v *FilePath) change(kind string) func() { return func() {} }
|
|
|
|
// UnitSearchString
|
|
|
|
func (v *UnitSearch) String() String { return String{v} }
|
|
func (v *UnitSearch) Value() string { return v.d.UnitSearchString }
|
|
func (v *UnitSearch) setValue(value string) { v.d.UnitSearchString = value }
|
|
func (v *UnitSearch) change(kind string) func() { return func() {} }
|
|
|
|
// InstrumentNameString
|
|
|
|
func (v *InstrumentName) String() String {
|
|
return String{v}
|
|
}
|
|
|
|
func (v *InstrumentName) Value() string {
|
|
if v.d.InstrIndex < 0 || v.d.InstrIndex >= len(v.d.Song.Patch) {
|
|
return ""
|
|
}
|
|
return v.d.Song.Patch[v.d.InstrIndex].Name
|
|
}
|
|
|
|
func (v *InstrumentName) setValue(value string) {
|
|
if v.d.InstrIndex < 0 || v.d.InstrIndex >= len(v.d.Song.Patch) {
|
|
return
|
|
}
|
|
v.d.Song.Patch[v.d.InstrIndex].Name = value
|
|
}
|
|
|
|
func (v *InstrumentName) change(kind string) func() {
|
|
return (*Model)(v).change("InstrumentNameString."+kind, PatchChange, MinorChange)
|
|
}
|
|
|
|
// InstrumentComment
|
|
|
|
func (v *InstrumentComment) String() String {
|
|
return String{v}
|
|
}
|
|
|
|
func (v *InstrumentComment) Value() string {
|
|
if v.d.InstrIndex < 0 || v.d.InstrIndex >= len(v.d.Song.Patch) {
|
|
return ""
|
|
}
|
|
return v.d.Song.Patch[v.d.InstrIndex].Comment
|
|
}
|
|
|
|
func (v *InstrumentComment) setValue(value string) {
|
|
if v.d.InstrIndex < 0 || v.d.InstrIndex >= len(v.d.Song.Patch) {
|
|
return
|
|
}
|
|
v.d.Song.Patch[v.d.InstrIndex].Comment = value
|
|
}
|
|
|
|
func (v *InstrumentComment) change(kind string) func() {
|
|
return (*Model)(v).change("InstrumentComment."+kind, PatchChange, MinorChange)
|
|
}
|