hydrogen 1.2.3
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-2024 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{
45 class CoreActionController;
46 class AudioEngine;
47 class SoundLibraryDatabase;
48
52
53class Hydrogen : public H2Core::Object<Hydrogen>
54{
56public:
57
60 enum class Tempo {
64 Song = 0,
66 Timeline = 1,
73 Jack = 2
74 };
79 static void create_instance();
83 static Hydrogen* get_instance(){ return __instance; };
84
88 ~Hydrogen();
89
90 /*
91 * return central instance of the audio engine
92 */
97
98// ***** SEQUENCER ********
100 void sequencer_play();
101
103 void sequencer_stop();
104
105 void midi_noteOn( Note *note );
106
110 int getLastMidiEventParameter() const;
111 void setLastMidiEventParameter( int nParam );
112
114 void toggleNextPattern( int nPatternNumber );
116 bool flushAndAddNextPattern( int nPatternNumber );
117
122 std::shared_ptr<Song> getSong() const{ return __song; }
132 void setSong ( std::shared_ptr<Song> newSong, bool bRelinking = true );
133
151 int getColumnForTick( long nTick, bool bLoopMode, long* pPatternStartTick ) const;
165 long getTickForColumn( int nColumn ) const;
166
167 Song::Mode getMode() const;
171 void setMode( Song::Mode mode );
172
177 void setActionMode( Song::ActionMode mode );
178
184
189 void setIsTimelineActivated( bool bEnabled );
190
191 void removeSong();
192
193 void updateSongSize();
194
195 void addRealtimeNote ( int instrument,
196 float velocity,
197 float fPan = 0.0f,
198 bool noteoff=false,
199 int msg1=0 );
200
201 void restartDrivers();
202
204 MidiInput* getMidiInput() const;
205 MidiOutput* getMidiOutput() const;
206
209 bool instrumentHasNotes( std::shared_ptr<Instrument> pInst );
210
212 void removeInstrument( int nInstrumentNumber );
213
215 QString getLastLoadedDrumkitName() const;
217 QString getLastLoadedDrumkitPath() const;
218
219 void raiseError( unsigned nErrorCode );
220
221
222void previewSample( Sample *pSample );
223 void previewInstrument( std::shared_ptr<Instrument> pInstr );
224
231 void recalculateRubberband( float fBpm );
234 void setIsModified( bool bIsModified );
237 bool getIsModified() const;
238
286
288 void setTapTempo( float fInterval );
289
290 void restartLadspaFX();
292 int getSelectedPatternNumber() const;
303 void setSelectedPatternNumber( int nPat,
304 bool bNeedsLock = true,
305 bool bForce = false );
306
311 void updateSelectedPattern( bool bNeedsLock = true );
312
313 int getSelectedInstrumentNumber() const;
323 void setSelectedInstrumentNumber( int nInstrument, bool bTriggerEvent = true );
324 std::shared_ptr<Instrument> getSelectedInstrument() const;
325
331 void renameJackPorts(std::shared_ptr<Song> pSong);
332
335 void toggleOscServer( bool bEnable );
338 void recreateOscServer();
339 void startNsmClient();
340
341 // beatconter
342 void setbeatsToCount( int beatstocount);
343 int getbeatsToCount();
344 void setNoteLength( float notelength);
345 float getNoteLength();
346 int getBcStatus();
347 bool handleBeatCounter();
348 void setBcOffsetAdjust();
349
352 void offJackMaster();
355 void onJackMaster();
356
357 void __panic();
358 std::shared_ptr<Timeline> getTimeline() const;
359 void setTimeline( std::shared_ptr<Timeline> );
360
361 //export management
362 bool getIsExportSessionActive() const;
364 bool startExportSession( int rate, int depth );
365 void stopExportSession();
366 void startExportSong( const QString& filename );
367 void stopExportSong();
368
370
371 /************************************************************/
372 /********************** Playback track **********************/
376 void mutePlaybackTrack( const bool bMuted );
384 void loadPlaybackTrack( QString sFilename );
385 /************************************************************/
386
388 enum class GUIState {
390 notReady = -1,
392 unavailable = 0,
394 ready = 1
395 };
396
398 GUIState getGUIState() const;
401 void setGUIState( const GUIState state );
406 bool hasJackAudioDriver() const;
412 bool hasJackTransport() const;
413 float getMasterBpm() const;
414
422 bool isTimelineEnabled() const;
423
428 bool isPatternEditorLocked() const;
429 void setIsPatternEditorLocked( bool bValue );
430
431 Tempo getTempoSource() const;
432
442 bool isUnderSessionManagement() const;
443
444 void setSessionDrumkitNeedsRelinking( bool bNeedsRelinking );
446 void setSessionIsExported( bool bIsExported );
447 bool getSessionIsExported() const;
448
451
462 void addInstrumentToDeathRow( std::shared_ptr<Instrument> pInstr );
463
471
480 QString toQString( const QString& sPrefix = "", bool bShort = true ) const override;
481
482private:
491
497 std::shared_ptr<Song> __song;
498
510 void initBeatcounter();
511
512 // beatcounter
518 double m_nBeatDiffs[16];
522 // ~ beatcounter
523
524
525 // used for song export
529
540
544 std::shared_ptr<Timeline> m_pTimeline;
549
551 std::list<std::shared_ptr<Instrument>> __instrument_death_row;
552
566
588
599
601
614 Hydrogen();
615
616 void __kill_instruments();
617
623
624};
625
626
627/*
628 * inline methods
629 */
630inline std::shared_ptr<Timeline> Hydrogen::getTimeline() const
631{
632 return m_pTimeline;
633}
634inline void Hydrogen::setTimeline( std::shared_ptr<Timeline> pTimeline )
635{
636 m_pTimeline = pTimeline;
637}
638
643
645{
647}
648
650 return m_pAudioEngine;
651}
652
654 return m_GUIState;
655}
656
657inline void Hydrogen::setGUIState( const Hydrogen::GUIState state ) {
658 m_GUIState = state;
659}
661{
663}
668
669inline void Hydrogen::setSessionDrumkitNeedsRelinking( bool bNeedsRelinking ) {
670 m_bSessionDrumkitNeedsRelinking = bNeedsRelinking;
671}
675inline void Hydrogen::setSessionIsExported( bool bSessionIsExported ) {
676 m_bSessionIsExported = bSessionIsExported;
677}
680}
685 m_lastMidiEvent = event;
686}
690inline void Hydrogen::setLastMidiEventParameter( int nParam ) {
692}
693};
694
695#endif
696
#define H2_OBJECT(name)
Definition Object.h:224
The audio engine deals with two distinct #TransportPosition.
Definition AudioEngine.h:97
Base abstract class for audio output classes.
Definition AudioOutput.h:39
Hydrogen Audio Engine.
Definition Hydrogen.h:54
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:539
bool getIsExportSessionActive() const
Definition Hydrogen.h:644
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:528
void initBeatcounter()
Auxiliary function setting a bunch of global variables.
Definition Hydrogen.cpp:206
JackAudioDriver::Timebase getJackTimebaseState() const
std::shared_ptr< Timeline > m_pTimeline
Local instance of the Timeline object.
Definition Hydrogen.h:544
bool getSessionDrumkitNeedsRelinking() const
Definition Hydrogen.h:672
void midi_noteOn(Note *note)
Definition Hydrogen.cpp:352
bool startExportSession(int rate, int depth)
Definition Hydrogen.cpp:631
float getMasterBpm() const
void setLastMidiEventParameter(int nParam)
Definition Hydrogen.h:690
void addRealtimeNote(int instrument, float velocity, float fPan=0.0f, bool noteoff=false, int msg1=0)
Definition Hydrogen.cpp:357
int m_nSelectedPatternNumber
Index of the pattern selected in the GUI or by a MIDI event.
Definition Hydrogen.h:565
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:521
void restartDrivers()
Definition Hydrogen.cpp:626
void onJackMaster()
Calling JackAudioDriver::initTimebaseMaster() directly from the GUI.
Tempo
Specifies where the #AudioEngine does get its current tempo updates from.
Definition Hydrogen.h:60
@ Jack
Hydrogen will disregard all internal tempo settings and uses the ones provided by the JACK server ins...
bool hasJackAudioDriver() const
void sequencer_stop()
Stop the internal sequencer.
Definition Hydrogen.cpp:226
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:931
~Hydrogen()
Destructor taking care of most of the clean up.
Definition Hydrogen.cpp:154
std::shared_ptr< Song > getSong() const
Get the current song.
Definition Hydrogen.h:122
int m_nSelectedInstrumentNumber
Instrument currently focused/selected in the GUI.
Definition Hydrogen.h:561
void toggleNextPattern(int nPatternNumber)
Wrapper around AudioEngine::toggleNextPattern().
Definition Hydrogen.cpp:598
QString getLastLoadedDrumkitPath() const
std::list< std::shared_ptr< Instrument > > __instrument_death_row
Deleting instruments too soon leads to potential crashes.
Definition Hydrogen.h:551
void removeInstrument(int nInstrumentNumber)
Delete an #Instrument.
Definition Hydrogen.cpp:754
void setBcOffsetAdjust()
Definition Hydrogen.cpp:983
void setIsTimelineActivated(bool bEnabled)
Wrapper around both Song::setIsTimelineActivated (recent) and Preferences::setUseTimelinebpm() (forme...
int m_nInstrumentLookupTable[MAX_INSTRUMENTS]
midi lookuptable
Definition Hydrogen.h:450
void stopExportSession()
Definition Hydrogen.cpp:699
int getSelectedInstrumentNumber() const
Definition Hydrogen.h:664
void setPatternMode(Song::PatternMode mode)
Wrapper around Song::setPatternMode() which also triggers EVENT_STACKED_MODE_ACTIVATION and should be...
void onTapTempoAccelEvent()
Definition Hydrogen.cpp:779
Song::ActionMode getActionMode() const
bool isUnderSessionManagement() const
void setTimeline(std::shared_ptr< Timeline >)
Definition Hydrogen.h:634
void setSong(std::shared_ptr< Song > newSong, bool bRelinking=true)
Sets the current song __song to newSong.
Definition Hydrogen.cpp:288
MidiInput * getMidiInput() const
Used to display midi driver info.
Definition Hydrogen.cpp:725
bool flushAndAddNextPattern(int nPatternNumber)
Wrapper around AudioEngine::flushAndAddNextPattern().
Definition Hydrogen.cpp:610
void setbeatsToCount(int beatstocount)
Updates m_nbeatsToCount.
Definition Hydrogen.cpp:958
void previewInstrument(std::shared_ptr< Instrument > pInstr)
GUIState
Specifies the state of the Qt GUI.
Definition Hydrogen.h:388
@ notReady
There is a GUI but it is not ready yet (during startup).
@ unavailable
No GUI available.
@ ready
There is a working GUI.
Song::PlaybackTrack getPlaybackTrackState() const
Wrapper around Song::getPlaybackTrackState().
Definition Hydrogen.cpp:240
int m_nLastRecordedMIDINoteTick
Onset of the recorded last in addRealtimeNote().
Definition Hydrogen.h:594
float m_ntaktoMeterCompute
beatcounter note length
Definition Hydrogen.h:513
std::shared_ptr< Song > __song
Pointer to the current song.
Definition Hydrogen.h:497
void setTapTempo(float fInterval)
Definition Hydrogen.cpp:804
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:518
Song::Mode getMode() const
int getSelectedPatternNumber() const
Definition Hydrogen.h:660
static void create_instance()
Creates all the instances used within Hydrogen in the right order.
Definition Hydrogen.cpp:181
void updateVirtualPatterns()
Processes the patterns added to any virtual ones in the #PatternList of the current Song and ensure b...
void setSelectedInstrumentNumber(int nInstrument, bool bTriggerEvent=true)
Definition Hydrogen.cpp:918
void restartLadspaFX()
Definition Hydrogen.cpp:864
std::shared_ptr< Timeline > getTimeline() const
Definition Hydrogen.h:630
SoundLibraryDatabase * m_pSoundLibraryDatabase
Definition Hydrogen.h:600
void offJackMaster()
Calling JackAudioDriver::releaseTimebaseMaster() directly from the GUI.
void mutePlaybackTrack(const bool bMuted)
Wrapper around Song::setPlaybackTrackEnabled().
Definition Hydrogen.cpp:250
AudioEngine * m_pAudioEngine
Central instance of the audio engine.
Definition Hydrogen.h:598
MidiMessage::Event m_lastMidiEvent
Cache last incoming MIDI event to be used in MidiSenseWidget.
Definition Hydrogen.h:621
static Hydrogen * get_instance()
Returns the current Hydrogen instance __instance.
Definition Hydrogen.h:83
void previewSample(Sample *pSample)
Song::PatternMode getPatternMode() const
static Hydrogen * __instance
Static reference to the Hydrogen singleton.
Definition Hydrogen.h:490
void __kill_instruments()
void updateSelectedPattern(bool bNeedsLock=true)
Updates the selected pattern to the one recorded note will be inserted to.
Definition Hydrogen.cpp:877
void setIsPatternEditorLocked(bool bValue)
MidiOutput * getMidiOutput() const
Definition Hydrogen.cpp:730
void setGUIState(const GUIState state)
Definition Hydrogen.h:657
void startExportSong(const QString &filename)
Export a song to a wav file.
Definition Hydrogen.cpp:680
int m_nTempoChangeCounter
count tempochanges for timeArray
Definition Hydrogen.h:516
int m_nbeatsToCount
beatcounter beats to count
Definition Hydrogen.h:514
bool handleBeatCounter()
Definition Hydrogen.cpp:993
bool getSessionIsExported() const
Definition Hydrogen.h:678
int m_nEventCount
beatcounter event
Definition Hydrogen.h:515
AudioEngine * getAudioEngine() const
Definition Hydrogen.h:649
void setNoteLength(float notelength)
Definition Hydrogen.cpp:968
void setLastMidiEvent(MidiMessage::Event event)
Definition Hydrogen.h:684
int getLastMidiEventParameter() const
Definition Hydrogen.h:687
void setSessionIsExported(bool bIsExported)
Definition Hydrogen.h:675
std::shared_ptr< Instrument > getSelectedInstrument() const
@ UNKNOWN_DRIVER
The provided input string in createDriver() does not match any of the choices for Preferences::m_sAud...
Definition Hydrogen.h:245
@ ERROR_STARTING_DRIVER
Unable to connect the audio driver stored in H2Core::AudioEngine::m_pAudioDriver in audioEngine_start...
Definition Hydrogen.h:252
@ JACK_CANNOT_ACTIVATE_CLIENT
Definition Hydrogen.h:254
@ JACK_ERROR_IN_PORT_REGISTER
Unable to register output ports for the JACK client using jack_port_register() (jack/jack....
Definition Hydrogen.h:278
@ OSC_CANNOT_CONNECT_TO_PORT
Unable to start the OSC server with the given port number.
Definition Hydrogen.h:283
@ 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:271
@ JACK_CANNOT_CONNECT_OUTPUT_PORT
Unable to connect either the JackAudioDriver::output_port_1 and the JackAudioDriver::output_port_name...
Definition Hydrogen.h:265
int m_nLastMidiEventParameter
Definition Hydrogen.h:622
void loadPlaybackTrack(QString sFilename)
Wrapper function for loading the playback track.
Definition Hydrogen.cpp:262
AudioOutput * getAudioOutput() const
Used to display audio driver info.
Definition Hydrogen.cpp:719
bool m_bOldLoopEnabled
Definition Hydrogen.h:527
void setIsModified(bool bIsModified)
Wrapper around Song::setIsModified() that checks whether a song is set.
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:736
QString toQString(const QString &sPrefix="", bool bShort=true) const override
Formatted string version for debugging purposes.
void setSessionDrumkitNeedsRelinking(bool bNeedsRelinking)
Definition Hydrogen.h:669
bool m_bSessionDrumkitNeedsRelinking
When using Hydrogen with session management it tries to keep all central files within a session folde...
Definition Hydrogen.h:582
bool isPatternEditorLocked() const
Convenience function checking whether using the Pattern Editor is locked in the song settings and the...
void stopExportSong()
Definition Hydrogen.cpp:692
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:889
SoundLibraryDatabase * getSoundLibraryDatabase() const
Definition Hydrogen.h:94
bool hasJackTransport() const
float getNoteLength()
Definition Hydrogen.cpp:973
void toggleOscServer(bool bEnable)
Starts/stops the OSC server.
bool getIsModified() const
Wrapper around Song::getIsModified() that checks whether a song is set.
timeval m_CurrentTime
timeval
Definition Hydrogen.h:519
QString getLastLoadedDrumkitName() const
CoreActionController * getCoreActionController() const
Definition Hydrogen.h:639
Song::Mode m_oldEngineMode
ms default 0
Definition Hydrogen.h:526
CoreActionController * m_pCoreActionController
Local instance of the CoreActionController object.
Definition Hydrogen.h:548
void raiseError(unsigned nErrorCode)
Definition Hydrogen.cpp:774
int m_nBeatCount
beatcounter beat to count
Definition Hydrogen.h:517
void sequencer_play()
Start the internal sequencer.
Definition Hydrogen.cpp:218
MidiMessage::Event getLastMidiEvent() const
Last received midi message.
Definition Hydrogen.h:681
GUIState getGUIState() const
Definition Hydrogen.h:653
bool m_bSessionIsExported
Indicates whether NSM session is saved or exported when entering the CoreActionController::saveSong()...
Definition Hydrogen.h:587
void recalculateRubberband(float fBpm)
Recalculates all Samples using RubberBand for a specific tempo fBpm.
Timebase
Whether Hydrogen or another program is Jack timebase master.
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:102
Song class.
Definition Song.h:61
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.
Timeline class storing and handling all TempoMarkers and Tags.
Definition Timeline.h:68
#define MAX_INSTRUMENTS
Maximum number of instruments allowed in Hydrogen.
Definition config.dox:70