Browse Source

Timeline: Split OSC send and receive functionality into different threads.

tags/non-daw-v1.3.0
Jonathan Moore Liles 2 years ago
parent
commit
ad6dbba07c
8 changed files with 169 additions and 27 deletions
  1. +2
    -2
      timeline/src/Control_Sequence.C
  2. +87
    -0
      timeline/src/OSC_Receive_Thread.C
  3. +3
    -3
      timeline/src/OSC_Receive_Thread.H
  4. +11
    -11
      timeline/src/OSC_Transmit_Thread.C
  5. +42
    -0
      timeline/src/OSC_Transmit_Thread.H
  6. +18
    -8
      timeline/src/Timeline.C
  7. +4
    -2
      timeline/src/Timeline.H
  8. +2
    -1
      timeline/wscript

+ 2
- 2
timeline/src/Control_Sequence.C View File

@@ -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


+ 87
- 0
timeline/src/OSC_Receive_Thread.C View File

@@ -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 <stdlib.h>
#include <unistd.h>

#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;
}


timeline/src/OSC_Thread.H → timeline/src/OSC_Receive_Thread.H View File

@@ -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; }

timeline/src/OSC_Thread.C → timeline/src/OSC_Transmit_Thread.C View File

@@ -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();


+ 42
- 0
timeline/src/OSC_Transmit_Thread.H View File

@@ -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 * );
};

+ 18
- 8
timeline/src/Timeline.C View File

@@ -53,7 +53,7 @@
#include "TLE.H"
/* */

#include "OSC_Thread.H"
#include "OSC/Endpoint.H"

#include <unistd.h>
@@ -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_transmit_thread = new OSC_Transmit_Thread();
osc_transmit_thread->start();
}

if ( ! osc_receive_thread )
{
osc_thread = new OSC_Thread();
osc_receive_thread = new OSC_Receive_Thread();
osc_thread->start();
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();



+ 4
- 2
timeline/src/Timeline.H View File

@@ -31,7 +31,8 @@
#include <assert.h>
#include <list>

#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


+ 2
- 1
timeline/wscript View File

@@ -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


Loading…
Cancel
Save