summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2015-12-07 02:00:55 -0500
committerAndrew Cady <d@jerkface.net>2015-12-07 02:00:55 -0500
commit7ed747a7db1fcfd5f57524b7ffca45a527951d9f (patch)
tree40149d947e0d5ab85415c0f9ece280fa261fa432
parent990bae4f495b80e38a2ca1c3f2fbe6482c2e6cc8 (diff)
Output replayed recordings to MIDI channel 1
The live output goes to channel 0. This prevents the two from messing with each other (cancelling each others' notes). Simply hard-coding channel 1 is a bad idea long-term, though. We actually could have input from more than one channel (if we pump a midi file into the program with "aplaymidi", for example). I suppose we want to map the entire range of channels based on the input source in order to prevent input sources from affecting one another. Then generated playback could be considered a separate input source. All of this will have to be done in order to deal with simultaneous looping of multiple tracks, anyway.
-rw-r--r--Midi.hs10
-rw-r--r--midi-dump.hs2
2 files changed, 11 insertions, 1 deletions
diff --git a/Midi.hs b/Midi.hs
index cc14eb6..eac587c 100644
--- a/Midi.hs
+++ b/Midi.hs
@@ -91,6 +91,16 @@ convertEvents = mapMaybe (maybesnd . fmap conv)
91 cpv f c p v = f (fi $ Event.unChannel c) (fi $ Event.unPitch p) (fi $ Event.unVelocity v) 91 cpv f c p v = f (fi $ Event.unChannel c) (fi $ Event.unPitch p) (fi $ Event.unVelocity v)
92 fi = fromIntegral 92 fi = fromIntegral
93 93
94setChannel :: Codec.Midi.Channel -> Codec.Midi.Message -> Codec.Midi.Message
95setChannel c (NoteOff _ k v) = (NoteOff c k v)
96setChannel c (NoteOn _ k v) = (NoteOn c k v)
97setChannel c (ProgramChange _ p) = (ProgramChange c p)
98setChannel c (ControlChange _ n v) = (ControlChange c n v)
99setChannel c (KeyPressure _ k p) = (KeyPressure c k p)
100setChannel c (ChannelPressure _ p) = (ChannelPressure c p)
101setChannel c (PitchWheel _ p) = (PitchWheel c p)
102setChannel _ x = x
103
94unConvertEvents :: [(TimeSpec, Codec.Midi.Message)] -> [(TimeSpec, Event.Data)] 104unConvertEvents :: [(TimeSpec, Codec.Midi.Message)] -> [(TimeSpec, Event.Data)]
95unConvertEvents = mapMaybe (maybesnd . fmap conv) 105unConvertEvents = mapMaybe (maybesnd . fmap conv)
96 where 106 where
diff --git a/midi-dump.hs b/midi-dump.hs
index 4c74792..534671f 100644
--- a/midi-dump.hs
+++ b/midi-dump.hs
@@ -215,7 +215,7 @@ playRecording = playEvents . playableEvents
215playEvents :: [RecordedEvent] -> RWST LoopEnv () LoopState IO () 215playEvents :: [RecordedEvent] -> RWST LoopEnv () LoopState IO ()
216playEvents evts@(_:_) = 216playEvents evts@(_:_) =
217 mapM_ (uncurry delayNoteEv) (zip (subtract (head delays) <$> delays) events) 217 mapM_ (uncurry delayNoteEv) (zip (subtract (head delays) <$> delays) events)
218 where (delays, events) = unzip $ reverse $ unConvertEvents evts 218 where (delays, events) = unzip $ reverse $ unConvertEvents $ (fmap.fmap) (setChannel 1) evts
219playEvents _ = return () 219playEvents _ = return ()
220 220
221getMidiSender :: MidiController MidiHook 221getMidiSender :: MidiController MidiHook