module Termtab.UI.Widgets.TrackPanel (renderTrackPanel, focusedTrackAttr) where
import Brick
import Data.Map.Strict qualified as Map
import Data.Text qualified as T
import Termtab.Types
import Termtab.UI.NotationGraphics (graphicsNotationActive, notationRegionWidget)
import Termtab.UI.Types
import Termtab.UI.Widgets.Notation (renderNotation)
import Termtab.UI.Widgets.Tablature (renderTablature)
focusedTrackAttr :: AttrName
focusedTrackAttr :: AttrName
focusedTrackAttr = String -> AttrName
attrName String
"focusedTrack"
renderTrackPanel :: AppState -> TrackIndex -> Track -> Widget ResourceName
renderTrackPanel :: AppState -> TrackIndex -> Track -> Widget ResourceName
renderTrackPanel AppState
st TrackIndex
tIdx Track
track =
let TrackIndex Int
i = TrackIndex
tIdx
label :: String
label = String
"Track " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
": " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Text -> String
T.unpack (Track -> Text
trackName Track
track)
isFocused :: Bool
isFocused = TrackIndex
tIdx TrackIndex -> TrackIndex -> Bool
forall a. Eq a => a -> a -> Bool
== AppState -> TrackIndex
asCurrentTrack AppState
st
header :: Widget n
header =
if Bool
isFocused
then AttrName -> Widget n -> Widget n
forall n. AttrName -> Widget n -> Widget n
withAttr AttrName
focusedTrackAttr (String -> Widget n
forall n. String -> Widget n
str String
label)
else String -> Widget n
forall n. String -> Widget n
str String
label
mode :: DisplayMode
mode = DisplayMode
-> TrackIndex -> Map TrackIndex DisplayMode -> DisplayMode
forall k a. Ord k => a -> k -> Map k a -> a
Map.findWithDefault (Track -> DisplayMode
defaultModeFor Track
track) TrackIndex
tIdx (AppState -> Map TrackIndex DisplayMode
asDisplayModes AppState
st)
effectiveMode :: DisplayMode
effectiveMode = case Track -> Instrument
trackInstrument Track
track of
Standard MidiProgram
_ -> DisplayMode
NotationOnly
Instrument
_ -> DisplayMode
mode
notation :: Widget ResourceName
notation
| AppState -> Bool
graphicsNotationActive AppState
st = TrackIndex -> Widget ResourceName
notationRegionWidget TrackIndex
tIdx
| Bool
otherwise = AppState -> TrackIndex -> Widget ResourceName
renderNotation AppState
st TrackIndex
tIdx
content :: Widget ResourceName
content = case DisplayMode
effectiveMode of
DisplayMode
TabOnly -> AppState -> TrackIndex -> Widget ResourceName
renderTablature AppState
st TrackIndex
tIdx
DisplayMode
NotationOnly -> Widget ResourceName
notation
DisplayMode
TabAndNotation ->
[Widget ResourceName] -> Widget ResourceName
forall n. [Widget n] -> Widget n
vBox
[ Widget ResourceName
notation
, AppState -> TrackIndex -> Widget ResourceName
renderTablature AppState
st TrackIndex
tIdx
]
in [Widget ResourceName] -> Widget ResourceName
forall n. [Widget n] -> Widget n
vBox [Widget ResourceName
forall {n}. Widget n
header, Widget ResourceName
content]
defaultModeFor :: Track -> DisplayMode
defaultModeFor :: Track -> DisplayMode
defaultModeFor Track
track = case Track -> Instrument
trackInstrument Track
track of
Guitar [Pitch]
_ Int
_ -> DisplayMode
TabOnly
Bass [Pitch]
_ Int
_ -> DisplayMode
TabOnly
Standard MidiProgram
_ -> DisplayMode
NotationOnly