A 28/01/2013, ?s 19:36, Martin Drautzburg escreveu:
> Hello all,
> I know how to play a Midi file. I also know how to read the keyboard. But I
> don't know how to bring the two together such that I can start and stop
> playing from the keyboard.
> It is not required (just nice to have) that the console remains responsive
> while the midi file plays. But it is essential that I can stop the
> Is this difficult?
I?m also a beginner, so take this with a grain of salt: I suppose the midi playing command doesn?t block until finished playing otherwise you couldn?t stop midway. If that is the case you can do something like
main = forever readFromConsole
readFromConsole = do
in <- getLine
Then the answer depends on how you are going about playing midi.
1. Is the api call for this playMidiFile :: FilePath -> IO (), where it
waits until the file finishes before it returns?
You may have to spawn a thread (forkIO) before you play, save it's threadId
in some sort of state and then attempt to kill it from the input thread
when the time comes.
2. Does it play the file and return an id you can reference for later
You can simply keep that reference in some sort of state and when the
command comes to kill it, just use that reference.
3. Are you sending external system commands to a sound system like mplayer
Just send the commands and let the system handle it.
On Wed, Jan 30, 2013 at 5:32 PM, Martin Drautzburg <Martin.Drautzburg at web.de
> On Tuesday, 29. January 2013 11:01:30 Miguel Negrao wrote:
> > main = forever readFromConsole
> > readFromConsole = do
> > in <- getLine
> > processInput in
> > processInput ?start? = startMidi
> > processInput ?stop? = stopMidi
> > where startMidi and stopMidi are functions.
> How to implement these functions is exactly my problem.
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners >
On Wednesday, 30. January 2013 23:51:03 David McBride wrote:
> Then the answer depends on how you are going about playing midi.
> 1. Is the api call for this playMidiFile :: FilePath -> IO (), where it
> waits until the file finishes before it returns?
> You may have to spawn a thread (forkIO) before you play, save it's threadId
> in some sort of state and then attempt to kill it from the input thread
> when the time comes.
Yes, my player is a function from Something to IO(), so forkIO is what I was