From 7ed747a7db1fcfd5f57524b7ffca45a527951d9f Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Mon, 7 Dec 2015 02:00:55 -0500 Subject: 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. --- Midi.hs | 10 ++++++++++ midi-dump.hs | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) 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) cpv f c p v = f (fi $ Event.unChannel c) (fi $ Event.unPitch p) (fi $ Event.unVelocity v) fi = fromIntegral +setChannel :: Codec.Midi.Channel -> Codec.Midi.Message -> Codec.Midi.Message +setChannel c (NoteOff _ k v) = (NoteOff c k v) +setChannel c (NoteOn _ k v) = (NoteOn c k v) +setChannel c (ProgramChange _ p) = (ProgramChange c p) +setChannel c (ControlChange _ n v) = (ControlChange c n v) +setChannel c (KeyPressure _ k p) = (KeyPressure c k p) +setChannel c (ChannelPressure _ p) = (ChannelPressure c p) +setChannel c (PitchWheel _ p) = (PitchWheel c p) +setChannel _ x = x + unConvertEvents :: [(TimeSpec, Codec.Midi.Message)] -> [(TimeSpec, Event.Data)] unConvertEvents = mapMaybe (maybesnd . fmap conv) 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 playEvents :: [RecordedEvent] -> RWST LoopEnv () LoopState IO () playEvents evts@(_:_) = mapM_ (uncurry delayNoteEv) (zip (subtract (head delays) <$> delays) events) - where (delays, events) = unzip $ reverse $ unConvertEvents evts + where (delays, events) = unzip $ reverse $ unConvertEvents $ (fmap.fmap) (setChannel 1) evts playEvents _ = return () getMidiSender :: MidiController MidiHook -- cgit v1.2.3