-- Copyright 2013 Evan Laforge
-- This program is distributed under the terms of the GNU General Public
-- License 3.0, see COPYING or http://www.gnu.org/licenses/gpl-3.0.txt

-- | Keymap cmds for a NoteTrack.  These apply regardless of the edit mode.
module Cmd.NoteTrackKeymap where
import qualified Ui.Key as Key
import qualified Cmd.Cmd as Cmd
import qualified Cmd.Keymap as Keymap
import qualified Cmd.ModifyEvents as ModifyEvents

import qualified Derive.ParseTitle as ParseTitle
import Global


keymap :: Cmd.Keymap Cmd.CmdId
errors :: [Text]
(Keymap CmdId
keymap, [Text]
errors) = forall (m :: * -> *). [Binding m] -> (Keymap m, [Text])
Keymap.make_keymap forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat forall a b. (a -> b) -> a -> b
$
    forall a b. (a -> b) -> [a] -> [b]
map forall {m :: * -> *}. M m => (Char, Text) -> [Binding m]
add_transform
        [(Char
'.', Text
"."), (Char
'v', Text
"v"), (Char
'6', Text
"^"), (Char
'=', Text
"+"), (Char
'-', Text
"-")]
    where
    add_transform :: (Char, Text) -> [Binding m]
add_transform (Char
c, Text
name) = forall (m :: * -> *).
M m =>
[SimpleMod] -> Key -> Text -> m () -> [Binding m]
Keymap.bind_key [SimpleMod
Keymap.SecondaryCommand]
        (Char -> Key
Key.Char Char
c) (Text
"add " forall a. Semigroup a => a -> a -> a
<> Text
name) (forall (m :: * -> *). M m => Text -> m ()
add_transform_generator Text
name)

-- | Add a call that works both as a transformer and generator, as long as
-- it isn't already there.
add_transform_generator :: Cmd.M m => Text -> m ()
add_transform_generator :: forall (m :: * -> *). M m => Text -> m ()
add_transform_generator Text
text = do
    forall (m :: * -> *). M m => Track m -> m ()
ModifyEvents.selection_visible forall a b. (a -> b) -> a -> b
$
        forall (m :: * -> *). M m => (Text -> Bool) -> Track m -> Track m
ModifyEvents.tracks_named Text -> Bool
ParseTitle.is_note_track forall a b. (a -> b) -> a -> b
$
        forall (m :: * -> *). Monad m => (Text -> Text) -> Track m
ModifyEvents.text forall a b. (a -> b) -> a -> b
$ ([[Text]] -> [[Text]]) -> Text -> Text
ModifyEvents.pipeline [[Text]] -> [[Text]]
add
    forall (m :: * -> *). M m => m ()
ModifyEvents.advance_if_point
    where
    add :: [[Text]] -> [[Text]]
add [] = [[Text
text]]
    add [[Text]]
calls
        | [Text
text] forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [[Text]]
calls = [[Text]]
calls
        | Bool
otherwise = [Text
text] forall a. a -> [a] -> [a]
: [[Text]]
calls