diff --git a/timeline/src/Control_Sequence.C b/timeline/src/Control_Sequence.C index 503052e..9fda53a 100644 --- a/timeline/src/Control_Sequence.C +++ b/timeline/src/Control_Sequence.C @@ -601,7 +601,7 @@ Control_Sequence::menu_cb ( const Fl_Menu_ *m ) void Control_Sequence::connect_osc ( void ) { - timeline->osc_thread->lock(); + timeline->osc_receive_thread->lock(); if ( _persistent_osc_connections.size() ) { @@ -623,7 +623,7 @@ Control_Sequence::connect_osc ( void ) /* header()->outputs_indicator->value( _osc_output() && _osc_output()->connected() ); */ - timeline->osc_thread->unlock(); + timeline->osc_receive_thread->unlock(); } void diff --git a/timeline/src/OSC_Receive_Thread.C b/timeline/src/OSC_Receive_Thread.C new file mode 100644 index 0000000..c1ed8a1 --- /dev/null +++ b/timeline/src/OSC_Receive_Thread.C @@ -0,0 +1,87 @@ + +/*******************************************************************************/ +/* 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_Receive_Thread.H" + +#include "Timeline.H" + +#include +#include + +#include "debug.h" + +#include "OSC/Endpoint.H" + +extern Timeline *timeline; + +OSC_Receive_Thread::OSC_Receive_Thread ( ) +{ + // _thread.init(); + _shutdown = false; +} + +OSC_Receive_Thread::~OSC_Receive_Thread ( ) +{ + lock(); + if ( _shutdown == false ) + { + _shutdown = true; + _thread.join(); + } + unlock(); +} + + +void +OSC_Receive_Thread::start ( ) +{ + _thread.clone( &OSC_Receive_Thread::process, this ); +} + +void +OSC_Receive_Thread::join ( ) +{ + _thread.join(); +} + +void +OSC_Receive_Thread::process ( void ) +{ + _thread.name( "OSC_Receive" ); + + DMESSAGE( "OSC Thread starting" ); + + while ( !_shutdown ) + { + timeline->osc->wait(20); + } + + DMESSAGE( "OSC Thread stopping." ); +} + +void * +OSC_Receive_Thread::process ( void *v ) +{ + OSC_Receive_Thread *t = (OSC_Receive_Thread*)v; + + t->process(); + + return NULL; +} + diff --git a/timeline/src/OSC_Thread.H b/timeline/src/OSC_Receive_Thread.H similarity index 94% rename from timeline/src/OSC_Thread.H rename to timeline/src/OSC_Receive_Thread.H index d678028..2d2e046 100644 --- a/timeline/src/OSC_Thread.H +++ b/timeline/src/OSC_Receive_Thread.H @@ -22,7 +22,7 @@ #include "Thread.H" #include "Mutex.H" -class OSC_Thread : public Mutex +class OSC_Receive_Thread : public Mutex { Thread _thread; /* io thread */ @@ -30,9 +30,9 @@ class OSC_Thread : public Mutex public: - OSC_Thread ( ); + OSC_Receive_Thread ( ); - virtual ~OSC_Thread ( ); + virtual ~OSC_Receive_Thread ( ); void join ( void ); void shutdown ( void ) { _shutdown = true; } diff --git a/timeline/src/OSC_Thread.C b/timeline/src/OSC_Transmit_Thread.C similarity index 83% rename from timeline/src/OSC_Thread.C rename to timeline/src/OSC_Transmit_Thread.C index 70fe6fe..95dd18b 100644 --- a/timeline/src/OSC_Thread.C +++ b/timeline/src/OSC_Transmit_Thread.C @@ -17,7 +17,7 @@ /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /*******************************************************************************/ -#include "OSC_Thread.H" +#include "OSC_Transmit_Thread.H" #include "Timeline.H" @@ -30,13 +30,13 @@ extern Timeline *timeline; -OSC_Thread::OSC_Thread ( ) +OSC_Transmit_Thread::OSC_Transmit_Thread ( ) { // _thread.init(); _shutdown = false; } -OSC_Thread::~OSC_Thread ( ) +OSC_Transmit_Thread::~OSC_Transmit_Thread ( ) { lock(); if ( _shutdown == false ) @@ -49,29 +49,29 @@ OSC_Thread::~OSC_Thread ( ) void -OSC_Thread::start ( ) +OSC_Transmit_Thread::start ( ) { - _thread.clone( &OSC_Thread::process, this ); + _thread.clone( &OSC_Transmit_Thread::process, this ); } void -OSC_Thread::join ( ) +OSC_Transmit_Thread::join ( ) { _thread.join(); } void -OSC_Thread::process ( void ) +OSC_Transmit_Thread::process ( void ) { - _thread.name( "OSC" ); + _thread.name( "OSC_Transmit" ); DMESSAGE( "OSC Thread starting" ); while ( !_shutdown ) { + if ( trylock() ) { - timeline->osc->check(); timeline->process_osc(); unlock(); } @@ -83,9 +83,9 @@ OSC_Thread::process ( void ) } void * -OSC_Thread::process ( void *v ) +OSC_Transmit_Thread::process ( void *v ) { - OSC_Thread *t = (OSC_Thread*)v; + OSC_Transmit_Thread *t = (OSC_Transmit_Thread*)v; t->process(); diff --git a/timeline/src/OSC_Transmit_Thread.H b/timeline/src/OSC_Transmit_Thread.H new file mode 100644 index 0000000..37c3e0d --- /dev/null +++ b/timeline/src/OSC_Transmit_Thread.H @@ -0,0 +1,42 @@ + +/*******************************************************************************/ +/* 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_Transmit_Thread : public Mutex +{ + Thread _thread; /* io thread */ + + volatile bool _shutdown; + +public: + + OSC_Transmit_Thread ( ); + + virtual ~OSC_Transmit_Thread ( ); + + void join ( void ); + void shutdown ( void ) { _shutdown = true; } + void start ( void ); + void process ( void ); + static void *process ( void * ); +}; diff --git a/timeline/src/Timeline.C b/timeline/src/Timeline.C index a2d8591..9e97ec5 100644 --- a/timeline/src/Timeline.C +++ b/timeline/src/Timeline.C @@ -53,7 +53,7 @@ #include "TLE.H" /* */ -#include "OSC_Thread.H" + #include "OSC/Endpoint.H" #include @@ -612,8 +612,10 @@ Timeline::ntracks ( void ) const Timeline::~Timeline ( ) { - delete osc_thread; - osc_thread = 0; + delete osc_transmit_thread; + osc_transmit_thread = 0; + delete osc_receive_thread; + osc_receive_thread = 0; delete osc; osc = 0; } @@ -627,7 +629,8 @@ Timeline::Timeline ( int X, int Y, int W, int H, const char* L ) : BASE( X, Y, W play_cursor_track = NULL; _created_new_takes = 0; - osc_thread = 0; + osc_transmit_thread = 0; + osc_receive_thread = 0; _sample_rate = 44100; box( FL_FLAT_BOX ); @@ -2179,11 +2182,18 @@ Timeline::init_osc ( const char *osc_port ) // osc->start(); - if ( ! osc_thread ) + if ( ! osc_transmit_thread ) { - osc_thread = new OSC_Thread(); + osc_transmit_thread = new OSC_Transmit_Thread(); - osc_thread->start(); + osc_transmit_thread->start(); + } + + if ( ! osc_receive_thread ) + { + osc_receive_thread = new OSC_Receive_Thread(); + + osc_receive_thread->start(); } return 0; @@ -2262,7 +2272,7 @@ Timeline::update_osc_connection_state ( void ) void Timeline::process_osc ( void ) { - THREAD_ASSERT( OSC ); + THREAD_ASSERT( OSC_Transmit ); sequence_lock.rdlock(); diff --git a/timeline/src/Timeline.H b/timeline/src/Timeline.H index 022c3af..d9c940f 100644 --- a/timeline/src/Timeline.H +++ b/timeline/src/Timeline.H @@ -31,7 +31,8 @@ #include #include -#include "OSC_Thread.H" +#include "OSC_Transmit_Thread.H" +#include "OSC_Receive_Thread.H" class Fl_Scroll; class Fl_Pack; @@ -136,7 +137,8 @@ public: void damage_sequence ( void ); OSC::Endpoint *osc; - OSC_Thread *osc_thread; + OSC_Transmit_Thread *osc_transmit_thread; + OSC_Receive_Thread *osc_receive_thread; void process_osc ( void ); #undef Bars diff --git a/timeline/wscript b/timeline/wscript index 2a46a59..9f486cb 100644 --- a/timeline/wscript +++ b/timeline/wscript @@ -76,7 +76,8 @@ src/Engine/Record_DS.C src/Engine/Timeline.C src/Engine/Track.C src/NSM.C -src/OSC_Thread.C +src/OSC_Transmit_Thread.C +src/OSC_Receive_Thread.C src/Project.C src/Sequence.C src/Sequence_Point.C