feat(sointu): add functions to figure out the stack use and need of a unit

This commit is contained in:
vsariola 2021-02-10 22:39:08 +02:00
parent 35d2ff6308
commit 8cfd915311
4 changed files with 63 additions and 5 deletions

View File

@ -452,6 +452,34 @@ func (s *Song) ParamHintString(instrIndex, unitIndex int, param string) string {
return ""
}
func (u *Unit) StackChange() int {
switch u.Type {
case "addp", "mulp", "pop", "out", "outaux", "aux":
return -1 - u.Parameters["stereo"]
case "envelope", "oscillator", "push", "noise", "receive", "loadnote", "loadval", "in", "compressor":
return 1 + u.Parameters["stereo"]
case "pan":
return 1 - u.Parameters["stereo"]
case "speed":
return -1
case "send":
return (-1 - u.Parameters["stereo"]) * u.Parameters["sendpop"]
}
return 0
}
func (u *Unit) StackNeed() int {
switch u.Type {
case "envelope", "oscillator", "noise", "receive", "loadnote", "loadval", "in":
return 0
case "mulp", "mul", "add", "addp", "xch":
return 2 * (1 + u.Parameters["stereo"])
case "speed":
return 1
}
return 1 + u.Parameters["stereo"]
}
func Play(synth Synth, song Song) ([]float32, error) {
err := song.Validate()
if err != nil {

View File

@ -2,6 +2,7 @@ package tracker
import (
"image"
"strconv"
"gioui.org/io/pointer"
"gioui.org/layout"
@ -154,15 +155,41 @@ func (t *Tracker) layoutInstrumentEditor(gtx C) D {
addUnitBtnStyle.Inset = layout.UniformInset(unit.Dp(4))
margin := layout.UniformInset(unit.Dp(2))
for len(t.StackUse) < len(t.song.Patch.Instruments[t.CurrentInstrument].Units) {
t.StackUse = append(t.StackUse, 0)
}
stackHeight := 0
for i, u := range t.song.Patch.Instruments[t.CurrentInstrument].Units {
stackHeight += u.StackChange()
t.StackUse[i] = stackHeight
}
element := func(gtx C, i int) D {
gtx.Constraints = layout.Exact(image.Pt(gtx.Px(unit.Dp(120)), gtx.Px(unit.Dp(20))))
u := t.song.Patch.Instruments[t.CurrentInstrument].Units[i]
labelStyle := LabelStyle{Text: u.Type, ShadeColor: black, Color: white, Font: labelDefaultFont, FontSize: unit.Sp(12)}
if labelStyle.Text == "" {
labelStyle.Text = "---"
labelStyle.Alignment = layout.Center
unitNameLabel := LabelStyle{Text: u.Type, ShadeColor: black, Color: white, Font: labelDefaultFont, FontSize: unit.Sp(12)}
if unitNameLabel.Text == "" {
unitNameLabel.Text = "---"
unitNameLabel.Alignment = layout.Center
}
return labelStyle.Layout(gtx)
var stackText string
if i < len(t.StackUse) {
stackText = strconv.FormatInt(int64(t.StackUse[i]), 10)
var prevStackUse int
if i > 0 {
prevStackUse = t.StackUse[i-1]
}
if u.StackNeed() > prevStackUse || (i == len(t.StackUse)-1 && t.StackUse[i] > 0) {
unitNameLabel.Color = errorColor
}
}
stackLabel := LabelStyle{Text: stackText, ShadeColor: black, Color: mediumEmphasisTextColor, Font: labelDefaultFont, FontSize: unit.Sp(12)}
return layout.Flex{Axis: layout.Horizontal}.Layout(gtx,
layout.Flexed(1, unitNameLabel.Layout),
layout.Rigid(stackLabel.Layout),
)
}
unitList := FilledDragList(t.Theme, t.UnitDragList, len(t.song.Patch.Instruments[t.CurrentInstrument].Units), element, t.SwapUnits)

View File

@ -109,3 +109,5 @@ var activeLightSurfaceColor = color.NRGBA{R: 45, G: 45, B: 45, A: 255}
var cursorColor = color.NRGBA{R: 100, G: 140, B: 255, A: 48}
var selectionColor = color.NRGBA{R: 100, G: 140, B: 255, A: 8}
var inactiveSelectionColor = color.NRGBA{R: 140, G: 140, B: 140, A: 16}
var errorColor = color.NRGBA{R: 207, G: 102, B: 121, A: 255}

View File

@ -76,6 +76,7 @@ type Tracker struct {
TopHorizontalSplit *Split
BottomHorizontalSplit *Split
VerticalSplit *Split
StackUse []int
sequencer *Sequencer
ticked chan struct{}