Skip to content

Commit

Permalink
Add OSC control to timemachine, port 7133, messages /start and /stop …
Browse files Browse the repository at this point in the history
…start and stop recordings
  • Loading branch information
Steve Harris committed Nov 29, 2008
1 parent ccd9097 commit 106654b
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 3 deletions.
13 changes: 10 additions & 3 deletions configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@ AM_PROG_CC_STDC
AC_HEADER_STDC

PKG_CHECK_MODULES(GTK, [gtk+-2.0 >= 2.0.0])

PKG_CHECK_MODULES(JACK, [jack >= 0.80.0])
PKG_CHECK_MODULES(LIBLO, liblo >= 0.24, LO_FOUND="yes", LO_FOUND="no")

if test "$LO_FOUND" = "yes"; then
AC_DEFINE(HAVE_LIBLO, 1, [whether or not we are supporting OSC])
EXTRA_PROGRAMS="timemachine-control"
AC_SUBST(LIBLO_CFLAGS)
AC_SUBST(LIBLO_LIBS)
fi

##############
### LASH ###
Expand Down Expand Up @@ -65,8 +72,8 @@ AC_CHECK_LIB([readline], [readline])

AC_CHECK_LIB([pthread], [pthread_self], , [AC_MSG_ERROR(Can't find libpthread)])

PACKAGE_CFLAGS="-g -Wall $GTK_CFLAGS $JACK_CFLAGS $LASH_CFLAGS $SNDFILE_CFLAGS"
PACKAGE_LIBS="-g $GTK_LIBS $JACK_LIBS $LASH_LIBS $SNDFILE_LIBS"
PACKAGE_CFLAGS="-g -Wall $GTK_CFLAGS $JACK_CFLAGS $LASH_CFLAGS $SNDFILE_CFLAGS $LIBLO_CFLAGS"
PACKAGE_LIBS="-g $GTK_LIBS $JACK_LIBS $LASH_LIBS $SNDFILE_LIBS $LIBLO_LIBS"

AC_SUBST(PACKAGE_CFLAGS)
AC_SUBST(PACKAGE_LIBS)
Expand Down
1 change: 1 addition & 0 deletions src/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
timemachine
timemachine-control
.deps
3 changes: 3 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ timemachine_SOURCES = \

timemachine_LDADD = @PACKAGE_LIBS@

timemachine_control_SOURCE = timemachine-control.c
timemachine_control_LDADD = @LIBLO_LIBS@

36 changes: 36 additions & 0 deletions src/callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#include "gtkmeter.h"
#include "gtkmeterscale.h"
#include "threads.h"
#ifdef HAVE_LIBLO
#include <lo/lo.h>
#endif

static int button_pressed = 0;

Expand Down Expand Up @@ -43,3 +46,36 @@ gboolean on_window_delete_event(GtkWidget * widget, GdkEvent * event,

return FALSE;
}

#ifdef HAVE_LIBLO
int osc_handler(const char *path, const char *types, lo_arg **argv, int argc,
lo_message msg, void *user_data)
{
GtkWidget *img = lookup_widget(main_window, "toggle_image");

if (user_data) {
recording_start();
gtk_image_set_from_pixbuf(GTK_IMAGE(img), img_on);
gtk_window_set_icon(GTK_WINDOW(main_window), icon_on);
} else {
recording_stop();
gtk_widget_set_sensitive(img, FALSE);
gtk_image_set_from_pixbuf(GTK_IMAGE(img), img_busy);
gtk_window_set_icon(GTK_WINDOW(main_window), icon_off);
}

return 0;
}

int osc_handler_nox(const char *path, const char *types, lo_arg **argv,
int argc, lo_message msg, void *user_data)
{
if (user_data) {
recording_start();
} else {
recording_stop();
}

return 0;
}
#endif
33 changes: 33 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ lash_client_t *lash_client;
#include <readline/history.h>
#endif

#ifdef HAVE_LIBLO
#include <lo/lo.h>
#endif

#include "threads.h"
#include "interface.h"
#include "meters.h"
Expand Down Expand Up @@ -72,6 +76,13 @@ jack_client_t *client;
GdkPixbuf *img_on, *img_off, *img_busy;
GdkPixbuf *icon_on, *icon_off;

#ifdef HAVE_LIBLO
int osc_handler(const char *path, const char *types, lo_arg **argv, int argc,
lo_message msg, void *user_data);
int osc_handler_nox(const char *path, const char *types, lo_arg **argv,
int argc, lo_message msg, void *user_data);
#endif

int main(int argc, char *argv[])
{
unsigned int i;
Expand Down Expand Up @@ -219,6 +230,17 @@ int main(int argc, char *argv[])

#ifdef HAVE_LIBREADLINE
if (console || !getenv("DISPLAY") || getenv("DISPLAY")[0] == '\0') {
#ifdef HAVE_LIBLO
lo_server_thread st = lo_server_thread_new(OSC_PORT, NULL);
if (st) {
lo_server_thread_add_method(st, "/start", "", osc_handler_nox, (void *)1);
lo_server_thread_add_method(st, "/stop", "", osc_handler_nox, (void *)0);
lo_server_thread_start(st);
printf("Listening for OSC requests on osc.udp://localhost:%s\n",
OSC_PORT);
}
#endif

int done = 0;
while (!done) {
char *line = readline("TimeMachine> ");
Expand Down Expand Up @@ -261,6 +283,17 @@ int main(int argc, char *argv[])
bind_meters();
g_timeout_add(100, meter_tick, NULL);

#ifdef HAVE_LIBLO
lo_server_thread st = lo_server_thread_new(OSC_PORT, NULL);
if (st) {
lo_server_thread_add_method(st, "/start", "", osc_handler, (void *)1);
lo_server_thread_add_method(st, "/stop", "", osc_handler, (void *)0);
lo_server_thread_start(st);
printf("Listening for OSC requests on osc.udp://localhost:%s\n",
OSC_PORT);
}
#endif

#ifdef HAVE_LASH
gtk_idle_add(idle_cb, lash_client);
#endif
Expand Down
2 changes: 2 additions & 0 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#define DEFAULT_FORMAT "wav"
#endif

#define OSC_PORT "7133"

extern GtkWidget *main_window;

extern GdkPixbuf *img_on, *img_off, *img_busy;
Expand Down

0 comments on commit 106654b

Please sign in to comment.