From 9ba283ee9471ff954de73c7d410b7b638bee42b9 Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Tue, 1 Apr 2008 20:27:39 +0000 Subject: [PATCH] - splitted track_container.h into track_container.h and track_container_view.h - splitted bb_editor.h into bb_track_container.h and bb_editor.h - moved view-component-implementations of trackContainer and bbTrackContainer to src/gui/ - added dummyInstrumentTrack-implementation git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@829 0778d3d1-df1d-0410-868b-ea421aaaa00d --- ChangeLog | 26 ++ Makefile.am | 8 +- include/bb_editor.h | 62 +--- include/bb_track_container.h | 83 +++++ include/engine.h | 2 + include/song_editor.h | 2 +- include/track_container.h | 142 +------ include/track_container_view.h | 185 +++++++++ src/core/automation_editor.cpp | 2 +- src/core/bb_track_container.cpp | 268 ++++++++++++++ src/core/engine.cpp | 1 + src/core/file_browser.cpp | 11 +- src/core/preset_preview_play_handle.cpp | 11 +- src/core/song.cpp | 1 + src/core/track.cpp | 1 + src/core/track_container.cpp | 449 ---------------------- src/gui/bb_editor.cpp | 275 +------------- src/gui/track_container_view.cpp | 473 ++++++++++++++++++++++++ src/tracks/bb_track.cpp | 3 +- src/tracks/pattern.cpp | 2 +- 20 files changed, 1070 insertions(+), 937 deletions(-) create mode 100644 include/bb_track_container.h create mode 100644 include/track_container_view.h create mode 100644 src/core/bb_track_container.cpp create mode 100644 src/gui/track_container_view.cpp diff --git a/ChangeLog b/ChangeLog index 24d4faf8d..34796adb8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,31 @@ 2008-04-01 Tobias Doerffel + * include/engine.h: + * include/bb_track_container.h: + * include/track_container_view.h: + * include/song_editor.h: + * include/bb_editor.h: + * include/track_container.h: + * src/gui/track_container_view.cpp: + * src/gui/bb_editor.cpp: + * src/tracks/bb_track.cpp: + * src/tracks/pattern.cpp: + * src/core/preset_preview_play_handle.cpp: + * src/core/track_container.cpp: + * src/core/song.cpp: + * src/core/bb_track_container.cpp: + * src/core/file_browser.cpp: + * src/core/track.cpp: + * src/core/engine.cpp: + * src/core/automation_editor.cpp: + * Makefile.am: + - splitted track_container.h into track_container.h and + track_container_view.h + - splitted bb_editor.h into bb_track_container.h and bb_editor.h + - moved view-component-implementations of trackContainer and + bbTrackContainer to src/gui/ + - added dummyInstrumentTrack-implementation + * plugins/ladspa_effect/caps/README.ardour: * plugins/ladspa_effect/caps/README.dist: * plugins/ladspa_effect/caps/Makefile.am: diff --git a/Makefile.am b/Makefile.am index 9ebd48982..9ab0fe07c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -53,6 +53,7 @@ lmms_MOC = \ ./automation_pattern.moc \ ./automation_track.moc \ ./bb_editor.moc \ + ./bb_track_container.moc \ ./bb_track.moc \ ./caption_menu.moc \ ./instrument_track.moc \ @@ -116,6 +117,7 @@ lmms_MOC = \ ./timeline.moc \ ./tool_button.moc \ ./track_container.moc \ + ./track_container_view.moc \ ./track.moc \ ./visualization_widget.moc \ ./volume_knob.moc @@ -162,7 +164,7 @@ lmms_SOURCES = \ $(srcdir)/src/core/about_dialog.cpp \ $(srcdir)/src/core/automation_editor.cpp \ $(srcdir)/src/core/automation_pattern.cpp \ - $(srcdir)/src/core/bb_editor.cpp \ + $(srcdir)/src/core/bb_track_container.cpp \ $(srcdir)/src/core/config_mgr.cpp \ $(srcdir)/src/core/effect_chain.cpp \ $(srcdir)/src/core/effect_control_dialog.cpp \ @@ -203,6 +205,8 @@ lmms_SOURCES = \ $(srcdir)/src/core/track_container.cpp \ $(srcdir)/src/core/surround_area.cpp \ $(srcdir)/src/core/timeline.cpp \ + $(srcdir)/src/gui/bb_editor.cpp \ + $(srcdir)/src/gui/track_container_view.cpp \ $(srcdir)/src/lib/clipboard.cpp \ $(srcdir)/src/lib/drumsynth.cpp \ $(srcdir)/src/lib/journalling_object.cpp \ @@ -296,6 +300,7 @@ lmms_SOURCES = \ $(srcdir)/include/instrument.h \ $(srcdir)/include/instrument_view.h \ $(srcdir)/include/bb_editor.h \ + $(srcdir)/include/bb_track_container.h \ $(srcdir)/include/piano.h \ $(srcdir)/include/fx_mixer.h \ $(srcdir)/include/pixmap_button.h \ @@ -331,6 +336,7 @@ lmms_SOURCES = \ $(srcdir)/include/side_bar_widget.h \ $(srcdir)/include/track.h \ $(srcdir)/include/track_container.h \ + $(srcdir)/include/track_container_view.h \ $(srcdir)/include/bb_track.h \ $(srcdir)/include/caption_menu.h \ $(srcdir)/include/sample_track.h \ diff --git a/include/bb_editor.h b/include/bb_editor.h index 340d05a48..7eaa3575b 100644 --- a/include/bb_editor.h +++ b/include/bb_editor.h @@ -1,5 +1,5 @@ /* - * bb_editor.h - declaration of class bbEditor, a basic-component of LMMS + * bb_editor.h - view-component of BB-Editor * * Copyright (c) 2004-2008 Tobias Doerffel * @@ -26,68 +26,14 @@ #ifndef _BB_EDITOR_H #define _BB_EDITOR_H -#include "track_container.h" -#include "combobox.h" +#include "track_container_view.h" -class QPixmap; - +class bbTrackContainer; +class comboBox; class toolButton; -class bbTrackContainer : public trackContainer -{ - Q_OBJECT - mapPropertyFromModel(int,currentBB,setCurrentBB,m_bbComboBoxModel); -public: - bbTrackContainer( void ); - virtual ~bbTrackContainer(); - - virtual bool play( midiTime _start, const fpp_t _frames, - const f_cnt_t _frame_base, - Sint16 _tco_num = -1 ); - -// virtual void saveSettings( QDomDocument & _doc, QDomElement & _parent ); -// virtual void loadSettings( const QDomElement & _this ); - virtual void updateAfterTrackAdd( void ); - - inline virtual QString nodeName( void ) const - { - return( "bbtrackcontainer" ); - } - - tact lengthOfBB( int _bb ); - inline tact lengthOfCurrentBB( void ) - { - return( lengthOfBB( currentBB() ) ); - } - int numOfBBs( void ) const; - void removeBB( int _bb ); - - void swapBB( int _bb1, int _bb2 ); - - void updateBBTrack( trackContentObject * _tco ); - - -public slots: - void play( void ); - void stop( void ); - void updateComboBox( void ); - void currentBBChanged( void ); - - -private: - void createTCOsForBB( int _bb ); - - comboBoxModel m_bbComboBoxModel; - - - friend class bbEditor; - -} ; - - - class bbEditor : public trackContainerView { Q_OBJECT diff --git a/include/bb_track_container.h b/include/bb_track_container.h new file mode 100644 index 000000000..323c53da3 --- /dev/null +++ b/include/bb_track_container.h @@ -0,0 +1,83 @@ +/* + * bb_track_container.h - model-component of BB-Editor + * + * Copyright (c) 2004-2008 Tobias Doerffel + * + * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net + * + * 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 (see COPYING); if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + */ + + +#ifndef _BB_TRACK_CONTAINER_H +#define _BB_TRACK_CONTAINER_H + +#include "track_container.h" +#include "combobox.h" + + +class bbTrackContainer : public trackContainer +{ + Q_OBJECT + mapPropertyFromModel(int,currentBB,setCurrentBB,m_bbComboBoxModel); +public: + bbTrackContainer( void ); + virtual ~bbTrackContainer(); + + virtual bool play( midiTime _start, const fpp_t _frames, + const f_cnt_t _frame_base, + Sint16 _tco_num = -1 ); + + virtual void updateAfterTrackAdd( void ); + + inline virtual QString nodeName( void ) const + { + return( "bbtrackcontainer" ); + } + + tact lengthOfBB( int _bb ); + inline tact lengthOfCurrentBB( void ) + { + return( lengthOfBB( currentBB() ) ); + } + int numOfBBs( void ) const; + void removeBB( int _bb ); + + void swapBB( int _bb1, int _bb2 ); + + void updateBBTrack( trackContentObject * _tco ); + + +public slots: + void play( void ); + void stop( void ); + void updateComboBox( void ); + void currentBBChanged( void ); + + +private: + void createTCOsForBB( int _bb ); + + comboBoxModel m_bbComboBoxModel; + + + friend class bbEditor; + +} ; + + +#endif diff --git a/include/engine.h b/include/engine.h index ec6e1a2a4..a223f48e4 100644 --- a/include/engine.h +++ b/include/engine.h @@ -35,6 +35,7 @@ class automationEditor; class bbEditor; class bbTrackContainer; +class dummyTrackContainer; class fxMixer; class fxMixerView; class projectJournal; @@ -147,6 +148,7 @@ private: static song * s_song; static bbTrackContainer * s_bbTrackContainer; static projectJournal * s_projectJournal; + static dummyTrackContainer * s_dummyTC; // GUI static mainWindow * s_mainWindow; diff --git a/include/song_editor.h b/include/song_editor.h index f6bf430ba..8eedf3a4d 100644 --- a/include/song_editor.h +++ b/include/song_editor.h @@ -27,7 +27,7 @@ #ifndef _SONG_EDITOR_H #define _SONG_EDITOR_H -#include "track_container.h" +#include "track_container_view.h" #include "lcd_spinbox.h" #include "automatable_slider.h" diff --git a/include/track_container.h b/include/track_container.h index e46b78cba..c6f91ac79 100644 --- a/include/track_container.h +++ b/include/track_container.h @@ -27,17 +27,12 @@ #ifndef _TRACK_CONTAINER_H #define _TRACK_CONTAINER_H -#include -#include -#include - - #include "track.h" #include "journalling_object.h" class trackContainerView; -class QVBoxLayout; +class instrumentTrack; class trackContainer : public model, public journallingObject @@ -79,9 +74,6 @@ public: } - //const QList tracks( void ) const; - - signals: void trackAdded( track * _track ); @@ -96,148 +88,30 @@ private: } ; - -class trackContainerView : public QWidget, public modelView, - public journallingObject +class dummyTrackContainer : public trackContainer { - Q_OBJECT public: - trackContainerView( trackContainer * _tc ); - virtual ~trackContainerView(); + dummyTrackContainer( void ); - QWidget * contentWidget( void ) + virtual ~dummyTrackContainer() { - return( m_scrollArea ); } - inline const midiTime & currentPosition( void ) const - { - return( m_currentPosition ); - } - - virtual bool fixedTCOs( void ) const - { - return( FALSE ); - } - - inline float pixelsPerTact( void ) const - { - return( m_ppt ); - } - - void setPixelsPerTact( int _ppt ); - - const trackView * trackViewAt( const int _y ) const; - - virtual bool allowRubberband( void ) const; - - inline bool rubberBandActive( void ) const - { - return( m_rubberBand->isVisible() ); - } - - inline QVector selectedObjects( void ) - { - if( allowRubberband() == TRUE ) - { - return( m_rubberBand->selectedObjects() ); - } - return( QVector() ); - } - - - trackContainer * model( void ) - { - return( m_tc ); - } - - const trackContainer * model( void ) const - { - return( m_tc ); - } - - void moveTrackViewUp( trackView * _tv ); - void moveTrackViewDown( trackView * _tv ); - - // -- for usage by trackView only --------------- - trackView * addTrackView( trackView * _tv ); - void removeTrackView( trackView * _tv ); - // ------------------------------------------------------- - - void clearAllTracks( void ); - virtual QString nodeName( void ) const { - return( "trackcontainerview" ); + return( "dummytrackcontainer" ); } - -public slots: - void realignTracks( void ); - void createTrackView( track * _t ); - - -protected: - static const int DEFAULT_PIXELS_PER_TACT = 16; - - const QList & trackViews( void ) const + instrumentTrack * dummyInstrumentTrack( void ) { - return( m_trackViews ); + return( m_dummyInstrumentTrack ); } - virtual void dragEnterEvent( QDragEnterEvent * _dee ); - virtual void dropEvent( QDropEvent * _de ); - virtual void mousePressEvent( QMouseEvent * _me ); - virtual void mouseMoveEvent( QMouseEvent * _me ); - virtual void mouseReleaseEvent( QMouseEvent * _me ); - virtual void resizeEvent( QResizeEvent * ); - - virtual void undoStep( journalEntry & _je ); - virtual void redoStep( journalEntry & _je ); - - midiTime m_currentPosition; - private: - enum Actions - { - AddTrack, - RemoveTrack - } ; - - class scrollArea : public QScrollArea - { - public: - scrollArea( trackContainerView * _parent ); - virtual ~scrollArea(); - - protected: - virtual void wheelEvent( QWheelEvent * _we ); - - private: - trackContainerView * m_trackContainerView; - - } ; - - trackContainer * m_tc; - typedef QList trackViewList; - trackViewList m_trackViews; - - scrollArea * m_scrollArea; - QVBoxLayout * m_scrollLayout; - - float m_ppt; - - rubberBand * m_rubberBand; - QPoint m_origin; - - -signals: - void positionChanged( const midiTime & _pos ); - + instrumentTrack * m_dummyInstrumentTrack; } ; - #endif diff --git a/include/track_container_view.h b/include/track_container_view.h new file mode 100644 index 000000000..83ce13f5c --- /dev/null +++ b/include/track_container_view.h @@ -0,0 +1,185 @@ +/* + * track_container_view.h - view-component for trackContainer + * + * Copyright (c) 2004-2008 Tobias Doerffel + * + * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net + * + * 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 (see COPYING); if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + */ + + +#ifndef _TRACK_CONTAINER_VIEW_H +#define _TRACK_CONTAINER_VIEW_H + +#include +#include +#include + + +#include "track.h" +#include "journalling_object.h" + + +class QVBoxLayout; +class trackContainer; + + +class trackContainerView : public QWidget, public modelView, + public journallingObject +{ + Q_OBJECT +public: + trackContainerView( trackContainer * _tc ); + virtual ~trackContainerView(); + + QWidget * contentWidget( void ) + { + return( m_scrollArea ); + } + + inline const midiTime & currentPosition( void ) const + { + return( m_currentPosition ); + } + + virtual bool fixedTCOs( void ) const + { + return( FALSE ); + } + + inline float pixelsPerTact( void ) const + { + return( m_ppt ); + } + + void setPixelsPerTact( int _ppt ); + + const trackView * trackViewAt( const int _y ) const; + + virtual bool allowRubberband( void ) const; + + inline bool rubberBandActive( void ) const + { + return( m_rubberBand->isVisible() ); + } + + inline QVector selectedObjects( void ) + { + if( allowRubberband() == TRUE ) + { + return( m_rubberBand->selectedObjects() ); + } + return( QVector() ); + } + + + trackContainer * model( void ) + { + return( m_tc ); + } + + const trackContainer * model( void ) const + { + return( m_tc ); + } + + void moveTrackViewUp( trackView * _tv ); + void moveTrackViewDown( trackView * _tv ); + + // -- for usage by trackView only --------------- + trackView * addTrackView( trackView * _tv ); + void removeTrackView( trackView * _tv ); + // ------------------------------------------------------- + + void clearAllTracks( void ); + + virtual QString nodeName( void ) const + { + return( "trackcontainerview" ); + } + + +public slots: + void realignTracks( void ); + void createTrackView( track * _t ); + + +protected: + static const int DEFAULT_PIXELS_PER_TACT = 16; + + const QList & trackViews( void ) const + { + return( m_trackViews ); + } + + virtual void dragEnterEvent( QDragEnterEvent * _dee ); + virtual void dropEvent( QDropEvent * _de ); + virtual void mousePressEvent( QMouseEvent * _me ); + virtual void mouseMoveEvent( QMouseEvent * _me ); + virtual void mouseReleaseEvent( QMouseEvent * _me ); + virtual void resizeEvent( QResizeEvent * ); + + virtual void undoStep( journalEntry & _je ); + virtual void redoStep( journalEntry & _je ); + + midiTime m_currentPosition; + + +private: + enum Actions + { + AddTrack, + RemoveTrack + } ; + + class scrollArea : public QScrollArea + { + public: + scrollArea( trackContainerView * _parent ); + virtual ~scrollArea(); + + protected: + virtual void wheelEvent( QWheelEvent * _we ); + + private: + trackContainerView * m_trackContainerView; + + } ; + + trackContainer * m_tc; + typedef QList trackViewList; + trackViewList m_trackViews; + + scrollArea * m_scrollArea; + QVBoxLayout * m_scrollLayout; + + float m_ppt; + + rubberBand * m_rubberBand; + QPoint m_origin; + + +signals: + void positionChanged( const midiTime & _pos ); + + +} ; + + + +#endif diff --git a/src/core/automation_editor.cpp b/src/core/automation_editor.cpp index df9655c9c..8fa389e70 100644 --- a/src/core/automation_editor.cpp +++ b/src/core/automation_editor.cpp @@ -61,7 +61,7 @@ #include "tool_button.h" #include "text_float.h" #include "combobox.h" -#include "bb_editor.h" +#include "bb_track_container.h" #include "piano_roll.h" #include "debug.h" diff --git a/src/core/bb_track_container.cpp b/src/core/bb_track_container.cpp new file mode 100644 index 000000000..3bd98b766 --- /dev/null +++ b/src/core/bb_track_container.cpp @@ -0,0 +1,268 @@ +/* + * bb_track_container.cpp - model-component of BB-Editor + * + * Copyright (c) 2004-2008 Tobias Doerffel + * + * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net + * + * 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 (see COPYING); if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + */ + + +#include "bb_track_container.h" +#include "bb_track.h" +#include "combobox.h" +#include "engine.h" +#include "song.h" + + + +bbTrackContainer::bbTrackContainer( void ) : + trackContainer(), + m_bbComboBoxModel( this ) +{ + connect( &m_bbComboBoxModel, SIGNAL( dataChanged() ), + this, SLOT( currentBBChanged() ), + Qt::QueuedConnection ); + // we *always* want to receive updates even in case BB actually did + // not change upon setCurrentBB()-call + connect( &m_bbComboBoxModel, SIGNAL( dataUnchanged() ), + this, SLOT( currentBBChanged() ), + Qt::QueuedConnection ); +} + + + + +bbTrackContainer::~bbTrackContainer() +{ +} + + + + +bool bbTrackContainer::play( midiTime _start, fpp_t _frames, + f_cnt_t _offset, + Sint16 _tco_num ) +{ + bool played_a_note = FALSE; + if( lengthOfBB( _tco_num ) <= 0 ) + { + return( played_a_note ); + } + + _start = ( _start.getTact() % lengthOfBB( _tco_num ) ) * 64 + + _start.getTact64th(); + QList tl = tracks(); + for( int i = 0; i < tl.size(); ++i ) + { + if( tl[i]->play( _start, _frames, _offset, _tco_num ) == TRUE ) + { + played_a_note = TRUE; + } + } + + return( played_a_note ); +} + + + + +void bbTrackContainer::updateAfterTrackAdd( void ) +{ + // make sure, new track(s) have TCOs for every beat/bassline + for( int i = 0; i < tMax( 1, numOfBBs() ); ++i ) + { + createTCOsForBB( i ); + } +} + + + + +tact bbTrackContainer::lengthOfBB( int _bb ) +{ + midiTime max_length; + + QList tl = tracks(); + for( int i = 0; i < tl.size(); ++i ) + { + trackContentObject * tco = tl[i]->getTCO( _bb ); + max_length = tMax( max_length, tco->length() ); + } + if( max_length.getTact64th() == 0 ) + { + return( max_length.getTact() ); + } + + return( max_length.getTact() + 1 ); +} + + + + +int bbTrackContainer::numOfBBs( void ) const +{ + return( engine::getSong()->countTracks( track::BBTrack ) ); +} + + + + +void bbTrackContainer::removeBB( int _bb ) +{ + QList tl = tracks(); + for( int i = 0; i < tl.size(); ++i ) + { + delete tl[i]->getTCO( _bb ); + tl[i]->removeTact( _bb * 64 ); + } + if( _bb <= currentBB() ) + { + setCurrentBB( tMax( currentBB() - 1, 0 ) ); + } +} + + + + +void bbTrackContainer::swapBB( int _bb1, int _bb2 ) +{ + QList tl = tracks(); + for( int i = 0; i < tl.size(); ++i ) + { + tl[i]->swapPositionOfTCOs( _bb1, _bb2 ); + } + updateComboBox(); +} + + + + +void bbTrackContainer::updateBBTrack( trackContentObject * _tco ) +{ + bbTrack * t = bbTrack::findBBTrack( _tco->startPosition() / 64 ); + if( t != NULL ) + { + t->dataChanged(); + //t->getTrackContentWidget()->update(); + } +} + + + + +void bbTrackContainer::play( void ) +{ + if( engine::getSong()->playing() ) + { + if( engine::getSong()->playMode() != song::Mode_PlayBB ) + { + engine::getSong()->stop(); + engine::getSong()->playBB(); + } + else + { + engine::getSong()->pause(); + } + } + else if( engine::getSong()->paused() ) + { + engine::getSong()->resumeFromPause(); + } + else + { + engine::getSong()->playBB(); + } + +} + + + + +void bbTrackContainer::stop( void ) +{ + engine::getSong()->stop(); +} + + + + +void bbTrackContainer::updateComboBox( void ) +{ + const int cur_bb = currentBB(); + + m_bbComboBoxModel.clear(); + + for( int i = 0; i < numOfBBs(); ++i ) + { + bbTrack * bbt = bbTrack::findBBTrack( i ); + m_bbComboBoxModel.addItem( bbt->name(), + bbt->pixmap() ? new QPixmap( *bbt->pixmap() ) + : NULL ); + } + setCurrentBB( cur_bb ); +} + + + + +void bbTrackContainer::currentBBChanged( void ) +{ + // first make sure, all channels have a TCO at current BB + createTCOsForBB( currentBB() ); + + // now update all track-labels (the current one has to become white, + // the others green) + for( int i = 0; i < numOfBBs(); ++i ) + { + bbTrack::findBBTrack( i )->dataChanged(); +//trackLabel()->update(); + } + + //emit dataChanged(); + //emit positionChanged( NULL ); +} + + + + +void bbTrackContainer::createTCOsForBB( int _bb ) +{ + if( numOfBBs() == 0 || engine::getSong()->isLoadingProject() ) + { + return; + } + + QList tl = tracks(); + for( int i = 0; i < tl.size(); ++i ) + { + while( tl[i]->numOfTCOs() < _bb + 1 ) + { + midiTime position = midiTime( tl[i]->numOfTCOs(), 0 ); + trackContentObject * tco = tl[i]->addTCO( + tl[i]->createTCO( position ) ); + tco->movePosition( position ); + tco->changeLength( midiTime( 1, 0 ) ); + } + } +} + + + +#include "bb_track_container.moc" + diff --git a/src/core/engine.cpp b/src/core/engine.cpp index 775808db5..b8bab9b50 100644 --- a/src/core/engine.cpp +++ b/src/core/engine.cpp @@ -28,6 +28,7 @@ #include "engine.h" #include "automation_editor.h" #include "bb_editor.h" +#include "bb_track_container.h" #include "config_mgr.h" #include "fx_mixer.h" #include "ladspa_2_lmms.h" diff --git a/src/core/file_browser.cpp b/src/core/file_browser.cpp index 8fcd7b644..ba0b93afa 100644 --- a/src/core/file_browser.cpp +++ b/src/core/file_browser.cpp @@ -1,5 +1,3 @@ -#ifndef SINGLE_SOURCE_COMPILE - /* * file_browser.cpp - implementation of the project-, preset- and * sample-file-browser @@ -26,17 +24,14 @@ */ -#include "file_browser.h" - - #include #include #include #include #include - -#include "bb_editor.h" +#include "file_browser.h" +#include "bb_track_container.h" #include "config_mgr.h" #include "debug.h" #include "embed.h" @@ -934,5 +929,3 @@ QString fileItem::extension( const QString & _file ) #include "file_browser.moc" - -#endif diff --git a/src/core/preset_preview_play_handle.cpp b/src/core/preset_preview_play_handle.cpp index 8b3f0b1a0..b226e89bb 100644 --- a/src/core/preset_preview_play_handle.cpp +++ b/src/core/preset_preview_play_handle.cpp @@ -61,16 +61,9 @@ public: { } - - // implement pure-virtual functions... - virtual inline bool fixedTCOs( void ) const + virtual QString nodeName( void ) const { - return( TRUE ); - } - - virtual inline QString nodeName( void ) const - { - return( "previewtc" ); + return( "bbtrackcontainer" ); } instrumentTrack * previewInstrumentTrack( void ) diff --git a/src/core/song.cpp b/src/core/song.cpp index b776b350e..4f6c9a1ae 100644 --- a/src/core/song.cpp +++ b/src/core/song.cpp @@ -46,6 +46,7 @@ #include "automation_editor.h" #include "bb_editor.h" #include "bb_track.h" +#include "bb_track_container.h" #include "config_mgr.h" #include "embed.h" #include "envelope_and_lfo_parameters.h" diff --git a/src/core/track.cpp b/src/core/track.cpp index 6e99468d2..7821f35e3 100644 --- a/src/core/track.cpp +++ b/src/core/track.cpp @@ -42,6 +42,7 @@ #include "automatable_model_templates.h" #include "bb_editor.h" #include "bb_track.h" +#include "bb_track_container.h" #include "clipboard.h" #include "embed.h" #include "engine.h" diff --git a/src/core/track_container.cpp b/src/core/track_container.cpp index a46792617..04c44f31a 100644 --- a/src/core/track_container.cpp +++ b/src/core/track_container.cpp @@ -1,5 +1,3 @@ -#ifndef SINGLE_SOURCE_COMPILE - /* * track_container.cpp - implementation of base-class for all track-containers * like Song-Editor, BB-Editor... @@ -30,28 +28,11 @@ #include -#include #include -#include -#include -#include "bb_track.h" -#include "config_mgr.h" -#include "debug.h" #include "engine.h" -#include "file_browser.h" -#include "import_filter.h" -#include "instrument.h" -#include "instrument_track.h" -#include "main_window.h" -#include "mixer.h" -#include "mmp.h" -#include "project_journal.h" -#include "rubberband.h" #include "song.h" -#include "string_pair_drag.h" -#include "track.h" trackContainer::trackContainer( void ) : @@ -222,435 +203,5 @@ void trackContainer::setMutedOfAllTracks( bool _muted ) - - - - - - - - -trackContainerView::trackContainerView( trackContainer * _tc ) : - QWidget(), - modelView( NULL ), - m_currentPosition( 0, 0 ), - m_tc( _tc ), - m_trackViews(), - m_scrollArea( new scrollArea( this ) ), - m_ppt( DEFAULT_PIXELS_PER_TACT ), - m_rubberBand( new rubberBand( m_scrollArea ) ), - m_origin() -{ - QVBoxLayout * layout = new QVBoxLayout( this ); - layout->setMargin( 0 ); - layout->setSpacing( 0 ); - layout->addWidget( m_scrollArea ); - - QWidget * scrollContent = new QWidget; - m_scrollLayout = new QVBoxLayout( scrollContent ); - m_scrollLayout->setMargin( 0 ); - m_scrollLayout->setSpacing( 0 ); - m_scrollLayout->setSizeConstraint( QLayout::SetMinimumSize ); - - m_scrollArea->setWidget( scrollContent ); - - m_scrollArea->show(); - m_rubberBand->hide(); - - setAcceptDrops( TRUE ); - - connect( m_tc, SIGNAL( trackAdded( track * ) ), - this, SLOT( createTrackView( track * ) ), - Qt::QueuedConnection ); -} - - - - -trackContainerView::~trackContainerView() -{ - while( !m_trackViews.empty() ) - { - delete m_trackViews.takeLast(); - } -} - - - - - -trackView * trackContainerView::addTrackView( trackView * _tv ) -{ - QMap map; - map["id"] = _tv->getTrack()->id(); - addJournalEntry( journalEntry( AddTrack, map ) ); - - m_trackViews.push_back( _tv ); - m_scrollLayout->addWidget( _tv ); - connect( this, SIGNAL( positionChanged( const midiTime & ) ), - _tv->getTrackContentWidget(), - SLOT( changePosition( const midiTime & ) ) ); - realignTracks(); - return( _tv ); -} - - - - -void trackContainerView::removeTrackView( trackView * _tv ) -{ - int index = m_trackViews.indexOf( _tv ); - if( index != -1 ) - { - QMap map; - multimediaProject mmp( multimediaProject::JournalData ); - _tv->getTrack()->saveState( mmp, mmp.content() ); - map["id"] = _tv->getTrack()->id(); - map["state"] = mmp.toString(); - addJournalEntry( journalEntry( RemoveTrack, map ) ); - - m_trackViews.removeAt( index ); - - disconnect( _tv ); - m_scrollLayout->removeWidget( _tv ); - - realignTracks(); - if( engine::getSong() ) - { - engine::getSong()->setModified(); - } - } -} - - - - -void trackContainerView::moveTrackViewUp( trackView * _tv ) -{ - for( int i = 1; i < m_trackViews.size(); ++i ) - { - trackView * t = m_trackViews[i]; - if( t == _tv ) - { - bbTrack::swapBBTracks( t->getTrack(), - m_trackViews[i - 1]->getTrack() ); - m_scrollLayout->removeWidget( t ); - m_scrollLayout->insertWidget( i - 1, t ); - m_tc->m_tracks.swap( i - 1, i ); - m_trackViews.swap( i - 1, i ); - realignTracks(); - break; - } - } -} - - - - -void trackContainerView::moveTrackViewDown( trackView * _tv ) -{ - for( int i = 0; i < m_trackViews.size()-1; ++i ) - { - trackView * t = m_trackViews[i]; - if( t == _tv ) - { - bbTrack::swapBBTracks( t->getTrack(), - m_trackViews[i + 1]->getTrack() ); - m_scrollLayout->removeWidget( t ); - m_scrollLayout->insertWidget( i + 1, t ); - m_tc->m_tracks.swap( i, i + 1 ); - m_trackViews.swap( i, i + 1 ); - realignTracks(); - break; - } - } -} - - - - - -void trackContainerView::realignTracks( void ) -{ - QWidget * content = m_scrollArea->widget(); - content->setFixedWidth( width() - - m_scrollArea->verticalScrollBar()->width() ); - content->setFixedHeight( content->minimumSizeHint().height() ); - - for( trackViewList::iterator it = m_trackViews.begin(); - it != m_trackViews.end(); ++it ) - { - ( *it )->show(); - ( *it )->update(); - } -} - - - - -void trackContainerView::createTrackView( track * _t ) -{ - _t->createView( this ); -} - - - - -const trackView * trackContainerView::trackViewAt( const int _y ) const -{ - const int abs_y = _y + m_scrollArea->viewport()->y(); - int y_cnt = 0; - for( trackViewList::const_iterator it = m_trackViews.begin(); - it != m_trackViews.end(); ++it ) - { - const int y_cnt1 = y_cnt; - y_cnt += ( *it )->height(); - if( abs_y >= y_cnt1 && abs_y < y_cnt ) - { - return( *it ); - } - } - return( NULL ); -} - - - - -bool trackContainerView::allowRubberband( void ) const -{ - return( FALSE ); -} - - - - -void trackContainerView::setPixelsPerTact( int _ppt ) -{ - m_ppt = _ppt; -} - - - - -void trackContainerView::clearAllTracks( void ) -{ - while( !m_trackViews.empty() ) - { - trackView * tv = m_trackViews.takeLast(); - track * t = tv->getTrack(); - delete tv; - delete t; - } -} - - - - -void trackContainerView::undoStep( journalEntry & _je ) -{ - saveJournallingState( FALSE ); - switch( _je.actionID() ) - { - case AddTrack: - { - QMap map = _je.data().toMap(); - track * t = - dynamic_cast( - engine::getProjectJournal()->getJournallingObject( - map["id"].toInt() ) ); - assert( t != NULL ); - multimediaProject mmp( multimediaProject::JournalData ); - t->saveState( mmp, mmp.content() ); - map["state"] = mmp.toString(); - _je.data() = map; - t->deleteLater(); - break; - } - - case RemoveTrack: - { - multimediaProject mmp( - _je.data().toMap()["state"].toString(), FALSE ); - track::create( mmp.content().firstChild().toElement(), - m_tc ); - break; - } - } - restoreJournallingState(); -} - - - - -void trackContainerView::redoStep( journalEntry & _je ) -{ - switch( _je.actionID() ) - { - case AddTrack: - case RemoveTrack: - _je.actionID() = ( _je.actionID() == AddTrack ) ? - RemoveTrack : AddTrack; - undoStep( _je ); - _je.actionID() = ( _je.actionID() == AddTrack ) ? - RemoveTrack : AddTrack; - break; - } -} - - - - -void trackContainerView::dragEnterEvent( QDragEnterEvent * _dee ) -{ - stringPairDrag::processDragEnterEvent( _dee, - QString( "presetfile,sampledata,samplefile,instrument,midifile," - "track_%1,track_%2" ). - arg( track::InstrumentTrack ). - arg( track::SampleTrack ) ); -} - - - - -void trackContainerView::dropEvent( QDropEvent * _de ) -{ - QString type = stringPairDrag::decodeKey( _de ); - QString value = stringPairDrag::decodeValue( _de ); - engine::getMixer()->lock(); - if( type == "instrument" ) - { - instrumentTrack * it = dynamic_cast( - track::create( track::InstrumentTrack, - m_tc ) ); - it->loadInstrument( value ); - //it->toggledInstrumentTrackButton( TRUE ); - _de->accept(); - } - else if( type == "sampledata" || type == "samplefile" ) - { - instrumentTrack * it = dynamic_cast( - track::create( track::InstrumentTrack, - m_tc ) ); - QString iname = type == "sampledata" ? "audiofileprocessor" : - engine::sampleExtensions()[fileItem::extension( - value )]; - instrument * i = it->loadInstrument( iname ); - i->setParameter( type, value ); - //it->toggledInstrumentTrackButton( TRUE ); - _de->accept(); - } - else if( type == "presetfile" ) - { - multimediaProject mmp( value ); - instrumentTrack * it = dynamic_cast( - track::create( track::InstrumentTrack, - m_tc ) ); - it->loadTrackSpecificSettings( mmp.content().firstChild(). - toElement() ); - //it->toggledInstrumentTrackButton( TRUE ); - _de->accept(); - } - else if( type == "midifile" ) - { - importFilter::import( value, m_tc ); - _de->accept(); - } - else if( type.left( 6 ) == "track_" ) - { - multimediaProject mmp( value, FALSE ); - track::create( mmp.content().firstChild().toElement(), m_tc ); - _de->accept(); - } - engine::getMixer()->unlock(); -} - - - - -void trackContainerView::mousePressEvent( QMouseEvent * _me ) -{ - if( allowRubberband() == TRUE ) - { - m_origin = m_scrollArea->mapFromParent( _me->pos() ); - m_rubberBand->setGeometry( QRect( m_origin, QSize() ) ); - m_rubberBand->show(); - } - QWidget::mousePressEvent( _me ); -} - - - - -void trackContainerView::mouseMoveEvent( QMouseEvent * _me ) -{ - if( rubberBandActive() == TRUE ) - { - m_rubberBand->setGeometry( QRect( m_origin, - m_scrollArea->mapFromParent( _me->pos() ) ). - normalized() ); - } - QWidget::mouseMoveEvent( _me ); -} - - - - -void trackContainerView::mouseReleaseEvent( QMouseEvent * _me ) -{ - m_rubberBand->hide(); - QWidget::mouseReleaseEvent( _me ); -} - - - - - -void trackContainerView::resizeEvent( QResizeEvent * _re ) -{ - realignTracks(); - QWidget::resizeEvent( _re ); -} - - - - -trackContainerView::scrollArea::scrollArea( trackContainerView * _parent ) : - QScrollArea( _parent ), - m_trackContainerView( _parent ) -{ - setFrameStyle( QFrame::NoFrame ); - setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); - setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOn ); -} - - - - -trackContainerView::scrollArea::~scrollArea() -{ -} - - - - -void trackContainerView::scrollArea::wheelEvent( QWheelEvent * _we ) -{ - // always pass wheel-event to parent-widget (song-editor - // bb-editor etc.) because they might want to use it for zooming - // or scrolling left/right if a modifier-key is pressed, otherwise - // they do not accept it and we pass it up to QScrollArea - m_trackContainerView->wheelEvent( _we ); - if( !_we->isAccepted() ) - { - QScrollArea::wheelEvent( _we ); - } -} - - - - - #include "track_container.moc" - -#endif diff --git a/src/gui/bb_editor.cpp b/src/gui/bb_editor.cpp index 38138a446..d228dfef3 100644 --- a/src/gui/bb_editor.cpp +++ b/src/gui/bb_editor.cpp @@ -1,5 +1,3 @@ -#ifndef SINGLE_SOURCE_COMPILE - /* * bb_editor.cpp - basic main-window for editing of beats and basslines * @@ -25,15 +23,12 @@ */ -#include "bb_editor.h" - - #include #include #include -#include - +#include "bb_editor.h" +#include "bb_track_container.h" #include "bb_track.h" #include "combobox.h" #include "embed.h" @@ -44,270 +39,6 @@ #include "templates.h" #include "tool_button.h" #include "tooltip.h" -#include "track_container.h" - - -bbTrackContainer::bbTrackContainer( void ) : - trackContainer(), - m_bbComboBoxModel( this ) -{ - connect( &m_bbComboBoxModel, SIGNAL( dataChanged() ), - this, SLOT( currentBBChanged() ), - Qt::QueuedConnection ); - // we *always* want to receive updates even in case BB actually did - // not change upon setCurrentBB()-call - connect( &m_bbComboBoxModel, SIGNAL( dataUnchanged() ), - this, SLOT( currentBBChanged() ), - Qt::QueuedConnection ); -} - - - - -bbTrackContainer::~bbTrackContainer() -{ -} - - - - -bool bbTrackContainer::play( midiTime _start, fpp_t _frames, - f_cnt_t _offset, - Sint16 _tco_num ) -{ - bool played_a_note = FALSE; - if( lengthOfBB( _tco_num ) <= 0 ) - { - return( played_a_note ); - } - - _start = ( _start.getTact() % lengthOfBB( _tco_num ) ) * 64 + - _start.getTact64th(); - QList tl = tracks(); - for( int i = 0; i < tl.size(); ++i ) - { - if( tl[i]->play( _start, _frames, _offset, _tco_num ) == TRUE ) - { - played_a_note = TRUE; - } - } - - return( played_a_note ); -} - - - -/* -void bbTrackContainer::saveSettings( QDomDocument & _doc, QDomElement & _parent ) -{ - trackContainer::saveSettings( _doc, _parent ); -} - - - - -void bbTrackContainer::loadSettings( const QDomElement & _this ) -{ - trackContainer::loadSettings( _this ); -} -*/ - - - -void bbTrackContainer::updateAfterTrackAdd( void ) -{ - // make sure, new track(s) have TCOs for every beat/bassline - for( int i = 0; i < tMax( 1, numOfBBs() ); ++i ) - { - createTCOsForBB( i ); - } -} - - - - -tact bbTrackContainer::lengthOfBB( int _bb ) -{ - midiTime max_length; - - QList tl = tracks(); - for( int i = 0; i < tl.size(); ++i ) - { - trackContentObject * tco = tl[i]->getTCO( _bb ); - max_length = tMax( max_length, tco->length() ); - } - if( max_length.getTact64th() == 0 ) - { - return( max_length.getTact() ); - } - - return( max_length.getTact() + 1 ); -} - - - - -int bbTrackContainer::numOfBBs( void ) const -{ - return( engine::getSong()->countTracks( track::BBTrack ) ); -} - - - - -void bbTrackContainer::removeBB( int _bb ) -{ - QList tl = tracks(); - for( int i = 0; i < tl.size(); ++i ) - { - delete tl[i]->getTCO( _bb ); - tl[i]->removeTact( _bb * 64 ); - } - if( _bb <= currentBB() ) - { - setCurrentBB( tMax( currentBB() - 1, 0 ) ); - } -} - - - - -void bbTrackContainer::swapBB( int _bb1, int _bb2 ) -{ - QList tl = tracks(); - for( int i = 0; i < tl.size(); ++i ) - { - tl[i]->swapPositionOfTCOs( _bb1, _bb2 ); - } - updateComboBox(); -} - - - - -void bbTrackContainer::updateBBTrack( trackContentObject * _tco ) -{ - bbTrack * t = bbTrack::findBBTrack( _tco->startPosition() / 64 ); - if( t != NULL ) - { - t->dataChanged(); - //t->getTrackContentWidget()->update(); - } -} - - - - -void bbTrackContainer::play( void ) -{ - if( engine::getSong()->playing() ) - { - if( engine::getSong()->playMode() != song::Mode_PlayBB ) - { - engine::getSong()->stop(); - engine::getSong()->playBB(); - } - else - { - engine::getSong()->pause(); - } - } - else if( engine::getSong()->paused() ) - { - engine::getSong()->resumeFromPause(); - } - else - { - engine::getSong()->playBB(); - } - -} - - - - -void bbTrackContainer::stop( void ) -{ - engine::getSong()->stop(); -} - - - - -void bbTrackContainer::updateComboBox( void ) -{ - const int cur_bb = currentBB(); - - m_bbComboBoxModel.clear(); - - for( int i = 0; i < numOfBBs(); ++i ) - { - bbTrack * bbt = bbTrack::findBBTrack( i ); - m_bbComboBoxModel.addItem( bbt->name(), - bbt->pixmap() ? new QPixmap( *bbt->pixmap() ) - : NULL ); - } - setCurrentBB( cur_bb ); -} - - - - -void bbTrackContainer::currentBBChanged( void ) -{ - // first make sure, all channels have a TCO at current BB - createTCOsForBB( currentBB() ); - - // now update all track-labels (the current one has to become white, - // the others green) - for( int i = 0; i < numOfBBs(); ++i ) - { - bbTrack::findBBTrack( i )->dataChanged(); -//trackLabel()->update(); - } - - //emit dataChanged(); - //emit positionChanged( NULL ); -} - - - - -void bbTrackContainer::createTCOsForBB( int _bb ) -{ - if( numOfBBs() == 0 || engine::getSong()->isLoadingProject() ) - { - return; - } - - QList tl = tracks(); - for( int i = 0; i < tl.size(); ++i ) - { - while( tl[i]->numOfTCOs() < _bb + 1 ) - { - midiTime position = midiTime( tl[i]->numOfTCOs(), 0 ); - trackContentObject * tco = tl[i]->addTCO( - tl[i]->createTCO( position ) ); - tco->movePosition( position ); - tco->changeLength( midiTime( 1, 0 ) ); - } - } -} - - - - - - - - - - - - - - - @@ -522,5 +253,3 @@ void bbEditor::keyPressEvent( QKeyEvent * _ke ) #include "bb_editor.moc" - -#endif diff --git a/src/gui/track_container_view.cpp b/src/gui/track_container_view.cpp new file mode 100644 index 000000000..03c28ce4d --- /dev/null +++ b/src/gui/track_container_view.cpp @@ -0,0 +1,473 @@ +/* + * track_container_view.cpp - view-component for trackContainer + * + * Copyright (c) 2004-2008 Tobias Doerffel + * + * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net + * + * 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 (see COPYING); if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + */ + + +#include "track_container_view.h" +#include "track_container.h" + + +#include +#include +#include +#include +#include + + +#include "bb_track.h" +#include "config_mgr.h" +#include "debug.h" +#include "file_browser.h" +#include "import_filter.h" +#include "instrument.h" +#include "instrument_track.h" +#include "mmp.h" +#include "project_journal.h" +#include "rubberband.h" +#include "song.h" +#include "string_pair_drag.h" +#include "track.h" + + +trackContainerView::trackContainerView( trackContainer * _tc ) : + QWidget(), + modelView( NULL ), + m_currentPosition( 0, 0 ), + m_tc( _tc ), + m_trackViews(), + m_scrollArea( new scrollArea( this ) ), + m_ppt( DEFAULT_PIXELS_PER_TACT ), + m_rubberBand( new rubberBand( m_scrollArea ) ), + m_origin() +{ + QVBoxLayout * layout = new QVBoxLayout( this ); + layout->setMargin( 0 ); + layout->setSpacing( 0 ); + layout->addWidget( m_scrollArea ); + + QWidget * scrollContent = new QWidget; + m_scrollLayout = new QVBoxLayout( scrollContent ); + m_scrollLayout->setMargin( 0 ); + m_scrollLayout->setSpacing( 0 ); + m_scrollLayout->setSizeConstraint( QLayout::SetMinimumSize ); + + m_scrollArea->setWidget( scrollContent ); + + m_scrollArea->show(); + m_rubberBand->hide(); + + setAcceptDrops( TRUE ); + + connect( m_tc, SIGNAL( trackAdded( track * ) ), + this, SLOT( createTrackView( track * ) ), + Qt::QueuedConnection ); +} + + + + +trackContainerView::~trackContainerView() +{ + while( !m_trackViews.empty() ) + { + delete m_trackViews.takeLast(); + } +} + + + + + +trackView * trackContainerView::addTrackView( trackView * _tv ) +{ + QMap map; + map["id"] = _tv->getTrack()->id(); + addJournalEntry( journalEntry( AddTrack, map ) ); + + m_trackViews.push_back( _tv ); + m_scrollLayout->addWidget( _tv ); + connect( this, SIGNAL( positionChanged( const midiTime & ) ), + _tv->getTrackContentWidget(), + SLOT( changePosition( const midiTime & ) ) ); + realignTracks(); + return( _tv ); +} + + + + +void trackContainerView::removeTrackView( trackView * _tv ) +{ + int index = m_trackViews.indexOf( _tv ); + if( index != -1 ) + { + QMap map; + multimediaProject mmp( multimediaProject::JournalData ); + _tv->getTrack()->saveState( mmp, mmp.content() ); + map["id"] = _tv->getTrack()->id(); + map["state"] = mmp.toString(); + addJournalEntry( journalEntry( RemoveTrack, map ) ); + + m_trackViews.removeAt( index ); + + disconnect( _tv ); + m_scrollLayout->removeWidget( _tv ); + + realignTracks(); + if( engine::getSong() ) + { + engine::getSong()->setModified(); + } + } +} + + + + +void trackContainerView::moveTrackViewUp( trackView * _tv ) +{ + for( int i = 1; i < m_trackViews.size(); ++i ) + { + trackView * t = m_trackViews[i]; + if( t == _tv ) + { + bbTrack::swapBBTracks( t->getTrack(), + m_trackViews[i - 1]->getTrack() ); + m_scrollLayout->removeWidget( t ); + m_scrollLayout->insertWidget( i - 1, t ); + m_tc->m_tracks.swap( i - 1, i ); + m_trackViews.swap( i - 1, i ); + realignTracks(); + break; + } + } +} + + + + +void trackContainerView::moveTrackViewDown( trackView * _tv ) +{ + for( int i = 0; i < m_trackViews.size()-1; ++i ) + { + trackView * t = m_trackViews[i]; + if( t == _tv ) + { + bbTrack::swapBBTracks( t->getTrack(), + m_trackViews[i + 1]->getTrack() ); + m_scrollLayout->removeWidget( t ); + m_scrollLayout->insertWidget( i + 1, t ); + m_tc->m_tracks.swap( i, i + 1 ); + m_trackViews.swap( i, i + 1 ); + realignTracks(); + break; + } + } +} + + + + + +void trackContainerView::realignTracks( void ) +{ + QWidget * content = m_scrollArea->widget(); + content->setFixedWidth( width() + - m_scrollArea->verticalScrollBar()->width() ); + content->setFixedHeight( content->minimumSizeHint().height() ); + + for( trackViewList::iterator it = m_trackViews.begin(); + it != m_trackViews.end(); ++it ) + { + ( *it )->show(); + ( *it )->update(); + } +} + + + + +void trackContainerView::createTrackView( track * _t ) +{ + _t->createView( this ); +} + + + + +const trackView * trackContainerView::trackViewAt( const int _y ) const +{ + const int abs_y = _y + m_scrollArea->viewport()->y(); + int y_cnt = 0; + for( trackViewList::const_iterator it = m_trackViews.begin(); + it != m_trackViews.end(); ++it ) + { + const int y_cnt1 = y_cnt; + y_cnt += ( *it )->height(); + if( abs_y >= y_cnt1 && abs_y < y_cnt ) + { + return( *it ); + } + } + return( NULL ); +} + + + + +bool trackContainerView::allowRubberband( void ) const +{ + return( FALSE ); +} + + + + +void trackContainerView::setPixelsPerTact( int _ppt ) +{ + m_ppt = _ppt; +} + + + + +void trackContainerView::clearAllTracks( void ) +{ + while( !m_trackViews.empty() ) + { + trackView * tv = m_trackViews.takeLast(); + track * t = tv->getTrack(); + delete tv; + delete t; + } +} + + + + +void trackContainerView::undoStep( journalEntry & _je ) +{ + saveJournallingState( FALSE ); + switch( _je.actionID() ) + { + case AddTrack: + { + QMap map = _je.data().toMap(); + track * t = + dynamic_cast( + engine::getProjectJournal()->getJournallingObject( + map["id"].toInt() ) ); + assert( t != NULL ); + multimediaProject mmp( multimediaProject::JournalData ); + t->saveState( mmp, mmp.content() ); + map["state"] = mmp.toString(); + _je.data() = map; + t->deleteLater(); + break; + } + + case RemoveTrack: + { + multimediaProject mmp( + _je.data().toMap()["state"].toString(), FALSE ); + track::create( mmp.content().firstChild().toElement(), + m_tc ); + break; + } + } + restoreJournallingState(); +} + + + + +void trackContainerView::redoStep( journalEntry & _je ) +{ + switch( _je.actionID() ) + { + case AddTrack: + case RemoveTrack: + _je.actionID() = ( _je.actionID() == AddTrack ) ? + RemoveTrack : AddTrack; + undoStep( _je ); + _je.actionID() = ( _je.actionID() == AddTrack ) ? + RemoveTrack : AddTrack; + break; + } +} + + + + +void trackContainerView::dragEnterEvent( QDragEnterEvent * _dee ) +{ + stringPairDrag::processDragEnterEvent( _dee, + QString( "presetfile,sampledata,samplefile,instrument,midifile," + "track_%1,track_%2" ). + arg( track::InstrumentTrack ). + arg( track::SampleTrack ) ); +} + + + + +void trackContainerView::dropEvent( QDropEvent * _de ) +{ + QString type = stringPairDrag::decodeKey( _de ); + QString value = stringPairDrag::decodeValue( _de ); + engine::getMixer()->lock(); + if( type == "instrument" ) + { + instrumentTrack * it = dynamic_cast( + track::create( track::InstrumentTrack, + m_tc ) ); + it->loadInstrument( value ); + //it->toggledInstrumentTrackButton( TRUE ); + _de->accept(); + } + else if( type == "sampledata" || type == "samplefile" ) + { + instrumentTrack * it = dynamic_cast( + track::create( track::InstrumentTrack, + m_tc ) ); + QString iname = type == "sampledata" ? "audiofileprocessor" : + engine::sampleExtensions()[fileItem::extension( + value )]; + instrument * i = it->loadInstrument( iname ); + i->setParameter( type, value ); + //it->toggledInstrumentTrackButton( TRUE ); + _de->accept(); + } + else if( type == "presetfile" ) + { + multimediaProject mmp( value ); + instrumentTrack * it = dynamic_cast( + track::create( track::InstrumentTrack, + m_tc ) ); + it->loadTrackSpecificSettings( mmp.content().firstChild(). + toElement() ); + //it->toggledInstrumentTrackButton( TRUE ); + _de->accept(); + } + else if( type == "midifile" ) + { + importFilter::import( value, m_tc ); + _de->accept(); + } + else if( type.left( 6 ) == "track_" ) + { + multimediaProject mmp( value, FALSE ); + track::create( mmp.content().firstChild().toElement(), m_tc ); + _de->accept(); + } + engine::getMixer()->unlock(); +} + + + + +void trackContainerView::mousePressEvent( QMouseEvent * _me ) +{ + if( allowRubberband() == TRUE ) + { + m_origin = m_scrollArea->mapFromParent( _me->pos() ); + m_rubberBand->setGeometry( QRect( m_origin, QSize() ) ); + m_rubberBand->show(); + } + QWidget::mousePressEvent( _me ); +} + + + + +void trackContainerView::mouseMoveEvent( QMouseEvent * _me ) +{ + if( rubberBandActive() == TRUE ) + { + m_rubberBand->setGeometry( QRect( m_origin, + m_scrollArea->mapFromParent( _me->pos() ) ). + normalized() ); + } + QWidget::mouseMoveEvent( _me ); +} + + + + +void trackContainerView::mouseReleaseEvent( QMouseEvent * _me ) +{ + m_rubberBand->hide(); + QWidget::mouseReleaseEvent( _me ); +} + + + + + +void trackContainerView::resizeEvent( QResizeEvent * _re ) +{ + realignTracks(); + QWidget::resizeEvent( _re ); +} + + + + +trackContainerView::scrollArea::scrollArea( trackContainerView * _parent ) : + QScrollArea( _parent ), + m_trackContainerView( _parent ) +{ + setFrameStyle( QFrame::NoFrame ); + setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); + setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOn ); +} + + + + +trackContainerView::scrollArea::~scrollArea() +{ +} + + + + +void trackContainerView::scrollArea::wheelEvent( QWheelEvent * _we ) +{ + // always pass wheel-event to parent-widget (song-editor + // bb-editor etc.) because they might want to use it for zooming + // or scrolling left/right if a modifier-key is pressed, otherwise + // they do not accept it and we pass it up to QScrollArea + m_trackContainerView->wheelEvent( _we ); + if( !_we->isAccepted() ) + { + QScrollArea::wheelEvent( _we ); + } +} + + + + + +#include "track_container_view.moc" + diff --git a/src/tracks/bb_track.cpp b/src/tracks/bb_track.cpp index fc823967b..a69d3ae25 100644 --- a/src/tracks/bb_track.cpp +++ b/src/tracks/bb_track.cpp @@ -31,8 +31,9 @@ #include -#include "bb_track.h" #include "bb_editor.h" +#include "bb_track.h" +#include "bb_track_container.h" #include "embed.h" #include "engine.h" #include "gui_templates.h" diff --git a/src/tracks/pattern.cpp b/src/tracks/pattern.cpp index ddad35a4b..d32eda4ff 100644 --- a/src/tracks/pattern.cpp +++ b/src/tracks/pattern.cpp @@ -49,7 +49,7 @@ #include "audio_sample_recorder.h" #include "song.h" #include "tooltip.h" -#include "bb_editor.h" +#include "bb_track_container.h" #include "string_pair_drag.h" #include "main_window.h"