Commit 522fd2b7 authored by sletz's avatar sletz
Browse files

rebase from trunk 3482:3502

git-svn-id: http://subversion.jackaudio.org/jack/jack2/branches/libjacknet@3503 0c269be4-1314-0410-8aa9-9f06e86f4224
parent 416928c2
......@@ -25,6 +25,10 @@ Paul Davis
Jackdmp changes log
---------------------------
2009-04-08 Stephane Letz <letz@grame.fr>
* Native MIDI backend (JackCoreMidiDriver, JackWinMMEDriver) in progress.
2009-04-03 Stephane Letz <letz@grame.fr>
* Simplify JackClient RT code, jack_thread_wait API marked deprecated."
......
......@@ -78,7 +78,8 @@ namespace Jack
fprintf(file, "set multiplot\n");
fprintf(file, "set grid\n");
fprintf(file, "set title \"Audio adapter timing\"\n");
fprintf(file, "set title \"Audio adapter timing: host [rate = %.1f kHz buffer = %d frames] adapter [rate = %.1f kHz buffer = %d frames] \"\n"
,float(fHostSampleRate)/1000.f, fHostBufferSize, float(fAdaptedSampleRate)/1000.f, fAdaptedBufferSize);
fprintf(file, "set xlabel \"audio cycles\"\n");
fprintf(file, "set ylabel \"frames\"\n");
fprintf(file, "plot ");
......@@ -109,7 +110,8 @@ namespace Jack
fprintf(file, "set multiplot\n");
fprintf(file, "set grid\n");
fprintf(file, "set title \"Audio adapter timing\"\n");
fprintf(file, "set title \"Audio adapter timing: host [rate = %.1f kHz buffer = %d frames] adapter [rate = %.1f kHz buffer = %d frames] \"\n"
,float(fHostSampleRate)/1000.f, fHostBufferSize, float(fAdaptedSampleRate)/1000.f, fAdaptedBufferSize);
fprintf(file, "set xlabel \"audio cycles\"\n");
fprintf(file, "set ylabel \"resampling ratio\"\n");
fprintf(file, "plot ");
......@@ -140,7 +142,8 @@ namespace Jack
fprintf(file, "set multiplot\n");
fprintf(file, "set grid\n");
fprintf(file, "set title \"Audio adapter timing\"\n");
fprintf(file, "set title \"Audio adapter timing: host [rate = %.1f kHz buffer = %d frames] adapter [rate = %.1f kHz buffer = %d frames] \"\n"
,float(fHostSampleRate)/1000.f, fHostBufferSize, float(fAdaptedSampleRate)/1000.f, fAdaptedBufferSize);
fprintf(file, "set xlabel \"audio cycles\"\n");
fprintf(file, "set ylabel \"frames\"\n");
fprintf(file, "plot ");
......
/*
Copyright (C) 2001 Paul Davis
Copyright (C) 2004-2008 GramefClientControl.
Copyright (C) 2004-2008 Grame.
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
......
......@@ -120,12 +120,12 @@ void JackClient::SetupDriverSync(bool freewheel)
jack_log("JackClient::SetupDriverSync driver sem in flush mode");
fSynchroTable[AUDIO_DRIVER_REFNUM].SetFlush(true);
fSynchroTable[FREEWHEEL_DRIVER_REFNUM].SetFlush(true);
fSynchroTable[LOOPBACK_DRIVER_REFNUM].SetFlush(true);
fSynchroTable[MIDI_DRIVER_REFNUM].SetFlush(true);
} else {
jack_log("JackClient::SetupDriverSync driver sem in normal mode");
fSynchroTable[AUDIO_DRIVER_REFNUM].SetFlush(false);
fSynchroTable[FREEWHEEL_DRIVER_REFNUM].SetFlush(false);
fSynchroTable[LOOPBACK_DRIVER_REFNUM].SetFlush(false);
fSynchroTable[MIDI_DRIVER_REFNUM].SetFlush(false);
}
}
......
......@@ -58,8 +58,8 @@ bool JackConnectionManager::IsLoopPathAux(int ref1, int ref2) const
|| ref2 == AUDIO_DRIVER_REFNUM
|| ref1 == FREEWHEEL_DRIVER_REFNUM
|| ref2 == FREEWHEEL_DRIVER_REFNUM
|| ref1 == LOOPBACK_DRIVER_REFNUM
|| ref2 == LOOPBACK_DRIVER_REFNUM) {
|| ref1 == MIDI_DRIVER_REFNUM
|| ref2 == MIDI_DRIVER_REFNUM) {
return false;
} else if (ref1 == ref2) { // Same refnum
return true;
......
......@@ -47,10 +47,10 @@
#define CLIENT_NUM 64
#endif
#define AUDIO_DRIVER_REFNUM 0 // Audio driver is initialized first, it will get the refnum 0
#define FREEWHEEL_DRIVER_REFNUM 1 // Freewheel driver is initialized second, it will get the refnum 1
#define LOOPBACK_DRIVER_REFNUM 2 // Loopback driver is initialized third, it will get the refnum 2
#define REAL_REFNUM LOOPBACK_DRIVER_REFNUM + 1 // Real clients start at LOOPBACK_DRIVER_REFNUM + 1
#define AUDIO_DRIVER_REFNUM 0 // Audio driver is initialized first, it will get the refnum 0
#define FREEWHEEL_DRIVER_REFNUM 1 // Freewheel driver is initialized second, it will get the refnum 1
#define MIDI_DRIVER_REFNUM 2 // Loopback driver is initialized third, it will get the refnum 2
#define REAL_REFNUM MIDI_DRIVER_REFNUM + 1 // Real clients start at MIDI_DRIVER_REFNUM + 1
#define JACK_DEFAULT_SERVER_NAME "default"
......
......@@ -42,6 +42,7 @@
#include "JackControlAPI.h"
#include "JackLockedEngine.h"
#include "JackConstants.h"
#include "JackDriverLoader.h"
using namespace Jack;
......@@ -95,6 +96,7 @@ struct jackctl_driver
jack_driver_desc_t * desc_ptr;
JSList * parameters;
JSList * set_parameters;
JackDriverInfo* info;
};
struct jackctl_internal
......@@ -1161,4 +1163,23 @@ EXPORT bool jackctl_server_unload_internal(
}
}
EXPORT bool jackctl_server_load_slave(jackctl_server * server_ptr, jackctl_driver * driver_ptr)
{
if (server_ptr->engine != NULL) {
driver_ptr->info = server_ptr->engine->AddSlave(driver_ptr->desc_ptr, driver_ptr->set_parameters);
return (driver_ptr->info != 0);
} else {
return false;
}
}
EXPORT bool jackctl_server_unload_slave(jackctl_server * server_ptr, jackctl_driver * driver_ptr)
{
if (server_ptr->engine != NULL) {
server_ptr->engine->RemoveSlave(driver_ptr->info);
return true;
} else {
return false;
}
}
......@@ -219,6 +219,13 @@ EXPORT bool jackctl_server_load_internal(
EXPORT bool jackctl_server_unload_internal(
jackctl_server * server,
jackctl_internal * internal);
EXPORT bool jackctl_server_load_slave(jackctl_server_t * server,
jackctl_driver_t * driver);
EXPORT bool jackctl_server_unload_slave(jackctl_server_t * server,
jackctl_driver_t * driver);
#if 0
{ /* Adjust editor indent */
......
......@@ -68,7 +68,7 @@ int JackDriver::Open()
int refnum = -1;
if (fEngine->ClientInternalOpen(fClientControl.fName, &refnum, &fEngineControl, &fGraphManager, this, false) != 0) {
jack_error("Cannot allocate internal client for audio driver");
jack_error("Cannot allocate internal client for driver");
return -1;
}
......@@ -79,6 +79,46 @@ int JackDriver::Open()
return 0;
}
int JackDriver::Open (bool capturing,
bool playing,
int inchannels,
int outchannels,
bool monitor,
const char* capture_driver_name,
const char* playback_driver_name,
jack_nframes_t capture_latency,
jack_nframes_t playback_latency)
{
jack_log("JackDriver::Open capture_driver_name = %s", capture_driver_name);
jack_log("JackDriver::Open playback_driver_name = %s", playback_driver_name);
int refnum = -1;
if (fEngine->ClientInternalOpen(fClientControl.fName, &refnum, &fEngineControl, &fGraphManager, this, false) != 0) {
jack_error("Cannot allocate internal client for driver");
return -1;
}
fClientControl.fRefNum = refnum;
fClientControl.fActive = true;
fCaptureLatency = capture_latency;
fPlaybackLatency = playback_latency;
assert(strlen(capture_driver_name) < JACK_CLIENT_NAME_SIZE);
assert(strlen(playback_driver_name) < JACK_CLIENT_NAME_SIZE);
strcpy(fCaptureDriverName, capture_driver_name);
strcpy(fPlaybackDriverName, playback_driver_name);
fEngineControl->fPeriodUsecs = jack_time_t(1000000.f / fEngineControl->fSampleRate * fEngineControl->fBufferSize); // in microsec
if (!fEngineControl->fTimeOut)
fEngineControl->fTimeOutUsecs = jack_time_t(2.f * fEngineControl->fPeriodUsecs);
//fGraphManager->SetBufferSize(fEngineControl->fBufferSize);
fGraphManager->DirectConnect(fClientControl.fRefNum, fClientControl.fRefNum); // Connect driver to itself for "sync" mode
SetupDriverSync(fClientControl.fRefNum, false);
return 0;
}
int JackDriver::Open(jack_nframes_t buffer_size,
jack_nframes_t samplerate,
bool capturing,
......@@ -96,7 +136,7 @@ int JackDriver::Open(jack_nframes_t buffer_size,
int refnum = -1;
if (fEngine->ClientInternalOpen(fClientControl.fName, &refnum, &fEngineControl, &fGraphManager, this, false) != 0) {
jack_error("Cannot allocate internal client for audio driver");
jack_error("Cannot allocate internal client for driver");
return -1;
}
......
......@@ -50,6 +50,17 @@ class SERVER_EXPORT JackDriverInterface
{}
virtual int Open() = 0;
virtual int Open (bool capturing,
bool playing,
int inchannels,
int outchannels,
bool monitor,
const char* capture_driver_name,
const char* playback_driver_name,
jack_nframes_t capture_latency,
jack_nframes_t playback_latency) = 0;
virtual int Open(jack_nframes_t buffer_size,
jack_nframes_t samplerate,
bool capturing,
......@@ -142,6 +153,17 @@ class SERVER_EXPORT JackDriver : public JackDriverClientInterface
int ProcessSlaves();
virtual int Open();
virtual int Open (bool capturing,
bool playing,
int inchannels,
int outchannels,
bool monitor,
const char* capture_driver_name,
const char* playback_driver_name,
jack_nframes_t capture_latency,
jack_nframes_t playback_latency);
virtual int Open(jack_nframes_t buffer_size,
jack_nframes_t samplerate,
bool capturing,
......
......@@ -800,7 +800,8 @@ Jack::JackDriverClientInterface* JackDriverInfo::Open(jack_driver_desc_t* driver
jack_error("no initialize function in shared object %s\n", driver_desc->file);
return NULL;
}
return fInitialize(engine, synchro, params);
fBackend = fInitialize(engine, synchro, params);
return fBackend;
}
......@@ -42,6 +42,7 @@ class JackDriverInfo
driverInitialize fInitialize;
DRIVER_HANDLE fHandle;
Jack::JackDriverClientInterface* fBackend;
public:
......@@ -54,6 +55,11 @@ class JackDriverInfo
}
Jack::JackDriverClientInterface* Open(jack_driver_desc_t* driver_desc, Jack::JackLockedEngine*, Jack::JackSynchro*, const JSList*);
Jack::JackDriverClientInterface* GetBackend()
{
return fBackend;
}
};
......
/*
Copyright (C) 2009 Grame.
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
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
(at your option) any later version.
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "JackSystemDeps.h"
#include "JackMidiDriver.h"
#include "JackTime.h"
#include "JackError.h"
#include "JackEngineControl.h"
#include "JackPort.h"
#include "JackGraphManager.h"
#include "JackException.h"
#include <assert.h>
namespace Jack
{
JackMidiDriver::JackMidiDriver(const char* name, const char* alias, JackLockedEngine* engine, JackSynchro* table)
: JackDriver(name, alias, engine, table),
fCaptureChannels(0),
fPlaybackChannels(0)
{
for (int i = 0; i < DRIVER_PORT_NUM; i++) {
fRingBuffer[i] = NULL;
}
}
JackMidiDriver::~JackMidiDriver()
{
for (int i = 0; i < fCaptureChannels; i++) {
if (fRingBuffer[i])
jack_ringbuffer_free(fRingBuffer[i]);
}
}
int JackMidiDriver::Open(bool capturing,
bool playing,
int inchannels,
int outchannels,
bool monitor,
const char* capture_driver_name,
const char* playback_driver_name,
jack_nframes_t capture_latency,
jack_nframes_t playback_latency)
{
fCaptureChannels = inchannels;
fPlaybackChannels = outchannels;
for (int i = 0; i < fCaptureChannels; i++) {
fRingBuffer[i] = jack_ringbuffer_create(sizeof(float) * BUFFER_SIZE_MAX);
}
return JackDriver::Open(capturing, playing, inchannels, outchannels, monitor, capture_driver_name, playback_driver_name, capture_latency, playback_latency);
}
int JackMidiDriver::Attach()
{
JackPort* port;
jack_port_id_t port_index;
char name[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE];
char alias[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE];
unsigned long port_flags = JackPortIsOutput | JackPortIsPhysical | JackPortIsTerminal;
int i;
jack_log("JackMidiDriver::Attach fBufferSize = %ld fSampleRate = %ld", fEngineControl->fBufferSize, fEngineControl->fSampleRate);
for (i = 0; i < fCaptureChannels; i++) {
snprintf(alias, sizeof(alias) - 1, "%s:%s:out%d", fAliasName, fCaptureDriverName, i + 1);
snprintf(name, sizeof(name) - 1, "%s:capture_%d", fClientControl.fName, i + 1);
if ((port_index = fGraphManager->AllocatePort(fClientControl.fRefNum, name, JACK_DEFAULT_MIDI_TYPE, (JackPortFlags)port_flags, fEngineControl->fBufferSize)) == NO_PORT) {
jack_error("driver: cannot register port for %s", name);
return -1;
}
port = fGraphManager->GetPort(port_index);
port->SetAlias(alias);
fCapturePortList[i] = port_index;
jack_log("JackMidiDriver::Attach fCapturePortList[i] port_index = %ld", port_index);
}
port_flags = JackPortIsInput | JackPortIsPhysical | JackPortIsTerminal;
for (i = 0; i < fPlaybackChannels; i++) {
snprintf(alias, sizeof(alias) - 1, "%s:%s:in%d", fAliasName, fPlaybackDriverName, i + 1);
snprintf(name, sizeof(name) - 1, "%s:playback_%d", fClientControl.fName, i + 1);
if ((port_index = fGraphManager->AllocatePort(fClientControl.fRefNum, name, JACK_DEFAULT_MIDI_TYPE, (JackPortFlags)port_flags, fEngineControl->fBufferSize)) == NO_PORT) {
jack_error("driver: cannot register port for %s", name);
return -1;
}
port = fGraphManager->GetPort(port_index);
port->SetAlias(alias);
fPlaybackPortList[i] = port_index;
jack_log("JackMidiDriver::Attach fPlaybackPortList[i] port_index = %ld", port_index);
}
return 0;
}
int JackMidiDriver::Detach()
{
int i;
jack_log("JackMidiDriver::Detach");
for (i = 0; i < fCaptureChannels; i++) {
fGraphManager->ReleasePort(fClientControl.fRefNum, fCapturePortList[i]);
}
for (i = 0; i < fPlaybackChannels; i++) {
fGraphManager->ReleasePort(fClientControl.fRefNum, fPlaybackPortList[i]);
}
return 0;
}
int JackMidiDriver::Read()
{
return 0;
}
int JackMidiDriver::Write()
{
return 0;
}
int JackMidiDriver::ProcessNull()
{
return 0;
}
int JackMidiDriver::Process()
{
// Read input buffers for the current cycle
if (Read() < 0) {
jack_error("JackMidiDriver::Process: read error, skip cycle");
return 0; // Skip cycle, but continue processing...
}
fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable);
if (fEngineControl->fSyncMode) {
if (fGraphManager->SuspendRefNum(&fClientControl, fSynchroTable, fEngineControl->fTimeOutUsecs) < 0) {
jack_error("JackFreewheelDriver::ProcessSync SuspendRefNum error");
return -1;
}
}
// Write output buffers for the current cycle
if (Write() < 0) {
jack_error("JackMidiDriver::Process: write error, skip cycle");
return 0; // Skip cycle, but continue processing...
}
return 0;
}
JackMidiBuffer* JackMidiDriver::GetInputBuffer(int port_index)
{
assert(fCapturePortList[port_index]);
return (JackMidiBuffer*)fGraphManager->GetBuffer(fCapturePortList[port_index], fEngineControl->fBufferSize);
}
JackMidiBuffer* JackMidiDriver::GetOutputBuffer(int port_index)
{
assert(fPlaybackPortList[port_index]);
return (JackMidiBuffer*)fGraphManager->GetBuffer(fPlaybackPortList[port_index], fEngineControl->fBufferSize);
}
} // end of namespace
/*
Copyright (C) 2009 Grame
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; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __JackMidiDriver__
#define __JackMidiDriver__
#include "JackDriver.h"
#include "JackMidiPort.h"
#include "JackLockedEngine.h"
#include "ringbuffer.h"
namespace Jack
{
/*!
\brief The base class for MIDI drivers: drivers with MIDI ports.
*/
class SERVER_EXPORT JackMidiDriver : public JackDriver
{
protected:
int fCaptureChannels;
int fPlaybackChannels;
jack_ringbuffer_t* fRingBuffer[DRIVER_PORT_NUM];
jack_port_id_t fCapturePortList[DRIVER_PORT_NUM];
jack_port_id_t fPlaybackPortList[DRIVER_PORT_NUM];
JackMidiBuffer* GetInputBuffer(int port_index);
JackMidiBuffer* GetOutputBuffer(int port_index);
public:
JackMidiDriver(const char* name, const char* alias, JackLockedEngine* engine, JackSynchro* table);
virtual ~JackMidiDriver();
virtual int Open(bool capturing,
bool playing,
int inchannels,
int outchannels,
bool monitor,
const char* capture_driver_name,
const char* playback_driver_name,
jack_nframes_t capture_latency,
jack_nframes_t playback_latency);
virtual int Process();
virtual int ProcessNull();
virtual int Attach();
virtual int Detach();
virtual int Read();
virtual int Write();
};
} // end of namespace
#endif
......@@ -27,7 +27,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
namespace Jack
{
void JackMidiBuffer::Reset(jack_nframes_t nframes)
SERVER_EXPORT void JackMidiBuffer::Reset(jack_nframes_t nframes)
{
/* This line ate 1 hour of my life... dsbaikov */
this->nframes = nframes;
......@@ -37,7 +37,7 @@ void JackMidiBuffer::Reset(jack_nframes_t nframes)
mix_index = 0;
}
jack_shmsize_t JackMidiBuffer::MaxEventSize() const
SERVER_EXPORT jack_shmsize_t JackMidiBuffer::MaxEventSize() const
{
assert (((jack_shmsize_t) - 1) < 0); // jack_shmsize_t should be signed
jack_shmsize_t left = buffer_size - (sizeof(JackMidiBuffer) + sizeof(JackMidiEvent) * (event_count + 1) + write_pos);
......@@ -48,7 +48,7 @@ jack_shmsize_t JackMidiBuffer::MaxEventSize() const
return left;
}
jack_midi_data_t* JackMidiBuffer::ReserveEvent(jack_nframes_t time, jack_shmsize_t size)
SERVER_EXPORT jack_midi_data_t* JackMidiBuffer::ReserveEvent(jack_nframes_t time, jack_shmsize_t size)
{
jack_shmsize_t space = MaxEventSize();
if (space == 0 || size > space) {
......
......@@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "types.h"
#include "JackConstants.h"
#include "JackPlatformPlug.h"
#include <stddef.h>
/** Type for raw event data contained in @ref jack_midi_event_t. */
......@@ -42,7 +43,7 @@ struct jack_midi_event_t
namespace Jack
{
struct JackMidiEvent
struct SERVER_EXPORT JackMidiEvent
{
// Most MIDI events are < 4 bytes in size, so we can save a lot, storing them inplace.
enum { INLINE_SIZE_MAX = sizeof(jack_shmsize_t) };
......
......@@ -22,7 +22,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "JackServerGlobals.h"
#include "JackTime.h"
#include "JackFreewheelDriver.h"
#include "JackLoopbackDriver.h"
#include "JackThreadedDriver.h"
#include "JackGlobals.h"
#include "JackLockedEngine.h"
......@@ -50,10 +49,8 @@ JackServer::JackServer(bool sync, bool temporary, long timeout, bool rt, long pr
fEngineControl = new JackEngineControl(sync, temporary, timeout, rt, priority, verbose, server_name);
fEngine = new JackLockedEngine(fGraphManager, GetSynchroTable(), fEngineControl);
fFreewheelDriver = new JackThreadedDriver(new JackFreewheelDriver(fEngine, GetSynchroTable()));
fLoopbackDriver = new JackLoopbackDriver(fEngine, GetSynchroTable());
fAudioDriver = NULL;
fFreewheel = false;
fLoopback = loopback;
JackServerGlobals::fInstance = this; // Unique instance
JackServerGlobals::fUserCount = 1; // One user
jack_verbose = verbose;
......@@ -64,7 +61,6 @@ JackServer::~JackServer()
delete fGraphManager;
delete fAudioDriver;
delete fFreewheelDriver;
delete fLoopbackDriver;
delete fEngine;
delete fEngineControl;
}
......@@ -94,35 +90,17 @@ int JackServer::Open(jack_driver_desc_t* driver_desc, JSList* driver_params)
goto fail_close4;
}