mirror of
https://github.com/vsariola/sointu.git
synced 2025-06-04 01:28:45 -04:00
feat(tracker): show currently active pattern notes with lighter text
This commit is contained in:
parent
12e1bde2a2
commit
91766e198d
@ -22,30 +22,17 @@ func (t *Tracker) layoutTracker(gtx layout.Context) layout.Dimensions {
|
||||
flexTracks := make([]layout.FlexChild, len(t.song.Tracks))
|
||||
t.playRowPatMutex.RLock()
|
||||
defer t.playRowPatMutex.RUnlock()
|
||||
playRow := int(t.PlayRow)
|
||||
if t.DisplayPattern != t.PlayPattern {
|
||||
playRow = -1
|
||||
}
|
||||
|
||||
for i, trk := range t.song.Tracks {
|
||||
sumLen := 0
|
||||
for _, patIndex := range trk.Sequence {
|
||||
sumLen += len(trk.Patterns[patIndex])
|
||||
}
|
||||
notes := make([]byte, sumLen)
|
||||
window := notes
|
||||
for _, patIndex := range trk.Sequence {
|
||||
elementsCopied := copy(window, trk.Patterns[patIndex])
|
||||
window = window[elementsCopied:]
|
||||
}
|
||||
songCursorRow := t.CursorRow + t.DisplayPattern*t.song.PatternRows()
|
||||
songPlayRow := playRow + t.PlayPattern*t.song.PatternRows()
|
||||
flexTracks[i] = layout.Rigid(Lowered(t.layoutTrack(
|
||||
notes,
|
||||
trk.Patterns,
|
||||
trk.Sequence,
|
||||
t.ActiveTrack == i,
|
||||
songCursorRow,
|
||||
t.CursorRow,
|
||||
t.DisplayPattern,
|
||||
t.CursorColumn,
|
||||
songPlayRow,
|
||||
t.PlayRow,
|
||||
t.PlayPattern,
|
||||
)))
|
||||
}
|
||||
return layout.Flex{Axis: layout.Horizontal}.Layout(gtx,
|
||||
|
@ -15,6 +15,7 @@ var neutral = color.RGBA{R: 73, G: 117, B: 130, A: 255}
|
||||
var light = color.RGBA{R: 138, G: 219, B: 243, A: 255}
|
||||
var dark = color.RGBA{R: 24, G: 40, B: 44, A: 255}
|
||||
var white = color.RGBA{R: 255, G: 255, B: 255, A: 255}
|
||||
var gray = color.RGBA{R: 127, G: 127, B: 127, A: 255}
|
||||
var black = color.RGBA{R: 0, G: 0, B: 0, A: 255}
|
||||
var yellow = color.RGBA{R: 255, G: 255, B: 130, A: 255}
|
||||
var red = color.RGBA{R: 255, G: 0, B: 0, A: 255}
|
||||
@ -31,6 +32,7 @@ var inactiveTrackColor = black
|
||||
|
||||
var trackerFont = fontCollection[6].Font
|
||||
var trackerFontSize = unit.Px(16)
|
||||
var trackerInactiveTextColor = gray
|
||||
var trackerTextColor = white
|
||||
var trackerActiveTextColor = yellow
|
||||
var trackerPlayColor = red
|
||||
|
@ -2,20 +2,21 @@ package tracker
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
"strings"
|
||||
|
||||
"gioui.org/f32"
|
||||
"gioui.org/layout"
|
||||
"gioui.org/op"
|
||||
"gioui.org/op/clip"
|
||||
"gioui.org/op/paint"
|
||||
"gioui.org/widget"
|
||||
"image"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const trackRowHeight = 16
|
||||
const trackWidth = 100
|
||||
|
||||
func (t *Tracker) layoutTrack(notes []byte, active bool, cursorRow, cursorCol, playingRow int) layout.Widget {
|
||||
func (t *Tracker) layoutTrack(patterns [][]byte, sequence []byte, active bool, cursorRow, cursorPattern, cursorCol, playRow, playPattern int) layout.Widget {
|
||||
return func(gtx layout.Context) layout.Dimensions {
|
||||
gtx.Constraints.Min.X = trackWidth
|
||||
gtx.Constraints.Max.X = trackWidth
|
||||
@ -43,21 +44,32 @@ func (t *Tracker) layoutTrack(notes []byte, active bool, cursorRow, cursorCol, p
|
||||
s.Pop()
|
||||
}
|
||||
}
|
||||
op.Offset(f32.Pt(0, (-1*trackRowHeight)*float32(cursorRow))).Add(gtx.Ops)
|
||||
for i, c := range notes {
|
||||
if i == playingRow {
|
||||
// TODO: this is a time bomb; as soon as one of the patterns is not the same length as rest. Find a solution
|
||||
// to fix the pattern lengths to a constant value
|
||||
cursorSongRow := cursorPattern*len(patterns[0]) + cursorRow
|
||||
playSongRow := playPattern*len(patterns[0]) + playRow
|
||||
op.Offset(f32.Pt(0, (-1*trackRowHeight)*float32(cursorSongRow))).Add(gtx.Ops)
|
||||
for i, s := range sequence {
|
||||
for j, c := range patterns[s] {
|
||||
songRow := i*len(patterns[0]) + j
|
||||
if songRow == playSongRow {
|
||||
paint.FillShape(gtx.Ops, trackerPlayColor, clip.Rect{Max: image.Pt(trackWidth, trackRowHeight)}.Op())
|
||||
}
|
||||
if i == cursorRow {
|
||||
if songRow == cursorSongRow {
|
||||
paint.ColorOp{Color: trackerActiveTextColor}.Add(gtx.Ops)
|
||||
} else {
|
||||
if cursorPattern == i {
|
||||
paint.ColorOp{Color: trackerTextColor}.Add(gtx.Ops)
|
||||
} else {
|
||||
paint.ColorOp{Color: trackerInactiveTextColor}.Add(gtx.Ops)
|
||||
}
|
||||
}
|
||||
widget.Label{}.Layout(gtx, textShaper, trackerFont, trackerFontSize, valueAsNote(c))
|
||||
op.Offset(f32.Pt(trackWidth/2, 0)).Add(gtx.Ops)
|
||||
widget.Label{}.Layout(gtx, textShaper, trackerFont, trackerFontSize, strings.ToUpper(fmt.Sprintf("%02x", c)))
|
||||
op.Offset(f32.Pt(-trackWidth/2, trackRowHeight)).Add(gtx.Ops)
|
||||
}
|
||||
}
|
||||
return layout.Dimensions{Size: gtx.Constraints.Max}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user