2 Copyright (C) 2001 Paul Davis
3 Copyright (C) 2008 Romain Moret at Grame
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "JackNetDriver.h"
21 #include "JackEngineControl.h"
22 #include "JackGraphManager.h"
23 #include "JackWaitThreadedDriver.h"
30 JackNetDriver::JackNetDriver ( const char* name
, const char* alias
, JackLockedEngine
* engine
, JackSynchro
* table
,
31 const char* ip
, int port
, int mtu
, int midi_input_ports
, int midi_output_ports
,
32 char* net_name
, uint transport_sync
, char network_mode
)
33 : JackAudioDriver ( name
, alias
, engine
, table
), JackNetSlaveInterface ( ip
, port
)
35 jack_log ( "JackNetDriver::JackNetDriver ip %s, port %d", ip
, port
);
37 // Use the hostname if no name parameter was given
38 if ( strcmp ( net_name
, "" ) == 0 )
39 GetHostName ( net_name
, JACK_CLIENT_NAME_SIZE
);
42 fParams
.fSendMidiChannels
= midi_input_ports
;
43 fParams
.fReturnMidiChannels
= midi_output_ports
;
44 strcpy ( fParams
.fName
, net_name
);
45 fSocket
.GetName ( fParams
.fSlaveNetName
);
46 fParams
.fTransportSync
= transport_sync
;
47 fParams
.fNetworkMode
= network_mode
;
48 fSendTransportData
.fState
= -1;
49 fReturnTransportData
.fState
= -1;
50 fLastTransportState
= -1;
51 fLastTimebaseMaster
= -1;
52 fMidiCapturePortList
= NULL
;
53 fMidiPlaybackPortList
= NULL
;
60 JackNetDriver::~JackNetDriver()
62 delete[] fMidiCapturePortList
;
63 delete[] fMidiPlaybackPortList
;
69 //open, close, attach and detach------------------------------------------------------
70 int JackNetDriver::Open ( jack_nframes_t buffer_size
, jack_nframes_t samplerate
, bool capturing
, bool playing
,
71 int inchannels
, int outchannels
, bool monitor
,
72 const char* capture_driver_name
, const char* playback_driver_name
,
73 jack_nframes_t capture_latency
, jack_nframes_t playback_latency
)
75 if ( JackAudioDriver::Open ( buffer_size
,
85 playback_latency
) == 0 )
87 fEngineControl
->fPeriod
= 0;
88 fEngineControl
->fComputation
= 500 * 1000;
89 fEngineControl
->fConstraint
= 500 * 1000;
98 int JackNetDriver::Close()
105 return JackDriver::Close();
108 // Attach and Detach are defined as empty methods: port allocation is done when driver actually start (that is in Init)
109 int JackNetDriver::Attach()
114 int JackNetDriver::Detach()
119 //init and restart--------------------------------------------------------------------
121 JackNetDriver is wrapped in a JackWaitThreadedDriver decorator that behaves
122 as a "dummy driver, until Init method returns.
125 bool JackNetDriver::Initialize()
127 jack_log("JackNetDriver::Initialize()");
129 //new loading, but existing socket, restart the driver
130 if (fSocket
.IsSocket()) {
131 jack_info("Restarting driver...");
135 //set the parameters to send
136 fParams
.fSendAudioChannels
= fCaptureChannels
;
137 fParams
.fReturnAudioChannels
= fPlaybackChannels
;
138 fParams
.fSlaveSyncMode
= fEngineControl
->fSyncMode
;
140 //display some additional infos
141 jack_info ( "NetDriver started in %s mode %s Master's transport sync.",
142 ( fParams
.fSlaveSyncMode
) ? "sync" : "async", ( fParams
.fTransportSync
) ? "with" : "without" );
145 if ( !JackNetSlaveInterface::Init() )
148 //set global parameters
151 //allocate midi ports lists
152 fMidiCapturePortList
= new jack_port_id_t
[fParams
.fSendMidiChannels
];
153 fMidiPlaybackPortList
= new jack_port_id_t
[fParams
.fReturnMidiChannels
];
154 assert ( fMidiCapturePortList
);
155 assert ( fMidiPlaybackPortList
);
157 //register jack ports
158 if ( AllocPorts() != 0 )
160 jack_error ( "Can't allocate ports." );
164 //init done, display parameters
165 SessionParamsDisplay ( &fParams
);
171 plot_name
= string ( fParams
.fName
);
172 plot_name
+= string ( "_slave" );
173 plot_name
+= ( fEngineControl
->fSyncMode
) ? string ( "_sync" ) : string ( "_async" );
174 switch ( fParams
.fNetworkMode
)
177 plot_name
+= string ( "_slow" );
181 plot_name
+= string ( "_normal" );
185 plot_name
+= string ( "_fast" );
188 fNetTimeMon
= new JackGnuPlotMonitor
<float> ( 128, 5, plot_name
);
189 string net_time_mon_fields
[] =
191 string ( "sync decoded" ),
192 string ( "end of read" ),
193 string ( "start of write" ),
194 string ( "sync send" ),
195 string ( "end of write" )
197 string net_time_mon_options
[] =
199 string ( "set xlabel \"audio cycles\"" ),
200 string ( "set ylabel \"% of audio cycle\"" )
202 fNetTimeMon
->SetPlotFile ( net_time_mon_options
, 2, net_time_mon_fields
, 5 );
204 //driver parametering
205 JackAudioDriver::SetBufferSize ( fParams
.fPeriodSize
);
206 JackAudioDriver::SetSampleRate ( fParams
.fSampleRate
);
208 JackDriver::NotifyBufferSize ( fParams
.fPeriodSize
);
209 JackDriver::NotifySampleRate ( fParams
.fSampleRate
);
211 //transport engine parametering
212 fEngineControl
->fTransport
.SetNetworkSync ( fParams
.fTransportSync
);
216 void JackNetDriver::FreeAll()
222 delete fNetAudioCaptureBuffer
;
223 delete fNetAudioPlaybackBuffer
;
224 delete fNetMidiCaptureBuffer
;
225 delete fNetMidiPlaybackBuffer
;
226 delete[] fMidiCapturePortList
;
227 delete[] fMidiPlaybackPortList
;
231 fNetAudioCaptureBuffer
= NULL
;
232 fNetAudioPlaybackBuffer
= NULL
;
233 fNetMidiCaptureBuffer
= NULL
;
234 fNetMidiPlaybackBuffer
= NULL
;
235 fMidiCapturePortList
= NULL
;
236 fMidiPlaybackPortList
= NULL
;
244 //jack ports and buffers--------------------------------------------------------------
245 int JackNetDriver::AllocPorts()
247 jack_log ( "JackNetDriver::AllocPorts fBufferSize = %ld fSampleRate = %ld", fEngineControl
->fBufferSize
, fEngineControl
->fSampleRate
);
250 jack_port_id_t port_id
;
251 char name
[JACK_CLIENT_NAME_SIZE
+ JACK_PORT_NAME_SIZE
];
252 char alias
[JACK_CLIENT_NAME_SIZE
+ JACK_PORT_NAME_SIZE
];
253 unsigned long port_flags
;
254 int audio_port_index
;
255 uint midi_port_index
;
256 jack_latency_range_t range
;
259 port_flags
= JackPortIsOutput
| JackPortIsPhysical
| JackPortIsTerminal
;
260 for ( audio_port_index
= 0; audio_port_index
< fCaptureChannels
; audio_port_index
++ )
262 snprintf ( alias
, sizeof ( alias
) - 1, "%s:%s:out%d", fAliasName
, fCaptureDriverName
, audio_port_index
+ 1 );
263 snprintf ( name
, sizeof ( name
) - 1, "%s:capture_%d", fClientControl
.fName
, audio_port_index
+ 1 );
264 if ( ( port_id
= fGraphManager
->AllocatePort ( fClientControl
.fRefNum
, name
, JACK_DEFAULT_AUDIO_TYPE
,
265 static_cast<JackPortFlags
> ( port_flags
), fEngineControl
->fBufferSize
) ) == NO_PORT
)
267 jack_error ( "driver: cannot register port for %s", name
);
270 port
= fGraphManager
->GetPort ( port_id
);
271 port
->SetAlias ( alias
);
273 range
.min
= range
.max
= fEngineControl
->fBufferSize
;
274 port
->SetLatencyRange(JackCaptureLatency
, &range
);
275 fCapturePortList
[audio_port_index
] = port_id
;
276 jack_log ( "JackNetDriver::AllocPorts() fCapturePortList[%d] audio_port_index = %ld fPortLatency = %ld", audio_port_index
, port_id
, port
->GetLatency() );
278 port_flags
= JackPortIsInput
| JackPortIsPhysical
| JackPortIsTerminal
;
279 for ( audio_port_index
= 0; audio_port_index
< fPlaybackChannels
; audio_port_index
++ )
281 snprintf ( alias
, sizeof ( alias
) - 1, "%s:%s:in%d", fAliasName
, fPlaybackDriverName
, audio_port_index
+ 1 );
282 snprintf ( name
, sizeof ( name
) - 1, "%s:playback_%d",fClientControl
.fName
, audio_port_index
+ 1 );
283 if ( ( port_id
= fGraphManager
->AllocatePort ( fClientControl
.fRefNum
, name
, JACK_DEFAULT_AUDIO_TYPE
,
284 static_cast<JackPortFlags
> ( port_flags
), fEngineControl
->fBufferSize
) ) == NO_PORT
)
286 jack_error ( "driver: cannot register port for %s", name
);
289 port
= fGraphManager
->GetPort ( port_id
);
290 port
->SetAlias ( alias
);
292 switch ( fParams
.fNetworkMode
)
295 range
.min
= range
.max
= (fEngineControl
->fSyncMode
) ? 0 : fEngineControl
->fBufferSize
;
298 range
.min
= range
.max
= (fEngineControl
->fBufferSize
+ (fEngineControl
->fSyncMode
) ? 0 : fEngineControl
->fBufferSize
);
301 range
.min
= range
.max
= (2 * fEngineControl
->fBufferSize
+ (fEngineControl
->fSyncMode
) ? 0 : fEngineControl
->fBufferSize
);
304 port
->SetLatencyRange(JackPlaybackLatency
, &range
);
305 fPlaybackPortList
[audio_port_index
] = port_id
;
306 jack_log ( "JackNetDriver::AllocPorts() fPlaybackPortList[%d] audio_port_index = %ld fPortLatency = %ld", audio_port_index
, port_id
, port
->GetLatency() );
309 port_flags
= JackPortIsOutput
| JackPortIsPhysical
| JackPortIsTerminal
;
310 for ( midi_port_index
= 0; midi_port_index
< fParams
.fSendMidiChannels
; midi_port_index
++ )
312 snprintf ( alias
, sizeof ( alias
) - 1, "%s:%s:out%d", fAliasName
, fCaptureDriverName
, midi_port_index
+ 1 );
313 snprintf ( name
, sizeof ( name
) - 1, "%s:midi_capture_%d", fClientControl
.fName
, midi_port_index
+ 1 );
314 if ( ( port_id
= fGraphManager
->AllocatePort ( fClientControl
.fRefNum
, name
, JACK_DEFAULT_MIDI_TYPE
,
315 static_cast<JackPortFlags
> ( port_flags
), fEngineControl
->fBufferSize
) ) == NO_PORT
)
317 jack_error ( "driver: cannot register port for %s", name
);
320 port
= fGraphManager
->GetPort ( port_id
);
322 range
.min
= range
.max
= fEngineControl
->fBufferSize
;
323 port
->SetLatencyRange(JackCaptureLatency
, &range
);
324 fMidiCapturePortList
[midi_port_index
] = port_id
;
325 jack_log ( "JackNetDriver::AllocPorts() fMidiCapturePortList[%d] midi_port_index = %ld fPortLatency = %ld", midi_port_index
, port_id
, port
->GetLatency() );
328 port_flags
= JackPortIsInput
| JackPortIsPhysical
| JackPortIsTerminal
;
329 for ( midi_port_index
= 0; midi_port_index
< fParams
.fReturnMidiChannels
; midi_port_index
++ )
331 snprintf ( alias
, sizeof ( alias
) - 1, "%s:%s:in%d", fAliasName
, fPlaybackDriverName
, midi_port_index
+ 1 );
332 snprintf ( name
, sizeof ( name
) - 1, "%s:midi_playback_%d", fClientControl
.fName
, midi_port_index
+ 1 );
333 if ( ( port_id
= fGraphManager
->AllocatePort ( fClientControl
.fRefNum
, name
, JACK_DEFAULT_MIDI_TYPE
,
334 static_cast<JackPortFlags
> ( port_flags
), fEngineControl
->fBufferSize
) ) == NO_PORT
)
336 jack_error ( "driver: cannot register port for %s", name
);
339 port
= fGraphManager
->GetPort ( port_id
);
341 switch ( fParams
.fNetworkMode
)
344 range
.min
= range
.max
= (fEngineControl
->fSyncMode
) ? 0 : fEngineControl
->fBufferSize
;
347 range
.min
= range
.max
= (fEngineControl
->fBufferSize
+ (fEngineControl
->fSyncMode
) ? 0 : fEngineControl
->fBufferSize
);
350 range
.min
= range
.max
= (2 * fEngineControl
->fBufferSize
+ (fEngineControl
->fSyncMode
) ? 0 : fEngineControl
->fBufferSize
);
353 port
->SetLatencyRange(JackPlaybackLatency
, &range
);
354 fMidiPlaybackPortList
[midi_port_index
] = port_id
;
355 jack_log ( "JackNetDriver::AllocPorts() fMidiPlaybackPortList[%d] midi_port_index = %ld fPortLatency = %ld", midi_port_index
, port_id
, port
->GetLatency() );
361 int JackNetDriver::FreePorts()
363 jack_log ( "JackNetDriver::FreePorts" );
365 int audio_port_index
;
366 uint midi_port_index
;
367 for ( audio_port_index
= 0; audio_port_index
< fCaptureChannels
; audio_port_index
++ )
368 if (fCapturePortList
[audio_port_index
] > 0)
369 fGraphManager
->ReleasePort ( fClientControl
.fRefNum
, fCapturePortList
[audio_port_index
] );
370 for ( audio_port_index
= 0; audio_port_index
< fPlaybackChannels
; audio_port_index
++ )
371 if (fPlaybackPortList
[audio_port_index
] > 0)
372 fGraphManager
->ReleasePort ( fClientControl
.fRefNum
, fPlaybackPortList
[audio_port_index
] );
373 for ( midi_port_index
= 0; midi_port_index
< fParams
.fSendMidiChannels
; midi_port_index
++ )
374 if (fMidiCapturePortList
[midi_port_index
] > 0)
375 fGraphManager
->ReleasePort ( fClientControl
.fRefNum
, fMidiCapturePortList
[midi_port_index
] );
376 for ( midi_port_index
= 0; midi_port_index
< fParams
.fReturnMidiChannels
; midi_port_index
++ )
377 if (fMidiPlaybackPortList
[midi_port_index
] > 0)
378 fGraphManager
->ReleasePort ( fClientControl
.fRefNum
, fMidiPlaybackPortList
[midi_port_index
] );
382 JackMidiBuffer
* JackNetDriver::GetMidiInputBuffer ( int port_index
)
384 return static_cast<JackMidiBuffer
*> ( fGraphManager
->GetBuffer ( fMidiCapturePortList
[port_index
], fEngineControl
->fBufferSize
) );
387 JackMidiBuffer
* JackNetDriver::GetMidiOutputBuffer ( int port_index
)
389 return static_cast<JackMidiBuffer
*> ( fGraphManager
->GetBuffer ( fMidiPlaybackPortList
[port_index
], fEngineControl
->fBufferSize
) );
392 //transport---------------------------------------------------------------------------
393 void JackNetDriver::DecodeTransportData()
395 //is there a new timebase master on the net master ?
396 // - release timebase master only if it's a non-conditional request
397 // - no change or no request : don't do anything
398 // - conditional request : don't change anything too, the master will know if this slave is actually the timebase master
401 if ( fSendTransportData
.fTimebaseMaster
== TIMEBASEMASTER
)
403 fEngineControl
->fTransport
.GetTimebaseMaster ( refnum
, conditional
);
405 fEngineControl
->fTransport
.ResetTimebase ( refnum
);
406 jack_info ( "The NetMaster is now the new timebase master." );
409 //is there a transport state change to handle ?
410 if ( fSendTransportData
.fNewState
&& ( fSendTransportData
.fState
!= fEngineControl
->fTransport
.GetState() ) )
413 switch ( fSendTransportData
.fState
)
415 case JackTransportStopped
:
416 fEngineControl
->fTransport
.SetCommand ( TransportCommandStop
);
417 jack_info ( "Master stops transport." );
420 case JackTransportStarting
:
421 fEngineControl
->fTransport
.RequestNewPos ( &fSendTransportData
.fPosition
);
422 fEngineControl
->fTransport
.SetCommand ( TransportCommandStart
);
423 jack_info ( "Master starts transport frame = %d", fSendTransportData
.fPosition
.frame
);
426 case JackTransportRolling
:
427 //fEngineControl->fTransport.SetCommand ( TransportCommandStart );
428 fEngineControl
->fTransport
.SetState ( JackTransportRolling
);
429 jack_info ( "Master is rolling." );
435 void JackNetDriver::EncodeTransportData()
438 //is there a timebase master change ?
441 fEngineControl->fTransport.GetTimebaseMaster ( refnum, conditional );
442 if ( refnum != fLastTimebaseMaster )
444 //timebase master has released its function
447 fReturnTransportData.fTimebaseMaster = RELEASE_TIMEBASEMASTER;
448 jack_info ( "Sending a timebase master release request." );
450 //there is a new timebase master
453 fReturnTransportData.fTimebaseMaster = ( conditional ) ? CONDITIONAL_TIMEBASEMASTER : TIMEBASEMASTER;
454 jack_info ( "Sending a %s timebase master request.", ( conditional ) ? "conditional" : "non-conditional" );
456 fLastTimebaseMaster = refnum;
459 fReturnTransportData.fTimebaseMaster = NO_CHANGE;
462 //update transport state and position
463 fReturnTransportData
.fState
= fEngineControl
->fTransport
.Query ( &fReturnTransportData
.fPosition
);
465 //is it a new state (that the master need to know...) ?
466 fReturnTransportData
.fNewState
= (( fReturnTransportData
.fState
== JackTransportNetStarting
) &&
467 ( fReturnTransportData
.fState
!= fLastTransportState
) &&
468 ( fReturnTransportData
.fState
!= fSendTransportData
.fState
) );
469 if ( fReturnTransportData
.fNewState
)
470 jack_info ( "Sending '%s'.", GetTransportState ( fReturnTransportData
.fState
) );
471 fLastTransportState
= fReturnTransportData
.fState
;
474 //driver processes--------------------------------------------------------------------
475 int JackNetDriver::Read()
477 uint midi_port_index
;
478 uint audio_port_index
;
481 for ( midi_port_index
= 0; midi_port_index
< fParams
.fSendMidiChannels
; midi_port_index
++ )
482 fNetMidiCaptureBuffer
->SetBuffer ( midi_port_index
, GetMidiInputBuffer ( midi_port_index
) );
483 for ( audio_port_index
= 0; audio_port_index
< fParams
.fSendAudioChannels
; audio_port_index
++ )
484 fNetAudioCaptureBuffer
->SetBuffer ( audio_port_index
, GetInputBuffer ( audio_port_index
) );
490 //receive sync (launch the cycle)
491 if ( SyncRecv() == SOCKET_ERROR
)
496 fRcvSyncUst
= GetMicroSeconds();
500 //if there is an error, don't return -1, it will skip Write() and the network error probably won't be identified
504 fNetTimeMon
->Add ( ( ( float ) ( GetMicroSeconds() - fRcvSyncUst
) / ( float ) fEngineControl
->fPeriodUsecs
) * 100.f
);
506 //audio, midi or sync if driver is late
507 if ( DataRecv() == SOCKET_ERROR
)
510 //take the time at the beginning of the cycle
511 JackDriver::CycleTakeBeginTime();
514 fNetTimeMon
->Add ( ( ( float ) ( GetMicroSeconds() - fRcvSyncUst
) / ( float ) fEngineControl
->fPeriodUsecs
) * 100.f
);
520 int JackNetDriver::Write()
522 uint midi_port_index
;
523 int audio_port_index
;
526 for ( midi_port_index
= 0; midi_port_index
< fParams
.fReturnMidiChannels
; midi_port_index
++ )
527 fNetMidiPlaybackBuffer
->SetBuffer ( midi_port_index
, GetMidiOutputBuffer ( midi_port_index
) );
528 for ( audio_port_index
= 0; audio_port_index
< fPlaybackChannels
; audio_port_index
++ )
529 fNetAudioPlaybackBuffer
->SetBuffer ( audio_port_index
, GetOutputBuffer ( audio_port_index
) );
532 fNetTimeMon
->Add ( ( ( float ) ( GetMicroSeconds() - fRcvSyncUst
) / ( float ) fEngineControl
->fPeriodUsecs
) * 100.f
);
539 if ( SyncSend() == SOCKET_ERROR
)
543 fNetTimeMon
->Add ( ( ( float ) ( GetMicroSeconds() - fRcvSyncUst
) / ( float ) fEngineControl
->fPeriodUsecs
) * 100.f
);
547 if ( DataSend() == SOCKET_ERROR
)
551 fNetTimeMon
->AddLast ( ( ( float ) ( GetMicroSeconds() - fRcvSyncUst
) / ( float ) fEngineControl
->fPeriodUsecs
) * 100.f
);
557 //driver loader-----------------------------------------------------------------------
563 SERVER_EXPORT jack_driver_desc_t
* driver_get_descriptor ()
565 jack_driver_desc_t
* desc
= ( jack_driver_desc_t
* ) calloc ( 1, sizeof ( jack_driver_desc_t
) );
567 strcpy ( desc
->name
, "net" ); // size MUST be less then JACK_DRIVER_NAME_MAX + 1
568 strcpy ( desc
->desc
, "netjack slave backend component" ); // size MUST be less then JACK_DRIVER_PARAM_DESC + 1
571 desc
->params
= ( jack_driver_param_desc_t
* ) calloc ( desc
->nparams
, sizeof ( jack_driver_param_desc_t
) );
574 strcpy ( desc
->params
[i
].name
, "multicast_ip" );
575 desc
->params
[i
].character
= 'a';
576 desc
->params
[i
].type
= JackDriverParamString
;
577 strcpy ( desc
->params
[i
].value
.str
, DEFAULT_MULTICAST_IP
);
578 strcpy ( desc
->params
[i
].short_desc
, "Multicast Address" );
579 strcpy ( desc
->params
[i
].long_desc
, desc
->params
[i
].short_desc
);
582 strcpy ( desc
->params
[i
].name
, "udp_net_port" );
583 desc
->params
[i
].character
= 'p';
584 desc
->params
[i
].type
= JackDriverParamInt
;
585 desc
->params
[i
].value
.i
= DEFAULT_PORT
;
586 strcpy ( desc
->params
[i
].short_desc
, "UDP port" );
587 strcpy ( desc
->params
[i
].long_desc
, desc
->params
[i
].short_desc
);
590 strcpy ( desc
->params
[i
].name
, "mtu" );
591 desc
->params
[i
].character
= 'M';
592 desc
->params
[i
].type
= JackDriverParamInt
;
593 desc
->params
[i
].value
.i
= DEFAULT_MTU
;
594 strcpy ( desc
->params
[i
].short_desc
, "MTU to the master" );
595 strcpy ( desc
->params
[i
].long_desc
, desc
->params
[i
].short_desc
);
598 strcpy ( desc
->params
[i
].name
, "input_ports" );
599 desc
->params
[i
].character
= 'C';
600 desc
->params
[i
].type
= JackDriverParamInt
;
601 desc
->params
[i
].value
.i
= 2;
602 strcpy ( desc
->params
[i
].short_desc
, "Number of audio input ports" );
603 strcpy ( desc
->params
[i
].long_desc
, desc
->params
[i
].short_desc
);
606 strcpy ( desc
->params
[i
].name
, "output_ports" );
607 desc
->params
[i
].character
= 'P';
608 desc
->params
[i
].type
= JackDriverParamInt
;
609 desc
->params
[i
].value
.i
= 2;
610 strcpy ( desc
->params
[i
].short_desc
, "Number of audio output ports" );
611 strcpy ( desc
->params
[i
].long_desc
, desc
->params
[i
].short_desc
);
614 strcpy ( desc
->params
[i
].name
, "midi_in_ports" );
615 desc
->params
[i
].character
= 'i';
616 desc
->params
[i
].type
= JackDriverParamInt
;
617 desc
->params
[i
].value
.i
= 0;
618 strcpy ( desc
->params
[i
].short_desc
, "Number of midi input ports" );
619 strcpy ( desc
->params
[i
].long_desc
, desc
->params
[i
].short_desc
);
622 strcpy ( desc
->params
[i
].name
, "midi_out_ports" );
623 desc
->params
[i
].character
= 'o';
624 desc
->params
[i
].type
= JackDriverParamUInt
;
625 desc
->params
[i
].value
.i
= 0;
626 strcpy ( desc
->params
[i
].short_desc
, "Number of midi output ports" );
627 strcpy ( desc
->params
[i
].long_desc
, desc
->params
[i
].short_desc
);
630 strcpy ( desc
->params
[i
].name
, "client_name" );
631 desc
->params
[i
].character
= 'n';
632 desc
->params
[i
].type
= JackDriverParamString
;
633 strcpy ( desc
->params
[i
].value
.str
, "'hostname'" );
634 strcpy ( desc
->params
[i
].short_desc
, "Name of the jack client" );
635 strcpy ( desc
->params
[i
].long_desc
, desc
->params
[i
].short_desc
);
638 strcpy ( desc
->params
[i
].name
, "transport_sync" );
639 desc
->params
[i
].character
= 't';
640 desc
->params
[i
].type
= JackDriverParamUInt
;
641 desc
->params
[i
].value
.ui
= 1U;
642 strcpy ( desc
->params
[i
].short_desc
, "Sync transport with master's" );
643 strcpy ( desc
->params
[i
].long_desc
, desc
->params
[i
].short_desc
);
646 strcpy ( desc
->params
[i
].name
, "mode" );
647 desc
->params
[i
].character
= 'm';
648 desc
->params
[i
].type
= JackDriverParamString
;
649 strcpy ( desc
->params
[i
].value
.str
, "slow" );
650 strcpy ( desc
->params
[i
].short_desc
, "Slow, Normal or Fast mode." );
651 strcpy ( desc
->params
[i
].long_desc
, desc
->params
[i
].short_desc
);
656 SERVER_EXPORT
Jack::JackDriverClientInterface
* driver_initialize ( Jack::JackLockedEngine
* engine
, Jack::JackSynchro
* table
, const JSList
* params
)
658 char multicast_ip
[16];
659 strcpy ( multicast_ip
, DEFAULT_MULTICAST_IP
);
660 char net_name
[JACK_CLIENT_NAME_SIZE
+ 1];
661 int udp_port
= DEFAULT_PORT
;
662 int mtu
= DEFAULT_MTU
;
663 uint transport_sync
= 1;
664 jack_nframes_t period_size
= 128;
665 jack_nframes_t sample_rate
= 48000;
666 int audio_capture_ports
= 2;
667 int audio_playback_ports
= 2;
668 int midi_input_ports
= 0;
669 int midi_output_ports
= 0;
670 bool monitor
= false;
671 char network_mode
= 's';
673 const jack_driver_param_t
* param
;
677 for ( node
= params
; node
; node
= jack_slist_next ( node
) )
679 param
= ( const jack_driver_param_t
* ) node
->data
;
680 switch ( param
->character
)
683 strncpy ( multicast_ip
, param
->value
.str
, 15 );
686 udp_port
= param
->value
.ui
;
689 mtu
= param
->value
.i
;
692 audio_capture_ports
= param
->value
.i
;
695 audio_playback_ports
= param
->value
.i
;
698 midi_input_ports
= param
->value
.i
;
701 midi_output_ports
= param
->value
.i
;
704 strncpy ( net_name
, param
->value
.str
, JACK_CLIENT_NAME_SIZE
);
707 transport_sync
= param
->value
.ui
;
710 if ( strcmp ( param
->value
.str
, "normal" ) == 0 )
712 else if ( strcmp ( param
->value
.str
, "slow" ) == 0 )
714 else if ( strcmp ( param
->value
.str
, "fast" ) == 0 )
717 jack_error ( "Unknown network mode, using 'normal' mode." );
725 Jack::JackDriverClientInterface
* driver
=
726 new Jack::JackWaitThreadedDriver (
727 new Jack::JackNetDriver ( "system", "net_pcm", engine
, table
, multicast_ip
, udp_port
, mtu
,
728 midi_input_ports
, midi_output_ports
, net_name
, transport_sync
, network_mode
) );
729 if ( driver
->Open ( period_size
, sample_rate
, 1, 1, audio_capture_ports
, audio_playback_ports
,
730 monitor
, "from_master_", "to_master_", 0, 0 ) == 0 )