root/trunk/libs/hydrogen/include/hydrogen/hydrogen.h @ 1487

Revision 1487, 7.5 KB (checked in by wolke, 3 years ago)

restore the right bpm value if you jump to an other position using ffwd rwd buttons, or by clicking on position ruler

Line 
1/*
2 * Hydrogen
3 * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net]
4 *
5 * http://www.hydrogen-music.org
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY, without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20 *
21 */
22#ifndef HYDROGEN_H
23#define HYDROGEN_H
24
25#include <stdint.h> // for uint32_t et al
26#include <hydrogen/action.h>
27#include <hydrogen/Song.h>
28#include <hydrogen/Object.h>
29#include <hydrogen/IO/AudioOutput.h>
30#include <hydrogen/IO/MidiInput.h>
31#include <hydrogen/IO/MidiOutput.h>
32#include <hydrogen/SoundLibrary.h>
33#include <cassert>
34
35// Engine states  (It's ok to use ==, <, and > when testing)
36#define STATE_UNINITIALIZED     1     // Not even the constructors have been called.
37#define STATE_INITIALIZED       2     // Not ready, but most pointers are now valid or NULL
38#define STATE_PREPARED          3     // Drivers are set up, but not ready to process audio.
39#define STATE_READY             4     // Ready to process audio
40#define STATE_PLAYING           5     // Currently playing a sequence.
41
42inline int randomValue( int max );
43
44namespace H2Core
45{
46
47///
48/// Hydrogen Audio Engine.
49///
50class Hydrogen : public Object
51{
52public:
53        /// Return the Hydrogen instance
54        static void create_instance();  // Also creates other instances, like AudioEngine
55        static Hydrogen* get_instance() { assert(__instance); return __instance; };
56
57        ~Hydrogen();
58
59// ***** SEQUENCER ********
60        /// Start the internal sequencer
61        void sequencer_play();
62
63        /// Stop the internal sequencer
64        void sequencer_stop();
65
66        void midi_noteOn( Note *note );
67
68        ///Last received midi message
69        QString lastMidiEvent;
70        int lastMidiEventParameter;
71
72
73        void sequencer_setNextPattern( int pos, bool appendPattern, bool deletePattern );
74        void togglePlaysSelected( void );
75// ***** ~SEQUENCER ********
76
77        /// Set current song
78        void setSong( Song *newSong );
79
80        /// Return the current song
81        Song* getSong();
82        void removeSong();
83
84        void addRealtimeNote ( int instrument, float velocity, float pan_L=1.0, float pan_R=1.0, float pitch=0.0, bool noteoff=false, bool forcePlay=false, int msg1=0 );
85
86        float getMasterPeak_L();
87        void setMasterPeak_L( float value );
88
89        float getMasterPeak_R();
90        void setMasterPeak_R( float value );
91
92        void getLadspaFXPeak( int nFX, float *fL, float *fR );
93        void setLadspaFXPeak( int nFX, float fL, float fR );
94
95
96        unsigned long getTickPosition();
97        unsigned long getRealtimeTickPosition();
98        unsigned long getTotalFrames();
99        unsigned long getRealtimeFrames();
100
101
102        PatternList * getCurrentPatternList();
103        void setCurrentPatternList( PatternList * pPatternList );
104
105        PatternList * getNextPatterns();
106
107        int getPatternPos();
108        void setPatternPos( int pos );
109       
110        void triggerRelocateDuringPlay();
111
112        long getTickForPosition( int );
113
114        void restartDrivers();
115
116        void startExportSong( const QString& filename, int rate, int depth  );
117        void stopExportSong();
118
119        AudioOutput* getAudioOutput();
120        MidiInput* getMidiInput();
121        MidiOutput* getMidiOutput();
122
123        int getState();
124
125        float getProcessTime();
126        float getMaxProcessTime();
127
128        int loadDrumkit( Drumkit *drumkitInfo );
129       
130        /// delete an instrument. If `conditional` is true, and there are patterns that
131        /// use this instrument, it's not deleted anyway
132        void removeInstrument( int instrumentnumber, bool conditional );
133
134        //return the name of the current drumkit
135        QString m_currentDrumkit;
136
137        const QString& getCurrentDrumkitname() {
138                return m_currentDrumkit;
139        }
140
141        void setCurrentDrumkitname( const QString& currentdrumkitname ) {
142                this->m_currentDrumkit = currentdrumkitname;
143        }
144
145        void raiseError( unsigned nErrorCode );
146
147
148        void previewSample( Sample *pSample );
149        void previewInstrument( Instrument *pInstr );
150
151        enum ErrorMessages {
152                UNKNOWN_DRIVER,
153                ERROR_STARTING_DRIVER,
154                JACK_SERVER_SHUTDOWN,
155                JACK_CANNOT_ACTIVATE_CLIENT,
156                JACK_CANNOT_CONNECT_OUTPUT_PORT,
157                JACK_ERROR_IN_PORT_REGISTER
158        };
159
160        void onTapTempoAccelEvent();
161        void setTapTempo( float fInterval );
162        void setBPM( float fBPM );
163
164        void restartLadspaFX();
165
166        int getSelectedPatternNumber();
167        void setSelectedPatternNumber( int nPat );
168
169        int getSelectedInstrumentNumber();
170        void setSelectedInstrumentNumber( int nInstrument );
171#ifdef JACK_SUPPORT
172        void renameJackPorts();
173#endif
174
175        ///playlist vector
176        struct HPlayListNode
177        {
178                QString m_hFile;
179                QString m_hScript;
180                QString m_hScriptEnabled;
181        };
182
183        std::vector<HPlayListNode> m_PlayList;
184       
185        ///beatconter
186        void setbeatsToCount( int beatstocount);
187        int getbeatsToCount();
188        void setNoteLength( float notelength);
189        float getNoteLength();
190        int getBcStatus();
191        void handleBeatCounter();
192        void setBcOffsetAdjust();
193
194        /// jack time master
195        unsigned long getHumantimeFrames();
196        void setHumantimeFrames(unsigned long hframes);
197        void offJackMaster();
198        void onJackMaster();
199        unsigned long getTimeMasterFrames();
200        long getTickForHumanPosition( int humanpos );
201        float getNewBpmJTM();
202        void setNewBpmJTM( float bpmJTM);
203        void ComputeHumantimeFrames(uint32_t nFrames);
204
205        void __panic();
206        int __get_selected_PatterNumber();
207        unsigned int __getMidiRealtimeNoteTickPosition();
208
209        ///sample editor vectors
210
211        void sortVolVectors();
212        void sortPanVectors();
213        void sortTimelineVector();
214        void sortTimelineTagVector();
215
216        struct HVeloVector
217        {
218                int m_hxframe;
219                int m_hyvalue;
220        };
221
222        std::vector<HVeloVector> m_volumen;
223
224        struct VolComparator
225        {
226                bool operator()( HVeloVector const& lhs, HVeloVector const& rhs)
227                {
228                        return lhs.m_hxframe < rhs.m_hxframe;
229                }
230        };
231
232        struct HPanVector
233        {
234                int m_hxframe;
235                int m_hyvalue;
236        };
237
238        std::vector<HPanVector> m_pan;
239
240        struct PanComparator
241        {
242                bool operator()( HPanVector const& lhs, HPanVector const& rhs)
243                {
244                        return lhs.m_hxframe < rhs.m_hxframe;
245                }
246        };
247
248/// timeline vector
249        struct HTimelineVector
250        {
251                int m_htimelinebeat;            //beat position in timeline
252//              int m_htimelinebar;             //bar position from current beat
253                float m_htimelinebpm;           //BPM
254//              bool m_htimelineslide;          //true if slide into new tempo
255//              int m_htimelineslidebeatbegin;  //position of slide begin (only beats, no bars)
256//              int m_htimelineslideend;        //position of slide end (only beats, no bars)
257//              int m_htimelineslidetype;       // 0 = slide up, 1 = slide down
258        };
259        std::vector<HTimelineVector> m_timelinevector;
260
261        struct TimelineComparator
262        {
263                bool operator()( HTimelineVector const& lhs, HTimelineVector const& rhs)
264                {
265                        return lhs.m_htimelinebeat < rhs.m_htimelinebeat;
266                }
267        };
268
269        void setTimelineBpm();
270
271/// timeline tag vector
272        struct HTimelineTagVector
273        {
274                int m_htimelinetagbeat;         //beat position in timeline
275//              int m_htimelineintensity;               //intensity
276                QString m_htimelinetag;         // tag
277        };
278        std::vector<HTimelineTagVector> m_timelinetagvector;
279
280        struct TimelineTagComparator
281        {
282                bool operator()( HTimelineTagVector const& lhs, HTimelineTagVector const& rhs)
283                {
284                        return lhs.m_htimelinetagbeat < rhs.m_htimelinetagbeat;
285                }
286        };
287
288
289private:
290        static Hydrogen* __instance;
291
292        // used for song export
293        Song::SongMode m_oldEngineMode;
294        bool m_bOldLoopEnabled;
295
296        std::list<Instrument*> __instrument_death_row; /// Deleting instruments too soon leads to potential crashes.
297
298
299        /// Private constructor
300        Hydrogen();
301
302        void __kill_instruments();
303
304};
305
306};
307
308#endif
309
Note: See TracBrowser for help on using the browser.