LASH/LADCCA howto
Thanks to Lars Luthman i can present this mini LASH howto which was born in the irc channel #lad on irc.freenode.org:
15:30 < tapas> swh: if an app author wants to integrate lash into his app, what
does he have to do?
15:30 < swh> tapas, theres a howto somewhere...
15:31 < swh> ... mental note, dont type "lash howto" into google again
15:31 < tapas> hehe
15:31 < swh> maybe linux audio lash howto would be safer!
15:31 < swh> LAD lash howto is not going to be any better!
15:31 < larsl> tapas: Call init_ladcca(), call some other functions to tell
LADCCA it's JACK name and ALSA ID, then call ladcca_get_events()
or something like that a few times each second and act on events.
Lars was also kind enough to provide some example code to make it easier for aspiring lash/ladcca users to hack support into their clients (it looks simple enough)..
Here’s the most basic lash/ladcca client ever:
-
#include <stdio.h>
-
#include <unistd.h>
-
-
#include <lash/lash.h>
-
-
-
lash_client_t* lash_client;
-
-
-
/* Check for new LADCCA events */
-
int check_events() {
-
int keep_running = 1;
-
lash_event_t* event;
-
while (event = lash_get_event(lash_client)) {
-
-
switch (lash_event_get_type(event)) {
-
-
case LASH_Save_File:
-
lash_event_get_string(event));
-
lash_send_event(lash_client, event);
-
continue;
-
-
case LASH_Restore_File:
-
lash_event_get_string(event));
-
lash_send_event(lash_client, event);
-
continue;
-
-
case LASH_Quit:
-
keep_running = 0;
-
break;
-
-
default:
-
}
-
-
lash_event_destroy(event);
-
}
-
-
return keep_running;
-
}
-
-
-
int main(int argc, char** argv) {
-
lash_client = lash_init(lash_extract_args(&argc, &argv), “lash-basic”,
-
LASH_Config_File, LASH_PROTOCOL(2, 0));
-
if (!lash_client)
-
return 1;
-
-
while (check_events())
-
usleep(200000);
-
-
return 0;
-
}
Here’s an example client that shows how to integrate ladcca into a gtkmm app:
-
#include <iostream>
-
-
#include <gtkmm.h>
-
#include <lash/lash.h>
-
-
-
lash_client_t* lash_client;
-
Gtk::Label* label;
-
-
-
/* Check for new LADLASH events */
-
bool check_events() {
-
lash_event_t* event;
-
while (event = lash_get_event(lash_client)) {
-
-
switch (lash_event_get_type(event)) {
-
-
case LASH_Save_File:
-
label->set_text(std::string(“Asked to save data in “) +
-
lash_event_get_string(event) + ” but we don’t have any”);
-
lash_send_event(lash_client, event);
-
continue;
-
-
case LASH_Restore_File:
-
label->set_text(std::string(“Asked to restore data from “) +
-
lash_event_get_string(event) + ” but we don’t have any”);
-
lash_send_event(lash_client, event);
-
continue;
-
-
case LASH_Quit:
-
std::cerr<<“Asked to quit!”<<std::endl;
-
Gtk::Main::quit();
-
break;
-
-
default:
-
label->set_text(“Got unhandled LASH event”);
-
}
-
-
lash_event_destroy(event);
-
}
-
-
return true;
-
}
-
-
-
int main(int argc, char** argv) {
-
lash_client = lash_init(lash_extract_args(&argc, &argv), “lash-gtkmm”,
-
LASH_Config_File, LASH_PROTOCOL(2, 0));
-
if (!lash_client)
-
return 1;
-
printf(“Successfully connected to the LADLASH daemon!\n“);
-
-
/* Initialise gtkmm and create a window */
-
Gtk::Main kit(argc, argv);
-
Gtk::Window main_win;
-
main_win.set_title(“lash-gtkmm”);
-
label = new Gtk::Label(“Hello world!”);
-
main_win.add(*label);
-
main_win.show_all();
-
-
/* Make the event callback run five times each second */
-
Glib::signal_timeout().connect(&check_events, 200);
-
-
kit.run(main_win);
-
-
return 0;
-
}
And finally one that also has some rudimentary jack functionality:
-
#include <iostream>
-
-
#include <gtkmm.h>
-
#include <lash/lash.h>
-
#include <jack/jack.h>
-
-
-
jack_client_t* jack_client;
-
lash_client_t* lash_client;
-
Gtk::Label* label;
-
-
-
/* Check for new LADLASH events */
-
bool check_events() {
-
lash_event_t* event;
-
while (event = lash_get_event(lash_client)) {
-
-
switch (lash_event_get_type(event)) {
-
-
case LASH_Save_File:
-
label->set_text(std::string(“Asked to save data in “) +
-
lash_event_get_string(event) + ” but we don’t have any”);
-
lash_send_event(lash_client, event);
-
continue;
-
-
case LASH_Restore_File:
-
label->set_text(std::string(“Asked to restore data from “) +
-
lash_event_get_string(event) + ” but we don’t have any”);
-
lash_send_event(lash_client, event);
-
continue;
-
-
case LASH_Quit:
-
std::cerr<<“Asked to quit!”<<std::endl;
-
Gtk::Main::quit();
-
break;
-
-
default:
-
label->set_text(“Got unhandled LASH event”);
-
}
-
-
lash_event_destroy(event);
-
}
-
-
return true;
-
}
-
-
-
int main(int argc, char** argv) {
-
-
lash_client = lash_init(lash_extract_args(&argc, &argv), “lash-gtkmm-jack”,
-
LASH_Config_File, LASH_PROTOCOL(2, 0));
-
if (!lash_client)
-
return 1;
-
-
/* Initialise JACK */
-
jack_client = jack_client_new(“lash-gtkmm-jack”);
-
if (!jack_client)
-
return 1;
-
jack_port_register(jack_client, “Audio output”, JACK_DEFAULT_AUDIO_TYPE,
-
JackPortIsOutput, 0);
-
jack_activate(jack_client);
-
-
/* Tell LADLASH out JACK client name */
-
lash_jack_client_name(lash_client, “lash-gtkmm-jack”);
-
-
/* Initialise gtkmm and create a window */
-
Gtk::Main kit(argc, argv);
-
Gtk::Window main_win;
-
main_win.set_title(“lash-gtkmm”);
-
label = new Gtk::Label(“Hello world!”);
-
main_win.add(*label);
-
main_win.show_all();
-
-
/* Make the event callback run five times each second */
-
Glib::signal_timeout().connect(&check_events, 200);
-
-
kit.run(main_win);
-
-
return 0;
-
}
You’ll be pleased to know that typing “lash howto” into google now returns this page as first result…
Hehe, thanks for the pointer.
Hi!
I think the howto is outdated since all function and variable name prefixes have changed from:
cca_xxx -> lash_xxx
CCA_xxx -> LASH_xxx
At least in the ubuntu feisty liblash-dev package.
You are completely right. I will fix it [was just too lazy until now].. But when people actually complain, it’s a different story :)
Thanks for the feedback.
ok, updated.
lash clients are supposed to send save/restore events back, not just destroy them