23#ifndef H2_JACK_OUTPUT_H
24#define H2_JACK_OUTPUT_H
30#if defined(H2CORE_HAVE_JACK) || _DOXYGEN_
37#include <jack/transport.h>
152 virtual int connect()
override;
168 virtual int getXRuns()
const override;
240 float*
getTrackOut_L( std::shared_ptr<Instrument> instr, std::shared_ptr<InstrumentComponent> pCompo );
255 float*
getTrackOut_R( std::shared_ptr<Instrument> instr, std::shared_ptr<InstrumentComponent> pCompo );
271 virtual int init(
unsigned bufferSize )
override;
373 static bool isBBTValid(
const jack_position_t& pos );
374 static double bbtToTick(
const jack_position_t& pos );
376 jack_position_t* pPos );
446 jack_nframes_t nFrames,
447 jack_position_t* pJackPosition,
488 void setTrackOutput(
int n, std::shared_ptr<Instrument> instr, std::shared_ptr<InstrumentComponent> pCompo, std::shared_ptr<Song> pSong );
636#ifdef HAVE_INTEGRATION_TESTS
639 static long m_nIntegrationLastRelocationFrame;
642 bool m_bIntegrationRelocationLoop;
643 bool m_bIntegrationCheckRelocationLoop;
655class JackAudioDriver :
public NullDriver {
virtual void disconnect() override
Disconnects the JACK client of the Hydrogen from the JACK server.
int m_nTrackPortCount
Total number of output ports currently in use.
static QString JackTransportStateToQString(const jack_transport_state_t &pPos)
long long m_nTimebaseFrameOffset
Stores an intended deviation of our transport position from the one hold by the JACK server.
jack_port_t * m_pTrackOutputPortsL[MAX_INSTRUMENTS]
Vector of all left audio output ports currently used by the local JACK client.
jack_position_t m_nextJackTransportPos
Use for relocation if Hydrogen is Timebase controller (and needs to provide valid BBT information in ...
void initTimebaseControl()
Acquires control of JACK Timebase.
TimebaseTracking
Used internally to keep track of the current Timebase state.
@ Valid
Current timebase state is on par with JACK server.
@ OnHold
We are uncertain of the current timebase state and wait a processing cycle to determine what to do ne...
static void transportToBBT(const TransportPosition &transportPos, jack_position_t *pPos)
virtual float * getOut_L() override
Get content in the left stereo output port.
Timebase m_timebaseState
Whether Hydrogen is receiving relocation and tempo changes as part of BBT information,...
static QString JackTransportPosToQString(const jack_position_t &pPos)
virtual int init(unsigned bufferSize) override
Initializes the JACK audio driver.
JackAudioDriver(JackProcessCallback m_processCallback)
Constructor of the JACK server driver.
bool m_bConnectDefaults
Specifies whether the default left and right (master) audio JACK ports will be automatically connecte...
static unsigned long jackServerSampleRate
Sample rate of the JACK audio server.
bool getConnectDefaults()
static JackAudioDriver * pJackDriverInstance
Instance of the JackAudioDriver.
QString m_sOutputPortName2
Destination of the right source port m_pOutputPort2, for which a connection will be established in co...
QString m_sOutputPortName1
Destination of the left source port m_pOutputPort1, for which a connection will be established in con...
float * getTrackOut_R(unsigned nTrack)
Get content of right output port of a specific track.
float getTimebaseControllerBpm() const
static int jackDriverSampleRate(jack_nframes_t nframes, void *param)
Callback function for the JACK audio server to set the sample rate jackServerSampleRate.
void clearPerTrackAudioBuffers(uint32_t nFrames)
Resets the buffers contained in m_pTrackOutputPortsL and m_pTrackOutputPortsR.
const jack_position_t & getJackPosition() const
jack_port_t * m_pOutputPort2
Right source port.
int m_trackMap[MAX_INSTRUMENTS][MAX_COMPONENTS]
Matrix containing the track number of each component of all instruments.
void startTransport()
Tells the JACK server to start transport.
friend class AudioEngineTests
virtual float * getOut_R() override
Get content in the right stereo output port.
static int jackServerXRuns
Number of XRuns since the driver started.
bool checkBBTPos() const
Used within the unit tests and checks whether the last JACK transport position retrieved has valid BB...
virtual unsigned getBufferSize() override
static QString TimebaseTrackingToQString(const TimebaseTracking &t)
void releaseTimebaseControl()
Release Hydrogen from the JACK Timebase control.
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 double bbtToTick(const jack_position_t &pos)
Timebase
Whether Hydrogen or another program is in Timebase control.
@ Listener
An external program is Timebase controller and Hydrogen will disregard all tempo markers on the Timel...
@ None
Only normal clients registered.
@ Controller
Hydrogen itself is Timebase controller and provides its current tempo to other Timebase listeners.
jack_client_t * m_pClient
Object holding the external client session with the JACK server.
void deactivate()
Deactivates the JACK client of Hydrogen and disconnects all ports belonging to it.
void setConnectDefaults(bool flag)
static Timebase TimebaseFromInt(int nState)
float m_fLastTimebaseBpm
Stores the last tempo sent by an external Timebase controller.
int m_lastTransportBits
Remembers the BBT capability bit received in a JACK process cycle.
virtual int connect() override
Connects to output ports via the JACK server.
Timebase getTimebaseState() const
static QString TimebaseToQString(const Timebase &t)
jack_position_t m_JackTransportPos
Current transport position obtained using jack_transport_query() (jack/transport.h).
jack_port_t * m_pOutputPort1
Left source port.
static int jackDriverBufferSize(jack_nframes_t nframes, void *arg)
Callback function for the JACK audio server to set the buffer size jackServerBufferSize.
static jack_nframes_t jackServerBufferSize
Buffer size of the JACK audio server.
void stopTransport()
Tells the JACK server to stop transport.
void updateTransportPosition()
The function queries the transport position and additional information from the JACK server,...
static bool isBBTValid(const jack_position_t &pos)
static void jackDriverShutdown(void *arg)
Callback function for the JACK audio server to shutting down the JACK driver.
TimebaseTracking m_timebaseTracking
Whether the current timebase state is stable or about to change.
static int jackXRunCallback(void *arg)
Report an XRun event to the GUI.
void makeTrackOutputs(std::shared_ptr< Song > pSong)
Creates per component output ports for each instrument.
virtual unsigned getSampleRate() override
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.
JackProcessCallback m_processCallback
Main process callback.
~JackAudioDriver()
Destructor of the JACK server driver.
void printState() const
Show debugging information.
float * getTrackOut_L(unsigned nTrack)
Get content of left output port of a specific track.
jack_transport_state_t m_JackTransportState
Current transport state returned by jack_transport_query() (jack/transport.h).
void relocateUsingBBT()
Uses the bar-beat-tick information to relocate the transport position.
jack_port_t * m_pTrackOutputPortsR[MAX_INSTRUMENTS]
Vector of all right audio output ports currently used by the local JACK client.
void locateTransport(long long nFrame)
Re-positions the transport position to nFrame.
virtual int getXRuns() const override
Get the number of XRuns that occurred since the audio driver has started.
Object holding most of the information about the transport state of the AudioEngine.
#define MAX_INSTRUMENTS
Maximum number of instruments allowed in Hydrogen.
#define MAX_COMPONENTS
Maximum number of components each Instrument is allowed to have.
int(* audioProcessCallback)(uint32_t, void *)