Skip to contentSkip to conversation

How to stop playback on alsa synth?

DISCUSSION Lukasz Pawelczyk 1 participant 2 messages Mar 16, 2008

lore
Share & tools
lore
#0 lore raw

Hello.

I'd like to ask how to completely stop playback using alsa synth.

Basically my program initialized output in the following way:

snd_seq_open()
snd_seq_set_client_name()
snd_seq_client_id()
snd_seq_parse_address()
snd_seq_create_simple_port()
snd_seq_connect_to()
snd_seq_alloc_named_queue()

Then I create a new thread that processes events.
It sets tempo and in infinite loop it does:
snd_seq_ev_set_fixed()
snd_seq_event_output()

This all is based on aplaymidi code.

How can I asynchronously immediately stop all the playback? Basicaly it requires breaking snd_seq_event_output() thats locked on my thread. I tried everything I could come up with. I know very little about alsa synth programming and basically thats the only thing i need to do now.

Tried:
snd_seq_ev_set_queue_stop()
snd_seq_stop_queue()
snd_seq_remove_events()

or even closing the seq completely to reopen it on another file playback with:
snd_seq_stop_queue()
snd_seq_disconnect_to()
snd_seq_delete_simple_port()
snd_seq_close()

All failed, results were very various. I simply run out of ideas. It doesn't matter if the method would require to close seq or not. I just need to stop the playback so i can gracefully stop the thread and play another file (with eventual reopening ports/seq).

Would appreciate any help.

Signature · 2 lines
Regards    Havner                     {jid,mail}:havner(at)pld-linux.org
                    "Quis custodiet ipsos custodes?"
#1 lore raw

I think I've done it, just don't know how correct my solution is

I've added snd_seq_drain_output() after snd_seq_event_output() in thread function so the events are processed more "real time" as I understand it. I've also moved queue creation to the beginning of thread function (because stop function deletes the queue).

Then the stop function calls:
sets a bool to break the thread loop.
snd_seq_free_queue()
snd_seq_drop_output()

This seems to work. Any comments?

One problem I got with it though is that sometimes when I stop one music and play another one some note(s) from the old one are played indefinitely during the new music. I suppose some 'clear' event should be sent to remove it. I've tried MIDI_CTL_ALL_SOUNDS_OFF control one (as pmidi does on exit) but no luck.

Signature · 2 lines
Regards    Havner                     {jid,mail}:havner(at)pld-linux.org
                    "Quis custodiet ipsos custodes?"