module Perform.Midi.Types where
import qualified Control.DeepSeq as DeepSeq
import qualified Data.Set as Set
import qualified Util.Pretty as Pretty
import qualified Util.TimeVector as TimeVector
import qualified Derive.ScoreT as ScoreT
import qualified Derive.Stack as Stack
import qualified Perform.Midi.Control as Control
import qualified Perform.Midi.MSignal as MSignal
import qualified Perform.Midi.Patch as Patch
import qualified Perform.Pitch as Pitch
import Global
import Types
data Patch = Patch {
Patch -> Instrument
patch_name :: !ScoreT.Instrument
, Patch -> [Keyswitch]
patch_keyswitches :: ![Patch.Keyswitch]
, Patch -> Bool
patch_hold_keyswitches :: !Bool
, Patch -> ControlMap
patch_control_map :: !Control.ControlMap
, Patch -> PbRange
patch_pitch_bend_range :: !Control.PbRange
, Patch -> Maybe RealTime
patch_decay :: !(Maybe RealTime)
} deriving (Patch -> Patch -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Patch -> Patch -> Bool
$c/= :: Patch -> Patch -> Bool
== :: Patch -> Patch -> Bool
$c== :: Patch -> Patch -> Bool
Eq, Eq Patch
Patch -> Patch -> Bool
Patch -> Patch -> Ordering
Patch -> Patch -> Patch
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Patch -> Patch -> Patch
$cmin :: Patch -> Patch -> Patch
max :: Patch -> Patch -> Patch
$cmax :: Patch -> Patch -> Patch
>= :: Patch -> Patch -> Bool
$c>= :: Patch -> Patch -> Bool
> :: Patch -> Patch -> Bool
$c> :: Patch -> Patch -> Bool
<= :: Patch -> Patch -> Bool
$c<= :: Patch -> Patch -> Bool
< :: Patch -> Patch -> Bool
$c< :: Patch -> Patch -> Bool
compare :: Patch -> Patch -> Ordering
$ccompare :: Patch -> Patch -> Ordering
Ord, Int -> Patch -> ShowS
[Patch] -> ShowS
Patch -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Patch] -> ShowS
$cshowList :: [Patch] -> ShowS
show :: Patch -> String
$cshow :: Patch -> String
showsPrec :: Int -> Patch -> ShowS
$cshowsPrec :: Int -> Patch -> ShowS
Show)
patch :: ScoreT.Instrument -> Patch.Config -> Patch.Patch -> Patch
patch :: Instrument -> Config -> Patch -> Patch
patch Instrument
score_inst Config
config =
Instrument -> Settings -> Patch -> Patch
patch_from_settings Instrument
score_inst (Config -> Settings
Patch.config_settings Config
config)
patch_from_settings :: ScoreT.Instrument -> Patch.Settings -> Patch.Patch
-> Patch
patch_from_settings :: Instrument -> Settings -> Patch -> Patch
patch_from_settings Instrument
score_inst Settings
settings Patch
patch = Patch
{ patch_name :: Instrument
patch_name = Instrument
score_inst
, patch_keyswitches :: [Keyswitch]
patch_keyswitches = []
, patch_hold_keyswitches :: Bool
patch_hold_keyswitches = forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
False (forall a. Ord a => a -> Set a -> Bool
Set.member Flag
Patch.HoldKeyswitch)
(Settings -> Maybe (Set Flag)
Patch.config_flags Settings
settings)
, patch_control_map :: ControlMap
patch_control_map = Patch -> ControlMap
Patch.patch_control_map Patch
patch
, patch_pitch_bend_range :: PbRange
patch_pitch_bend_range = forall a. a -> Maybe a -> a
fromMaybe (-Int
100, Int
100) forall a b. (a -> b) -> a -> b
$
Settings -> Maybe PbRange
Patch.config_pitch_bend_range Settings
settings
, patch_decay :: Maybe RealTime
patch_decay = Settings -> Maybe RealTime
Patch.config_decay Settings
settings
}
instance DeepSeq.NFData Patch where
rnf :: Patch -> ()
rnf Patch
inst = forall a. NFData a => a -> ()
DeepSeq.rnf (Patch -> [Keyswitch]
patch_keyswitches Patch
inst)
instance Pretty Patch where
format :: Patch -> Doc
format (Patch Instrument
name [Keyswitch]
keyswitches Bool
hold_keyswitches ControlMap
cmap PbRange
pb_range Maybe RealTime
decay) =
Doc -> [(Text, Doc)] -> Doc
Pretty.record Doc
"Patch"
[ (Text
"name", forall a. Pretty a => a -> Doc
Pretty.format Instrument
name)
, (Text
"keyswitches", forall a. Pretty a => a -> Doc
Pretty.format [Keyswitch]
keyswitches)
, (Text
"hold_keyswitches", forall a. Pretty a => a -> Doc
Pretty.format Bool
hold_keyswitches)
, (Text
"control_map", forall a. Pretty a => a -> Doc
Pretty.format ControlMap
cmap)
, (Text
"pb_range", forall a. Pretty a => a -> Doc
Pretty.format PbRange
pb_range)
, (Text
"decay", forall a. Pretty a => a -> Doc
Pretty.format Maybe RealTime
decay)
]
default_decay :: RealTime
default_decay :: RealTime
default_decay = RealTime
1.0
data Event = Event {
Event -> RealTime
event_start :: !RealTime
, Event -> RealTime
event_duration :: !RealTime
, Event -> Patch
event_patch :: !Patch
, Event -> Map Control Signal
event_controls :: !(Map ScoreT.Control MSignal.Signal)
, Event -> Signal
event_pitch :: !MSignal.Signal
, Event -> UnboxedY
event_start_velocity :: !MSignal.Y
, Event -> UnboxedY
event_end_velocity :: !MSignal.Y
, Event -> Stack
event_stack :: !Stack.Stack
} deriving (Event -> Event -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Event -> Event -> Bool
$c/= :: Event -> Event -> Bool
== :: Event -> Event -> Bool
$c== :: Event -> Event -> Bool
Eq, Int -> Event -> ShowS
[Event] -> ShowS
Event -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Event] -> ShowS
$cshowList :: [Event] -> ShowS
show :: Event -> String
$cshow :: Event -> String
showsPrec :: Int -> Event -> ShowS
$cshowsPrec :: Int -> Event -> ShowS
Show)
instance DeepSeq.NFData Event where
rnf :: Event -> ()
rnf (Event RealTime
start RealTime
dur Patch
inst Map Control Signal
controls Signal
pitch UnboxedY
_svel UnboxedY
_evel Stack
stack) =
forall a. NFData a => a -> ()
rnf RealTime
start seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf RealTime
dur seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf Patch
inst seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf Map Control Signal
controls
seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf Signal
pitch seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf Stack
stack
where
rnf :: DeepSeq.NFData a => a -> ()
rnf :: forall a. NFData a => a -> ()
rnf = forall a. NFData a => a -> ()
DeepSeq.rnf
instance Pretty Event where
format :: Event -> Doc
format (Event RealTime
start RealTime
dur Patch
patch Map Control Signal
controls Signal
pitch UnboxedY
svel UnboxedY
evel Stack
stack) =
Doc -> [(Text, Doc)] -> Doc
Pretty.record Doc
"Event"
[ (Text
"start", forall a. Pretty a => a -> Doc
Pretty.format RealTime
start)
, (Text
"duration", forall a. Pretty a => a -> Doc
Pretty.format RealTime
dur)
, (Text
"patch", forall a. Pretty a => a -> Doc
Pretty.format (Patch -> Instrument
patch_name Patch
patch))
, (Text
"keyswitches", forall a. Pretty a => a -> Doc
Pretty.format (Patch -> [Keyswitch]
patch_keyswitches Patch
patch))
, (Text
"controls", forall a. Pretty a => a -> Doc
Pretty.format Map Control Signal
controls)
, (Text
"pitch", forall a. Pretty a => a -> Doc
Pretty.format Signal
pitch)
, (Text
"velocity", forall a. Pretty a => a -> Doc
Pretty.format (UnboxedY
svel, UnboxedY
evel))
, (Text
"stack", forall a. Pretty a => a -> Doc
Pretty.format Stack
stack)
]
show_short :: Event -> Text
show_short :: Event -> Text
show_short Event
event =
forall a. Pretty a => a -> Text
pretty (RealTime
start, Event -> RealTime
event_duration Event
event, Instrument
name, Maybe NoteNumber
pitch, Event -> Map Control Signal
event_controls Event
event)
where
start :: RealTime
start = Event -> RealTime
event_start Event
event
name :: Instrument
name = Patch -> Instrument
patch_name (Event -> Patch
event_patch Event
event)
pitch :: Maybe NoteNumber
pitch = UnboxedY -> NoteNumber
Pitch.NoteNumber forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (v :: * -> *) y.
Vector v (Sample y) =>
RealTime -> v (Sample y) -> Maybe y
TimeVector.at RealTime
start (Event -> Signal
event_pitch Event
event)
event_end :: Event -> RealTime
event_end :: Event -> RealTime
event_end Event
event = Event -> RealTime
event_start Event
event forall a. Num a => a -> a -> a
+ Event -> RealTime
event_duration Event
event
event_instrument :: Event -> ScoreT.Instrument
event_instrument :: Event -> Instrument
event_instrument = Patch -> Instrument
patch_name forall b c a. (b -> c) -> (a -> b) -> a -> c
. Event -> Patch
event_patch