File: osc.c

package info (click to toggle)
jack-capture 0.9.67-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 344 kB
  • sloc: ansic: 2,176; cpp: 1,583; makefile: 179; sh: 114
file content (130 lines) | stat: -rw-r--r-- 4,116 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/* 
    jack_capture - OSC remote control

    Kjetil Matheussen, 2005-2010.
    Written 2012 by Robin Gareus <robin@gareus.org>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/


#include "das_config.h"

#if HAVE_LIBLO

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <lo/lo.h>

#include <stdbool.h>
extern bool verbose;
extern bool silent;

/* message flags */
extern bool queued_file_rotate;
void osc_stop();

/***************************************************************************
 * specific OSC callbacks */

int oscb_record (const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data){
  if (verbose==true) fprintf(stderr, "OSC: %s <- s:%s\n", path, &argv[0]->s);
  // TODO ?? akin use_jack_transport jack_transport_started
  return(0);
}

int oscb_stop (const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data){
  if (verbose==true) fprintf(stderr, "OSC: %s\n", path);
  osc_stop();
  return(0);
}

int oscb_frotate (const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data){
  if (verbose==true) fprintf(stderr, "OSC: %s\n", path);
  queued_file_rotate=true;
  return(0);
}

#if 0
int oscb_offset (const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data){
  if (verbose==true) fprintf(stderr, "OSC: %s <- f:%f\n", path, argv[0]->f);
  if (verbose==true) fprintf(stderr, "OSC: %s <- i:%i\n", path, argv[1]->i);
  return(0);
}
#endif


/***************************************************************************
 * general callbacks */
int oscb_quit (const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data){
  fprintf(stderr, "OSC 'quit' command recv.\n");
  //loop_flag=0;
  return(0);
}

static void oscb_error(int num, const char *m, const char *path) {
  fprintf(stderr, "liblo server error %d in path %s: %s\n", num, path, m);
}

/* ///////////////////////////////////////////////////////////////////////// */
/* main OSC server code                                                      */

lo_server_thread osc_server = NULL;

int init_osc(int osc_port) {
  char tmp[8];
  if (osc_port < 0) return(1);
  uint32_t port = (osc_port>100 && osc_port< 60000)?osc_port:7654;

  snprintf(tmp, sizeof(tmp), "%d", port);
  if(verbose==true)
    fprintf(stderr, "OSC trying port:%i\n",port);
  osc_server = lo_server_thread_new (tmp, oscb_error);

  if (!osc_server) {
    if(silent==false) fprintf(stderr, "OSC start failed.");
    return(1);
  }

  if(silent==false) {
    char *urlstr;
    urlstr = lo_server_thread_get_url (osc_server);
    fprintf(stderr, "OSC server name: %s\n",urlstr);
    free (urlstr);
  }

  //lo_server_thread_add_method(osc_server, "/jack_capture/start",  "s", &oscb_record, NULL); 
  lo_server_thread_add_method(osc_server, "/jack_capture/stop",   "",  &oscb_stop, NULL); 
  lo_server_thread_add_method(osc_server, "/jack_capture/rotate", "",  &oscb_frotate, NULL); 

  lo_server_thread_start(osc_server);
  if(verbose==true) fprintf(stderr, "OSC server started on port %i\n",port);
  return (0);
}

void shutdown_osc(void) {
  if (!osc_server) return;
  lo_server_thread_stop(osc_server);
  if(verbose==true) fprintf(stderr, "OSC server shut down.\n");
}

#else
int init_osc(int osc_port) {return(1);}
void shutdown_osc(void) {;}
#endif

/* vi:set ts=8 sts=2 sw=2: */