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

module User.Generic.Instrument.OBXd where
import qualified Cmd.Instrument.MidiInst as MidiInst
import qualified Derive.ScoreT as ScoreT
import qualified Midi.Midi as Midi


synth :: MidiInst.Synth
synth :: Synth
synth =
    SynthName -> SynthName -> [Patch] -> Synth
MidiInst.synth SynthName
"obxd" SynthName
"https://www.discodsp.com/obxd/" forall a b. (a -> b) -> a -> b
$
        [(Control, Control)] -> [Patch] -> [Patch]
MidiInst.synth_controls [(Control, Control)]
controls
        [PbRange -> [(Control, Control)] -> Patch
MidiInst.default_patch PbRange
pb_range []]

-- According to midiMap.h, it actually has bendrange at 118, but it's
-- overwritten by level-dif.  It toggles between 2 and 12.
--
-- Since it's open source if I wanted to I could probably patch it to support
-- Midi.pitch_bend_range.
pb_range :: (Int, Int)
pb_range :: PbRange
pb_range = (-Int
2, Int
2)

controls :: [(Midi.Control, ScoreT.Control)]
controls :: [(Control, Control)]
controls =
    [ (Control
15, Control
"voice-count")
    , (Control
16, Control
"unison")
    , (Control
17, Control
"octave")
    , (Control
18, Control
"filter-warm")
    , (Control
19, Control
"lfofreq")
    , (Control
20, Control
"vampenv")
    , (Control
21, Control
"asplayedallocation")
    , (Control
22, Control
"lfo1amt")
    , (Control
23, Control
"portamento")
    , (Control
24, Control
"udet")
    , (Control
25, Control
"lfo2amt")
    , (Control
33, Control
"tune")
    , (Control
34, Control
"bendosc2")
    , (Control
35, Control
"legatomode")
    , (Control
36, Control
"ldec")
    , (Control
37, Control
"lsus")
    , (Control
38, Control
"fatk")
    , (Control
39, Control
"fdec")
    , (Control
40, Control
"fsus")
    , (Control
41, Control
"frel")
    , (Control
42, Control
"resonance")
    , (Control
43, Control
"osc2-det")
    , (Control
44, Control
"lfosinwave")
    , (Control
45, Control
"lfosquarewave")
    , (Control
46, Control
"lfoshwave")
    , (Control
47, Control
"lfoosc1")
    , (Control
48, Control
"lfoosc2")
    , (Control
49, Control
"lfofilter")
    , (Control
50, Control
"lfopw1")
    , (Control
51, Control
"lfopw2")
    , (Control
52, Control
"osc2hs")
    , (Control
53, Control
"xmod")
    , (Control
54, Control
"osc1p")
    , (Control
55, Control
"osc2p")
    , (Control
56, Control
"oscquantize")
    , (Control
57, Control
"osc1saw")
    , (Control
58, Control
"osc1pul")
    , (Control
59, Control
"osc2saw")
    , (Control
60, Control
"osc2pul")
    , (Control
61, Control
"pw")
    , (Control
62, Control
"brightness")
    , (Control
63, Control
"envpitch")
    , (Control
71, Control
"volume")
    , (Control
72, Control
"lrel")
    , (Control
73, Control
"latk")
    , (Control
74, Control
"cutoff")
    , (Control
75, Control
"bendlforate")
    , (Control
76, Control
"vfltenv")
    , (Control
77, Control
"osc1mix")
    , (Control
78, Control
"osc2mix")
    , (Control
81, Control
"pan1")
    , (Control
82, Control
"pan2")
    , (Control
83, Control
"pan3")
    , (Control
84, Control
"pan4")
    , (Control
85, Control
"pan5")
    , (Control
86, Control
"pan6")
    , (Control
87, Control
"pan7")
    , (Control
88, Control
"pan8")
    , (Control
102, Control
"noisemix")
    , (Control
103, Control
"flt-kf")
    , (Control
104, Control
"multimode")
    , (Control
105, Control
"bandpass")
    , (Control
106, Control
"fourpole")
    , (Control
107, Control
"envelope-amt")
    , (Control
108, Control
"envder")
    , (Control
109, Control
"filterder")
    , (Control
110, Control
"portader")
    , (Control
111, Control
"economy-mode")
    , (Control
113, Control
"pw-env")
    , (Control
114, Control
"pw-env-both")
    , (Control
115, Control
"env-pitch-both")
    , (Control
116, Control
"fenv-invert")
    , (Control
117, Control
"pw-osc2-ofs")
    , (Control
118, Control
"level-dif") -- bendrange?
    , (Control
119, Control
"self-osc_push")
    ]