This repository has been archived by the owner on Aug 16, 2018. It is now read-only.
forked from Sensebloom/OSCeleton
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added osc recording and playback tools so that you can record and dev…
…elop on th e go without dragging hardware around. Only tested on Mac, but should work if added to visual studio projects. They are only in beta form at the moment and just modify liblo's LPGL examples.
- Loading branch information
AdbC99
committed
Jul 3, 2011
1 parent
583c680
commit bda293b
Showing
137 changed files
with
304 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright (C) 2004 Steve Harris, Uwe Koloska | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details. | ||
* | ||
* $Id$ | ||
*/ | ||
|
||
/* Modified to read osc bundles from a file and output them */ | ||
|
||
#include <math.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
|
||
#define LINE_MAX 255 | ||
|
||
#include "lo/lo.h" | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
int ret; | ||
FILE * fp; | ||
|
||
if (argc < 3) | ||
{ | ||
printf("- Missing Arguments -\nUsage: file2osc filename address port\n"); | ||
exit(1); | ||
} | ||
|
||
int countar; | ||
|
||
fp = fopen(argv[1], "r"); | ||
|
||
if(!fp) | ||
{ | ||
printf("- Couldn't open %s -", argv[1]); | ||
exit(ret); | ||
} | ||
|
||
lo_address addr = lo_address_new(argv[2], argv[3]); | ||
|
||
char str[200]; | ||
|
||
if(!fp) return 1; // bail out if file not found | ||
|
||
/* | ||
while(fgets(str,sizeof(str),fp) != NULL) | ||
{ | ||
// strip trailing '\n' if it exists | ||
int len = strlen(str)-1; | ||
if(str[len] == '\n') | ||
str[len] = 0; | ||
printf("\n%s", str); | ||
}*/ | ||
int len = 0; | ||
double sec = 0; | ||
|
||
size_t result; | ||
|
||
while (1 == 1) | ||
{ | ||
if ((ret = fscanf(fp, "%d %lf\n", &len, &sec)) != 2) | ||
{ | ||
printf("Couldn't read file any further\n"); | ||
fclose(fp); | ||
exit(0); | ||
} | ||
|
||
printf("length %d sec %f\n", len, sec); | ||
|
||
char * buffer = (char *) malloc (sizeof(char)*len); | ||
|
||
result = fread (buffer,sizeof(char),len, fp); | ||
|
||
if (result != len) | ||
{fputs ("Reading error",stderr); fclose(fp); exit (3);} | ||
|
||
printf("readit %.*s\n", len, buffer); | ||
|
||
usleep((unsigned long) (1000000 * sec)); | ||
send_data(addr, NULL, buffer, len); | ||
|
||
} | ||
|
||
return 0; | ||
} | ||
|
||
/* vi:set ts=8 sts=4 sw=4: */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
/* | ||
* Copyright (C) 2004 Steve Harris, Uwe Koloska | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details. | ||
* | ||
* $Id$ | ||
*/ | ||
|
||
/* Modifications made to make this write to file instead of stdout */ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#ifndef WIN32 | ||
#include <unistd.h> | ||
#endif | ||
|
||
#include "lo/lo.h" | ||
|
||
int done = 0; | ||
|
||
int recording = 1; | ||
|
||
lo_timetag start_time; | ||
|
||
FILE * pFile; | ||
|
||
void error(int num, const char *m, const char *path); | ||
|
||
int generic_handler(const char *path, const char *types, lo_arg **argv, | ||
int argc, void *data, void *user_data); | ||
|
||
int quit_handler(const char *path, const char *types, lo_arg **argv, int argc, | ||
void *data, void *user_data); | ||
|
||
int stop_handler(const char *path, const char *types, lo_arg **argv, int argc, | ||
void *data, void *user_data); | ||
|
||
int start_handler(const char *path, const char *types, lo_arg **argv, int argc, | ||
void *data, void *user_data); | ||
|
||
int main(int argc, char * argv[]) | ||
{ | ||
lo_timetag_now(&start_time); | ||
|
||
if (argc < 3) | ||
{ | ||
printf("- Missing Arguments -\nUsage: osc2file port filename\n"); | ||
exit(1); | ||
} | ||
|
||
char port[6]; | ||
int ret; | ||
|
||
/* TODO: We could have some better port number checks here, rather than letting | ||
* liblo handle it | ||
*/ | ||
if ((ret = snprintf(port,6,"%s",argv[1])) < 0) | ||
{ | ||
printf("- Invalid port -"); | ||
exit(ret); | ||
} | ||
|
||
pFile = fopen(argv[2], "w"); | ||
|
||
if(!pFile) | ||
{ | ||
printf("- Couldn't open %s -", argv[2]); | ||
exit(ret); | ||
} | ||
|
||
printf("Initializing Server\n"); | ||
|
||
/* start a new server on provided port */ | ||
lo_server_thread st = lo_server_thread_new(port, error); | ||
|
||
/* add method that will match any path and args */ | ||
lo_server_thread_add_method(st, NULL, NULL, generic_handler, NULL); | ||
|
||
/* add method that will match the path /quit with no args */ | ||
lo_server_thread_add_method(st, "/quit", "", quit_handler, NULL); | ||
|
||
/* add method that will match the path /start with no args */ | ||
lo_server_thread_add_method(st, "/start", "", start_handler, NULL); | ||
|
||
/* add method that will match the path /stop with no args */ | ||
lo_server_thread_add_method(st, "/stop", "", stop_handler, NULL); | ||
|
||
lo_server_thread_start(st); | ||
|
||
printf("Server Begin\n"); | ||
printf(" send /start to begin recording\n"); | ||
printf(" send /stop to end recording\n"); | ||
printf(" send /quit to quit this tool\n\n"); | ||
|
||
|
||
|
||
while (!done) { | ||
#ifdef WIN32 | ||
Sleep(1); | ||
#else | ||
usleep(1000); | ||
#endif | ||
} | ||
|
||
lo_server_thread_free(st); | ||
|
||
return 0; | ||
} | ||
|
||
void error(int num, const char *msg, const char *path) | ||
{ | ||
printf("liblo server error %d in path %s: %s\n", num, path, msg); | ||
fflush(stdout); | ||
} | ||
|
||
/* catch any incoming messages and display them. returning 1 means that the | ||
* message has not been fully handled and the server should try other methods */ | ||
int generic_handler(const char *path, const char *types, lo_arg **argv, | ||
int argc, void *data, void *user_data) | ||
{ | ||
/* data is the lo_message */ | ||
if (!data) | ||
return 1; | ||
|
||
lo_timetag end_time; | ||
double diff; | ||
|
||
lo_timetag_now(&end_time); | ||
|
||
diff = lo_timetag_diff(end_time, start_time); | ||
|
||
lo_bundle bundle = lo_bundle_new(LO_TT_IMMEDIATE); | ||
|
||
lo_message * msg = (lo_message *)data; | ||
|
||
lo_bundle_add_message(bundle, path, msg); | ||
|
||
const size_t data_len = lo_bundle_length(bundle); | ||
|
||
char *serial = (char *)lo_bundle_serialise(bundle, NULL, NULL); | ||
|
||
int i; | ||
|
||
if (recording) | ||
{ | ||
char buff[255]; | ||
|
||
/* Max out here */ | ||
snprintf(buff,255,"%d %lf\n",data_len, diff); | ||
|
||
fputs(buff, pFile); | ||
|
||
fwrite((const void *)serial, sizeof(char),data_len, pFile); | ||
|
||
fputs("\n", pFile); | ||
|
||
fflush(pFile); | ||
} | ||
|
||
lo_timetag_now(&start_time); | ||
|
||
return 1; | ||
} | ||
|
||
int start_handler(const char *path, const char *types, lo_arg **argv, int argc, | ||
void *data, void *user_data) | ||
{ | ||
recording = 1; | ||
printf("Started Recording\n"); | ||
lo_timetag_now(&start_time); | ||
|
||
return 0; | ||
} | ||
|
||
int stop_handler(const char *path, const char *types, lo_arg **argv, int argc, | ||
void *data, void *user_data) | ||
{ | ||
recording = 0; | ||
printf("Stopped Recording\n"); | ||
lo_timetag_now(&start_time); | ||
|
||
return 0; | ||
} | ||
|
||
int quit_handler(const char *path, const char *types, lo_arg **argv, int argc, | ||
void *data, void *user_data) | ||
{ | ||
done = 1; | ||
printf("quiting\n\n"); | ||
fflush(stdout); | ||
fclose(pFile); | ||
|
||
return 0; | ||
} | ||
|
||
/* vi:set ts=8 sts=4 sw=4: */ |