* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
- * $Id$
*/
#include <iostream>
+#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <cerrno>
#include <unistd.h>
#include <fcntl.h>
+#include <glibmm/miscutils.h>
+
+#include <pbd/pthread_utils.h>
+#include <pbd/file_utils.h>
+#include <pbd/filesystem.h>
+
#include <ardour/osc.h>
#include <ardour/session.h>
#include <ardour/route.h>
#include <ardour/audio_track.h>
+#include <ardour/dB.h>
+#include <ardour/filesystem_paths.h>
#include "i18n.h"
OSC::start ()
{
char tmpstr[255];
+
+ if (_osc_server) {
+ /* already started */
+ return 0;
+ }
for (int j=0; j < 20; ++j) {
snprintf(tmpstr, sizeof(tmpstr), "%d", _port);
#endif
cerr << "OSC @ " << get_server_url () << endl;
+
+ PBD::sys::path url_file;
+
+ if (find_file_in_search_path (ardour_search_path() + system_config_search_path(),
+ "osc_url", url_file)) {
+ _osc_url_file = url_file.to_string();
+ ofstream urlfile;
+ urlfile.open(_osc_url_file.c_str(), ios::trunc);
+ if ( urlfile )
+ {
+ urlfile << get_server_url () << endl;
+ urlfile.close();
+ }
+ else
+ {
+ cerr << "Couldn't write '" << _osc_url_file << "'" <<endl;
+ }
+ }
register_callbacks();
int
OSC::stop ()
{
+ if (_osc_server == 0) {
+ /* already stopped */
+ return 0;
+ }
+
+ // stop server thread
+ terminate_osc_thread();
+
lo_server_free (_osc_server);
+ _osc_server = 0;
if (!_osc_unix_socket_path.empty()) {
// unlink it
unlink(_osc_unix_socket_path.c_str());
}
- // stop server thread
- terminate_osc_thread();
-
+ if (! _osc_url_file.empty() ) {
+ unlink(_osc_url_file.c_str() );
+ }
return 0;
}
#define REGISTER_CALLBACK(serv,path,types, function) lo_server_add_method (serv, path, types, OSC::_ ## function, this)
REGISTER_CALLBACK (serv, "/ardour/add_marker", "", add_marker);
+ REGISTER_CALLBACK (serv, "/ardour/access_action", "s", access_action);
REGISTER_CALLBACK (serv, "/ardour/loop_toggle", "", loop_toggle);
REGISTER_CALLBACK (serv, "/ardour/goto_start", "", goto_start);
REGISTER_CALLBACK (serv, "/ardour/goto_end", "", goto_end);
REGISTER_CALLBACK (serv, "/ardour/rec_enable_toggle", "", rec_enable_toggle);
REGISTER_CALLBACK (serv, "/ardour/toggle_all_rec_enables", "", toggle_all_rec_enables);
+ REGISTER_CALLBACK (serv, "/ardour/routes/mute", "ii", route_mute);
+ REGISTER_CALLBACK (serv, "/ardour/routes/solo", "ii", route_solo);
+ REGISTER_CALLBACK (serv, "/ardour/routes/recenable", "ii", route_recenable);
+ REGISTER_CALLBACK (serv, "/ardour/routes/gainabs", "if", route_set_gain_abs);
+ REGISTER_CALLBACK (serv, "/ardour/routes/gaindB", "if", route_set_gain_dB);
+
#if 0
REGISTER_CALLBACK (serv, "/ardour/*/#current_value", "", current_value);
REGISTER_CALLBACK (serv, "/ardour/set", "", set);
void *
OSC::_osc_receiver(void * arg)
{
+ PBD::notify_gui_about_thread_creation (pthread_self(), X_("OSC"));
+
static_cast<OSC*> (arg)->osc_receiver();
return 0;
}
if (pfd[i].revents & POLLIN)
{
// this invokes callbacks
- //cerr << "invoking recv on " << pfd[i].fd << endl;
+ // cerr << "invoking recv on " << pfd[i].fd << endl;
lo_server_recv(srvs[i]);
}
}
if (_osc_server) {
int fd = lo_server_get_socket_fd(_osc_server);
if (fd >=0) {
- // hack around
+ // hack around
close(fd);
}
lo_server_free (_osc_server);
{
session = &s;
session->GoingAway.connect (mem_fun (*this, &OSC::session_going_away));
+
+ // "Application Hooks"
+ session_loaded( s );
+ session->Exported.connect( mem_fun( *this, &OSC::session_exported ) );
}
void
session = 0;
}
+// "Application Hook" Handlers //
+void
+OSC::session_loaded( Session& s ) {
+ lo_address listener = lo_address_new( NULL, "7770" );
+ lo_send( listener, "/session/loaded", "ss", s.path().c_str(), s.name().c_str() );
+}
+
+void
+OSC::session_exported( std::string path, std::string name ) {
+ lo_address listener = lo_address_new( NULL, "7770" );
+ lo_send( listener, "/session/exported", "ss", path.c_str(), name.c_str() );
+}
+
+// end "Application Hook" Handlers //
+
/* path callbacks */
int
#endif
return 0;
}
+
+int
+OSC::route_mute (int rid, int yn)
+{
+ if (!session) return -1;
+
+ boost::shared_ptr<Route> r = session->route_by_remote_id (rid);
+
+ if (r) {
+ r->set_mute (yn, this);
+ }
+ return 0;
+}
+
+int
+OSC::route_solo (int rid, int yn)
+{
+ if (!session) return -1;
+
+ boost::shared_ptr<Route> r = session->route_by_remote_id (rid);
+
+ if (r) {
+ r->set_solo (yn, this);
+ }
+ return 0;
+}
+
+int
+OSC::route_recenable (int rid, int yn)
+{
+ if (!session) return -1;
+
+ boost::shared_ptr<Route> r = session->route_by_remote_id (rid);
+
+ if (r) {
+ r->set_record_enable (yn, this);
+ }
+ return 0;
+}
+
+int
+OSC::route_set_gain_abs (int rid, float level)
+{
+ if (!session) return -1;
+
+ boost::shared_ptr<Route> r = session->route_by_remote_id (rid);
+
+ if (r) {
+ r->set_gain (level, this);
+ }
+
+ return 0;
+}
+
+int
+OSC::route_set_gain_dB (int rid, float dB)
+{
+ if (!session) return -1;
+
+ boost::shared_ptr<Route> r = session->route_by_remote_id (rid);
+
+ if (r) {
+ r->set_gain (dB_to_coefficient (dB), this);
+ }
+
+ return 0;
+}