Nice work. I was about to help you write something a lot like what you're got.
On Thu, May 12, 2016 at 11:06 AM, Jörg Krause <[email protected]> wrote: > After fighting hard with uv I had success! If anyone is interested here is > my piece of code: > https://gist.github.com/joerg-krause/8c0a1fe1c67e1a34b28ff7efec9d5dec. > > On Thursday, May 12, 2016 at 10:11:47 AM UTC+2, Jörg Krause wrote: >> >> Hi, >> >> I am trying to integrate ALSA volume event handling into a Luvit project. >> I have some working (LuaJIT) code now: >> >> function elem_event(elem, mask) >> print("Volume changed...") >> >> -- self:emit("volumechange") >> >> return 0 >> end >> >> >> >> function mixer_event(mixer, mask, elem) >> >> local sid_ptr = ffi.new("snd_mixer_selem_id_t") >> >> local sid = sid_ptr >> >> >> >> alsa.snd_mixer_selem_get_id(elem, sid) >> print("event add"); >> >> >> alsa.snd_mixer_elem_set_callback(elem, elem_event) >> >> >> return 0 >> end >> >> >> function M.monitor(card) >> local mixer_ptr = ffi.new("snd_mixer_t *[1]") >> >> alsa.snd_mixer_open(mixer_ptr, 0) >> local handle = mixer_ptr[0] >> >> alsa.snd_mixer_attach(handle, card) >> >> alsa.snd_mixer_selem_register(handle, nil, nil) >> >> alsa.snd_mixer_set_callback(handle, mixer_event) >> >> >> alsa.snd_mixer_load(handle) >> >> print("Ready to listen...\n"); >> while true do >> local err = alsa.snd_mixer_wait(handle, -1) >> if err >= 0 then >> print("Poll ok: " .. err) >> err = alsa.snd_mixer_handle_events(handle) >> p(err) >> end >> end >> >> alsa.snd_mixer_close(handle) >> end >> >> functio M.get_volume(card) >> [..] >> end >> >> I have read the blog post about integrating libcurl into Luvit. Howeverm, >> I still do not know, how to integrate the poll loop into Luvit, so that I >> can run the monitor function and call other functions from the module, like >> get_volume(). Furthermore, I want to emit an event, when the volume has >> changed. >> >> I'm thankful for any hints! >> >> Best regards >> Jörg Krause >> >> >> -- > You received this message because you are subscribed to the Google Groups > "luvit" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "luvit" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
