diff options
author | Andrew Cady <d@jerkface.net> | 2015-12-07 01:31:21 -0500 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2015-12-07 01:31:21 -0500 |
commit | 990bae4f495b80e38a2ca1c3f2fbe6482c2e6cc8 (patch) | |
tree | 2ba344f3f1265dcfe30e4cdf08c43da85039c9d1 | |
parent | 9adf1aff92e1921203feeedf361deee1984fe2c6 (diff) |
Implement playing MIDI from the database
Currently, the "dump" command plays the entire database. Only the SQL
SELECT statement needs to be changed in order to play a specific
time-range.
-rw-r--r-- | Midi.hs | 5 | ||||
-rw-r--r-- | midi-dump.hs | 74 |
2 files changed, 49 insertions, 30 deletions
@@ -59,6 +59,11 @@ instance ToRow CompleteRecording where | |||
59 | where | 59 | where |
60 | (CompleteRecording (TimeSpec s ns) (TimeSpec s' ns') (TimeSpec s'' ns'') (TimeSpec s''' ns''') midi) = reco | 60 | (CompleteRecording (TimeSpec s ns) (TimeSpec s' ns') (TimeSpec s'' ns'') (TimeSpec s''' ns''') midi) = reco |
61 | 61 | ||
62 | instance Monoid CompleteRecording where | ||
63 | mempty = CompleteRecording 0 0 0 0 [] | ||
64 | (CompleteRecording s _e f _l evts) `mappend` (CompleteRecording _s' e' _f' l' evts') = | ||
65 | CompleteRecording s e' f l' (evts' ++ evts) | ||
66 | |||
62 | maybesnd :: forall t t1. (t, Maybe t1) -> Maybe (t, t1) | 67 | maybesnd :: forall t t1. (t, Maybe t1) -> Maybe (t, t1) |
63 | maybesnd (_, Nothing) = Nothing | 68 | maybesnd (_, Nothing) = Nothing |
64 | maybesnd (x, Just y) = Just (x, y) | 69 | maybesnd (x, Just y) = Just (x, y) |
diff --git a/midi-dump.hs b/midi-dump.hs index 064ce88..4c74792 100644 --- a/midi-dump.hs +++ b/midi-dump.hs | |||
@@ -75,38 +75,51 @@ getAbsTime = do | |||
75 | return $ now - startTime + startTimeReal | 75 | return $ now - startTime + startTimeReal |
76 | 76 | ||
77 | createTable :: Query | 77 | createTable :: Query |
78 | createTable = fromString $ concat | 78 | createTable = fromString . concat $ |
79 | ["CREATE TABLE IF NOT EXISTS axis_input", | 79 | [ "CREATE TABLE IF NOT EXISTS axis_input" |
80 | " (id INTEGER PRIMARY KEY,", | 80 | , " (id INTEGER PRIMARY KEY," |
81 | 81 | , " start_sec INTEGER," | |
82 | " start_sec INTEGER,", | 82 | , " start_nsec INTEGER," |
83 | " start_nsec INTEGER,", | 83 | , " end_sec INTEGER," |
84 | " end_sec INTEGER,", | 84 | , " end_nsec INTEGER," |
85 | " end_nsec INTEGER,", | 85 | , " first_sec INTEGER," |
86 | 86 | , " first_nsec INTEGER," | |
87 | " first_sec INTEGER,", | 87 | , " last_sec INTEGER," |
88 | " first_nsec INTEGER,", | 88 | , " last_nsec INTEGER," |
89 | " last_sec INTEGER,", | 89 | , " midi BLOB)" |
90 | " last_nsec INTEGER,", | 90 | ] |
91 | |||
92 | " midi BLOB)"] | ||
93 | 91 | ||
94 | sqlInsert :: Query | 92 | sqlInsert :: Query |
95 | sqlInsert = fromString $ concat | 93 | sqlInsert = fromString . concat $ |
96 | ["INSERT INTO axis_input", | 94 | [ "INSERT INTO axis_input " |
97 | 95 | , "(start_sec," | |
98 | "(start_sec,", | 96 | , " start_nsec," |
99 | " start_nsec,", | 97 | , " end_sec," |
100 | " end_sec,", | 98 | , " end_nsec," |
101 | " end_nsec,", | 99 | , " first_sec," |
102 | 100 | , " first_nsec," | |
103 | " first_sec,", | 101 | , " last_sec," |
104 | " first_nsec,", | 102 | , " last_nsec," |
105 | " last_sec,", | 103 | , " midi)" |
106 | " last_nsec,", | 104 | , "VALUES (?,?,?,?, ?,?,?,?, ?)" |
107 | 105 | ] | |
108 | " midi)", | 106 | |
109 | "VALUES (?,?,?,?, ?,?,?,?, ?)"] | 107 | sqlSelectEVERYTHING :: MidiController [CompleteRecording] |
108 | sqlSelectEVERYTHING = do | ||
109 | conn <- asks _sqlite | ||
110 | liftIO $ query_ conn $ fromString . concat $ | ||
111 | [ "SELECT " | ||
112 | , "start_sec," | ||
113 | , "start_nsec," | ||
114 | , "end_sec," | ||
115 | , "end_nsec," | ||
116 | , "first_sec," | ||
117 | , "first_nsec," | ||
118 | , "last_sec," | ||
119 | , "last_nsec," | ||
120 | , "midi" | ||
121 | , " FROM axis_input ORDER BY start_sec, start_nsec;" | ||
122 | ] | ||
110 | 123 | ||
111 | main' :: IO () | 124 | main' :: IO () |
112 | main' = withAlsaInit $ \h public private q publicAddr privateAddr -> do | 125 | main' = withAlsaInit $ \h public private q publicAddr privateAddr -> do |
@@ -176,6 +189,7 @@ processCommand :: String -> MidiController () | |||
176 | processCommand "exit" = modify $ \s -> s { _wantExit = True } | 189 | processCommand "exit" = modify $ \s -> s { _wantExit = True } |
177 | -- processCommand "" = return () | 190 | -- processCommand "" = return () |
178 | processCommand "" = gets _replay >>= playRecording | 191 | processCommand "" = gets _replay >>= playRecording |
192 | processCommand "dump" = sqlSelectEVERYTHING >>= playRecording . mconcat | ||
179 | processCommand "C" = do | 193 | processCommand "C" = do |
180 | let notes = (Event.NoteEv Event.NoteOn . mkNote) <$> [60, 64, 67] | 194 | let notes = (Event.NoteEv Event.NoteOn . mkNote) <$> [60, 64, 67] |
181 | forM_ notes (delayNoteEv (TimeSpec 0 0)) | 195 | forM_ notes (delayNoteEv (TimeSpec 0 0)) |