hydrogen 1.2.6
Hydrogen.h
Go to the documentation of this file.
1/*
2 * Hydrogen
3 * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net]
4 * Copyright(c) 2008-2025 The hydrogen development team [hydrogen-devel@lists.sourceforge.net]
5 *
6 * http://www.hydrogen-music.org
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY, without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see https://www.gnu.org/licenses
20 *
21 */
22#ifndef HYDROGEN_H
23#define HYDROGEN_H
24
25#include <core/config.h>
26#include <core/Basics/Drumkit.h>
27#include <core/Basics/Song.h>
28#include <core/Basics/Sample.h>
29#include <core/Object.h>
30#include <core/Timeline.h>
31#include <core/IO/AudioOutput.h>
32#include <core/IO/MidiCommon.h>
33#include <core/IO/MidiInput.h>
34#include <core/IO/MidiOutput.h>
37#include <core/Timehelper.h>
38
39#include <stdint.h> // for uint32_t et al
40#include <cassert>
41#include <memory>
42
43namespace H2Core
44{
46 class AudioEngine;
48
52
53class Hydrogen : public H2Core::Object<Hydrogen>
54{
56public:
57
60 enum class Tempo {
64 Song = 0,
72 Jack = 2
73 };
74
75
80 static void create_instance();
84 static Hydrogen* get_instance(){ return __instance; };
85
89 ~Hydrogen();
90
91 /*
92 * return central instance of the audio engine
93 */
98
99// ***** SEQUENCER ********
101 void sequencer_play();
102
104 void sequencer_stop();
105
106 void midi_noteOn( Note *note );
107
111 int getLastMidiEventParameter() const;
112 void setLastMidiEventParameter( int nParam );
113
115 void toggleNextPattern( int nPatternNumber );
117 bool flushAndAddNextPattern( int nPatternNumber );
118
123 std::shared_ptr<Song> getSong() const{ return __song; }
133 void setSong ( std::shared_ptr<Song> newSong, bool bRelinking = true );
134
152 int getColumnForTick( long nTick, bool bLoopMode, long* pPatternStartTick ) const;
166 long getTickForColumn( int nColumn ) const;
167
168 Song::Mode getMode() const;
172 void setMode( Song::Mode mode );
173
178 void setActionMode( Song::ActionMode mode );
179
185
190 void setIsTimelineActivated( bool bEnabled );
191
192 void removeSong();
193
194 void updateSongSize();
195
196 bool addRealtimeNote ( int instrument,
197 float velocity,
198 bool noteoff=false,
199 int msg1=0 );
200
201 int getHihatOpenness() const;
202 void setHihatOpenness( int nValue );
203
204 void restartDrivers();
205
207 MidiInput* getMidiInput() const;
208 MidiOutput* getMidiOutput() const;
209
212 bool instrumentHasNotes( std::shared_ptr<Instrument> pInst );
213
215 void removeInstrument( int nInstrumentNumber );
216
218 QString getLastLoadedDrumkitName() const;
220 QString getLastLoadedDrumkitPath() const;
221
222 void raiseError( unsigned nErrorCode );
223
224
225void previewSample( Sample *pSample );
226 void previewInstrument( std::shared_ptr<Instrument> pInstr );
227
234 void recalculateRubberband( float fBpm );
237 void setIsModified( bool bIsModified );
240 bool getIsModified() const;
241
288
290 void setTapTempo( float fInterval );
291
292 void restartLadspaFX();
294 int getSelectedPatternNumber() const;
305 void setSelectedPatternNumber( int nPat,
306 bool bNeedsLock = true,
307 bool bForce = false );
308
313 void updateSelectedPattern( bool bNeedsLock = true );
314
315 int getSelectedInstrumentNumber() const;
325 void setSelectedInstrumentNumber( int nInstrument, bool bTriggerEvent = true );
326 std::shared_ptr<Instrument> getSelectedInstrument() const;
327
333 void renameJackPorts(std::shared_ptr<Song> pSong);
334
337 void toggleOscServer( bool bEnable );
340 void recreateOscServer();
341 void startNsmClient();
342
343 // beatconter
344 void setbeatsToCount( int beatstocount);
345 int getbeatsToCount();
346 void setNoteLength( float notelength);
347 float getNoteLength();
348 int getBcStatus();
349 bool handleBeatCounter();
350 void setBcOffsetAdjust();
351
358
359 void __panic();
360 std::shared_ptr<Timeline> getTimeline() const;
361 void setTimeline( std::shared_ptr<Timeline> );
362
363 //export management
364 bool getIsExportSessionActive() const;
374 bool startExportSession( int nSampleRate, int nSampleDepth,
375 double fCompressionLevel = 0.0 );
376 void stopExportSession();
377 void startExportSong( const QString& filename );
378 void stopExportSong();
379
381
382 /************************************************************/
383 /********************** Playback track **********************/
387 void mutePlaybackTrack( const bool bMuted );
395 void loadPlaybackTrack( QString sFilename );
396 /************************************************************/
397
399 enum class GUIState {
406 };
407
409 GUIState getGUIState() const;
412 void setGUIState( const GUIState state );
417 bool hasJackAudioDriver() const;
423 bool hasJackTransport() const;
424 float getJackTimebaseControllerBpm() const;
425
433 bool isTimelineEnabled() const;
434
439 bool isPatternEditorLocked() const;
440 void setIsPatternEditorLocked( bool bValue );
441
442 Tempo getTempoSource() const;
443
453 bool isUnderSessionManagement() const;
454
455 void setSessionDrumkitNeedsRelinking( bool bNeedsRelinking );
457 void setSessionIsExported( bool bIsExported );
458 bool getSessionIsExported() const;
459
462
473 void addInstrumentToDeathRow( std::shared_ptr<Instrument> pInstr );
474
482
491 QString toQString( const QString& sPrefix = "", bool bShort = true ) const override;
492
493private:
502
508 std::shared_ptr<Song> __song;
509
521 void initBeatcounter();
522
523 // beatcounter
529 double m_nBeatDiffs[16];
533 // ~ beatcounter
534
535
536 // used for song export
540
551
555 std::shared_ptr<Timeline> m_pTimeline;
560
562 std::list<std::shared_ptr<Instrument>> __instrument_death_row;
563
577
599
610
612
615
628 Hydrogen();
629
630 void __kill_instruments();
631
637
638};
639
640
641/*
642 * inline methods
643 */
644inline std::shared_ptr<Timeline> Hydrogen::getTimeline() const
645{
646 return m_pTimeline;
647}
648inline void Hydrogen::setTimeline( std::shared_ptr<Timeline> pTimeline )
649{
650 m_pTimeline = pTimeline;
651}
652
657
659{
661}
662
664 return m_pAudioEngine;
665}
666
668 return m_GUIState;
669}
670
671inline void Hydrogen::setGUIState( const Hydrogen::GUIState state ) {
672 m_GUIState = state;
673}
675{
677}
682
683inline void Hydrogen::setSessionDrumkitNeedsRelinking( bool bNeedsRelinking ) {
684 m_bSessionDrumkitNeedsRelinking = bNeedsRelinking;
685}
689inline void Hydrogen::setSessionIsExported( bool bSessionIsExported ) {
690 m_bSessionIsExported = bSessionIsExported;
691}
694}
699 m_lastMidiEvent = event;
700}
704inline void Hydrogen::setLastMidiEventParameter( int nParam ) {
706}
707inline int Hydrogen::getHihatOpenness() const {
708 return m_nHihatOpenness;
709}
710inline void Hydrogen::setHihatOpenness( int nValue ) {
711 m_nHihatOpenness = std::clamp( nValue, 0, 127 );
712}
713};
714
715#endif
716
#define H2_OBJECT(name)
Definition Object.h:227
The audio engine deals with two distinct TransportPosition.
Definition AudioEngine.h:99
Base abstract class for audio output classes.
Definition AudioOutput.h:39
bool isTimelineEnabled() const
Convenience function checking whether using the Timeline tempo is set in the Preferences,...
GUIState m_GUIState
Specifies whether the Qt5 GUI is active.
Definition Hydrogen.h:550
bool getIsExportSessionActive() const
Definition Hydrogen.h:658
void setMode(Song::Mode mode)
Wrapper around Song::setMode() which also triggers EVENT_SONG_MODE_ACTIVATION and should be used by a...
bool m_bExportSessionIsActive
Definition Hydrogen.h:539
void initBeatcounter()
Auxiliary function setting a bunch of global variables.
Definition Hydrogen.cpp:209
JackAudioDriver::Timebase getJackTimebaseState() const
std::shared_ptr< Timeline > m_pTimeline
Local instance of the Timeline object.
Definition Hydrogen.h:555
int getHihatOpenness() const
Definition Hydrogen.h:707
bool getSessionDrumkitNeedsRelinking() const
Definition Hydrogen.h:686
void midi_noteOn(Note *note)
Definition Hydrogen.cpp:366
void setLastMidiEventParameter(int nParam)
Definition Hydrogen.h:704
int m_nSelectedPatternNumber
Index of the pattern selected in the GUI or by a MIDI event.
Definition Hydrogen.h:576
Hydrogen()
Constructor, entry point, and initialization of the Hydrogen application.
Definition Hydrogen.cpp:105
long getTickForColumn(int nColumn) const
Get the total number of ticks passed up to a nColumn / pattern group.
int m_nStartOffset
ms default 0
Definition Hydrogen.h:532
void restartDrivers()
Definition Hydrogen.cpp:641
Tempo
Specifies where the AudioEngine does get its current tempo updates from.
Definition Hydrogen.h:60
@ Timeline
Only tempo markers on the Timeline are considered.
Definition Hydrogen.h:66
@ Jack
Hydrogen will disregard all internal tempo settings and uses the ones provided by the JACK server ins...
Definition Hydrogen.h:72
@ Song
BeatCounter, TapTempo, OSC and MIDI commands as well as the BPM widget in the PlayerControl are used ...
Definition Hydrogen.h:64
bool hasJackAudioDriver() const
void sequencer_stop()
Stop the internal sequencer.
Definition Hydrogen.cpp:231
void recreateOscServer()
Destroys and recreates the OscServer singleton in order to adopt a new OSC port.
void renameJackPorts(std::shared_ptr< Song > pSong)
Calls audioEngine_renameJackPorts() if Preferences::m_bJackTrackOuts is set to true.
Definition Hydrogen.cpp:957
~Hydrogen()
Destructor taking care of most of the clean up.
Definition Hydrogen.cpp:155
std::shared_ptr< Song > getSong() const
Get the current song.
Definition Hydrogen.h:123
int m_nSelectedInstrumentNumber
Instrument currently focused/selected in the GUI.
Definition Hydrogen.h:572
void toggleNextPattern(int nPatternNumber)
Wrapper around AudioEngine::toggleNextPattern().
Definition Hydrogen.cpp:613
QString getLastLoadedDrumkitPath() const
std::list< std::shared_ptr< Instrument > > __instrument_death_row
Deleting instruments too soon leads to potential crashes.
Definition Hydrogen.h:562
void removeInstrument(int nInstrumentNumber)
Delete an Instrument.
Definition Hydrogen.cpp:780
void setBcOffsetAdjust()
void setIsTimelineActivated(bool bEnabled)
Wrapper around both Song::setIsTimelineActivated (recent) and Preferences::setUseTimelinebpm() (forme...
int m_nInstrumentLookupTable[MAX_INSTRUMENTS]
midi lookuptable
Definition Hydrogen.h:461
bool addRealtimeNote(int instrument, float velocity, bool noteoff=false, int msg1=0)
Definition Hydrogen.cpp:371
void stopExportSession()
Definition Hydrogen.cpp:716
int getSelectedInstrumentNumber() const
Definition Hydrogen.h:678
void setPatternMode(Song::PatternMode mode)
Wrapper around Song::setPatternMode() which also triggers EVENT_STACKED_MODE_ACTIVATION and should be...
void onTapTempoAccelEvent()
Definition Hydrogen.cpp:805
Song::ActionMode getActionMode() const
bool isUnderSessionManagement() const
void setTimeline(std::shared_ptr< Timeline >)
Definition Hydrogen.h:648
void setSong(std::shared_ptr< Song > newSong, bool bRelinking=true)
Sets the current song __song to newSong.
Definition Hydrogen.cpp:293
MidiInput * getMidiInput() const
Used to display midi driver info.
Definition Hydrogen.cpp:747
bool flushAndAddNextPattern(int nPatternNumber)
Wrapper around AudioEngine::flushAndAddNextPattern().
Definition Hydrogen.cpp:625
void setbeatsToCount(int beatstocount)
Updates m_nbeatsToCount.
Definition Hydrogen.cpp:982
void previewInstrument(std::shared_ptr< Instrument > pInstr)
GUIState
Specifies the state of the Qt GUI.
Definition Hydrogen.h:399
@ notReady
There is a GUI but it is not ready yet (during startup).
Definition Hydrogen.h:401
@ unavailable
No GUI available.
Definition Hydrogen.h:403
@ ready
There is a working GUI.
Definition Hydrogen.h:405
Song::PlaybackTrack getPlaybackTrackState() const
Wrapper around Song::getPlaybackTrackState().
Definition Hydrogen.cpp:245
int m_nLastRecordedMIDINoteTick
Onset of the recorded last in addRealtimeNote().
Definition Hydrogen.h:605
float m_ntaktoMeterCompute
beatcounter note length
Definition Hydrogen.h:524
std::shared_ptr< Song > __song
Pointer to the current song.
Definition Hydrogen.h:508
void setTapTempo(float fInterval)
Definition Hydrogen.cpp:830
Tempo getTempoSource() const
int getColumnForTick(long nTick, bool bLoopMode, long *pPatternStartTick) const
Find a PatternList/column corresponding to the supplied tick position nTick.
double m_nBeatDiffs[16]
beat diff
Definition Hydrogen.h:529
Song::Mode getMode() const
int getSelectedPatternNumber() const
Definition Hydrogen.h:674
static void create_instance()
Creates all the instances used within Hydrogen in the right order.
Definition Hydrogen.cpp:184
void updateVirtualPatterns()
Processes the patterns added to any virtual ones in the PatternList of the current Song and ensure bo...
void setSelectedInstrumentNumber(int nInstrument, bool bTriggerEvent=true)
Definition Hydrogen.cpp:944
void restartLadspaFX()
Definition Hydrogen.cpp:890
std::shared_ptr< Timeline > getTimeline() const
Definition Hydrogen.h:644
SoundLibraryDatabase * m_pSoundLibraryDatabase
Definition Hydrogen.h:611
void mutePlaybackTrack(const bool bMuted)
Wrapper around Song::setPlaybackTrackEnabled().
Definition Hydrogen.cpp:255
AudioEngine * m_pAudioEngine
Central instance of the audio engine.
Definition Hydrogen.h:609
MidiMessage::Event m_lastMidiEvent
Cache last incoming MIDI event to be used in MidiSenseWidget.
Definition Hydrogen.h:635
static Hydrogen * get_instance()
Returns the current Hydrogen instance __instance.
Definition Hydrogen.h:84
void previewSample(Sample *pSample)
Song::PatternMode getPatternMode() const
static Hydrogen * __instance
Static reference to the Hydrogen singleton.
Definition Hydrogen.h:501
void __kill_instruments()
void updateSelectedPattern(bool bNeedsLock=true)
Updates the selected pattern to the one recorded note will be inserted to.
Definition Hydrogen.cpp:903
float getJackTimebaseControllerBpm() const
void setIsPatternEditorLocked(bool bValue)
MidiOutput * getMidiOutput() const
Definition Hydrogen.cpp:752
void setGUIState(const GUIState state)
Definition Hydrogen.h:671
void startExportSong(const QString &filename)
Export a song to a wav file.
Definition Hydrogen.cpp:697
int m_nTempoChangeCounter
count tempochanges for timeArray
Definition Hydrogen.h:527
int m_nbeatsToCount
beatcounter beats to count
Definition Hydrogen.h:525
bool handleBeatCounter()
bool getSessionIsExported() const
Definition Hydrogen.h:692
int m_nEventCount
beatcounter event
Definition Hydrogen.h:526
AudioEngine * getAudioEngine() const
Definition Hydrogen.h:663
void setNoteLength(float notelength)
Definition Hydrogen.cpp:992
void releaseJackTimebaseControl()
Calling JackAudioDriver::releaseTimebaseControl() directly from the GUI.
void setLastMidiEvent(MidiMessage::Event event)
Definition Hydrogen.h:698
int getLastMidiEventParameter() const
Definition Hydrogen.h:701
void setSessionIsExported(bool bIsExported)
Definition Hydrogen.h:689
std::shared_ptr< Instrument > getSelectedInstrument() const
int m_nHihatOpenness
Controls the instrument selection within a hihat group.
Definition Hydrogen.h:614
@ UNKNOWN_DRIVER
The provided input in createDriver() does not match any of the choices for H2Core::Preferences::Audio...
Definition Hydrogen.h:247
@ ERROR_STARTING_DRIVER
Unable to connect the audio driver stored in H2Core::AudioEngine::m_pAudioDriver in audioEngine_start...
Definition Hydrogen.h:254
@ JACK_CANNOT_ACTIVATE_CLIENT
Definition Hydrogen.h:256
@ JACK_ERROR_IN_PORT_REGISTER
Unable to register output ports for the JACK client using jack_port_register() (jack/jack....
Definition Hydrogen.h:280
@ OSC_CANNOT_CONNECT_TO_PORT
Unable to start the OSC server with the given port number.
Definition Hydrogen.h:285
@ JACK_CANNOT_CLOSE_CLIENT
The client of Hydrogen can not be disconnected from the JACK server using jack_client_close() (jack/j...
Definition Hydrogen.h:273
@ JACK_CANNOT_CONNECT_OUTPUT_PORT
Unable to connect either the JackAudioDriver::output_port_1 and the JackAudioDriver::output_port_name...
Definition Hydrogen.h:267
int m_nLastMidiEventParameter
Definition Hydrogen.h:636
void loadPlaybackTrack(QString sFilename)
Wrapper function for loading the playback track.
Definition Hydrogen.cpp:267
AudioOutput * getAudioOutput() const
Used to display audio driver info.
Definition Hydrogen.cpp:741
bool m_bOldLoopEnabled
Definition Hydrogen.h:538
void setIsModified(bool bIsModified)
Wrapper around Song::setIsModified() that checks whether a song is set.
void initJackTimebaseControl()
Calling JackAudioDriver::initTimebaseControl() directly from the GUI.
void addInstrumentToDeathRow(std::shared_ptr< Instrument > pInstr)
Add pInstr to __instrument_death_row and triggers __kill_instruments().
bool instrumentHasNotes(std::shared_ptr< Instrument > pInst)
Test if an Instrument has some Note in the Pattern (used to test before deleting an Instrument)
Definition Hydrogen.cpp:758
QString toQString(const QString &sPrefix="", bool bShort=true) const override
Formatted string version for debugging purposes.
void setSessionDrumkitNeedsRelinking(bool bNeedsRelinking)
Definition Hydrogen.h:683
bool m_bSessionDrumkitNeedsRelinking
When using Hydrogen with session management it tries to keep all central files within a session folde...
Definition Hydrogen.h:593
bool isPatternEditorLocked() const
Convenience function checking whether using the Pattern Editor is locked in the song settings and the...
void stopExportSong()
Definition Hydrogen.cpp:709
void setActionMode(Song::ActionMode mode)
Wrapper around Song::setActionMode() which also triggers EVENT_ACTION_MODE_CHANGE and should be used ...
void setSelectedPatternNumber(int nPat, bool bNeedsLock=true, bool bForce=false)
Sets m_nSelectedPatternNumber.
Definition Hydrogen.cpp:915
SoundLibraryDatabase * getSoundLibraryDatabase() const
Definition Hydrogen.h:95
bool hasJackTransport() const
float getNoteLength()
Definition Hydrogen.cpp:997
void toggleOscServer(bool bEnable)
Starts/stops the OSC server.
bool getIsModified() const
Wrapper around Song::getIsModified() that checks whether a song is set.
bool startExportSession(int nSampleRate, int nSampleDepth, double fCompressionLevel=0.0)
Definition Hydrogen.cpp:646
timeval m_CurrentTime
timeval
Definition Hydrogen.h:530
QString getLastLoadedDrumkitName() const
CoreActionController * getCoreActionController() const
Definition Hydrogen.h:653
void setHihatOpenness(int nValue)
Definition Hydrogen.h:710
Song::Mode m_oldEngineMode
ms default 0
Definition Hydrogen.h:537
CoreActionController * m_pCoreActionController
Local instance of the CoreActionController object.
Definition Hydrogen.h:559
void raiseError(unsigned nErrorCode)
Definition Hydrogen.cpp:800
int m_nBeatCount
beatcounter beat to count
Definition Hydrogen.h:528
void sequencer_play()
Start the internal sequencer.
Definition Hydrogen.cpp:221
MidiMessage::Event getLastMidiEvent() const
Last received midi message.
Definition Hydrogen.h:695
GUIState getGUIState() const
Definition Hydrogen.h:667
bool m_bSessionIsExported
Indicates whether NSM session is saved or exported when entering the CoreActionController::saveSong()...
Definition Hydrogen.h:598
void recalculateRubberband(float fBpm)
Recalculates all Samples using RubberBand for a specific tempo fBpm.
Timebase
Whether Hydrogen or another program is in Timebase control.
MIDI input base class.
Definition MidiInput.h:39
Event
Subset of incoming MIDI events that will be handled by Hydrogen.
Definition MidiCommon.h:66
MIDI input base class.
Definition MidiOutput.h:41
A note plays an associated instrument with a velocity left and right pan.
Definition Note.h:101
ActionMode
Defines the type of user interaction experienced in the SongEditor.
Definition Song.h:74
PlaybackTrack
Determines the state of the Playback track with respect to audio processing.
Definition Song.h:115
PatternMode
Determines how patterns will be added to AudioEngine::m_pPlayingPatterns if transport is in Song::Mod...
Definition Song.h:101
This class holds information about all installed soundlibrary items.
#define MAX_INSTRUMENTS
Maximum number of instruments allowed in Hydrogen.
Definition config.dox:70