mirror of
https://github.com/vsariola/sointu.git
synced 2025-05-25 18:00:37 -04:00
refactor: move UnitNames to top level package
This commit is contained in:
parent
b6ec5d1a04
commit
beb06727b0
13
patch.go
13
patch.go
@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"sort"
|
||||
)
|
||||
|
||||
type (
|
||||
@ -178,6 +179,18 @@ const (
|
||||
Sample = iota
|
||||
)
|
||||
|
||||
// UnitNames is a list of all the names of units, sorted
|
||||
// alphabetically.
|
||||
var UnitNames []string
|
||||
|
||||
func init() {
|
||||
UnitNames = make([]string, 0, len(UnitTypes))
|
||||
for k := range UnitTypes {
|
||||
UnitNames = append(UnitNames, k)
|
||||
}
|
||||
sort.Strings(UnitNames)
|
||||
}
|
||||
|
||||
// Ports is static map allowing quickly finding the parameters of a unit that
|
||||
// can be modulated. This is populated based on the UnitTypes list during
|
||||
// init(). Thus, should be immutable, but Go not supporting that, then this will
|
||||
|
@ -19,6 +19,7 @@ import (
|
||||
"gioui.org/widget"
|
||||
"gioui.org/widget/material"
|
||||
"gioui.org/x/eventx"
|
||||
"github.com/vsariola/sointu"
|
||||
"github.com/vsariola/sointu/tracker"
|
||||
"github.com/vsariola/sointu/vm"
|
||||
"golang.org/x/exp/shiny/materialdesign/icons"
|
||||
@ -447,7 +448,7 @@ func (ie *InstrumentEditor) layoutInstrumentEditor(gtx C, t *Tracker) D {
|
||||
if ok {
|
||||
ie.unitDragList.Focus()
|
||||
if text := ie.unitTypeEditor.Text(); text != "" {
|
||||
for _, n := range tracker.UnitTypeNames {
|
||||
for _, n := range sointu.UnitNames {
|
||||
if strings.HasPrefix(n, ie.unitTypeEditor.Text()) {
|
||||
t.SetUnitType(n)
|
||||
break
|
||||
|
@ -16,7 +16,6 @@ import (
|
||||
"gioui.org/unit"
|
||||
"gioui.org/widget"
|
||||
"github.com/vsariola/sointu"
|
||||
"github.com/vsariola/sointu/tracker"
|
||||
"golang.org/x/exp/shiny/materialdesign/icons"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
@ -50,7 +49,7 @@ func NewParamEditor() *ParamEditor {
|
||||
list: &layout.List{Axis: layout.Vertical},
|
||||
scrollBar: &ScrollBar{Axis: layout.Vertical},
|
||||
}
|
||||
for range tracker.UnitTypeNames {
|
||||
for range sointu.UnitNames {
|
||||
ret.ChooseUnitTypeBtns = append(ret.ChooseUnitTypeBtns, new(widget.Clickable))
|
||||
}
|
||||
return ret
|
||||
@ -220,10 +219,10 @@ func (pe *ParamEditor) layoutUnitFooter(t *Tracker) layout.Widget {
|
||||
func (pe *ParamEditor) layoutUnitTypeChooser(gtx C, t *Tracker) D {
|
||||
listElem := func(gtx C, i int) D {
|
||||
for pe.ChooseUnitTypeBtns[i].Clicked() {
|
||||
t.SetUnitType(tracker.UnitTypeNames[i])
|
||||
t.InstrumentEditor.unitTypeEditor.SetText(tracker.UnitTypeNames[i])
|
||||
t.SetUnitType(sointu.UnitNames[i])
|
||||
t.InstrumentEditor.unitTypeEditor.SetText(sointu.UnitNames[i])
|
||||
}
|
||||
text := tracker.UnitTypeNames[i]
|
||||
text := sointu.UnitNames[i]
|
||||
if t.InstrumentEditor.unitTypeEditor.Focused() && !strings.HasPrefix(text, t.InstrumentEditor.unitTypeEditor.Text()) {
|
||||
return D{}
|
||||
}
|
||||
@ -248,10 +247,10 @@ func (pe *ParamEditor) layoutUnitTypeChooser(gtx C, t *Tracker) D {
|
||||
}
|
||||
return layout.Stack{}.Layout(gtx,
|
||||
layout.Stacked(func(gtx C) D {
|
||||
return pe.list.Layout(gtx, len(tracker.UnitTypeNames), listElem)
|
||||
return pe.list.Layout(gtx, len(sointu.UnitNames), listElem)
|
||||
}),
|
||||
layout.Expanded(func(gtx C) D {
|
||||
return pe.scrollBar.Layout(gtx, unit.Dp(10), len(tracker.UnitTypeNames), &pe.list.Position)
|
||||
return pe.scrollBar.Layout(gtx, unit.Dp(10), len(sointu.UnitNames), &pe.list.Position)
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
@ -113,16 +113,6 @@ var reverbs = []delayPreset{
|
||||
{"right", 0, []int{1140, 1212, 1300, 1380, 1446, 1516, 1580, 1642}},
|
||||
}
|
||||
|
||||
var UnitTypeNames []string
|
||||
|
||||
func init() {
|
||||
UnitTypeNames = make([]string, 0, len(sointu.UnitTypes))
|
||||
for k := range sointu.UnitTypes {
|
||||
UnitTypeNames = append(UnitTypeNames, k)
|
||||
}
|
||||
sort.Strings(UnitTypeNames)
|
||||
}
|
||||
|
||||
type instrumentPresets []sointu.Instrument
|
||||
|
||||
//go:embed presets/*
|
||||
|
Loading…
Reference in New Issue
Block a user