zynaddsubfx

ZynAddSubFX open source synthesizer
Log | Files | Refs | Submodules | LICENSE

commit b8fd22169beb74881ab718bb74dd1b475bb107f4
parent 7346fef91b2b73e444a90da70f6c02c4c30f2bd8
Author: paulnasca <paulnasca>
Date:   Wed,  1 Nov 2006 21:07:27 +0000

*** empty log message ***

Diffstat:
Asrc/Misc/LASHClient.C | 73+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/Misc/LASHClient.h | 35+++++++++++++++++++++++++++++++++++
2 files changed, 108 insertions(+), 0 deletions(-)

diff --git a/src/Misc/LASHClient.C b/src/Misc/LASHClient.C @@ -0,0 +1,73 @@ +#include <unistd.h> +#include <iostream> +#include <string> + +#include "LASHClient.h" + + +LASHClient::LASHClient(int* argc, char*** argv) { + client = lash_init(lash_extract_args(argc, argv), "ZynAddSubFX", + LASH_Config_File, LASH_PROTOCOL(2, 0)); +} + + +void LASHClient::setalsaid(int id) { + if (lash_enabled(client)) { + if (id != -1) + lash_alsa_client_id(client, id); + } +} + + +void LASHClient::setjackname(const char* name) { + if (lash_enabled(client)) { + if (name != NULL) + lash_jack_client_name(client, name); + } +} + + +LASHClient::Event LASHClient::checkevents(std::string& filename) { + + if (!lash_enabled(client)) + return NoEvent; + + Event received = NoEvent; + lash_event_t* event; + while (event = lash_get_event(client)) { + + // save + if (lash_event_get_type(event) == LASH_Save_File) { + std::cerr<<"LASH event: LASH_Save_File"<<std::endl; + filename = std::string(lash_event_get_string(event)) + "/master.xmz"; + received = Save; + break; + } + + // restore + else if (lash_event_get_type(event) == LASH_Restore_File) { + std::cerr<<"LASH event: LASH_Restore_File"<<std::endl; + filename = std::string(lash_event_get_string(event)) + "/master.xmz"; + received = Restore; + break; + } + + // quit + else if (lash_event_get_type(event) == LASH_Quit) { + std::cerr<<"LASH event: LASH_Quit"<<std::endl; + received = Quit; + break; + } + + lash_event_destroy(event); + } + return received; +} + + +void LASHClient::confirmevent(Event event) { + if (event == Save) + lash_send_event(client, lash_event_new_with_type(LASH_Save_File)); + else if (event == Restore) + lash_send_event(client, lash_event_new_with_type(LASH_Restore_File)); +} diff --git a/src/Misc/LASHClient.h b/src/Misc/LASHClient.h @@ -0,0 +1,35 @@ +#ifndef LASHClient_h +#define LASHClient_h + +#include <string> +#include <pthread.h> +#include <lash/lash.h> + + +/** This class wraps up some functions for initialising and polling + the LASH daemon. */ +class LASHClient { + public: + + enum Event { + Save, + Restore, + Quit, + NoEvent + }; + + LASHClient(int* argc, char*** argv); + + void setalsaid(int id); + void setjackname(const char* name); + Event checkevents(std::string& filename); + void confirmevent(Event event); + + private: + + lash_client_t* client; +}; + + +#endif +