Timeline: Run OSC output in a dedicated thread.

This commit is contained in:
Jonathan Moore Liles 2012-02-24 01:59:26 -08:00
parent 5a0527c623
commit 62c8490c17
7 changed files with 178 additions and 28 deletions

View File

@ -76,7 +76,7 @@ Control_Sequence::Control_Sequence ( Track *track ) : Sequence( 0 )
Control_Sequence::~Control_Sequence ( ) Control_Sequence::~Control_Sequence ( )
{ {
Fl::remove_timeout( &Control_Sequence::process_osc, this ); // Fl::remove_timeout( &Control_Sequence::process_osc, this );
Loggable::block_start(); Loggable::block_start();
@ -110,8 +110,6 @@ Control_Sequence::init ( void )
interpolation( Linear ); interpolation( Linear );
frequency( 10 ); frequency( 10 );
Fl::add_timeout( _interval, &Control_Sequence::process_osc, this );
} }
@ -140,7 +138,7 @@ Control_Sequence::get_unjournaled ( Log_Entry &e ) const
free( path ); free( path );
free( peer ); free( peer );
} }
e.add( ":frequency", frequency() ); /* e.add( ":frequency", frequency() ); */
} }
void void
@ -173,8 +171,8 @@ Control_Sequence::set ( Log_Entry &e )
name( v ); name( v );
else if ( ! strcmp( ":interpolation", s ) ) else if ( ! strcmp( ":interpolation", s ) )
interpolation( (curve_type_e)atoi( v ) ); interpolation( (curve_type_e)atoi( v ) );
else if ( ! strcmp( ":frequency", s ) ) /* else if ( ! strcmp( ":frequency", s ) ) */
frequency( atoi( v ) ); /* frequency( atoi( v ) ); */
else if ( ! strcmp( ":osc_peer", s ) ) else if ( ! strcmp( ":osc_peer", s ) )
{ {
_osc_connected_peer = strdup( v ); _osc_connected_peer = strdup( v );
@ -380,18 +378,18 @@ Control_Sequence::menu_cb ( const Fl_Menu_ *m )
interpolation( Linear ); interpolation( Linear );
else if ( ! strcmp( picked, "Interpolation/None" ) ) else if ( ! strcmp( picked, "Interpolation/None" ) )
interpolation( None ); interpolation( None );
else if ( ! strcmp( picked, "Frequency/1Hz" ) ) /* else if ( ! strcmp( picked, "Frequency/1Hz" ) ) */
frequency( 1 ); /* frequency( 1 ); */
else if ( ! strcmp( picked, "Frequency/5Hz" ) ) /* else if ( ! strcmp( picked, "Frequency/5Hz" ) ) */
frequency( 5 ); /* frequency( 5 ); */
else if ( ! strcmp( picked, "Frequency/10Hz" ) ) /* else if ( ! strcmp( picked, "Frequency/10Hz" ) ) */
frequency( 10 ); /* frequency( 10 ); */
else if ( ! strcmp( picked, "Frequency/20Hz" ) ) /* else if ( ! strcmp( picked, "Frequency/20Hz" ) ) */
frequency( 20 ); /* frequency( 20 ); */
else if ( ! strcmp( picked, "Frequency/30Hz" ) ) /* else if ( ! strcmp( picked, "Frequency/30Hz" ) ) */
frequency( 30 ); /* frequency( 30 ); */
else if ( ! strcmp( picked, "Frequency/60Hz" ) ) /* else if ( ! strcmp( picked, "Frequency/60Hz" ) ) */
frequency( 60 ); /* frequency( 60 ); */
else if ( ! strcmp( picked, "/Rename" ) ) else if ( ! strcmp( picked, "/Rename" ) )
{ {
@ -435,8 +433,6 @@ Control_Sequence::process_osc ( void *v )
void void
Control_Sequence::process_osc ( void ) Control_Sequence::process_osc ( void )
{ {
Fl::repeat_timeout( _interval, &Control_Sequence::process_osc, this );
if ( _osc_output && _osc_output->connected() ) if ( _osc_output && _osc_output->connected() )
{ {
sample_t buf[1]; sample_t buf[1];
@ -500,12 +496,12 @@ Control_Sequence::handle ( int m )
menu.add( "Interpolation/None", 0, 0, 0, FL_MENU_RADIO | ( interpolation() == None ? FL_MENU_VALUE : 0 ) ); menu.add( "Interpolation/None", 0, 0, 0, FL_MENU_RADIO | ( interpolation() == None ? FL_MENU_VALUE : 0 ) );
menu.add( "Interpolation/Linear", 0, 0, 0, FL_MENU_RADIO | ( interpolation() == Linear ? FL_MENU_VALUE : 0 ) ); menu.add( "Interpolation/Linear", 0, 0, 0, FL_MENU_RADIO | ( interpolation() == Linear ? FL_MENU_VALUE : 0 ) );
menu.add( "Frequency/1Hz", 0, 0, 0, FL_MENU_RADIO | ( frequency() == 1 ? FL_MENU_VALUE : 0 ) ); /* menu.add( "Frequency/1Hz", 0, 0, 0, FL_MENU_RADIO | ( frequency() == 1 ? FL_MENU_VALUE : 0 ) ); */
menu.add( "Frequency/5Hz", 0, 0, 0, FL_MENU_RADIO | ( frequency() == 5 ? FL_MENU_VALUE : 0 ) ); /* menu.add( "Frequency/5Hz", 0, 0, 0, FL_MENU_RADIO | ( frequency() == 5 ? FL_MENU_VALUE : 0 ) ); */
menu.add( "Frequency/10Hz", 0, 0, 0, FL_MENU_RADIO | ( frequency() == 10 ? FL_MENU_VALUE : 0 ) ); /* menu.add( "Frequency/10Hz", 0, 0, 0, FL_MENU_RADIO | ( frequency() == 10 ? FL_MENU_VALUE : 0 ) ); */
menu.add( "Frequency/20Hz", 0, 0, 0, FL_MENU_RADIO | ( frequency() == 20 ? FL_MENU_VALUE : 0 ) ); /* menu.add( "Frequency/20Hz", 0, 0, 0, FL_MENU_RADIO | ( frequency() == 20 ? FL_MENU_VALUE : 0 ) ); */
menu.add( "Frequency/30Hz", 0, 0, 0, FL_MENU_RADIO | ( frequency() == 30 ? FL_MENU_VALUE : 0 ) ); /* menu.add( "Frequency/30Hz", 0, 0, 0, FL_MENU_RADIO | ( frequency() == 30 ? FL_MENU_VALUE : 0 ) ); */
menu.add( "Frequency/60Hz", 0, 0, 0, FL_MENU_RADIO | ( frequency() == 60 ? FL_MENU_VALUE : 0 ) ); /* menu.add( "Frequency/60Hz", 0, 0, 0, FL_MENU_RADIO | ( frequency() == 60 ? FL_MENU_VALUE : 0 ) ); */
menu.add( "Rename", 0, 0, 0 ); menu.add( "Rename", 0, 0, 0 );

View File

@ -62,8 +62,6 @@ private:
static void menu_cb ( Fl_Widget *w, void *v ); static void menu_cb ( Fl_Widget *w, void *v );
void menu_cb ( const Fl_Menu_ *m ); void menu_cb ( const Fl_Menu_ *m );
static void process_osc ( void *v );
void process_osc ( void );
float _rate; float _rate;
@ -85,6 +83,9 @@ protected:
public: public:
static void process_osc ( void *v );
void process_osc ( void );
void connect_osc ( void ); void connect_osc ( void );
static bool draw_with_gradient; static bool draw_with_gradient;

71
timeline/src/OSC_Thread.C Normal file
View File

@ -0,0 +1,71 @@
/*******************************************************************************/
/* Copyright (C) 2012 Jonathan Moore Liles */
/* */
/* 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; see the file COPYING. If not,write to the Free Software */
/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/*******************************************************************************/
#include "OSC_Thread.H"
#include "Timeline.H"
#include <stdlib.h>
#include <unistd.h>
extern Timeline *timeline;
OSC_Thread::OSC_Thread ( )
{
// _thread.init();
}
OSC_Thread::~OSC_Thread ( )
{
}
void
OSC_Thread::start ( )
{
_thread.clone( &OSC_Thread::process, this );
}
void
OSC_Thread::process ( void )
{
_thread.name( "OSC" );
for ( ;; )
{
usleep( 100 * 1000 );
lock();
timeline->process_osc();
unlock();
}
}
void *
OSC_Thread::process ( void *v )
{
OSC_Thread *t = (OSC_Thread*)v;
t->process();
return NULL;
}

38
timeline/src/OSC_Thread.H Normal file
View File

@ -0,0 +1,38 @@
/*******************************************************************************/
/* Copyright (C) 2012 Jonathan Moore Liles */
/* */
/* 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; see the file COPYING. If not,write to the Free Software */
/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/*******************************************************************************/
#pragma once
#include "Thread.H"
#include "Mutex.H"
class OSC_Thread : public Mutex
{
Thread _thread; /* io thread */
public:
OSC_Thread ( );
virtual ~OSC_Thread ( );
void start ( void );
void process ( void );
static void *process ( void * );
};

View File

@ -51,6 +51,8 @@
#include "TLE.H" #include "TLE.H"
/* */ /* */
#include "OSC_Thread.H"
#include "NSM.H" #include "NSM.H"
extern NSM_Client *nsm; extern NSM_Client *nsm;
@ -394,6 +396,7 @@ Timeline::Timeline ( int X, int Y, int W, int H, const char* L ) : BASE( X, Y, W
{ {
Loggable::snapshot_callback( &Timeline::snapshot, this ); Loggable::snapshot_callback( &Timeline::snapshot, this );
osc_thread = 0;
_sample_rate = 0; _sample_rate = 0;
box( FL_FLAT_BOX ); box( FL_FLAT_BOX );
@ -1458,8 +1461,12 @@ Timeline::add_track ( Track *track )
engine->lock(); engine->lock();
osc_thread->lock();
tracks->add( track ); tracks->add( track );
osc_thread->unlock();
engine->unlock(); engine->unlock();
/* FIXME: why is this necessary? doesn't the above add do DAMAGE_CHILD? */ /* FIXME: why is this necessary? doesn't the above add do DAMAGE_CHILD? */
@ -1475,9 +1482,13 @@ Timeline::remove_track ( Track *track )
engine->lock(); engine->lock();
osc_thread->lock();
/* FIXME: what to do about track contents? */ /* FIXME: what to do about track contents? */
tracks->remove( track ); tracks->remove( track );
osc_thread->unlock();
engine->unlock(); engine->unlock();
/* FIXME: why is this necessary? doesn't the above add do DAMAGE_CHILD? */ /* FIXME: why is this necessary? doesn't the above add do DAMAGE_CHILD? */
@ -1585,6 +1596,13 @@ Timeline::init_osc ( const char *osc_port )
/* poll so we can keep OSC handlers running in the GUI thread and avoid extra sync */ /* poll so we can keep OSC handlers running in the GUI thread and avoid extra sync */
Fl::add_timeout( OSC_INTERVAL, &Timeline::check_osc, this ); Fl::add_timeout( OSC_INTERVAL, &Timeline::check_osc, this );
if ( ! osc_thread )
{
osc_thread = new OSC_Thread();
osc_thread->start();
}
return 0; return 0;
} }
@ -1664,6 +1682,7 @@ Timeline::discover_peers ( void )
c->connect_osc(); c->connect_osc();
} }
} }
} }
void void
@ -1697,5 +1716,22 @@ Timeline::add_osc_peers_to_menu ( Fl_Menu_Button *m, const char *prefix )
osc->list_peers( &Timeline::peer_callback, this ); osc->list_peers( &Timeline::peer_callback, this );
} }
/* runs in the OSC thread... */
void
Timeline::process_osc ( void )
{
THREAD_ASSERT( OSC );
/* reconnect OSC signals */
for ( int i = tracks->children(); i-- ; )
{
Track *t = (Track*)tracks->child( i );
for ( int j = t->control->children(); j--; )
{
Control_Sequence *c = (Control_Sequence*)t->control->child( j );
c->process_osc();
}
}
}

View File

@ -32,6 +32,7 @@
#include <list> #include <list>
#include "OSC/Endpoint.H" #include "OSC/Endpoint.H"
#include "OSC_Thread.H"
class Fl_Scroll; class Fl_Scroll;
class Fl_Pack; class Fl_Pack;
@ -120,7 +121,9 @@ class Timeline : public Fl_Single_Window, public RWLock
public: public:
OSC::Endpoint *osc; OSC::Endpoint *osc;
OSC_Thread *osc_thread;
void process_osc ( void );
#undef Bars #undef Bars
#undef Beats #undef Beats
#undef None #undef None
@ -253,6 +256,7 @@ public:
private: private:
static void snapshot ( void *v ) { ((Timeline*)v)->snapshot(); } static void snapshot ( void *v ) { ((Timeline*)v)->snapshot(); }
void snapshot ( void ); void snapshot ( void );

View File

@ -581,8 +581,12 @@ Track::remove ( Control_Sequence *t )
engine->lock(); engine->lock();
timeline->osc_thread->lock();
control->remove( t ); control->remove( t );
timeline->osc_thread->unlock();
engine->unlock(); engine->unlock();
resize(); resize();