|
hydrogen 1.2.3
|
JACK (Jack Audio Connection Kit) server driver. More...
#include <JackAudioDriver.h>
Public Types | |
| enum class | Timebase { Master = 1 , Slave = 0 , None = -1 } |
| Whether Hydrogen or another program is Jack timebase master. More... | |
Public Member Functions | |
| JackAudioDriver (JackProcessCallback m_processCallback) | |
| Constructor of the JACK server driver. | |
| ~JackAudioDriver () | |
| Destructor of the JACK server driver. | |
| void | clearPerTrackAudioBuffers (uint32_t nFrames) |
| Resets the buffers contained in m_pTrackOutputPortsL and m_pTrackOutputPortsR. | |
| virtual int | connect () override |
| Connects to output ports via the JACK server. | |
| void | deactivate () |
| Deactivates the JACK client of Hydrogen and disconnects all ports belonging to it. | |
| virtual void | disconnect () override |
| Disconnects the JACK client of the Hydrogen from the JACK server. | |
| virtual unsigned | getBufferSize () override |
| bool | getConnectDefaults () |
| float | getMasterBpm () const |
| virtual float * | getOut_L () override |
| Get content in the left stereo output port. | |
| virtual float * | getOut_R () override |
| Get content in the right stereo output port. | |
| virtual unsigned | getSampleRate () override |
| Timebase | getTimebaseState () const |
| float * | getTrackOut_L (std::shared_ptr< Instrument > instr, std::shared_ptr< InstrumentComponent > pCompo) |
| Convenience function looking up the track number of a component of an instrument using in m_trackMap using their IDs Instrument::__id and InstrumentComponent::__related_drumkit_componentID. | |
| float * | getTrackOut_L (unsigned nTrack) |
| Get content of left output port of a specific track. | |
| float * | getTrackOut_R (std::shared_ptr< Instrument > instr, std::shared_ptr< InstrumentComponent > pCompo) |
| Convenience function looking up the track number of a component of an instrument using in m_trackMap using their IDs Instrument::__id and InstrumentComponent::__related_drumkit_componentID. | |
| float * | getTrackOut_R (unsigned nTrack) |
| Get content of right output port of a specific track. | |
| virtual int | getXRuns () const override |
| Get the number of XRuns that occurred since the audio driver has started. | |
| virtual int | init (unsigned bufferSize) override |
| Initializes the JACK audio driver. | |
| void | initTimebaseMaster () |
| Registers Hydrogen as JACK timebase master. | |
| void | locateTransport (long long nFrame) |
| Re-positions the transport position to nFrame. | |
| void | makeTrackOutputs (std::shared_ptr< Song > pSong) |
| Creates per component output ports for each instrument. | |
| void | releaseTimebaseMaster () |
| Release Hydrogen from the JACK timebase master responsibilities. | |
| void | relocateUsingBBT () |
| Uses the bar-beat-tick information to relocate the transport position. | |
| void | setConnectDefaults (bool flag) |
| void | startTransport () |
| Tells the JACK server to start transport. | |
| void | stopTransport () |
| Tells the JACK server to stop transport. | |
| void | updateTransportPosition () |
| The function queries the transport position and additional information from the JACK server, writes them to m_JackTransportPos and in m_JackTransportState, and updates the AudioEngine in case of a mismatch. | |
Public Member Functions inherited from Object< JackAudioDriver > | |
| Object () | |
| Object (const Object< JackAudioDriver > &other) | |
Public Member Functions inherited from Base | |
| Base () | |
| Base (const Base &other) | |
| virtual const char * | class_name () const |
| void | Print (bool bShort=true) const |
| Prints content of toQString() via DEBUGLOG. | |
| virtual QString | toQString (const QString &sPrefix="", bool bShort=true) const |
| Formatted string version for debugging purposes. | |
Public Member Functions inherited from AudioOutput | |
| AudioOutput ()=default | |
| virtual | ~AudioOutput () |
| virtual int | getLatency () |
| Approximate audio latency (in frames) A reasonable approximation is the buffer time on most audio systems. | |
Public Member Functions inherited from Object< AudioOutput > | |
| Object () | |
| Object (const Object< AudioOutput > &other) | |
Static Public Member Functions | |
| static bool | checkSupport () |
| Attempts to call several JACK executables in order to check for existing JACK support. | |
| static int | jackDriverBufferSize (jack_nframes_t nframes, void *arg) |
| Callback function for the JACK audio server to set the buffer size jackServerBufferSize. | |
| static int | jackDriverSampleRate (jack_nframes_t nframes, void *param) |
| Callback function for the JACK audio server to set the sample rate jackServerSampleRate. | |
| static int | jackXRunCallback (void *arg) |
| Report an XRun event to the GUI. | |
Static Public Member Functions inherited from Base | |
| static const char * | _class_name () |
| return the class name | |
| static QString | base_clock (const QString &sMsg) |
| Measures the current time and stores it in __last_clock. | |
| static QString | base_clock_in (const QString &sMsg) |
| static int | bootstrap (Logger *logger, bool count=false) |
| must be called before any Object instantiation ! | |
| static bool | count_active () |
| static int | getAliveObjectCount () |
| static object_map_t | getObjectMap () |
| static Logger * | logger () |
| return the logger instance | |
| static int | objects_count () |
| static void | printObjectMapDiff (object_map_t map) |
| Creates the difference between a snapshot of the object map and its current state and prints it to std::cout. | |
| static void | set_count (bool flag) |
| enable/disable class instances counting | |
| static void | write_objects_map_to (std::ostream &out, object_map_t *map=nullptr) |
| output the full objects map to a given ostream | |
| static void | write_objects_map_to_cerr () |
| output objects map to stderr | |
Static Public Member Functions inherited from AudioOutput | |
| static QStringList | getDevices () |
Data Fields | |
| jack_client_t * | m_pClient |
| Object holding the external client session with the JACK server. | |
Static Public Attributes | |
| static jack_nframes_t | jackServerBufferSize = 0 |
| Buffer size of the JACK audio server. | |
| static unsigned long | jackServerSampleRate = 0 |
| Sample rate of the JACK audio server. | |
| static int | jackServerXRuns = 0 |
| Number of XRuns since the driver started. | |
| static JackAudioDriver * | pJackDriverInstance = nullptr |
| Instance of the JackAudioDriver. | |
Static Public Attributes inherited from Base | |
| static QString | sPrintIndention = " " |
| String used to format the debugging string output of some core classes. | |
Private Member Functions | |
| bool | compareAdjacentBBT () const |
| Compares the BBT information stored in m_JackTransportPos and m_previousJackTransportPos with respect to the tempo and the transport position in bars, beats, and ticks. | |
| void | printState () const |
| Show debugging information. | |
| void | setTrackOutput (int n, std::shared_ptr< Instrument > instr, std::shared_ptr< InstrumentComponent > pCompo, std::shared_ptr< Song > pSong) |
| Renames the n 'th port of JACK client and creates it if it's not already present. | |
Static Private Member Functions | |
| static QString | checkExecutable (const QString &sExecutable, const QString &sOption) |
| Calls sExecutable in a subprocess using the sOption CLI option and reports the results. | |
| static void | jackDriverShutdown (void *arg) |
| Callback function for the JACK audio server to shutting down the JACK driver. | |
| static void | JackTimebaseCallback (jack_transport_state_t state, jack_nframes_t nFrames, jack_position_t *pJackPosition, int new_pos, void *arg) |
| Callback function for the JACK server to supply additional timebase information. | |
| static void | printJackTransportPos (const jack_position_t *pPos) |
Private Attributes | |
| bool | m_bConnectDefaults |
| Specifies whether the default left and right (master) audio JACK ports will be automatically connected to the system's sink when registering the JACK client in connect(). | |
| jack_position_t | m_JackTransportPos |
| Current transport position obtained using jack_transport_query() (jack/transport.h). | |
| jack_transport_state_t | m_JackTransportState |
| Current transport state returned by jack_transport_query() (jack/transport.h). | |
| int | m_nTimebaseTracking |
| Whether Hydrogen or another program is Jack timebase master. | |
| int | m_nTrackPortCount |
| Total number of output ports currently in use. | |
| jack_port_t * | m_pOutputPort1 |
| Left source port. | |
| jack_port_t * | m_pOutputPort2 |
| Right source port. | |
| jack_position_t | m_previousJackTransportPos |
| Used for detecting changes in the BBT transport information with external timebase master application, which do not propagate these changes on time. | |
| JackProcessCallback | m_processCallback |
| Main process callback. | |
| jack_port_t * | m_pTrackOutputPortsL [MAX_INSTRUMENTS] |
| Vector of all left audio output ports currently used by the local JACK client. | |
| jack_port_t * | m_pTrackOutputPortsR [MAX_INSTRUMENTS] |
| Vector of all right audio output ports currently used by the local JACK client. | |
| QString | m_sOutputPortName1 |
| Destination of the left source port m_pOutputPort1, for which a connection will be established in connect(). | |
| QString | m_sOutputPortName2 |
| Destination of the right source port m_pOutputPort2, for which a connection will be established in connect(). | |
| Timebase | m_timebaseState |
| More user-friendly version of m_nTimebaseTracking. | |
| int | m_trackMap [MAX_INSTRUMENTS][MAX_COMPONENTS] |
| Matrix containing the track number of each component of all instruments. | |
Additional Inherited Members | |
Protected Member Functions inherited from Object< JackAudioDriver > | |
| ~Object () | |
Protected Member Functions inherited from Base | |
| ~Base () | |
Protected Member Functions inherited from Object< AudioOutput > | |
| ~Object () | |
Static Protected Member Functions inherited from Base | |
| static void | registerClass (const char *name, const atomic_obj_cpt_t *counters) |
Static Protected Attributes inherited from Base | |
| static bool | __count = false |
| should we count class instances | |
| static timeval | __last_clock = { 0, 0 } |
| static Logger * | __logger = nullptr |
JACK (Jack Audio Connection Kit) server driver.
Transport Control:
Each JACK client can start and stop the transport or relocate the current transport position. The request will take place in cycles. During the first the status of the transport changes to JackTransportStarting to inform all clients a change is about to happen. During the second the status is again JackTransportRolling and the transport position is updated according to the request.
Also note that Hydrogen overwrites its local TransportPosition only with the transport position of the JACK server if there is a mismatch due to a relocation triggered by another JACK client. During normal transport the current position TransportPosition::m_nFrames will be always the same as the one of JACK during a cycle and incremented by the buffer size in audioEngine_process() at the very end of the cycle. The same happens for the transport information of the JACK server but in parallel.
Timebase Master:
The timebase master is responsible for providing additional transport information to the JACK server apart from the transport position in frames, like current beat, bar, tick, tick size, speed etc. Of all these information Hydrogen does only use the provided tempo (and overrides all internal ones). Therefore, unlike many other application, it does not respond to changes in measure (since these would have to be mapped to the length of the current pattern). Every client can be registered as timebase master by supplying a callback (for Hydrogen this would be JackTimebaseCallback()) but there can be at most one timebase master at a time. Having none at all is perfectly fine too. Apart from this additional responsibility, the registered client has no other rights compared to others.
After the status of the JACK transport has changed from JackTransportStarting to JackTransportRolling, the timebase master needs an additional cycle to update its information.
Definition at line 94 of file JackAudioDriver.h.
|
strong |
Whether Hydrogen or another program is Jack timebase master.
| Enumerator | |
|---|---|
| Master | Hydrogen itself is timebase master. |
| Slave | An external program is timebase master and Hydrogen will disregard all tempo markers on the Timeline and, instead, only use the BPM provided by JACK. |
| None | Only normal clients registered. |
Definition at line 101 of file JackAudioDriver.h.
| JackAudioDriver | ( | JackProcessCallback | m_processCallback | ) |
Constructor of the JACK server driver.
| m_processCallback | Function that is called by the AudioEngine during every processing cycle. |
Definition at line 99 of file JackAudioDriver.cpp.
| ~JackAudioDriver | ( | ) |
Destructor of the JACK server driver.
Calling disconnect().
Definition at line 127 of file JackAudioDriver.cpp.
|
staticprivate |
Calls sExecutable in a subprocess using the sOption CLI option and reports the results.
Definition at line 1247 of file JackAudioDriver.cpp.
|
static |
Attempts to call several JACK executables in order to check for existing JACK support.
In an earlier version I tried checking the presence of the libjack.so shared library. But this one comes preinstalled with most Linux distribution regardless of JACK itself is present or not.
Definition at line 1209 of file JackAudioDriver.cpp.
| void clearPerTrackAudioBuffers | ( | uint32_t | nFrames | ) |
Resets the buffers contained in m_pTrackOutputPortsL and m_pTrackOutputPortsR.
| nFrames | Size of the buffers used in the audio process callback function. |
Definition at line 255 of file JackAudioDriver.cpp.
|
private |
Compares the BBT information stored in m_JackTransportPos and m_previousJackTransportPos with respect to the tempo and the transport position in bars, beats, and ticks.
Definition at line 408 of file JackAudioDriver.cpp.
|
overridevirtual |
Connects to output ports via the JACK server.
0 : on success.
Implements AudioOutput.
Definition at line 132 of file JackAudioDriver.cpp.
| void deactivate | ( | ) |
Deactivates the JACK client of Hydrogen and disconnects all ports belonging to it.
Definition at line 233 of file JackAudioDriver.cpp.
|
overridevirtual |
Disconnects the JACK client of the Hydrogen from the JACK server.
Implements AudioOutput.
Definition at line 213 of file JackAudioDriver.cpp.
|
overridevirtual |
Implements AudioOutput.
Definition at line 245 of file JackAudioDriver.cpp.
|
inline |
Definition at line 180 of file JackAudioDriver.h.
| float getMasterBpm | ( | ) | const |
Definition at line 1162 of file JackAudioDriver.cpp.
|
overridevirtual |
Get content in the left stereo output port.
Implements AudioOutput.
Definition at line 602 of file JackAudioDriver.cpp.
|
overridevirtual |
Get content in the right stereo output port.
Implements AudioOutput.
Definition at line 616 of file JackAudioDriver.cpp.
|
overridevirtual |
Implements AudioOutput.
Definition at line 250 of file JackAudioDriver.cpp.
| JackAudioDriver::Timebase getTimebaseState | ( | ) | const |
Definition at line 1156 of file JackAudioDriver.cpp.
| float * getTrackOut_L | ( | std::shared_ptr< Instrument > | instr, |
| std::shared_ptr< InstrumentComponent > | pCompo ) |
Convenience function looking up the track number of a component of an instrument using in m_trackMap using their IDs Instrument::__id and InstrumentComponent::__related_drumkit_componentID.
Using the track number it then calls getTrackOut_L( unsigned ) and returns its result.
| instr | Pointer to an Instrument |
| pCompo | Pointer to one of the instrument's components. |
Definition at line 650 of file JackAudioDriver.cpp.
| float * getTrackOut_L | ( | unsigned | nTrack | ) |
Get content of left output port of a specific track.
| nTrack | Track number. Must not be bigger than m_nTrackPortCount. |
Definition at line 622 of file JackAudioDriver.cpp.
| float * getTrackOut_R | ( | std::shared_ptr< Instrument > | instr, |
| std::shared_ptr< InstrumentComponent > | pCompo ) |
Convenience function looking up the track number of a component of an instrument using in m_trackMap using their IDs Instrument::__id and InstrumentComponent::__related_drumkit_componentID.
Using the track number it then calls getTrackOut_R( unsigned ) and returns its result.
| instr | Pointer to an Instrument |
| pCompo | Pointer to one of the instrument's components. |
Definition at line 655 of file JackAudioDriver.cpp.
| float * getTrackOut_R | ( | unsigned | nTrack | ) |
Get content of right output port of a specific track.
| nTrack | Track number. Must not be bigger than m_nTrackPortCount. |
Definition at line 636 of file JackAudioDriver.cpp.
|
overridevirtual |
Get the number of XRuns that occurred since the audio driver has started.
Reimplemented from AudioOutput.
Definition at line 1172 of file JackAudioDriver.cpp.
|
overridevirtual |
Initializes the JACK audio driver.
| bufferSize | Unused and only present to assure compatibility with the JACK API. |
Implements AudioOutput.
Definition at line 677 of file JackAudioDriver.cpp.
| void initTimebaseMaster | ( | ) |
Registers Hydrogen as JACK timebase master.
Definition at line 992 of file JackAudioDriver.cpp.
|
static |
Callback function for the JACK audio server to set the buffer size jackServerBufferSize.
| nframes | New buffer size. |
| arg | Not used |
Definition at line 71 of file JackAudioDriver.cpp.
|
static |
Callback function for the JACK audio server to set the sample rate jackServerSampleRate.
| nframes | New sample rate. |
| param | Object inheriting from the #Logger class. |
Definition at line 58 of file JackAudioDriver.cpp.
|
staticprivate |
Callback function for the JACK audio server to shutting down the JACK driver.
| arg | Unused. |
Definition at line 80 of file JackAudioDriver.cpp.
|
staticprivate |
Callback function for the JACK server to supply additional timebase information.
The function it will be called after the audioEngine_process() function and only if the m_JackTransportState is JackTransportRolling.
What is the BBT information?
There is no formal definition in the JACK API but the way it is interpreted by Hydrogen is the following:
bar: Number of patterns passed since the beginning of the song. beat: Number of quarters passed since the beginning of the pattern. tick: Number of ticks passed since the last beat (with respect to the current frame).
A tick is an internal measure representing the smallest resolution of the transport position in terms of the patterns. It consist of pAudioEngine->getTickSize() frames, which changes depending on the current tempo.
| state | Unused. |
| nFrames | Unused. |
| pJackPosition | Current transport position. |
| new_pos | Unused. |
| arg | Pointer to a JackAudioDriver instance. |
Definition at line 1078 of file JackAudioDriver.cpp.
|
static |
Report an XRun event to the GUI.
Definition at line 87 of file JackAudioDriver.cpp.
| void locateTransport | ( | long long | nFrame | ) |
Re-positions the transport position to nFrame.
The new position takes effect in two process cycles during which JACK's state will be in JackTransportStarting and the transport won't be rolling.
| nFrame | Requested new transport position. |
Definition at line 978 of file JackAudioDriver.cpp.
| void makeTrackOutputs | ( | std::shared_ptr< Song > | pSong | ) |
Creates per component output ports for each instrument.
Definition at line 872 of file JackAudioDriver.cpp.
|
staticprivate |
Definition at line 1191 of file JackAudioDriver.cpp.
|
private |
Show debugging information.
Definition at line 1176 of file JackAudioDriver.cpp.
| void releaseTimebaseMaster | ( | ) |
Release Hydrogen from the JACK timebase master responsibilities.
This causes the JackTimebaseCallback() callback function to not be called by the JACK server anymore.
Definition at line 1051 of file JackAudioDriver.cpp.
| void relocateUsingBBT | ( | ) |
Uses the bar-beat-tick information to relocate the transport position.
This type of operation is triggered whenever the transport position gets relocated or the tempo is changed using Jack in the presence of an external timebase master.
Definition at line 274 of file JackAudioDriver.cpp.
|
inline |
| flag | Sets m_bConnectDefaults |
Definition at line 176 of file JackAudioDriver.h.
|
private |
Renames the n 'th port of JACK client and creates it if it's not already present.
If the track number n is bigger than the number of ports currently in usage m_nTrackPortCount, n + 1 - m_nTrackPortCount new stereo ports will be created using jack_port_register() (jack/jack.h) and m_nTrackPortCount updated to n + 1.
Afterwards, the n 'th port is renamed to a concatenation of "Track_", DrumkitComponent::__name, "_", n + 1, "_", Instrument::__name, and "_L", or "_R" using either jack_port_rename() (if HAVE_JACK_PORT_RENAME is defined) or jack_port_set_name() (both jack/jack.h). The former renaming function triggers a PortRename notifications to clients that have registered a port rename handler.
| n | Track number for which a port should be renamed (and created). |
| instr | Pointer to the corresponding Instrument. |
| pCompo | Pointer to the corresponding InstrumentComponent. |
| pSong | Pointer to the corresponding Song. |
Definition at line 918 of file JackAudioDriver.cpp.
| void startTransport | ( | ) |
Tells the JACK server to start transport.
Definition at line 960 of file JackAudioDriver.cpp.
| void stopTransport | ( | ) |
Tells the JACK server to stop transport.
Definition at line 969 of file JackAudioDriver.cpp.
| void updateTransportPosition | ( | ) |
The function queries the transport position and additional information from the JACK server, writes them to m_JackTransportPos and in m_JackTransportState, and updates the AudioEngine in case of a mismatch.
Definition at line 490 of file JackAudioDriver.cpp.
|
static |
Buffer size of the JACK audio server.
Definition at line 316 of file JackAudioDriver.h.
|
static |
Sample rate of the JACK audio server.
Definition at line 312 of file JackAudioDriver.h.
|
static |
Number of XRuns since the driver started.
Definition at line 322 of file JackAudioDriver.h.
|
private |
Specifies whether the default left and right (master) audio JACK ports will be automatically connected to the system's sink when registering the JACK client in connect().
Definition at line 557 of file JackAudioDriver.h.
|
private |
Current transport position obtained using jack_transport_query() (jack/transport.h).
It corresponds to the first frame of the current cycle.
The valid member of m_JackTransportPos will show which fields contain valid data. Thus, if it is set to JackPositionBBT, bar, beat, and tick information are provided by the current timebase master in addition to the transport information in frames. It is of class jack_position_bits_t (jack/types.h) and is an enumerator with five different options:
Definition at line 545 of file JackAudioDriver.h.
|
private |
Current transport state returned by jack_transport_query() (jack/transport.h).
It is valid for the entire cycle and can have five different values:
The actual number of states depends on your JACK version. The listing above was done for version 1.9.12.
Definition at line 522 of file JackAudioDriver.h.
|
private |
Whether Hydrogen or another program is Jack timebase master.
While Hydrogen can unregister as timebase master on its own, it can not be observed directly whether another application has taken over as timebase master. When the JACK server is releasing Hydrogen in the later case, it won't advertise this fact but simply won't call the JackTimebaseCallback() anymore. But since this will be called in every cycle after updateTransportPosition(), we can use this variable to determine if Hydrogen is still timebase master.
As Hydrogen registered as timebase master using initTimebaseMaster() it will be initialized with 1, decremented in updateTransportPosition(), and reset to 1 in JackTimebaseCallback(). Whenever it is zero in updateTransportPosition(), m_nTimebaseTracking will be updated accordingly.
Definition at line 584 of file JackAudioDriver.h.
|
private |
Total number of output ports currently in use.
Definition at line 493 of file JackAudioDriver.h.
| jack_client_t* m_pClient |
Object holding the external client session with the JACK server.
Definition at line 116 of file JackAudioDriver.h.
|
private |
Left source port.
Definition at line 465 of file JackAudioDriver.h.
|
private |
Right source port.
Definition at line 469 of file JackAudioDriver.h.
|
private |
Used for detecting changes in the BBT transport information with external timebase master application, which do not propagate these changes on time.
Definition at line 550 of file JackAudioDriver.h.
|
private |
Main process callback.
Definition at line 461 of file JackAudioDriver.h.
|
private |
Vector of all left audio output ports currently used by the local JACK client.
Definition at line 498 of file JackAudioDriver.h.
|
private |
Vector of all right audio output ports currently used by the local JACK client.
Definition at line 503 of file JackAudioDriver.h.
|
private |
Destination of the left source port m_pOutputPort1, for which a connection will be established in connect().
Definition at line 474 of file JackAudioDriver.h.
|
private |
Destination of the right source port m_pOutputPort2, for which a connection will be established in connect().
Definition at line 479 of file JackAudioDriver.h.
|
private |
More user-friendly version of m_nTimebaseTracking.
Definition at line 589 of file JackAudioDriver.h.
|
private |
Matrix containing the track number of each component of all instruments.
Its rows represent the instruments and its columns their components. m_trackMap[2][1]=6 thus therefore mean the output of the second component of the third instrument is assigned the seventh output port. Since its total size is defined by MAX_INSTRUMENTS and MAX_COMPONENTS, most of its entries will be zero.
Definition at line 489 of file JackAudioDriver.h.
|
static |
Instance of the JackAudioDriver.
Definition at line 320 of file JackAudioDriver.h.