-- 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

-- | E-mu morpheus module.
module User.Elaforge.Instrument.Morpheus where
import           System.FilePath ((</>))

import qualified App.Config as Config
import qualified App.Path as Path
import qualified Cmd.Instrument.MidiInst as MidiInst
import qualified Cmd.Instrument.MidiInstDb as MidiInstDb
import qualified Derive.ScoreT as ScoreT
import qualified Instrument.InstT as InstT
import qualified Instrument.Parse as Parse
import qualified Midi.Midi as Midi
import qualified Perform.Midi.Patch as Patch

import           Global


synth_name :: InstT.SynthName
synth_name :: SynthName
synth_name = SynthName
"morpheus"

load :: Path.AppDir -> IO (Maybe MidiInst.Synth)
load :: AppDir -> IO (Maybe Synth)
load = (Patch -> Code)
-> SynthName -> SynthName -> AppDir -> IO (Maybe Synth)
MidiInstDb.load_synth (forall a b. a -> b -> a
const forall a. Monoid a => a
mempty) SynthName
synth_name SynthName
"E-mu Morpheus"

make_db :: Path.AppDir -> IO ()
make_db :: AppDir -> IO ()
make_db AppDir
app_dir = do
    let fname :: FilePath
fname = AppDir -> Relative -> FilePath
Path.to_absolute AppDir
app_dir Relative
Config.instrument_dir
            FilePath -> FilePath -> FilePath
</> SynthName -> FilePath
untxt SynthName
synth_name
    [Patch]
patches <- forall a b. (a -> b) -> [a] -> [b]
map (Patch, Common ()) -> Patch
MidiInst.patch_from_pair forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FilePath -> IO [(Patch, Common ())]
Parse.patch_file FilePath
fname
    [Patch]
patches <- forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$
        forall a b. (a -> b) -> [a] -> [b]
map (Patch :-> Patch
MidiInst.patchforall a b c. Lens a b -> Lens b c -> Lens a c
#Patch :-> Settings
Patch.defaultsforall a b c. Lens a b -> Lens b c -> Lens a c
#Settings :-> Maybe PbRange
Patch.pitch_bend_range
                #= Just (-12, 12))
            [Patch]
patches
    AppDir -> SynthName -> [Patch] -> IO ()
MidiInstDb.save_synth AppDir
app_dir SynthName
synth_name [Patch]
patches

synth_controls :: [(Midi.Control, ScoreT.Control)]
synth_controls :: [(Control, Control)]
synth_controls =
    -- Definitions depend on the preset.
    [ (Control
1, Control
"a"), (Control
2, Control
"b"), (Control
3, Control
"c"), (Control
4, Control
"d")
    , (Control
64, Control
"switch1"), (Control
65, Control
"switch2"), (Control
66, Control
"switch3")
    ]