From d47584034892fae755ddbcfc710d7a8c2dd375a7 Mon Sep 17 00:00:00 2001 From: Sebastian Moors Date: Fri, 14 Nov 2014 22:22:12 +0100 Subject: [PATCH 1/5] Moved US_DIVIDER to globals.h --- src/core/include/hydrogen/globals.h | 6 ++++++ src/core/src/hydrogen.cpp | 6 ------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/core/include/hydrogen/globals.h b/src/core/include/hydrogen/globals.h index ce6426c24..388520783 100644 --- a/src/core/include/hydrogen/globals.h +++ b/src/core/include/hydrogen/globals.h @@ -43,4 +43,10 @@ #define UNUSED( v ) (v = v) +// m_nBeatCounter +//100,000 ms in 1 second. +#define US_DIVIDER .000001 +// ~m_nBeatCounter + + #endif // H2C_GLOBALS_H diff --git a/src/core/src/hydrogen.cpp b/src/core/src/hydrogen.cpp index 19542b7be..cdf745eff 100644 --- a/src/core/src/hydrogen.cpp +++ b/src/core/src/hydrogen.cpp @@ -100,12 +100,6 @@ float m_fMaxProcessTime = 0.0f; ///< max ms usable in process with no xrun //~ info - -// m_nBeatCounter -//100,000 ms in 1 second. -#define US_DIVIDER .000001 -// ~m_nBeatCounter - //jack time master float m_nNewBpmJTM = 120; unsigned long m_nHumantimeFrames = 0; From 4679003bf42d2af1e14983096a57af9205b1ada7 Mon Sep 17 00:00:00 2001 From: Sebastian Moors Date: Fri, 14 Nov 2014 22:49:58 +0100 Subject: [PATCH 2/5] hydrogen.h / hydrogen.cpp: code cleanup.. --- src/core/include/hydrogen/hydrogen.h | 223 ++++++++++++++------------- src/core/src/hydrogen.cpp | 125 +++++++-------- 2 files changed, 180 insertions(+), 168 deletions(-) diff --git a/src/core/include/hydrogen/hydrogen.h b/src/core/include/hydrogen/hydrogen.h index 7ec670724..1366aa9ef 100644 --- a/src/core/include/hydrogen/hydrogen.h +++ b/src/core/include/hydrogen/hydrogen.h @@ -54,100 +54,102 @@ class Hydrogen : public H2Core::Object H2_OBJECT public: /// Return the Hydrogen instance - static void create_instance(); // Also creates other instances, like AudioEngine - static Hydrogen* get_instance() { assert(__instance); return __instance; }; + static void create_instance(); // Also creates other instances, like AudioEngine + static Hydrogen* get_instance() { assert(__instance); return __instance; }; ~Hydrogen(); // ***** SEQUENCER ******** /// Start the internal sequencer - void sequencer_play(); + void sequencer_play(); /// Stop the internal sequencer - void sequencer_stop(); + void sequencer_stop(); - void midi_noteOn( Note *note ); + void midi_noteOn( Note *note ); ///Last received midi message - QString lastMidiEvent; - int lastMidiEventParameter; + QString lastMidiEvent; + int lastMidiEventParameter; - void sequencer_setNextPattern( int pos ); - void togglePlaysSelected( void ); + void sequencer_setNextPattern( int pos ); + void togglePlaysSelected( void ); // ***** ~SEQUENCER ******** /// Set/Get current song - Song* getSong() { return __song; } - void setSong( Song *newSong ); + Song* getSong() { return __song; } + void setSong ( Song *newSong ); - void removeSong(); + void removeSong(); - 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 ); + 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 ); - float getMasterPeak_L(); - void setMasterPeak_L( float value ); + float getMasterPeak_L(); + void setMasterPeak_L( float value ); - float getMasterPeak_R(); - void setMasterPeak_R( float value ); + float getMasterPeak_R(); + void setMasterPeak_R( float value ); - void getLadspaFXPeak( int nFX, float *fL, float *fR ); - void setLadspaFXPeak( int nFX, float fL, float fR ); + void getLadspaFXPeak( int nFX, float *fL, float *fR ); + void setLadspaFXPeak( int nFX, float fL, float fR ); - unsigned long getTickPosition(); - unsigned long getRealtimeTickPosition(); - unsigned long getTotalFrames(); + unsigned long getTickPosition(); + unsigned long getRealtimeTickPosition(); + unsigned long getTotalFrames(); - void setRealtimeFrames( unsigned long frames ); - unsigned long getRealtimeFrames(); + void setRealtimeFrames( unsigned long frames ); + unsigned long getRealtimeFrames(); - PatternList * getCurrentPatternList(); - void setCurrentPatternList( PatternList * pPatternList ); + PatternList * getCurrentPatternList(); + void setCurrentPatternList( PatternList * pPatternList ); - PatternList * getNextPatterns(); + PatternList * getNextPatterns(); - int getPatternPos(); - void setPatternPos( int pos ); + int getPatternPos(); + void setPatternPos( int pos ); - void triggerRelocateDuringPlay(); + void triggerRelocateDuringPlay(); - long getTickForPosition( int ); + long getTickForPosition( int ); - void restartDrivers(); + void restartDrivers(); - void startExportSong( const QString& filename, int rate, int depth ); - void stopExportSong( bool reconnectOldDriver ); + void startExportSong( const QString& filename, int rate, int depth ); + void stopExportSong( bool reconnectOldDriver ); - AudioOutput* getAudioOutput(); - MidiInput* getMidiInput(); - MidiOutput* getMidiOutput(); + AudioOutput* getAudioOutput(); + MidiInput* getMidiInput(); + MidiOutput* getMidiOutput(); - int getState(); + int getState(); - float getProcessTime(); - float getMaxProcessTime(); + float getProcessTime(); + float getMaxProcessTime(); - int loadDrumkit( Drumkit *drumkitInfo ); + int loadDrumkit( Drumkit *drumkitInfo ); /// delete an instrument. If `conditional` is true, and there are patterns that /// use this instrument, it's not deleted anyway - void removeInstrument( int instrumentnumber, bool conditional ); + void removeInstrument( int instrumentnumber, bool conditional ); //return the name of the current drumkit - QString m_currentDrumkit; + QString m_currentDrumkit; - const QString& getCurrentDrumkitname() { - return m_currentDrumkit; - } + const QString& getCurrentDrumkitname(); + void setCurrentDrumkitname( const QString& currentdrumkitname ); - void setCurrentDrumkitname( const QString& currentdrumkitname ) { - this->m_currentDrumkit = currentdrumkitname; - } + void raiseError( unsigned nErrorCode ); - void raiseError( unsigned nErrorCode ); - - void previewSample( Sample *pSample ); - void previewInstrument( Instrument *pInstr ); + void previewSample( Sample *pSample ); + void previewInstrument( Instrument *pInstr ); enum ErrorMessages { UNKNOWN_DRIVER, @@ -158,24 +160,24 @@ class Hydrogen : public H2Core::Object JACK_ERROR_IN_PORT_REGISTER }; - void onTapTempoAccelEvent(); - void setTapTempo( float fInterval ); - void setBPM( float fBPM ); + void onTapTempoAccelEvent(); + void setTapTempo( float fInterval ); + void setBPM( float fBPM ); - void restartLadspaFX(); - void setSelectedPatternNumberWithoutGuiEvent( int nPat ); - int getSelectedPatternNumber(); - void setSelectedPatternNumber( int nPat ); + void restartLadspaFX(); + void setSelectedPatternNumberWithoutGuiEvent( int nPat ); + int getSelectedPatternNumber(); + void setSelectedPatternNumber( int nPat ); - int getSelectedInstrumentNumber(); - void setSelectedInstrumentNumber( int nInstrument ); + int getSelectedInstrumentNumber(); + void setSelectedInstrumentNumber( int nInstrument ); #ifdef H2CORE_HAVE_JACK - void renameJackPorts(); + void renameJackPorts(); #endif #ifdef H2CORE_HAVE_NSMSESSION - void startNsmClient(); + void startNsmClient(); #endif ///playlist vector @@ -190,44 +192,38 @@ class Hydrogen : public H2Core::Object std::vector m_PlayList; ///beatconter - void setbeatsToCount( int beatstocount); - int getbeatsToCount(); - void setNoteLength( float notelength); - float getNoteLength(); - int getBcStatus(); - void handleBeatCounter(); - void setBcOffsetAdjust(); + void setbeatsToCount( int beatstocount); + int getbeatsToCount(); + void setNoteLength( float notelength); + float getNoteLength(); + int getBcStatus(); + void handleBeatCounter(); + void setBcOffsetAdjust(); /// jack time master - unsigned long getHumantimeFrames(); - void setHumantimeFrames(unsigned long hframes); - void offJackMaster(); - void onJackMaster(); - unsigned long getTimeMasterFrames(); - long getTickForHumanPosition( int humanpos ); - float getNewBpmJTM(); - void setNewBpmJTM( float bpmJTM); - void ComputeHumantimeFrames(uint32_t nFrames); - - void __panic(); - int __get_selected_PatterNumber(); - unsigned int __getMidiRealtimeNoteTickPosition(); + unsigned long getHumantimeFrames(); + void setHumantimeFrames(unsigned long hframes); + void offJackMaster(); + void onJackMaster(); + unsigned long getTimeMasterFrames(); + long getTickForHumanPosition( int humanpos ); + float getNewBpmJTM(); + void setNewBpmJTM( float bpmJTM); + void ComputeHumantimeFrames(uint32_t nFrames); + + void __panic(); + int __get_selected_PatterNumber(); + unsigned int __getMidiRealtimeNoteTickPosition(); ///sample editor vectors - - void sortTimelineVector(); - void sortTimelineTagVector(); + void sortTimelineVector(); + void sortTimelineTagVector(); /// timeline vector struct HTimelineVector { - int m_htimelinebeat; //beat position in timeline -// int m_htimelinebar; //bar position from current beat - float m_htimelinebpm; //BPM -// bool m_htimelineslide; //true if slide into new tempo -// int m_htimelineslidebeatbegin; //position of slide begin (only beats, no bars) -// int m_htimelineslideend; //position of slide end (only beats, no bars) -// int m_htimelineslidetype; // 0 = slide up, 1 = slide down + int m_htimelinebeat; //beat position in timeline + float m_htimelinebpm; //BPM }; std::vector m_timelinevector; @@ -244,8 +240,7 @@ class Hydrogen : public H2Core::Object /// timeline tag vector struct HTimelineTagVector { - int m_htimelinetagbeat; //beat position in timeline -// int m_htimelineintensity; //intensity + int m_htimelinetagbeat; //beat position in timeline QString m_htimelinetag; // tag }; std::vector m_timelinetagvector; @@ -260,7 +255,6 @@ class Hydrogen : public H2Core::Object ///midi lookuptable int m_nInstrumentLookupTable[MAX_INSTRUMENTS]; - //void editInstrumentLookupTable( int instrument, int index); private: @@ -273,16 +267,16 @@ class Hydrogen : public H2Core::Object // beatcounter float m_ntaktoMeterCompute; ///< beatcounter note length int m_nbeatsToCount; ///< beatcounter beats to count - int m_nEventCount; ///< beatcounter event - int m_nTempoChangeCounter; ///< count tempochanges for timeArray - int m_nBeatCount; ///< beatcounter beat to count - double m_nBeatDiffs[16]; ///< beat diff - timeval m_CurrentTime; ///< timeval - timeval m_LastTime; ///< timeval - double m_nLastBeatTime; ///< timediff - double m_nCurrentBeatTime; ///< timediff - double m_nBeatDiff; ///< timediff - float m_fBeatCountBpm; ///< bpm + int m_nEventCount; ///< beatcounter event + int m_nTempoChangeCounter; ///< count tempochanges for timeArray + int m_nBeatCount; ///< beatcounter beat to count + double m_nBeatDiffs[16]; ///< beat diff + timeval m_CurrentTime; ///< timeval + timeval m_LastTime; ///< timeval + double m_nLastBeatTime; ///< timediff + double m_nCurrentBeatTime; ///< timediff + double m_nBeatDiff; ///< timediff + float m_fBeatCountBpm; ///< bpm int m_nCoutOffset; ///ms default 0 int m_nStartOffset; ///ms default 0 //~ beatcounter @@ -302,6 +296,21 @@ class Hydrogen : public H2Core::Object }; + +/* + * inline methods + */ + +inline const QString& Hydrogen::getCurrentDrumkitname() +{ + return m_currentDrumkit; +} + +inline void Hydrogen::setCurrentDrumkitname( const QString& currentdrumkitname ) +{ + this->m_currentDrumkit = currentdrumkitname; +} + }; #endif diff --git a/src/core/src/hydrogen.cpp b/src/core/src/hydrogen.cpp index cdf745eff..0ed25f161 100644 --- a/src/core/src/hydrogen.cpp +++ b/src/core/src/hydrogen.cpp @@ -93,23 +93,23 @@ namespace H2Core // GLOBALS // info -float m_fMasterPeak_L = 0.0f; ///< Master peak (left channel) -float m_fMasterPeak_R = 0.0f; ///< Master peak (right channel) -float m_fProcessTime = 0.0f; ///< time used in process function -float m_fMaxProcessTime = 0.0f; ///< max ms usable in process with no xrun +float m_fMasterPeak_L = 0.0f; ///< Master peak (left channel) +float m_fMasterPeak_R = 0.0f; ///< Master peak (right channel) +float m_fProcessTime = 0.0f; ///< time used in process function +float m_fMaxProcessTime = 0.0f; ///< max ms usable in process with no xrun //~ info //jack time master -float m_nNewBpmJTM = 120; -unsigned long m_nHumantimeFrames = 0; +float m_nNewBpmJTM = 120; +unsigned long m_nHumantimeFrames = 0; //~ jack time master -AudioOutput *m_pAudioDriver = NULL; ///< Audio output -QMutex mutex_OutputPointer; ///< Mutex for audio output pointer, allows multiple readers +AudioOutput * m_pAudioDriver = NULL; ///< Audio output +QMutex mutex_OutputPointer; ///< Mutex for audio output pointer, allows multiple readers ///< When locking this AND AudioEngine, always lock AudioEngine first. -MidiInput *m_pMidiDriver = NULL; ///< MIDI input -MidiOutput *m_pMidiDriverOut = NULL; ///< MIDI output +MidiInput * m_pMidiDriver = NULL; ///< MIDI input +MidiOutput * m_pMidiDriverOut = NULL; ///< MIDI output // overload the the > operator of Note objects for priority_queue struct compare_pNotes { @@ -124,73 +124,72 @@ struct compare_pNotes { /// Song Note FIFO std::priority_queue, compare_pNotes > m_songNoteQueue; -std::deque m_midiNoteQueue; ///< Midi Note FIFO +std::deque m_midiNoteQueue; ///< Midi Note FIFO -PatternList* m_pNextPatterns; ///< Next pattern (used only in Pattern mode) -bool m_bAppendNextPattern; ///< Add the next pattern to the list instead -/// of replace. -bool m_bDeleteNextPattern; ///< Delete the next pattern from the list. +PatternList* m_pNextPatterns; ///< Next pattern (used only in Pattern mode) +bool m_bAppendNextPattern; ///< Add the next pattern to the list instead of replace. +bool m_bDeleteNextPattern; ///< Delete the next pattern from the list. -PatternList* m_pPlayingPatterns; -int m_nSongPos; ///< Is the position inside the song +PatternList* m_pPlayingPatterns; +int m_nSongPos; ///< Is the position inside the song -int m_nSelectedPatternNumber; -int m_nSelectedInstrumentNumber; +int m_nSelectedPatternNumber; +int m_nSelectedInstrumentNumber; -Instrument *m_pMetronomeInstrument = NULL; ///< Metronome instrument +Instrument * m_pMetronomeInstrument = NULL; ///< Metronome instrument // Buffers used in the process function -unsigned m_nBufferSize = 0; -float *m_pMainBuffer_L = NULL; -float *m_pMainBuffer_R = NULL; +unsigned m_nBufferSize = 0; +float * m_pMainBuffer_L = NULL; +float * m_pMainBuffer_R = NULL; -Hydrogen* hydrogenInstance = NULL; ///< Hydrogen class instance (used for log) +Hydrogen* hydrogenInstance = NULL; ///< Hydrogen class instance (used for log) -int m_audioEngineState = STATE_UNINITIALIZED; ///< Audio engine state +int m_audioEngineState = STATE_UNINITIALIZED; ///< Audio engine state #ifdef H2CORE_HAVE_LADSPA -float m_fFXPeak_L[MAX_FX]; -float m_fFXPeak_R[MAX_FX]; +float m_fFXPeak_L[MAX_FX]; +float m_fFXPeak_R[MAX_FX]; #endif -int m_nPatternStartTick = -1; -unsigned int m_nPatternTickPosition = 0; -int m_nLookaheadFrames = 0; +int m_nPatternStartTick = -1; +unsigned int m_nPatternTickPosition = 0; +int m_nLookaheadFrames = 0; // used in findPatternInTick -int m_nSongSizeInTicks = 0; +int m_nSongSizeInTicks = 0; -struct timeval m_currentTickTime; +struct timeval m_currentTickTime; -unsigned long m_nRealtimeFrames = 0; -unsigned int m_naddrealtimenotetickposition = 0; +unsigned long m_nRealtimeFrames = 0; +unsigned int m_naddrealtimenotetickposition = 0; // PROTOTYPES -void audioEngine_init(); -void audioEngine_destroy(); -int audioEngine_start( bool bLockEngine = false, unsigned nTotalFrames = 0 ); -void audioEngine_stop( bool bLockEngine = false ); -void audioEngine_setSong( Song *newSong ); -void audioEngine_removeSong(); -static void audioEngine_noteOn( Note *note ); +void audioEngine_init(); +void audioEngine_destroy(); +int audioEngine_start( bool bLockEngine = false, unsigned nTotalFrames = 0 ); +void audioEngine_stop( bool bLockEngine = false ); +void audioEngine_setSong( Song *newSong ); +void audioEngine_removeSong(); +static void audioEngine_noteOn( Note *note ); -int audioEngine_process( uint32_t nframes, void *arg ); -inline void audioEngine_clearNoteQueue(); -inline void audioEngine_process_checkBPMChanged(); -inline void audioEngine_process_playNotes( unsigned long nframes ); -inline void audioEngine_process_transport(); +int audioEngine_process( uint32_t nframes, void *arg ); +inline void audioEngine_clearNoteQueue(); +inline void audioEngine_process_checkBPMChanged(); +inline void audioEngine_process_playNotes( unsigned long nframes ); +inline void audioEngine_process_transport(); -inline unsigned audioEngine_renderNote( Note* pNote, const unsigned& nBufferSize ); -inline int audioEngine_updateNoteQueue( unsigned nFrames ); -inline void audioEngine_prepNoteQueue(); +inline unsigned audioEngine_renderNote( Note* pNote, const unsigned& nBufferSize ); +inline int audioEngine_updateNoteQueue( unsigned nFrames ); +inline void audioEngine_prepNoteQueue(); -inline int findPatternInTick( int tick, bool loopMode, int *patternStartTick ); +inline int findPatternInTick( int tick, bool loopMode, int *patternStartTick ); -void audioEngine_seek( long long nFrames, bool bLoopMode = false ); +void audioEngine_seek( long long nFrames, bool bLoopMode = false ); -void audioEngine_restartAudioDrivers(); -void audioEngine_startAudioDrivers(); -void audioEngine_stopAudioDrivers(); +void audioEngine_restartAudioDrivers(); +void audioEngine_startAudioDrivers(); +void audioEngine_stopAudioDrivers(); inline timeval currentTime2() { @@ -3086,11 +3085,13 @@ unsigned long Hydrogen::getTimeMasterFrames() long Hydrogen::getTickForHumanPosition( int humanpos ) { Song* pSong = getSong(); - if ( ! pSong ) return -1; + if ( ! pSong ){ + return -1; + } - std::vector< PatternList* > *columns = pSong->get_pattern_group_vector(); + std::vector< PatternList* > * pColumns = pSong->get_pattern_group_vector(); - int nPatternGroups = columns->size(); + int nPatternGroups = pColumns->size(); if ( humanpos >= nPatternGroups ) { if ( pSong->is_loop_enabled() ) { humanpos = humanpos % nPatternGroups; @@ -3099,10 +3100,12 @@ long Hydrogen::getTickForHumanPosition( int humanpos ) } } - // ERRORLOG( "Kick me! " ); - if ( humanpos < 1 ) return MAX_NOTES; - PatternList* pl = columns->at( humanpos - 1 ); - Pattern *pPattern = pl->get( 0 ); + if ( humanpos < 1 ){ + return MAX_NOTES; + } + + PatternList* pPatternList = pColumns->at( humanpos - 1 ); + Pattern *pPattern = pPatternList->get( 0 ); if ( pPattern ) { return pPattern->get_length(); } else { From 0b1b9089e978ce258d8d1cb6827cb8f5138fd3b1 Mon Sep 17 00:00:00 2001 From: Sebastian Moors Date: Sat, 15 Nov 2014 00:50:52 +0100 Subject: [PATCH 3/5] Added Timeline class --- src/core/include/hydrogen/timeline.h | 81 ++++++++++++++++++++++++++++ src/core/src/timeline.cpp | 47 ++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 src/core/include/hydrogen/timeline.h create mode 100644 src/core/src/timeline.cpp diff --git a/src/core/include/hydrogen/timeline.h b/src/core/include/hydrogen/timeline.h new file mode 100644 index 000000000..35d0f1403 --- /dev/null +++ b/src/core/include/hydrogen/timeline.h @@ -0,0 +1,81 @@ +/* + * Hydrogen + * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net] + * + * http://www.hydrogen-music.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY, without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifndef TIMELINE_H +#define TIMELINE_H + +#include + +namespace H2Core +{ + class Timeline : public H2Core::Object + { + H2_OBJECT + + public: + Timeline(); + + ///sample editor vectors + void sortTimelineVector(); + void sortTimelineTagVector(); + + /// timeline vector + struct HTimelineVector + { + int m_htimelinebeat; //beat position in timeline + float m_htimelinebpm; //BPM + }; + + /// timeline tag vector + struct HTimelineTagVector + { + int m_htimelinetagbeat; //beat position in timeline + QString m_htimelinetag; // tag + }; + + + std::vector m_timelinevector; + std::vector m_timelinetagvector; + + struct TimelineComparator + { + bool operator()( HTimelineVector const& lhs, HTimelineVector const& rhs) + { + return lhs.m_htimelinebeat < rhs.m_htimelinebeat; + } + }; + + struct TimelineTagComparator + { + bool operator()( HTimelineTagVector const& lhs, HTimelineTagVector const& rhs) + { + return lhs.m_htimelinetagbeat < rhs.m_htimelinetagbeat; + } + }; + + + private: + + }; +}; + +#endif // TIMELINE_H diff --git a/src/core/src/timeline.cpp b/src/core/src/timeline.cpp new file mode 100644 index 000000000..c9f8e3b07 --- /dev/null +++ b/src/core/src/timeline.cpp @@ -0,0 +1,47 @@ +/* + * Hydrogen + * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net] + * + * http://www.hydrogen-music.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY, without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + + +#include + +namespace H2Core +{ + const char* Timeline::__class_name = "Timeline"; + + Timeline::Timeline() : Object( __class_name ) + { + } + + void Timeline::sortTimelineVector() + { + //sort the timeline vector to beats a < b + sort(m_timelinevector.begin(), m_timelinevector.end(), TimelineComparator()); + } + + void Timeline::sortTimelineTagVector() + { + //sort the timeline vector to beats a < b + sort(m_timelinetagvector.begin(), m_timelinetagvector.end(), TimelineTagComparator()); + } + +}; + From 71b29364e75e09995734972eba8777ea7c90ffc1 Mon Sep 17 00:00:00 2001 From: Sebastian Moors Date: Sat, 15 Nov 2014 00:54:31 +0100 Subject: [PATCH 4/5] Refactoring: Move Timeline functionality out of Hydrogen class --- src/core/include/hydrogen/hydrogen.h | 50 +++--------- src/core/src/IO/disk_writer_driver.cpp | 11 ++- src/core/src/basics/song.cpp | 18 +++-- src/core/src/hydrogen.cpp | 25 +++--- src/core/src/local_file_mgr.cpp | 20 +++-- src/gui/src/Director.cpp | 16 ++-- src/gui/src/Director.h | 29 ++++--- src/gui/src/ExportSongDialog.cpp | 30 +++---- src/gui/src/MainForm.cpp | 24 +++--- src/gui/src/PlaylistEditor/PlaylistDialog.cpp | 7 +- src/gui/src/SongEditor/SongEditor.cpp | 79 +++++++++++-------- .../SongEditor/SongEditorPanelBpmWidget.cpp | 24 +++--- .../SongEditor/SongEditorPanelTagWidget.cpp | 13 ++- 13 files changed, 179 insertions(+), 167 deletions(-) diff --git a/src/core/include/hydrogen/hydrogen.h b/src/core/include/hydrogen/hydrogen.h index 1366aa9ef..69d6fba33 100644 --- a/src/core/include/hydrogen/hydrogen.h +++ b/src/core/include/hydrogen/hydrogen.h @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -215,46 +216,12 @@ class Hydrogen : public H2Core::Object int __get_selected_PatterNumber(); unsigned int __getMidiRealtimeNoteTickPosition(); - ///sample editor vectors - void sortTimelineVector(); - void sortTimelineTagVector(); + void setTimelineBpm(); + Timeline* getTimeline() const; -/// timeline vector - struct HTimelineVector - { - int m_htimelinebeat; //beat position in timeline - float m_htimelinebpm; //BPM - }; - std::vector m_timelinevector; - - struct TimelineComparator - { - bool operator()( HTimelineVector const& lhs, HTimelineVector const& rhs) - { - return lhs.m_htimelinebeat < rhs.m_htimelinebeat; - } - }; - void setTimelineBpm(); - -/// timeline tag vector - struct HTimelineTagVector - { - int m_htimelinetagbeat; //beat position in timeline - QString m_htimelinetag; // tag - }; - std::vector m_timelinetagvector; - - struct TimelineTagComparator - { - bool operator()( HTimelineTagVector const& lhs, HTimelineTagVector const& rhs) - { - return lhs.m_htimelinetagbeat < rhs.m_htimelinetagbeat; - } - }; - - ///midi lookuptable - int m_nInstrumentLookupTable[MAX_INSTRUMENTS]; + ///midi lookuptable + int m_nInstrumentLookupTable[MAX_INSTRUMENTS]; private: @@ -286,6 +253,9 @@ class Hydrogen : public H2Core::Object Song::SongMode m_oldEngineMode; bool m_bOldLoopEnabled; + //Timline information + Timeline* m_pTimeline; + std::list __instrument_death_row; /// Deleting instruments too soon leads to potential crashes. @@ -300,6 +270,10 @@ class Hydrogen : public H2Core::Object /* * inline methods */ +inline Timeline* Hydrogen::getTimeline() const +{ + return m_pTimeline; +} inline const QString& Hydrogen::getCurrentDrumkitname() { diff --git a/src/core/src/IO/disk_writer_driver.cpp b/src/core/src/IO/disk_writer_driver.cpp index deb5ceb0f..acc11928f 100644 --- a/src/core/src/IO/disk_writer_driver.cpp +++ b/src/core/src/IO/disk_writer_driver.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -167,12 +168,14 @@ void* diskWriterDriver_thread( void* param ) ticksize = pDriver->m_nSampleRate * 60.0 / engine->getSong()->__bpm / engine->getSong()->__resolution; // check pattern bpm if timeline bpm is in use + Timeline* pTimeline = engine->getTimeline(); if(Preferences::get_instance()->getUseTimelineBpm() ){ - if( engine->m_timelinevector.size() >= 1 ){ + if( pTimeline->m_timelinevector.size() >= 1 ){ - for ( int t = 0; t < engine->m_timelinevector.size(); t++){ - if(engine->m_timelinevector[t].m_htimelinebeat == patternposition && engine->m_timelinevector[t].m_htimelinebpm != validBpm){ - validBpm = engine->m_timelinevector[t].m_htimelinebpm; + for ( int t = 0; t < pTimeline->m_timelinevector.size(); t++){ + if(pTimeline->m_timelinevector[t].m_htimelinebeat == patternposition && + pTimeline->m_timelinevector[t].m_htimelinebpm != validBpm){ + validBpm = pTimeline->m_timelinevector[t].m_htimelinebpm; } } diff --git a/src/core/src/basics/song.cpp b/src/core/src/basics/song.cpp index 2e9ec8160..002e4bf69 100644 --- a/src/core/src/basics/song.cpp +++ b/src/core/src/basics/song.cpp @@ -30,6 +30,7 @@ #include #include +#include #include #include #include @@ -822,32 +823,33 @@ Song* SongReader::readSong( const QString& filename ) WARNINGLOG( "ladspa node not found" ); } - Hydrogen::get_instance()->m_timelinevector.clear(); - Hydrogen::HTimelineVector tlvector; + Timeline* pTimeline = Hydrogen::get_instance()->getTimeline(); + pTimeline->m_timelinevector.clear(); + Timeline::HTimelineVector tlvector; QDomNode bpmTimeLine = songNode.firstChildElement( "BPMTimeLine" ); if ( !bpmTimeLine.isNull() ) { QDomNode newBPMNode = bpmTimeLine.firstChildElement( "newBPM" ); while( !newBPMNode.isNull() ) { tlvector.m_htimelinebeat = LocalFileMng::readXmlInt( newBPMNode, "BAR", 0 ); tlvector.m_htimelinebpm = LocalFileMng::readXmlFloat( newBPMNode, "BPM", 120.0 ); - Hydrogen::get_instance()->m_timelinevector.push_back( tlvector ); - Hydrogen::get_instance()->sortTimelineVector(); + pTimeline->m_timelinevector.push_back( tlvector ); + pTimeline->sortTimelineVector(); newBPMNode = newBPMNode.nextSiblingElement( "newBPM" ); } } else { WARNINGLOG( "bpmTimeLine node not found" ); } - Hydrogen::get_instance()->m_timelinetagvector.clear(); - Hydrogen::HTimelineTagVector tltagvector; + pTimeline->m_timelinetagvector.clear(); + Timeline::HTimelineTagVector tltagvector; QDomNode timeLineTag = songNode.firstChildElement( "timeLineTag" ); if ( !timeLineTag.isNull() ) { QDomNode newTAGNode = timeLineTag.firstChildElement( "newTAG" ); while( !newTAGNode.isNull() ) { tltagvector.m_htimelinetagbeat = LocalFileMng::readXmlInt( newTAGNode, "BAR", 0 ); tltagvector.m_htimelinetag = LocalFileMng::readXmlString( newTAGNode, "TAG", "" ); - Hydrogen::get_instance()->m_timelinetagvector.push_back( tltagvector ); - Hydrogen::get_instance()->sortTimelineTagVector(); + pTimeline->m_timelinetagvector.push_back( tltagvector ); + pTimeline->sortTimelineTagVector(); newTAGNode = newTAGNode.nextSiblingElement( "newTAG" ); } } else { diff --git a/src/core/src/hydrogen.cpp b/src/core/src/hydrogen.cpp index 0ed25f161..ece3299c0 100644 --- a/src/core/src/hydrogen.cpp +++ b/src/core/src/hydrogen.cpp @@ -64,6 +64,7 @@ #include #include #include +#include #ifdef H2CORE_HAVE_NSMSESSION #include @@ -1705,6 +1706,9 @@ Hydrogen::Hydrogen() INFOLOG( "[Hydrogen]" ); __song = NULL; + + m_pTimeline = new Timeline(); + hydrogenInstance = this; initBeatcounter(); @@ -1741,6 +1745,9 @@ Hydrogen::~Hydrogen() audioEngine_stopAudioDrivers(); audioEngine_destroy(); __kill_instruments(); + + delete m_pTimeline; + __instance = NULL; } @@ -3204,17 +3211,6 @@ unsigned int Hydrogen::__getMidiRealtimeNoteTickPosition() return m_naddrealtimenotetickposition; } -void Hydrogen::sortTimelineVector() -{ - //sort the timeline vector to beats a < b - sort(m_timelinevector.begin(), m_timelinevector.end(), TimelineComparator()); -} - -void Hydrogen::sortTimelineTagVector() -{ - //sort the timeline vector to beats a < b - sort(m_timelinetagvector.begin(), m_timelinetagvector.end(), TimelineTagComparator()); -} void Hydrogen::setTimelineBpm() { @@ -3223,11 +3219,12 @@ void Hydrogen::setTimelineBpm() //time line test if ( Preferences::get_instance()->getUseTimelineBpm() ) { float bpm = pSong->__bpm; - for ( int i = 0; i < static_cast(m_timelinevector.size() ); i++) { - if ( m_timelinevector[i].m_htimelinebeat > getPatternPos() ) + + for ( int i = 0; i < static_cast(m_pTimeline->m_timelinevector.size() ); i++) { + if ( m_pTimeline->m_timelinevector[i].m_htimelinebeat > getPatternPos() ) break; - bpm = m_timelinevector[i].m_htimelinebpm; + bpm = m_pTimeline->m_timelinevector[i].m_htimelinebpm; } if ( bpm != pSong->__bpm ) diff --git a/src/core/src/local_file_mgr.cpp b/src/core/src/local_file_mgr.cpp index 8ca828417..b8b8cb0dd 100644 --- a/src/core/src/local_file_mgr.cpp +++ b/src/core/src/local_file_mgr.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -1476,12 +1477,15 @@ int SongWriter::writeSong( Song *song, const QString& filename ) //bpm time line + Timeline * pTimeline = Hydrogen::get_instance()->getTimeline(); + QDomNode bpmTimeLine = doc.createElement( "BPMTimeLine" ); - if(Hydrogen::get_instance()->m_timelinevector.size() >= 1 ){ - for ( int t = 0; t < static_cast(Hydrogen::get_instance()->m_timelinevector.size()); t++){ + + if(pTimeline->m_timelinevector.size() >= 1 ){ + for ( int t = 0; t < static_cast(pTimeline->m_timelinevector.size()); t++){ QDomNode newBPMNode = doc.createElement( "newBPM" ); - LocalFileMng::writeXmlString( newBPMNode, "BAR",QString("%1").arg( Hydrogen::get_instance()->m_timelinevector[t].m_htimelinebeat )); - LocalFileMng::writeXmlString( newBPMNode, "BPM", QString("%1").arg( Hydrogen::get_instance()->m_timelinevector[t].m_htimelinebpm ) ); + LocalFileMng::writeXmlString( newBPMNode, "BAR",QString("%1").arg( pTimeline->m_timelinevector[t].m_htimelinebeat )); + LocalFileMng::writeXmlString( newBPMNode, "BPM", QString("%1").arg( pTimeline->m_timelinevector[t].m_htimelinebpm ) ); bpmTimeLine.appendChild( newBPMNode ); } } @@ -1489,11 +1493,11 @@ int SongWriter::writeSong( Song *song, const QString& filename ) //time line tag QDomNode timeLineTag = doc.createElement( "timeLineTag" ); - if(Hydrogen::get_instance()->m_timelinetagvector.size() >= 1 ){ - for ( int t = 0; t < static_cast(Hydrogen::get_instance()->m_timelinetagvector.size()); t++){ + if(pTimeline->m_timelinetagvector.size() >= 1 ){ + for ( int t = 0; t < static_cast(pTimeline->m_timelinetagvector.size()); t++){ QDomNode newTAGNode = doc.createElement( "newTAG" ); - LocalFileMng::writeXmlString( newTAGNode, "BAR",QString("%1").arg( Hydrogen::get_instance()->m_timelinetagvector[t].m_htimelinetagbeat )); - LocalFileMng::writeXmlString( newTAGNode, "TAG", QString("%1").arg( Hydrogen::get_instance()->m_timelinetagvector[t].m_htimelinetag ) ); + LocalFileMng::writeXmlString( newTAGNode, "BAR",QString("%1").arg( pTimeline->m_timelinetagvector[t].m_htimelinetagbeat )); + LocalFileMng::writeXmlString( newTAGNode, "TAG", QString("%1").arg( pTimeline->m_timelinetagvector[t].m_htimelinetag ) ); timeLineTag.appendChild( newTAGNode ); } } diff --git a/src/gui/src/Director.cpp b/src/gui/src/Director.cpp index b17cad7bb..43207ac05 100644 --- a/src/gui/src/Director.cpp +++ b/src/gui/src/Director.cpp @@ -58,6 +58,7 @@ #include #include +#include #include @@ -79,6 +80,7 @@ Director::Director ( QWidget* pParent ) p_wechselblink = width() * 5/100; f_bpm = Hydrogen::get_instance()->getSong()->__bpm; + m_pTimeline = Hydrogen::get_instance()->getTimeline(); timer = new QTimer( this ); connect( timer, SIGNAL( timeout() ), this, SLOT( updateMetronomBackground() ) ); } @@ -144,15 +146,15 @@ void Director::metronomeEvent( int nValue ) // get tags __TAG=""; __TAG2=""; - for ( size_t t = 0; t < Hydrogen::get_instance()->m_timelinetagvector.size(); t++){ - if(t+1m_timelinetagvector.size() && - Hydrogen::get_instance()->m_timelinetagvector[t+1].m_htimelinetagbeat == p_bar ){ - __TAG2 = Hydrogen::get_instance()->m_timelinetagvector[t+1].m_htimelinetag ; + for ( size_t t = 0; t < m_pTimeline->m_timelinetagvector.size(); t++){ + if(t+1m_timelinetagvector.size() && + m_pTimeline->m_timelinetagvector[t+1].m_htimelinetagbeat == p_bar ){ + __TAG2 = m_pTimeline->m_timelinetagvector[t+1].m_htimelinetag ; } - if ( Hydrogen::get_instance()->m_timelinetagvector[t].m_htimelinetagbeat <= p_bar-1){ - __TAG = Hydrogen::get_instance()->m_timelinetagvector[t].m_htimelinetag ; + if ( m_pTimeline->m_timelinetagvector[t].m_htimelinetagbeat <= p_bar-1){ + __TAG = m_pTimeline->m_timelinetagvector[t].m_htimelinetag ; } - if( Hydrogen::get_instance()->m_timelinetagvector[t].m_htimelinetagbeat > p_bar-1){ + if( m_pTimeline->m_timelinetagvector[t].m_htimelinetagbeat > p_bar-1){ break; } } diff --git a/src/gui/src/Director.h b/src/gui/src/Director.h index c6b098c5a..8a01b6a37 100644 --- a/src/gui/src/Director.h +++ b/src/gui/src/Director.h @@ -29,6 +29,7 @@ #include #include #include +#include #include "EventListener.h" @@ -45,25 +46,23 @@ class Director : public QDialog, public Ui_Director_UI, public H2Core::Object, p virtual void paintEvent( QPaintEvent*); private slots: - void updateMetronomBackground(); - //void updateBackground(); private: - QTimer *timer; - QColor __color; - // QPixmap *m_pBackground; - QPalette __blinkerPalette; - int p_counter; - int p_fadealpha; - float f_bpm; - int p_bar; - int p_wechselblink; - QString __TAG; - QString __TAG2; - QString __songName; - int p_tagbeat; + QTimer *timer; + H2Core::Timeline *m_pTimeline; + QColor __color; + QPalette __blinkerPalette; + int p_counter; + int p_fadealpha; + float f_bpm; + int p_bar; + int p_wechselblink; + QString __TAG; + QString __TAG2; + QString __songName; + int p_tagbeat; }; diff --git a/src/gui/src/ExportSongDialog.cpp b/src/gui/src/ExportSongDialog.cpp index ff3e8d5a7..8d9f95a19 100644 --- a/src/gui/src/ExportSongDialog.cpp +++ b/src/gui/src/ExportSongDialog.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -68,14 +69,15 @@ ExportSongDialog::ExportSongDialog(QWidget* parent) exportTypeCombo->addItem(trUtf8("Both")); HydrogenApp::get_instance()->addEventListener( this ); + Hydrogen * pHydrogen = Hydrogen::get_instance(); m_pProgressBar->setValue( 0 ); sampleRateCombo->setCurrentIndex(1); sampleDepthCombo->setCurrentIndex(1); - QString defaultFilename( Hydrogen::get_instance()->getSong()->get_filename() ); - if( Hydrogen::get_instance()->getSong()->get_filename().isEmpty() ) - defaultFilename = Hydrogen::get_instance()->getSong()->__name; + QString defaultFilename( pHydrogen->getSong()->get_filename() ); + if( pHydrogen->getSong()->get_filename().isEmpty() ) + defaultFilename = pHydrogen->getSong()->__name; defaultFilename.replace( '*', "_" ); defaultFilename.replace( ".h2song", "" ); defaultFilename += ".wav"; @@ -99,7 +101,7 @@ ExportSongDialog::ExportSongDialog(QWidget* parent) // use of timeline - if( Hydrogen::get_instance()->m_timelinevector.size() > 0 ){ + if( pHydrogen->getTimeline()->m_timelinevector.size() > 0 ){ toggleTimeLineBPMCheckBox->setChecked(Preferences::get_instance()->getUseTimelineBpm()); b_oldTimeLineBPMMode = Preferences::get_instance()->getUseTimelineBpm(); connect(toggleTimeLineBPMCheckBox, SIGNAL(toggled(bool)), this, SLOT(togglTimeLineBPMMode( bool ))); @@ -200,8 +202,6 @@ void ExportSongDialog::on_okBtn_clicked() bool warn = Preferences::get_instance()->getShowExportWarning(); - std::vector timelineVector = engine->m_timelinevector; - /* 0: Export to single track * 1: Export to multiple tracks * 2: Export to both @@ -555,20 +555,22 @@ void ExportSongDialog::calculateRubberbandTime() closeBtn->setEnabled(false); resampleComboBox->setEnabled(false); okBtn->setEnabled(false); - Hydrogen* engine = Hydrogen::get_instance(); - float oldBPM = engine->getSong()->__bpm; + Hydrogen* pHydrogen = Hydrogen::get_instance(); + Timeline* pTimeline = pHydrogen->getTimeline(); + + float oldBPM = pHydrogen->getSong()->__bpm; float lowBPM = oldBPM; - if( engine->m_timelinevector.size() >= 1 ){ - for ( int t = 0; t < engine->m_timelinevector.size(); t++){ - if(engine->m_timelinevector[t].m_htimelinebpm < lowBPM){ - lowBPM = engine->m_timelinevector[t].m_htimelinebpm; + if( pTimeline->m_timelinevector.size() >= 1 ){ + for ( int t = 0; t < pTimeline->m_timelinevector.size(); t++){ + if(pTimeline->m_timelinevector[t].m_htimelinebpm < lowBPM){ + lowBPM = pTimeline->m_timelinevector[t].m_htimelinebpm; } } } - engine->setBPM(lowBPM); + pHydrogen->setBPM(lowBPM); time_t sTime = time(NULL); Hydrogen *pEngine = Hydrogen::get_instance(); Song *song = pEngine->getSong(); @@ -610,7 +612,7 @@ void ExportSongDialog::calculateRubberbandTime() } } Preferences::get_instance()->setRubberBandCalcTime(time(NULL) - sTime); - engine->setBPM(oldBPM); + pHydrogen->setBPM(oldBPM); closeBtn->setEnabled(true); resampleComboBox->setEnabled(true); okBtn->setEnabled(true); diff --git a/src/gui/src/MainForm.cpp b/src/gui/src/MainForm.cpp index c5b2eb940..d88b07b90 100644 --- a/src/gui/src/MainForm.cpp +++ b/src/gui/src/MainForm.cpp @@ -20,18 +20,20 @@ * */ +#include #include #include #include #include #include #include +#include #include #include #include #include #include -#include + #include "AboutDialog.h" #include "AudioEngineInfoForm.h" @@ -453,8 +455,9 @@ bool MainForm::action_file_exit() void MainForm::action_file_new() { - if ( (Hydrogen::get_instance()->getState() == STATE_PLAYING) ) { - Hydrogen::get_instance()->sequencer_stop(); + Hydrogen * pEngine = Hydrogen::get_instance(); + if ( (pEngine->getState() == STATE_PLAYING) ) { + pEngine->sequencer_stop(); } bool proceed = handleUnsavedChanges(); @@ -463,14 +466,14 @@ void MainForm::action_file_new() } h2app->m_undoStack->clear(); - Hydrogen::get_instance()->m_timelinevector.clear(); + pEngine->getTimeline()->m_timelinevector.clear(); Song * song = Song::get_empty_song(); song->set_filename( "" ); h2app->setSong(song); - Hydrogen::get_instance()->setSelectedPatternNumber( 0 ); - HydrogenApp::get_instance()->getInstrumentRack()->getSoundLibraryPanel()->update_background_color(); - HydrogenApp::get_instance()->getSongEditorPanel()->updatePositionRuler(); - Hydrogen::get_instance()->m_timelinetagvector.clear(); + pEngine->setSelectedPatternNumber( 0 ); + h2app->getInstrumentRack()->getSoundLibraryPanel()->update_background_color(); + h2app->getSongEditorPanel()->updatePositionRuler(); + pEngine->getTimeline()->m_timelinetagvector.clear(); // update director tags EventQueue::get_instance()->push_event( EVENT_METRONOME, 2 ); @@ -1142,15 +1145,16 @@ void MainForm::openSongFile( const QString& sFilename ) engine->sequencer_stop(); } - engine->m_timelinetagvector.clear(); + engine->getTimeline()->m_timelinetagvector.clear(); h2app->closeFXProperties(); - LocalFileMng mng; + Song *pSong = Song::load( sFilename ); if ( pSong == NULL ) { QMessageBox::information( this, "Hydrogen", trUtf8("Error loading song.") ); return; } + h2app->m_undoStack->clear(); // add the new loaded song in the "last used song" vector diff --git a/src/gui/src/PlaylistEditor/PlaylistDialog.cpp b/src/gui/src/PlaylistEditor/PlaylistDialog.cpp index 85db39672..f38b8a1ec 100644 --- a/src/gui/src/PlaylistEditor/PlaylistDialog.cpp +++ b/src/gui/src/PlaylistEditor/PlaylistDialog.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include "../widgets/Button.h" @@ -67,7 +68,6 @@ PlaylistDialog::PlaylistDialog ( QWidget* pParent ) // menubar QMenuBar *m_pMenubar = new QMenuBar( this ); -// setMenuBar( m_pMenubar ); // Playlist menu QMenu *m_pPlaylistMenu = m_pMenubar->addMenu( trUtf8( "&Playlist" ) ); @@ -76,7 +76,7 @@ PlaylistDialog::PlaylistDialog ( QWidget* pParent ) m_pPlaylistMenu->addAction( trUtf8( "Add ¤t song to Playlist" ), this, SLOT( addCurrentSong() ), QKeySequence( "" ) ); m_pPlaylistMenu->addSeparator(); // ----- m_pPlaylistMenu->addAction( trUtf8( "&Remove selected song from Playlist" ), this, SLOT( removeFromList() ), QKeySequence( "" ) ); - m_pPlaylistMenu->addAction( trUtf8( "&New Playlist" ), this, SLOT( clearPlaylist() ), QKeySequence( "" ) ); + m_pPlaylistMenu->addAction( trUtf8( "&New Playlist" ), this, SLOT( clearPlaylist() ), QKeySequence( "" ) ); m_pPlaylistMenu->addSeparator(); m_pPlaylistMenu->addAction( trUtf8( "&Open Playlist" ), this, SLOT( loadList() ), QKeySequence( "" ) ); m_pPlaylistMenu->addSeparator(); @@ -791,7 +791,8 @@ void PlaylistDialog::on_m_pPlaylistTree_itemDoubleClicked () m_pPlayBtn->setPressed(false); - engine->m_timelinetagvector.clear(); + Timeline* pTimeline = engine->getTimeline(); + pTimeline->m_timelinetagvector.clear(); Song *pSong = Song::load ( selected ); if ( pSong == NULL ){ diff --git a/src/gui/src/SongEditor/SongEditor.cpp b/src/gui/src/SongEditor/SongEditor.cpp index 70e456290..be7db7785 100644 --- a/src/gui/src/SongEditor/SongEditor.cpp +++ b/src/gui/src/SongEditor/SongEditor.cpp @@ -32,6 +32,8 @@ #include #include #include +#include +#include using namespace H2Core; #include "UndoActions.h" @@ -51,7 +53,9 @@ using namespace H2Core; #include "../SongPropertiesDialog.h" #include "../Skin.h" #include "../VirtualPatternDialog.h" -#include + + + #ifdef WIN32 #include @@ -977,11 +981,12 @@ void SongEditorPatternList::patternChangedEvent() { update(); ///here we check the timeline && m_pSong->get_mode() == Song::SONG_MODE Hydrogen *engine = Hydrogen::get_instance(); + Timeline *pTimeline = engine->getTimeline(); if ( ( Preferences::get_instance()->getUseTimelineBpm() ) && ( engine->getSong()->get_mode() == Song::SONG_MODE ) ){ - for ( int i = 0; i < static_cast(engine->m_timelinevector.size()); i++){ - if ( ( engine->m_timelinevector[i].m_htimelinebeat == engine->getPatternPos() ) - && ( engine->getNewBpmJTM() != engine->m_timelinevector[i].m_htimelinebpm ) ){ - engine->setBPM( engine->m_timelinevector[i].m_htimelinebpm ); + for ( int i = 0; i < static_cast(pTimeline->m_timelinevector.size()); i++){ + if ( ( pTimeline->m_timelinevector[i].m_htimelinebeat == engine->getPatternPos() ) + && ( engine->getNewBpmJTM() != pTimeline->m_timelinevector[i].m_htimelinebpm ) ){ + engine->setBPM( pTimeline->m_timelinevector[i].m_htimelinebpm ); }//if }//for }//if @@ -1913,6 +1918,8 @@ void SongEditorPositionRuler::createBackground() m_pBackgroundPixmap->fill( backgroundColor ); Preferences *pref = Preferences::get_instance(); + Timeline * pTimeline = Hydrogen::get_instance()->getTimeline(); + QString family = pref->getApplicationFontFamily(); int size = pref->getApplicationFontPointSize(); QFont font( family, size ); @@ -1924,8 +1931,8 @@ void SongEditorPositionRuler::createBackground() char tmp[10]; for (uint i = 0; i < m_nMaxPatternSequence + 1; i++) { uint x = 10 + i * m_nGridWidth; - for ( int t = 0; t < static_cast(Hydrogen::get_instance()->m_timelinetagvector.size()); t++){ - if ( Hydrogen::get_instance()->m_timelinetagvector[t].m_htimelinetagbeat == i ) { + for ( int t = 0; t < static_cast(pTimeline->m_timelinetagvector.size()); t++){ + if ( pTimeline->m_timelinetagvector[t].m_htimelinetagbeat == i ) { p.setPen( Qt::cyan ); p.drawText( x - m_nGridWidth / 2 , 12, m_nGridWidth * 2, height() , Qt::AlignCenter, "T"); } @@ -1958,9 +1965,9 @@ void SongEditorPositionRuler::createBackground() uint x = 10 + i * m_nGridWidth; p.drawLine( x, 2, x, 5 ); p.drawLine( x, 19, x, 20 ); - for ( int t = 0; t < static_cast(Hydrogen::get_instance()->m_timelinevector.size()); t++){ - if ( Hydrogen::get_instance()->m_timelinevector[t].m_htimelinebeat == i ) { - sprintf( tempo, "%d", ((int)Hydrogen::get_instance()->m_timelinevector[t].m_htimelinebpm) ); + for ( int t = 0; t < static_cast(pTimeline->m_timelinevector.size()); t++){ + if ( pTimeline->m_timelinevector[t].m_htimelinebeat == i ) { + sprintf( tempo, "%d", ((int)pTimeline->m_timelinevector[t].m_htimelinebpm) ); p.drawText( x - m_nGridWidth, 3, m_nGridWidth * 2, height() / 2 - 5, Qt::AlignCenter, tempo ); } } @@ -2133,25 +2140,26 @@ void SongEditorPositionRuler::updatePosition() void SongEditorPositionRuler::editTimeLineAction( int newPosition, float newBpm ) { Hydrogen* engine = Hydrogen::get_instance(); + Timeline* pTimeline = engine->getTimeline(); //erase the value to set the new value - if( engine->m_timelinevector.size() >= 1 ){ - for ( int t = 0; t < engine->m_timelinevector.size(); t++){ - if ( engine->m_timelinevector[t].m_htimelinebeat == newPosition -1 ) { - engine->m_timelinevector.erase( engine->m_timelinevector.begin() + t); + if( pTimeline->m_timelinevector.size() >= 1 ){ + for ( int t = 0; t < pTimeline->m_timelinevector.size(); t++){ + if ( pTimeline->m_timelinevector[t].m_htimelinebeat == newPosition -1 ) { + pTimeline->m_timelinevector.erase( pTimeline->m_timelinevector.begin() + t); } } } - Hydrogen::HTimelineVector tlvector; + Timeline::HTimelineVector tlvector; tlvector.m_htimelinebeat = newPosition -1 ; if( newBpm < 30.0 ) newBpm = 30.0; if( newBpm > 500.0 ) newBpm = 500.0; tlvector.m_htimelinebpm = newBpm; - engine->m_timelinevector.push_back( tlvector ); - engine->sortTimelineVector(); + pTimeline->m_timelinevector.push_back( tlvector ); + pTimeline->sortTimelineVector(); createBackground(); } @@ -2160,11 +2168,13 @@ void SongEditorPositionRuler::editTimeLineAction( int newPosition, float newBpm void SongEditorPositionRuler::deleteTimeLinePosition( int position ) { Hydrogen* engine = Hydrogen::get_instance(); + Timeline* pTimeline = engine->getTimeline(); + //erase the value to set the new value - if( engine->m_timelinevector.size() >= 1 ){ - for ( int t = 0; t < engine->m_timelinevector.size(); t++){ - if ( engine->m_timelinevector[t].m_htimelinebeat == position -1 ) { - engine->m_timelinevector.erase( engine->m_timelinevector.begin() + t); + if( pTimeline->m_timelinevector.size() >= 1 ){ + for ( int t = 0; t < pTimeline->m_timelinevector.size(); t++){ + if ( pTimeline->m_timelinevector[t].m_htimelinebeat == position -1 ) { + pTimeline->m_timelinevector.erase( pTimeline->m_timelinevector.begin() + t); } } } @@ -2175,21 +2185,22 @@ void SongEditorPositionRuler::deleteTimeLinePosition( int position ) void SongEditorPositionRuler::editTagAction( QString text, int position, QString textToReplace) { Hydrogen* engine = Hydrogen::get_instance(); + Timeline* pTimeline = engine->getTimeline(); //check vector for old entries and remove them. - for( int i = 0; i < engine->m_timelinetagvector.size(); ++i ){ - if( ( engine->m_timelinetagvector[i].m_htimelinetag == textToReplace ) && - ( engine->m_timelinetagvector[i].m_htimelinetagbeat == position ) ){ + for( int i = 0; i < pTimeline->m_timelinetagvector.size(); ++i ){ + if( ( pTimeline->m_timelinetagvector[i].m_htimelinetag == textToReplace ) && + ( pTimeline->m_timelinetagvector[i].m_htimelinetagbeat == position ) ){ - engine->m_timelinetagvector.erase( engine->m_timelinetagvector.begin() + i ); + pTimeline->m_timelinetagvector.erase( pTimeline->m_timelinetagvector.begin() + i ); break; } } - Hydrogen::HTimelineTagVector tlvector; + Timeline::HTimelineTagVector tlvector; tlvector.m_htimelinetagbeat = position; tlvector.m_htimelinetag = text; - engine->m_timelinetagvector.push_back( tlvector ); - engine->sortTimelineTagVector(); + pTimeline->m_timelinetagvector.push_back( tlvector ); + pTimeline->sortTimelineTagVector(); createBackground(); } @@ -2197,14 +2208,16 @@ void SongEditorPositionRuler::deleteTagAction( QString text, int position ) { Hydrogen* engine = Hydrogen::get_instance(); - for( int i = 0; i < engine->m_timelinetagvector.size(); ++i ){ - if( ( engine->m_timelinetagvector[i].m_htimelinetag == text ) && - ( engine->m_timelinetagvector[i].m_htimelinetagbeat == position ) ){ + Timeline* pTimeline = engine->getTimeline(); + + for( int i = 0; i < pTimeline->m_timelinetagvector.size(); ++i ){ + if( ( pTimeline->m_timelinetagvector[i].m_htimelinetag == text ) && + ( pTimeline->m_timelinetagvector[i].m_htimelinetagbeat == position ) ){ - engine->m_timelinetagvector.erase( engine->m_timelinetagvector.begin() + i ); + pTimeline->m_timelinetagvector.erase( pTimeline->m_timelinetagvector.begin() + i ); break; } } - engine->sortTimelineTagVector(); + pTimeline->sortTimelineTagVector(); createBackground(); } diff --git a/src/gui/src/SongEditor/SongEditorPanelBpmWidget.cpp b/src/gui/src/SongEditor/SongEditorPanelBpmWidget.cpp index da097c760..62baef8cd 100644 --- a/src/gui/src/SongEditor/SongEditorPanelBpmWidget.cpp +++ b/src/gui/src/SongEditor/SongEditorPanelBpmWidget.cpp @@ -28,6 +28,7 @@ #include "SongEditorPanel.h" #include "SongEditor.h" #include +#include namespace H2Core { @@ -48,7 +49,8 @@ SongEditorPanelBpmWidget::SongEditorPanelBpmWidget( QWidget* pParent, int beat ) deleteBtn->setEnabled ( false ); Hydrogen* engine = Hydrogen::get_instance(); - std::vector timelineVector = engine->m_timelinevector; + Timeline* pTimeline = engine->getTimeline(); + std::vector timelineVector = pTimeline->m_timelinevector; //restore the bpm value if( timelineVector.size() > 0 ){ @@ -90,12 +92,14 @@ void SongEditorPanelBpmWidget::on_CancelBtn_clicked() void SongEditorPanelBpmWidget::on_okBtn_clicked() { Hydrogen* engine = Hydrogen::get_instance(); + Timeline* pTimeline = engine->getTimeline(); + float oldBpm = -1.0; //search for an old entry - if( engine->m_timelinevector.size() >= 1 ){ - for ( int t = 0; t < engine->m_timelinevector.size(); t++){ - if ( engine->m_timelinevector[t].m_htimelinebeat == ( QString( lineEditBeat->text() ).toInt() ) -1 ) { - oldBpm = engine->m_timelinevector[t].m_htimelinebpm; + if( pTimeline->m_timelinevector.size() >= 1 ){ + for ( int t = 0; t < pTimeline->m_timelinevector.size(); t++){ + if ( pTimeline->m_timelinevector[t].m_htimelinebeat == ( QString( lineEditBeat->text() ).toInt() ) -1 ) { + oldBpm = pTimeline->m_timelinevector[t].m_htimelinebpm; } } } @@ -110,12 +114,14 @@ void SongEditorPanelBpmWidget::on_okBtn_clicked() void SongEditorPanelBpmWidget::on_deleteBtn_clicked() { Hydrogen* engine = Hydrogen::get_instance(); + Timeline* pTimeline = engine->getTimeline(); + float oldBpm = -1.0; //search for an old entry - if( engine->m_timelinevector.size() >= 1 ){ - for ( int t = 0; t < engine->m_timelinevector.size(); t++){ - if ( engine->m_timelinevector[t].m_htimelinebeat == ( QString( lineEditBeat->text() ).toInt() ) -1 ) { - oldBpm = engine->m_timelinevector[t].m_htimelinebpm; + if( pTimeline->m_timelinevector.size() >= 1 ){ + for ( int t = 0; t < pTimeline->m_timelinevector.size(); t++){ + if ( pTimeline->m_timelinevector[t].m_htimelinebeat == ( QString( lineEditBeat->text() ).toInt() ) -1 ) { + oldBpm = pTimeline->m_timelinevector[t].m_htimelinebpm; } } } diff --git a/src/gui/src/SongEditor/SongEditorPanelTagWidget.cpp b/src/gui/src/SongEditor/SongEditorPanelTagWidget.cpp index 80b697947..4f220fb90 100644 --- a/src/gui/src/SongEditor/SongEditorPanelTagWidget.cpp +++ b/src/gui/src/SongEditor/SongEditorPanelTagWidget.cpp @@ -27,7 +27,9 @@ #include "SongEditorPanelTagWidget.h" #include "SongEditorPanel.h" #include "SongEditor.h" + #include +#include namespace H2Core { @@ -62,6 +64,7 @@ void SongEditorPanelTagWidget::a_itemIsChanged(QTableWidgetItem *item) void SongEditorPanelTagWidget::createTheTagTableWidget() { Hydrogen* engine = Hydrogen::get_instance(); + Timeline* pTimeline = engine->getTimeline(); int patterngroupvectorsize; patterngroupvectorsize = engine->getSong()->get_pattern_group_vector()->size(); @@ -70,7 +73,7 @@ void SongEditorPanelTagWidget::createTheTagTableWidget() tagTableWidget->insertRow( i ); } - std::vector timelineTagVector = engine->m_timelinetagvector; + std::vector timelineTagVector = pTimeline->m_timelinetagvector; //read the tag vector and fill all tags into items if( timelineTagVector.size() > 0 ){ @@ -124,18 +127,20 @@ void SongEditorPanelTagWidget::on_CancelBtn_clicked() void SongEditorPanelTagWidget::on_okBtn_clicked() { Hydrogen* engine = Hydrogen::get_instance(); + Timeline* pTimeline = engine->getTimeline(); + int patterngroupvectorsize; patterngroupvectorsize = engine->getSong()->get_pattern_group_vector()->size(); //oldText list contains all old item values. we need them for undo an item QStringList oldText; - if(engine->m_timelinetagvector.size() > 0){ + if(pTimeline->m_timelinetagvector.size() > 0){ for (int i = 0; i < patterngroupvectorsize; i++){ oldText << ""; } - for(int i = 0; i < engine->m_timelinetagvector.size(); ++i){ - oldText.replace(engine->m_timelinetagvector[i].m_htimelinetagbeat , engine->m_timelinetagvector[i].m_htimelinetag); + for(int i = 0; i < pTimeline->m_timelinetagvector.size(); ++i){ + oldText.replace(pTimeline->m_timelinetagvector[i].m_htimelinetagbeat , pTimeline->m_timelinetagvector[i].m_htimelinetag); } } From 095f546f0c36a84f86d8ef6ca42339afced988e5 Mon Sep 17 00:00:00 2001 From: Sebastian Moors Date: Sat, 15 Nov 2014 01:02:59 +0100 Subject: [PATCH 5/5] Director: renamed member --- src/gui/src/Director.cpp | 62 ++++++++++++++++++++++------------------ src/gui/src/Director.h | 14 ++++----- 2 files changed, 41 insertions(+), 35 deletions(-) diff --git a/src/gui/src/Director.cpp b/src/gui/src/Director.cpp index 43207ac05..a84f69b93 100644 --- a/src/gui/src/Director.cpp +++ b/src/gui/src/Director.cpp @@ -74,15 +74,15 @@ Director::Director ( QWidget* pParent ) //INFOLOG ( "INIT" ); setWindowTitle ( trUtf8 ( "Director" ) ); - p_counter = 1; // to compute the right beat - p_fadealpha = 255; //default alpha - p_bar = 1; // default bar - p_wechselblink = width() * 5/100; + m_nCounter = 1; // to compute the right beat + m_nFadeAlpha = 255; //default alpha + m_nBar = 1; // default bar + m_nFlashingArea = width() * 5/100; - f_bpm = Hydrogen::get_instance()->getSong()->__bpm; + m_fBpm = Hydrogen::get_instance()->getSong()->__bpm; m_pTimeline = Hydrogen::get_instance()->getTimeline(); - timer = new QTimer( this ); - connect( timer, SIGNAL( timeout() ), this, SLOT( updateMetronomBackground() ) ); + m_pTimer = new QTimer( this ); + connect( m_pTimer, SIGNAL( timeout() ), this, SLOT( updateMetronomBackground() ) ); } @@ -105,7 +105,9 @@ void Director::metronomeEvent( int nValue ) __songName = list.last().replace( ".h2song", "" ); // if songname is not set, default on an empty song, we call them "Untitled Song". - if( __songName== "" ) __songName = QString("Untitled Song"); + if( __songName.isEmpty() ){ + __songName = QString("Untitled Song"); + } } update(); @@ -114,33 +116,37 @@ void Director::metronomeEvent( int nValue ) //bpm - f_bpm = Hydrogen::get_instance()->getSong()->__bpm; + m_fBpm = Hydrogen::get_instance()->getSong()->__bpm; //bar - p_bar = Hydrogen::get_instance()->getPatternPos() +1; - if ( p_bar <= 0 ) - p_bar = 1; + m_nBar = Hydrogen::get_instance()->getPatternPos() + 1; + + if ( m_nBar <= 0 ){ + m_nBar = 1; + } + // 1000 ms / bpm / 60s - timer->start( static_cast( 1000 / ( f_bpm / 60 )) / 2 ); - p_wechselblink = width() * 5/100; - p_fadealpha = 255; + m_pTimer->start( static_cast( 1000 / ( m_fBpm / 60 )) / 2 ); + m_nFlashingArea = width() * 5/100; + m_nFadeAlpha = 255; + if ( nValue == 2 ){ - p_fadealpha = 0; + m_nFadeAlpha = 0; update(); __TAG=""; __TAG2=""; return; } + if ( nValue == 1 ) { //foregroundcolor "rect" for first blink __color = QColor( 255, 50, 1 ,255 ); - p_counter = 1; + m_nCounter = 1; } else { //foregroundcolor "rect" for all other blinks - p_counter++; - if( p_counter %2 == 0 ) - p_wechselblink = width() * 52.5/100; + m_nCounter++; + if( m_nCounter %2 == 0 ) + m_nFlashingArea = width() * 52.5/100; __color = QColor( 24, 250, 31, 255 ); - } // get tags @@ -148,13 +154,13 @@ void Director::metronomeEvent( int nValue ) __TAG2=""; for ( size_t t = 0; t < m_pTimeline->m_timelinetagvector.size(); t++){ if(t+1m_timelinetagvector.size() && - m_pTimeline->m_timelinetagvector[t+1].m_htimelinetagbeat == p_bar ){ + m_pTimeline->m_timelinetagvector[t+1].m_htimelinetagbeat == m_nBar ){ __TAG2 = m_pTimeline->m_timelinetagvector[t+1].m_htimelinetag ; } - if ( m_pTimeline->m_timelinetagvector[t].m_htimelinetagbeat <= p_bar-1){ + if ( m_pTimeline->m_timelinetagvector[t].m_htimelinetagbeat <= m_nBar-1){ __TAG = m_pTimeline->m_timelinetagvector[t].m_htimelinetag ; } - if( m_pTimeline->m_timelinetagvector[t].m_htimelinetagbeat > p_bar-1){ + if( m_pTimeline->m_timelinetagvector[t].m_htimelinetagbeat > m_nBar-1){ break; } } @@ -165,7 +171,7 @@ void Director::metronomeEvent( int nValue ) void Director::updateMetronomBackground() { __color.setAlpha( 0 ); - timer->stop(); + m_pTimer->stop(); update(); } @@ -183,18 +189,18 @@ void Director::paintEvent( QPaintEvent* ev ) //draw the metronome painter.setPen( QPen(QColor( 249, 235, 116, 200 ) ,1 , Qt::SolidLine ) ); painter.setBrush( __color ); - painter.drawRect ( p_wechselblink, height() * 25/100, width() * 42.5/100, height() * 35/100); + painter.drawRect ( m_nFlashingArea, height() * 25/100, width() * 42.5/100, height() * 35/100); //draw bars painter.setPen(Qt::white); painter.setFont(QFont("Arial", height() * 25/100 )); QRect r1(QPoint( width() * 5/100 , height() * 25/100 ), QSize( width() * 42.5/100, height() * 35/100)); - painter.drawText( r1, Qt::AlignCenter, QString("%1").arg( p_bar) ); + painter.drawText( r1, Qt::AlignCenter, QString("%1").arg( m_nBar) ); //draw beats QRect r2(QPoint( width() * 52.5/100 , height() * 25/100 ), QSize( width() * 42.5/100, height() * 35/100)); - painter.drawText( r2, Qt::AlignCenter, QString("%1").arg( p_counter) ); + painter.drawText( r2, Qt::AlignCenter, QString("%1").arg( m_nCounter) ); if( __TAG == __TAG2 ) __TAG2 = ""; diff --git a/src/gui/src/Director.h b/src/gui/src/Director.h index 8a01b6a37..d39be120f 100644 --- a/src/gui/src/Director.h +++ b/src/gui/src/Director.h @@ -50,19 +50,19 @@ private slots: private: - QTimer *timer; + QTimer *m_pTimer; H2Core::Timeline *m_pTimeline; QColor __color; QPalette __blinkerPalette; - int p_counter; - int p_fadealpha; - float f_bpm; - int p_bar; - int p_wechselblink; + int m_nCounter; + int m_nFadeAlpha; + float m_fBpm; + int m_nBar; + int m_nFlashingArea; QString __TAG; QString __TAG2; QString __songName; - int p_tagbeat; + int m_nTagbeat; };