feat!: rewrote the GUI and model for better testability

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.
This commit is contained in:
5684185+vsariola@users.noreply.github.com
2023-10-24 13:35:43 +03:00
parent 6d3c65e11d
commit d92426a100
53 changed files with 5992 additions and 4507 deletions

94
tracker/string.go Normal file
View File

@ -0,0 +1,94 @@
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)
}