refactor(tracker): split Volume to PeakVolume and AverageVolume

This commit is contained in:
5684185+vsariola@users.noreply.github.com
2023-10-19 22:16:13 +03:00
parent 1a8a317464
commit 50ccfe03da
5 changed files with 65 additions and 47 deletions

View File

@ -218,6 +218,6 @@ func (t *Tracker) layoutSongOptions(gtx C) D {
gtx.Constraints.Min = image.Pt(0, 0)
return recordBtnStyle.Layout(gtx)
}),
layout.Rigid(VuMeter{Volume: t.lastVolume, Range: 100}.Layout),
layout.Rigid(VuMeter{AverageVolume: t.lastAvgVolume, PeakVolume: t.lastPeakVolume, Range: 100}.Layout),
)
}

View File

@ -55,7 +55,8 @@ type Tracker struct {
TrackEditor *TrackEditor
Explorer *explorer.Explorer
lastVolume tracker.Volume
lastAvgVolume tracker.Volume
lastPeakVolume tracker.Volume
wavFilePath string
quitChannel chan struct{}
@ -198,7 +199,8 @@ mainloop:
if err, ok := e.Inner.(tracker.PlayerVolumeErrorMessage); ok {
t.Alert.Update(err.Error(), Warning, time.Second*3)
}
t.lastVolume = e.Volume
t.lastAvgVolume = e.AverageVolume
t.lastPeakVolume = e.PeakVolume
t.InstrumentEditor.voiceStates = e.VoiceStates
t.ProcessPlayerMessage(e)
w.Invalidate()

View File

@ -11,8 +11,9 @@ import (
)
type VuMeter struct {
Volume tracker.Volume
Range float32
AverageVolume tracker.Volume
PeakVolume tracker.Volume
Range float32
}
func (v VuMeter) Layout(gtx C) D {
@ -20,7 +21,7 @@ func (v VuMeter) Layout(gtx C) D {
gtx.Constraints.Max.Y = gtx.Dp(unit.Dp(12))
height := gtx.Dp(unit.Dp(6))
for j := 0; j < 2; j++ {
value := float32(v.Volume.Average[j]) + v.Range
value := float32(v.AverageVolume[j]) + v.Range
if value > 0 {
x := int(value/v.Range*float32(gtx.Constraints.Max.X) + 0.5)
if x > gtx.Constraints.Max.X {
@ -28,7 +29,7 @@ func (v VuMeter) Layout(gtx C) D {
}
paint.FillShape(gtx.Ops, mediumEmphasisTextColor, clip.Rect(image.Rect(0, 0, x, height)).Op())
}
valueMax := float32(v.Volume.Peak[j]) + v.Range
valueMax := float32(v.PeakVolume[j]) + v.Range
if valueMax > 0 {
color := white
if valueMax >= v.Range {