2009-12-25 01:59:39 +01:00
|
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
/* Copyright (C) 2008 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 "Engine.H"
|
|
|
|
|
|
|
|
|
|
#include "../Mixer.H" // for process()
|
|
|
|
|
|
|
|
|
|
/* This is the home of the JACK process callback */
|
|
|
|
|
|
|
|
|
|
// #include "const.h"
|
2010-02-01 07:25:16 +01:00
|
|
|
|
#include "debug.h"
|
|
|
|
|
#include "Thread.H"
|
2009-12-25 01:59:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-16 09:00:47 +01:00
|
|
|
|
Engine::Engine ( void (*process_callback)(nframes_t nframes, void *), void *user_data ) : _thread( "RT" )
|
2009-12-25 01:59:39 +01:00
|
|
|
|
{
|
2010-01-16 09:00:47 +01:00
|
|
|
|
_process_callback = process_callback;
|
2010-01-30 09:35:32 +01:00
|
|
|
|
_process_callback_user_data = user_data;
|
|
|
|
|
_buffer_size_callback = 0;
|
2009-12-25 01:59:39 +01:00
|
|
|
|
_buffers_dropped = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Engine::~Engine ( )
|
|
|
|
|
{
|
2010-01-24 03:53:56 +01:00
|
|
|
|
deactivate();
|
2009-12-25 01:59:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-30 09:35:32 +01:00
|
|
|
|
void
|
|
|
|
|
Engine::buffer_size_callback ( void ( *buffer_size_callback ) ( nframes_t, void * ), void *user_data )
|
|
|
|
|
{
|
|
|
|
|
_buffer_size_callback = buffer_size_callback;
|
|
|
|
|
_buffer_size_callback_user_data = user_data;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-25 01:59:39 +01:00
|
|
|
|
/*************/
|
|
|
|
|
/* Callbacks */
|
|
|
|
|
/*************/
|
|
|
|
|
|
|
|
|
|
/* THREAD: RT */
|
|
|
|
|
/** This is the jack xrun callback */
|
|
|
|
|
int
|
|
|
|
|
Engine::xrun ( void )
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* THREAD: RT */
|
|
|
|
|
void
|
|
|
|
|
Engine::freewheel ( bool starting )
|
|
|
|
|
{
|
|
|
|
|
if ( starting )
|
|
|
|
|
DMESSAGE( "entering freewheeling mode" );
|
|
|
|
|
else
|
|
|
|
|
DMESSAGE( "leaving freewheeling mode" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* THREAD: RT (non-RT) */
|
|
|
|
|
int
|
2010-01-30 09:35:32 +01:00
|
|
|
|
Engine::buffer_size ( nframes_t nframes )
|
2009-12-25 01:59:39 +01:00
|
|
|
|
{
|
2010-01-30 09:35:32 +01:00
|
|
|
|
/* JACK calls this in the RT thread, even though it's a
|
|
|
|
|
* non-realtime operation. This mucks up our ability to do
|
|
|
|
|
* THREAD_ASSERT, so just lie and say this is the UI thread... */
|
|
|
|
|
|
|
|
|
|
_thread.set( "UI" );
|
|
|
|
|
|
|
|
|
|
_buffer_size_callback( nframes, _buffer_size_callback_user_data );
|
|
|
|
|
|
|
|
|
|
_thread.set( "RT" );
|
2009-12-25 01:59:39 +01:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* THREAD: RT */
|
|
|
|
|
int
|
|
|
|
|
Engine::process ( nframes_t nframes )
|
|
|
|
|
{
|
|
|
|
|
/* FIXME: wrong place for this */
|
|
|
|
|
_thread.set( "RT" );
|
|
|
|
|
|
2010-01-30 09:35:32 +01:00
|
|
|
|
if ( ! trylock() )
|
2009-12-25 01:59:39 +01:00
|
|
|
|
{
|
2010-01-30 09:35:32 +01:00
|
|
|
|
/* the data structures we need to access here (tracks and
|
|
|
|
|
* their ports, but not track contents) may be in an
|
|
|
|
|
* inconsistent state at the moment. Just punt and drop this
|
|
|
|
|
* buffer. */
|
|
|
|
|
++_buffers_dropped;
|
|
|
|
|
return 0;
|
2009-12-25 01:59:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
2010-01-30 09:35:32 +01:00
|
|
|
|
_process_callback(nframes, _process_callback_user_data);
|
|
|
|
|
|
|
|
|
|
unlock();
|
|
|
|
|
|
2009-12-25 01:59:39 +01:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* TRHEAD: RT */
|
|
|
|
|
void
|
|
|
|
|
Engine::thread_init ( void )
|
|
|
|
|
{
|
|
|
|
|
_thread.set( "RT" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* THREAD: RT */
|
|
|
|
|
void
|
|
|
|
|
Engine::shutdown ( void )
|
|
|
|
|
{
|
|
|
|
|
}
|