| 1 | /* |
|---|
| 2 | * Hydrogen |
|---|
| 3 | * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net] |
|---|
| 4 | * |
|---|
| 5 | * http://www.hydrogen-music.org |
|---|
| 6 | * |
|---|
| 7 | * This program is free software; you can redistribute it and/or modify |
|---|
| 8 | * it under the terms of the GNU General Public License as published by |
|---|
| 9 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 10 | * (at your option) any later version. |
|---|
| 11 | * |
|---|
| 12 | * This program is distributed in the hope that it will be useful, |
|---|
| 13 | * but WITHOUT ANY WARRANTY, without even the implied warranty of |
|---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | * GNU General Public License for more details. |
|---|
| 16 | * |
|---|
| 17 | * You should have received a copy of the GNU General Public License |
|---|
| 18 | * along with this program; if not, write to the Free Software |
|---|
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 20 | * |
|---|
| 21 | */ |
|---|
| 22 | #include "SongEditorPanel.h" |
|---|
| 23 | |
|---|
| 24 | #include "../HydrogenApp.h" |
|---|
| 25 | #include "../PatternPropertiesDialog.h" |
|---|
| 26 | #include "../SongPropertiesDialog.h" |
|---|
| 27 | #include "../widgets/Button.h" |
|---|
| 28 | #include "../widgets/PixmapWidget.h" |
|---|
| 29 | #include "../Skin.h" |
|---|
| 30 | |
|---|
| 31 | #include "SongEditor.h" |
|---|
| 32 | #include "UndoActions.h" |
|---|
| 33 | |
|---|
| 34 | #include <hydrogen/hydrogen.h> |
|---|
| 35 | #include <hydrogen/Preferences.h> |
|---|
| 36 | #include <hydrogen/audio_engine.h> |
|---|
| 37 | #include <hydrogen/basics/pattern.h> |
|---|
| 38 | #include <hydrogen/basics/pattern_list.h> |
|---|
| 39 | using namespace H2Core; |
|---|
| 40 | using namespace std; |
|---|
| 41 | |
|---|
| 42 | const char* SongEditorPanel::__class_name = "SongEditorPanel"; |
|---|
| 43 | |
|---|
| 44 | SongEditorPanel::SongEditorPanel(QWidget *pParent) |
|---|
| 45 | : QWidget( pParent ) |
|---|
| 46 | , Object( __class_name ) |
|---|
| 47 | , m_actionMode( DRAW_ACTION ) |
|---|
| 48 | { |
|---|
| 49 | m_nInitialWidth = 600; |
|---|
| 50 | m_nInitialHeight = 250; |
|---|
| 51 | |
|---|
| 52 | setWindowTitle( trUtf8( "Song Editor" ) ); |
|---|
| 53 | |
|---|
| 54 | // background |
|---|
| 55 | PixmapWidget *pBackPanel = new PixmapWidget( NULL ); |
|---|
| 56 | pBackPanel->setFixedSize( 196, 49 ); |
|---|
| 57 | pBackPanel->setPixmap( "/songEditor/bg_topPanel.png" ); |
|---|
| 58 | |
|---|
| 59 | // time line toggle button |
|---|
| 60 | m_pTimeLineToggleBtn = new ToggleButton( |
|---|
| 61 | pBackPanel, |
|---|
| 62 | "/songEditor/btn_bpm_on.png", |
|---|
| 63 | "/songEditor/btn_bpm_off.png", |
|---|
| 64 | "/songEditor/btn_bpm_over.png", |
|---|
| 65 | QSize( 54, 13 ) |
|---|
| 66 | ); |
|---|
| 67 | m_pTimeLineToggleBtn->move( 133, 6 ); |
|---|
| 68 | m_pTimeLineToggleBtn->setToolTip( trUtf8( "Enable time line edit") ); |
|---|
| 69 | connect( m_pTimeLineToggleBtn, SIGNAL( clicked( Button* ) ), this, SLOT( timeLineBtnPressed(Button* ) ) ); |
|---|
| 70 | m_pTimeLineToggleBtn->setPressed( Preferences::get_instance()->__usetimeline ); |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | // clear sequence button |
|---|
| 74 | m_pClearPatternSeqBtn = new Button( |
|---|
| 75 | pBackPanel, |
|---|
| 76 | "/songEditor/btn_clear_on.png", |
|---|
| 77 | "/songEditor/btn_clear_off.png", |
|---|
| 78 | "/songEditor/btn_clear_over.png", |
|---|
| 79 | QSize(53,13) |
|---|
| 80 | ); |
|---|
| 81 | m_pClearPatternSeqBtn->move( 6, 5 + 25 ); |
|---|
| 82 | m_pClearPatternSeqBtn->setToolTip( trUtf8("Clear pattern sequence") ); |
|---|
| 83 | connect( m_pClearPatternSeqBtn, SIGNAL( clicked( Button* ) ), this, SLOT( clearSequence(Button*) ) ); |
|---|
| 84 | |
|---|
| 85 | // new pattern button |
|---|
| 86 | Button *newPatBtn = new Button( |
|---|
| 87 | pBackPanel, |
|---|
| 88 | "/songEditor/btn_new_on.png", |
|---|
| 89 | "/songEditor/btn_new_off.png", |
|---|
| 90 | "/songEditor/btn_new_over.png", |
|---|
| 91 | QSize(19, 13) |
|---|
| 92 | ); |
|---|
| 93 | newPatBtn->move( 64, 5 + 25); |
|---|
| 94 | newPatBtn->setToolTip( trUtf8("Create new pattern") ); |
|---|
| 95 | connect( newPatBtn, SIGNAL( clicked( Button* ) ), this, SLOT( newPatBtnClicked( Button* ) ) ); |
|---|
| 96 | |
|---|
| 97 | // down button |
|---|
| 98 | m_pDownBtn = new Button( |
|---|
| 99 | pBackPanel, |
|---|
| 100 | "/songEditor/btn_down_on.png", |
|---|
| 101 | "/songEditor/btn_down_off.png", |
|---|
| 102 | "/songEditor/btn_down_over.png", |
|---|
| 103 | QSize(18,13) |
|---|
| 104 | ); |
|---|
| 105 | m_pDownBtn->move( 89, 5 + 25); |
|---|
| 106 | m_pDownBtn->setToolTip( trUtf8("Move the selected pattern down") ); |
|---|
| 107 | connect( m_pDownBtn, SIGNAL( clicked( Button* ) ), this, SLOT( downBtnClicked( Button* ) ) ); |
|---|
| 108 | |
|---|
| 109 | // up button |
|---|
| 110 | m_pUpBtn = new Button( |
|---|
| 111 | pBackPanel, |
|---|
| 112 | "/songEditor/btn_up_on.png", |
|---|
| 113 | "/songEditor/btn_up_off.png", |
|---|
| 114 | "/songEditor/btn_up_over.png", |
|---|
| 115 | QSize(18,13) |
|---|
| 116 | ); |
|---|
| 117 | m_pUpBtn->move( 106, 5 + 25 ); |
|---|
| 118 | m_pUpBtn->setToolTip( trUtf8("Move the selected pattern up") ); |
|---|
| 119 | connect( m_pUpBtn, SIGNAL( clicked( Button* ) ), this, SLOT( upBtnClicked( Button* ) ) ); |
|---|
| 120 | |
|---|
| 121 | // select toggle button |
|---|
| 122 | m_pPointerActionBtn = new ToggleButton( |
|---|
| 123 | pBackPanel, |
|---|
| 124 | "/songEditor/btn_select_on.png", |
|---|
| 125 | "/songEditor/btn_select_off.png", |
|---|
| 126 | "/songEditor/btn_select_over.png", |
|---|
| 127 | QSize( 18, 13 ) |
|---|
| 128 | ); |
|---|
| 129 | m_pPointerActionBtn->move( 128, 5 + 25 ); |
|---|
| 130 | m_pPointerActionBtn->setToolTip( trUtf8( "Select mode" ) ); |
|---|
| 131 | connect( m_pPointerActionBtn, SIGNAL( clicked( Button* ) ), this, SLOT( pointerActionBtnPressed(Button*) ) ); |
|---|
| 132 | |
|---|
| 133 | // draw toggle button |
|---|
| 134 | m_pDrawActionBtn = new ToggleButton( |
|---|
| 135 | pBackPanel, |
|---|
| 136 | "/songEditor/btn_draw_on.png", |
|---|
| 137 | "/songEditor/btn_draw_off.png", |
|---|
| 138 | "/songEditor/btn_draw_over.png", |
|---|
| 139 | QSize( 18, 13 ) |
|---|
| 140 | ); |
|---|
| 141 | m_pDrawActionBtn->move( 147, 5 + 25 ); |
|---|
| 142 | m_pDrawActionBtn->setToolTip( trUtf8( "Draw mode") ); |
|---|
| 143 | connect( m_pDrawActionBtn, SIGNAL( clicked( Button* ) ), this, SLOT( drawActionBtnPressed(Button* ) ) ); |
|---|
| 144 | m_pDrawActionBtn->setPressed( true ); |
|---|
| 145 | |
|---|
| 146 | m_pModeActionBtn = new ToggleButton( |
|---|
| 147 | pBackPanel, |
|---|
| 148 | "/songEditor/btn_mode_on.png", |
|---|
| 149 | "/songEditor/btn_mode_off.png", |
|---|
| 150 | "/songEditor/btn_mode_over.png", |
|---|
| 151 | QSize( 18, 13 ) |
|---|
| 152 | ); |
|---|
| 153 | m_pModeActionBtn->move( 169, 5 + 25 ); |
|---|
| 154 | m_pModeActionBtn->setToolTip( trUtf8( "stacked mode") ); |
|---|
| 155 | m_pModeActionBtn->setPressed( Preferences::get_instance()->patternModePlaysSelected() ); |
|---|
| 156 | connect( m_pModeActionBtn, SIGNAL( clicked( Button* ) ), this, SLOT( modeActionBtnPressed() ) ); |
|---|
| 157 | |
|---|
| 158 | // ZOOM |
|---|
| 159 | m_pHScrollBar = new QScrollBar( Qt::Horizontal,NULL ); |
|---|
| 160 | connect( m_pHScrollBar, SIGNAL(valueChanged(int)), this, SLOT( syncToExternalScrollBar() ) ); |
|---|
| 161 | |
|---|
| 162 | // zoom-in btn |
|---|
| 163 | Button* pZoomInBtn = new Button( |
|---|
| 164 | NULL, |
|---|
| 165 | "/songEditor/btn_new_on.png", |
|---|
| 166 | "/songEditor/btn_new_off.png", |
|---|
| 167 | "/songEditor/btn_new_over.png", |
|---|
| 168 | QSize( 19, 13 ) |
|---|
| 169 | ); |
|---|
| 170 | connect( pZoomInBtn, SIGNAL( clicked( Button* ) ), this, SLOT( zoomOutBtnPressed(Button* ) ) ); |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | |
|---|
| 174 | // zoom-out btn |
|---|
| 175 | Button* pZoomOutBtn = new Button( |
|---|
| 176 | NULL, |
|---|
| 177 | "/songEditor/btn_minus_on.png", |
|---|
| 178 | "/songEditor/btn_minus_off.png", |
|---|
| 179 | "/songEditor/btn_minus_over.png", |
|---|
| 180 | QSize( 19, 13 ) |
|---|
| 181 | ); |
|---|
| 182 | connect( pZoomOutBtn, SIGNAL( clicked( Button* ) ), this, SLOT( zoomInBtnPressed(Button* ) ) ); |
|---|
| 183 | |
|---|
| 184 | QHBoxLayout *pHZoomLayout = new QHBoxLayout(); |
|---|
| 185 | pHZoomLayout->setSpacing( 0 ); |
|---|
| 186 | pHZoomLayout->setMargin( 0 ); |
|---|
| 187 | pHZoomLayout->addWidget( m_pHScrollBar ); |
|---|
| 188 | pHZoomLayout->addWidget( pZoomInBtn ); |
|---|
| 189 | pHZoomLayout->addWidget( pZoomOutBtn ); |
|---|
| 190 | |
|---|
| 191 | QWidget *pHScrollbarPanel = new QWidget(); |
|---|
| 192 | pHScrollbarPanel->setLayout( pHZoomLayout ); |
|---|
| 193 | |
|---|
| 194 | //~ ZOOM |
|---|
| 195 | |
|---|
| 196 | // PATTERN LIST |
|---|
| 197 | m_pPatternListScrollView = new QScrollArea( NULL ); |
|---|
| 198 | m_pPatternListScrollView->setFrameShape( QFrame::NoFrame ); |
|---|
| 199 | m_pPatternListScrollView->setFixedWidth( m_nPatternListWidth ); |
|---|
| 200 | m_pPatternListScrollView->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); |
|---|
| 201 | m_pPatternListScrollView->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); |
|---|
| 202 | connect( m_pPatternListScrollView->verticalScrollBar(), SIGNAL( valueChanged(int) ), this, SLOT( on_patternListScroll() ) ); |
|---|
| 203 | |
|---|
| 204 | m_pPatternList = new SongEditorPatternList( m_pPatternListScrollView->viewport() ); |
|---|
| 205 | m_pPatternListScrollView->setWidget( m_pPatternList ); |
|---|
| 206 | |
|---|
| 207 | |
|---|
| 208 | // EDITOR |
|---|
| 209 | m_pEditorScrollView = new QScrollArea( NULL ); |
|---|
| 210 | m_pEditorScrollView->setFrameShape( QFrame::NoFrame ); |
|---|
| 211 | m_pEditorScrollView->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); |
|---|
| 212 | m_pEditorScrollView->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); |
|---|
| 213 | m_pSongEditor = new SongEditor( m_pEditorScrollView->viewport() ); |
|---|
| 214 | m_pEditorScrollView->setWidget( m_pSongEditor ); |
|---|
| 215 | |
|---|
| 216 | connect( m_pEditorScrollView->horizontalScrollBar(), SIGNAL( valueChanged(int) ), this, SLOT( on_EditorScroll() ) ); |
|---|
| 217 | connect( m_pEditorScrollView->verticalScrollBar(), SIGNAL( valueChanged(int) ), this, SLOT( on_EditorScroll() ) ); |
|---|
| 218 | |
|---|
| 219 | |
|---|
| 220 | // POSITION RULER |
|---|
| 221 | m_pPositionRulerScrollView = new QScrollArea( NULL ); |
|---|
| 222 | m_pPositionRulerScrollView->setFrameShape( QFrame::NoFrame ); |
|---|
| 223 | m_pPositionRulerScrollView->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); |
|---|
| 224 | m_pPositionRulerScrollView->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); |
|---|
| 225 | m_pPositionRuler = new SongEditorPositionRuler( m_pPositionRulerScrollView->viewport() ); |
|---|
| 226 | m_pPositionRulerScrollView->setWidget( m_pPositionRuler ); |
|---|
| 227 | m_pPositionRulerScrollView->setFixedHeight( 50 ); |
|---|
| 228 | |
|---|
| 229 | m_pVScrollBar = new QScrollBar( Qt::Vertical, NULL ); |
|---|
| 230 | connect( m_pVScrollBar, SIGNAL(valueChanged(int)), this, SLOT( syncToExternalScrollBar() ) ); |
|---|
| 231 | |
|---|
| 232 | |
|---|
| 233 | |
|---|
| 234 | // ok...let's build the layout |
|---|
| 235 | QGridLayout *pGridLayout = new QGridLayout(); |
|---|
| 236 | pGridLayout->setSpacing( 0 ); |
|---|
| 237 | pGridLayout->setMargin( 0 ); |
|---|
| 238 | |
|---|
| 239 | pGridLayout->addWidget( pBackPanel, 0, 0 ); |
|---|
| 240 | pGridLayout->addWidget( m_pPositionRulerScrollView, 0, 1 ); |
|---|
| 241 | pGridLayout->addWidget( m_pPatternListScrollView, 1, 0 ); |
|---|
| 242 | pGridLayout->addWidget( m_pEditorScrollView, 1, 1 ); |
|---|
| 243 | pGridLayout->addWidget( m_pVScrollBar, 1, 2 ); |
|---|
| 244 | //pGridLayout->addWidget( m_pHScrollBar, 2, 1 ); |
|---|
| 245 | pGridLayout->addWidget( pHScrollbarPanel, 2, 1 ); |
|---|
| 246 | |
|---|
| 247 | |
|---|
| 248 | |
|---|
| 249 | this->setLayout( pGridLayout ); |
|---|
| 250 | QPalette defaultPalette; |
|---|
| 251 | defaultPalette.setColor( QPalette::Background, QColor( 58, 62, 72 ) ); |
|---|
| 252 | this->setPalette( defaultPalette ); |
|---|
| 253 | |
|---|
| 254 | |
|---|
| 255 | show(); |
|---|
| 256 | |
|---|
| 257 | updateAll(); |
|---|
| 258 | |
|---|
| 259 | HydrogenApp::get_instance()->addEventListener( this ); |
|---|
| 260 | |
|---|
| 261 | m_pTimer = new QTimer(this); |
|---|
| 262 | connect(m_pTimer, SIGNAL(timeout()), this, SLOT( updatePlayHeadPosition() ) ); |
|---|
| 263 | m_pTimer->start(100); |
|---|
| 264 | } |
|---|
| 265 | |
|---|
| 266 | |
|---|
| 267 | |
|---|
| 268 | SongEditorPanel::~SongEditorPanel() |
|---|
| 269 | { |
|---|
| 270 | m_pTimer->stop(); |
|---|
| 271 | } |
|---|
| 272 | |
|---|
| 273 | |
|---|
| 274 | |
|---|
| 275 | void SongEditorPanel::updatePlayHeadPosition() |
|---|
| 276 | { |
|---|
| 277 | Song *pSong = Hydrogen::get_instance()->getSong(); |
|---|
| 278 | |
|---|
| 279 | if ( Preferences::get_instance()->m_bFollowPlayhead && pSong->get_mode() == Song::SONG_MODE) { |
|---|
| 280 | if ( Hydrogen::get_instance()->getState() != STATE_PLAYING ) { |
|---|
| 281 | return; |
|---|
| 282 | } |
|---|
| 283 | |
|---|
| 284 | QPoint pos = m_pPositionRuler->pos(); |
|---|
| 285 | int x = -pos.x(); |
|---|
| 286 | int w = m_pPositionRulerScrollView->viewport()->width(); |
|---|
| 287 | |
|---|
| 288 | // int x = m_pPositionRulerScrollView->contentsX(); |
|---|
| 289 | // int w = m_pPositionRulerScrollView->visibleWidth(); |
|---|
| 290 | int nPlayHeadPosition = Hydrogen::get_instance()->getPatternPos() * m_pSongEditor->getGridWidth(); |
|---|
| 291 | |
|---|
| 292 | if ( nPlayHeadPosition > ( x + w - 50 ) ) { |
|---|
| 293 | m_pEditorScrollView->horizontalScrollBar()->setValue( m_pEditorScrollView->horizontalScrollBar()->value() + 100 ); |
|---|
| 294 | on_EditorScroll(); // force a re-sync |
|---|
| 295 | } |
|---|
| 296 | else if ( nPlayHeadPosition < x ) { |
|---|
| 297 | m_pEditorScrollView->horizontalScrollBar()->setValue( m_pEditorScrollView->horizontalScrollBar()->value() - 100 ); |
|---|
| 298 | on_EditorScroll(); // force a re-sync |
|---|
| 299 | } |
|---|
| 300 | } |
|---|
| 301 | } |
|---|
| 302 | |
|---|
| 303 | |
|---|
| 304 | |
|---|
| 305 | void SongEditorPanel::on_patternListScroll() |
|---|
| 306 | { |
|---|
| 307 | m_pEditorScrollView->verticalScrollBar()->setValue( m_pPatternListScrollView->verticalScrollBar()->value() ); |
|---|
| 308 | } |
|---|
| 309 | |
|---|
| 310 | |
|---|
| 311 | |
|---|
| 312 | /// |
|---|
| 313 | /// Synchronize the patternlist with the patternsequence |
|---|
| 314 | /// |
|---|
| 315 | void SongEditorPanel::on_EditorScroll() |
|---|
| 316 | { |
|---|
| 317 | resyncExternalScrollBar(); |
|---|
| 318 | m_pPatternListScrollView->verticalScrollBar()->setValue( m_pEditorScrollView->verticalScrollBar()->value() ); |
|---|
| 319 | m_pPositionRulerScrollView->horizontalScrollBar()->setValue( m_pEditorScrollView->horizontalScrollBar()->value() ); |
|---|
| 320 | } |
|---|
| 321 | |
|---|
| 322 | |
|---|
| 323 | |
|---|
| 324 | void SongEditorPanel::syncToExternalScrollBar() |
|---|
| 325 | { |
|---|
| 326 | m_pEditorScrollView->horizontalScrollBar()->setValue( m_pHScrollBar->value() ); |
|---|
| 327 | m_pEditorScrollView->verticalScrollBar()->setValue( m_pVScrollBar->value() ); |
|---|
| 328 | } |
|---|
| 329 | |
|---|
| 330 | |
|---|
| 331 | |
|---|
| 332 | /// |
|---|
| 333 | /// Update and redraw all... |
|---|
| 334 | /// |
|---|
| 335 | void SongEditorPanel::updateAll() |
|---|
| 336 | { |
|---|
| 337 | m_pPatternList->createBackground(); |
|---|
| 338 | m_pPatternList->update(); |
|---|
| 339 | |
|---|
| 340 | m_pSongEditor->cleanUp(); |
|---|
| 341 | |
|---|
| 342 | m_pSongEditor->createBackground(); |
|---|
| 343 | m_pSongEditor->update(); |
|---|
| 344 | |
|---|
| 345 | resyncExternalScrollBar(); |
|---|
| 346 | } |
|---|
| 347 | |
|---|
| 348 | |
|---|
| 349 | void SongEditorPanel::updatePositionRuler() |
|---|
| 350 | { |
|---|
| 351 | m_pPositionRuler->createBackground(); |
|---|
| 352 | } |
|---|
| 353 | |
|---|
| 354 | /// |
|---|
| 355 | /// Create a new pattern |
|---|
| 356 | /// |
|---|
| 357 | void SongEditorPanel::newPatBtnClicked( Button* btn) |
|---|
| 358 | { |
|---|
| 359 | UNUSED( btn ); |
|---|
| 360 | Hydrogen *engine = Hydrogen::get_instance(); |
|---|
| 361 | Song *song = engine->getSong(); |
|---|
| 362 | PatternList *patternList = song->get_pattern_list(); |
|---|
| 363 | int emptyPatternNo = patternList->size() + 1; |
|---|
| 364 | |
|---|
| 365 | Pattern *emptyPattern = new Pattern(); |
|---|
| 366 | emptyPattern->set_name( trUtf8("Pattern %1").arg(emptyPatternNo) ); |
|---|
| 367 | emptyPattern->set_category( trUtf8("not_categorized") ); |
|---|
| 368 | |
|---|
| 369 | PatternPropertiesDialog *dialog = new PatternPropertiesDialog( this, emptyPattern, 0, true ); |
|---|
| 370 | if ( dialog->exec() == QDialog::Accepted ) { |
|---|
| 371 | |
|---|
| 372 | SE_addEmptyPatternAction*action = new SE_addEmptyPatternAction( emptyPattern->get_name() , emptyPattern->get_category(), emptyPatternNo); |
|---|
| 373 | HydrogenApp::get_instance()->m_undoStack->push( action ); |
|---|
| 374 | patternList->del( emptyPattern ); |
|---|
| 375 | delete emptyPattern; |
|---|
| 376 | emptyPattern = NULL; |
|---|
| 377 | } |
|---|
| 378 | else { |
|---|
| 379 | patternList->del( emptyPattern ); |
|---|
| 380 | delete emptyPattern; |
|---|
| 381 | emptyPattern = NULL; |
|---|
| 382 | } |
|---|
| 383 | delete dialog; |
|---|
| 384 | dialog = NULL; |
|---|
| 385 | } |
|---|
| 386 | |
|---|
| 387 | |
|---|
| 388 | void SongEditorPanel::addEmptyPattern( QString newPatternName , QString newPatternCategory, int patternPosition ) |
|---|
| 389 | { |
|---|
| 390 | Hydrogen *engine = Hydrogen::get_instance(); |
|---|
| 391 | Song *song = engine->getSong(); |
|---|
| 392 | PatternList *patternList = song->get_pattern_list(); |
|---|
| 393 | |
|---|
| 394 | Pattern *emptyPattern = new Pattern(); |
|---|
| 395 | emptyPattern->set_name( newPatternName ); |
|---|
| 396 | emptyPattern->set_category( newPatternCategory ); |
|---|
| 397 | patternList->add( emptyPattern ); |
|---|
| 398 | if( patternPosition != patternList->size() ){ |
|---|
| 399 | for (int nPatr = patternList->size() +1 ; nPatr >= patternPosition; nPatr--) { |
|---|
| 400 | H2Core::Pattern *pPattern = patternList->get(nPatr - 1); |
|---|
| 401 | patternList->replace( nPatr, pPattern ); |
|---|
| 402 | } |
|---|
| 403 | patternList->replace( patternPosition, emptyPattern ); |
|---|
| 404 | } |
|---|
| 405 | song->__is_modified = true; |
|---|
| 406 | updateAll(); |
|---|
| 407 | } |
|---|
| 408 | |
|---|
| 409 | |
|---|
| 410 | void SongEditorPanel::revertaddEmptyPattern( int patternPosition ) |
|---|
| 411 | { |
|---|
| 412 | |
|---|
| 413 | Hydrogen *engine = Hydrogen::get_instance(); |
|---|
| 414 | |
|---|
| 415 | Song *song = engine->getSong(); |
|---|
| 416 | PatternList *patternList = song->get_pattern_list(); |
|---|
| 417 | H2Core::Pattern *pattern = patternList->get( patternPosition ); |
|---|
| 418 | |
|---|
| 419 | if(patternPosition == engine->getSelectedPatternNumber() )engine->setSelectedPatternNumber( patternPosition -1 ); |
|---|
| 420 | patternList->del(pattern); |
|---|
| 421 | delete pattern; |
|---|
| 422 | pattern = NULL; |
|---|
| 423 | song->__is_modified = true; |
|---|
| 424 | updateAll(); |
|---|
| 425 | } |
|---|
| 426 | |
|---|
| 427 | /// |
|---|
| 428 | /// Move up a pattern in the patternList |
|---|
| 429 | /// |
|---|
| 430 | void SongEditorPanel::upBtnClicked( Button* btn ) |
|---|
| 431 | { |
|---|
| 432 | UNUSED( btn ); |
|---|
| 433 | Hydrogen *pEngine = Hydrogen::get_instance(); |
|---|
| 434 | |
|---|
| 435 | if( pEngine->getSelectedPatternNumber() < 0 || !pEngine->getSelectedPatternNumber() ) return; |
|---|
| 436 | int nSelectedPatternPos = pEngine->getSelectedPatternNumber(); |
|---|
| 437 | |
|---|
| 438 | SE_movePatternListItemAction *action = new SE_movePatternListItemAction( nSelectedPatternPos, nSelectedPatternPos -1 ) ; |
|---|
| 439 | HydrogenApp::get_instance()->m_undoStack->push( action ); |
|---|
| 440 | } |
|---|
| 441 | |
|---|
| 442 | |
|---|
| 443 | |
|---|
| 444 | /// |
|---|
| 445 | /// Move down a pattern in the patternList |
|---|
| 446 | /// |
|---|
| 447 | void SongEditorPanel::downBtnClicked( Button* btn ) |
|---|
| 448 | { |
|---|
| 449 | UNUSED( btn ); |
|---|
| 450 | Hydrogen *pEngine = Hydrogen::get_instance(); |
|---|
| 451 | Song *pSong = pEngine->getSong(); |
|---|
| 452 | PatternList *pPatternList = pSong->get_pattern_list(); |
|---|
| 453 | |
|---|
| 454 | if( pEngine->getSelectedPatternNumber() +1 >= pSong->get_pattern_list()->size() ) return; |
|---|
| 455 | int nSelectedPatternPos = pEngine->getSelectedPatternNumber(); |
|---|
| 456 | |
|---|
| 457 | SE_movePatternListItemAction *action = new SE_movePatternListItemAction( nSelectedPatternPos, nSelectedPatternPos +1 ) ; |
|---|
| 458 | HydrogenApp::get_instance()->m_undoStack->push( action ); |
|---|
| 459 | } |
|---|
| 460 | |
|---|
| 461 | |
|---|
| 462 | |
|---|
| 463 | |
|---|
| 464 | void SongEditorPanel::clearSequence( Button* btn) |
|---|
| 465 | { |
|---|
| 466 | UNUSED( btn ); |
|---|
| 467 | |
|---|
| 468 | int res = QMessageBox::information( this, "Hydrogen", tr( "Warning, this will erase your pattern sequence.\nAre you sure?"), tr("&Ok"), tr("&Cancel"), 0, 1 ); |
|---|
| 469 | if ( res == 1 ) { |
|---|
| 470 | return; |
|---|
| 471 | } |
|---|
| 472 | |
|---|
| 473 | //create a unique filename |
|---|
| 474 | time_t thetime; |
|---|
| 475 | thetime = time(NULL); |
|---|
| 476 | QString filename = Preferences::get_instance()->getTmpDirectory() +QString("%1").arg(thetime)+ QString( "SEQ.xml" ); |
|---|
| 477 | SE_deletePatternSequenceAction *action = new SE_deletePatternSequenceAction( filename ); |
|---|
| 478 | HydrogenApp::get_instance()->m_undoStack->push( action ); |
|---|
| 479 | } |
|---|
| 480 | |
|---|
| 481 | |
|---|
| 482 | void SongEditorPanel::restoreGroupVector( QString filename ) |
|---|
| 483 | { |
|---|
| 484 | //clear the old sequese |
|---|
| 485 | vector<PatternList*> *pPatternGroupsVect = Hydrogen::get_instance()->getSong()->get_pattern_group_vector(); |
|---|
| 486 | for (uint i = 0; i < pPatternGroupsVect->size(); i++) { |
|---|
| 487 | PatternList *pPatternList = (*pPatternGroupsVect)[i]; |
|---|
| 488 | pPatternList->clear(); |
|---|
| 489 | delete pPatternList; |
|---|
| 490 | } |
|---|
| 491 | pPatternGroupsVect->clear(); |
|---|
| 492 | |
|---|
| 493 | Hydrogen::get_instance()->getSong()->readTempPatternList( filename ); |
|---|
| 494 | m_pSongEditor->updateEditorandSetTrue(); |
|---|
| 495 | updateAll(); |
|---|
| 496 | } |
|---|
| 497 | |
|---|
| 498 | |
|---|
| 499 | void SongEditorPanel::resyncExternalScrollBar() |
|---|
| 500 | { |
|---|
| 501 | m_pHScrollBar->setMinimum( m_pEditorScrollView->horizontalScrollBar()->minimum() ); |
|---|
| 502 | m_pHScrollBar->setMaximum( m_pEditorScrollView->horizontalScrollBar()->maximum() ); |
|---|
| 503 | m_pHScrollBar->setSingleStep( m_pEditorScrollView->horizontalScrollBar()->singleStep() ); |
|---|
| 504 | m_pHScrollBar->setPageStep( m_pEditorScrollView->horizontalScrollBar()->pageStep() ); |
|---|
| 505 | m_pHScrollBar->setValue( m_pEditorScrollView->horizontalScrollBar()->value() ); |
|---|
| 506 | |
|---|
| 507 | m_pVScrollBar->setMinimum( m_pEditorScrollView->verticalScrollBar()->minimum() ); |
|---|
| 508 | m_pVScrollBar->setMaximum( m_pEditorScrollView->verticalScrollBar()->maximum() ); |
|---|
| 509 | m_pVScrollBar->setSingleStep( m_pEditorScrollView->verticalScrollBar()->singleStep() ); |
|---|
| 510 | m_pVScrollBar->setPageStep( m_pEditorScrollView->verticalScrollBar()->pageStep() ); |
|---|
| 511 | m_pVScrollBar->setValue( m_pEditorScrollView->verticalScrollBar()->value() ); |
|---|
| 512 | } |
|---|
| 513 | |
|---|
| 514 | |
|---|
| 515 | void SongEditorPanel::resizeEvent( QResizeEvent *ev ) |
|---|
| 516 | { |
|---|
| 517 | UNUSED( ev ); |
|---|
| 518 | resyncExternalScrollBar(); |
|---|
| 519 | } |
|---|
| 520 | |
|---|
| 521 | void SongEditorPanel::pointerActionBtnPressed( Button* pBtn ) |
|---|
| 522 | { |
|---|
| 523 | pBtn->setPressed( true ); |
|---|
| 524 | m_pDrawActionBtn->setPressed( false ); |
|---|
| 525 | m_actionMode = SELECT_ACTION; |
|---|
| 526 | } |
|---|
| 527 | |
|---|
| 528 | |
|---|
| 529 | |
|---|
| 530 | void SongEditorPanel::drawActionBtnPressed( Button* pBtn ) |
|---|
| 531 | { |
|---|
| 532 | pBtn->setPressed( true ); |
|---|
| 533 | m_pPointerActionBtn->setPressed( false ); |
|---|
| 534 | m_actionMode = DRAW_ACTION; |
|---|
| 535 | |
|---|
| 536 | } |
|---|
| 537 | |
|---|
| 538 | |
|---|
| 539 | |
|---|
| 540 | void SongEditorPanel::timeLineBtnPressed( Button* pBtn ) |
|---|
| 541 | { |
|---|
| 542 | if( m_pTimeLineToggleBtn->isPressed() ){ |
|---|
| 543 | Preferences::get_instance()->__usetimeline = true; |
|---|
| 544 | Hydrogen::get_instance()->setTimelineBpm(); |
|---|
| 545 | } |
|---|
| 546 | else |
|---|
| 547 | { |
|---|
| 548 | Preferences::get_instance()->__usetimeline = false; |
|---|
| 549 | } |
|---|
| 550 | m_pPositionRuler->createBackground(); |
|---|
| 551 | } |
|---|
| 552 | |
|---|
| 553 | |
|---|
| 554 | void SongEditorPanel::modeActionBtnPressed( ) |
|---|
| 555 | { |
|---|
| 556 | if( m_pModeActionBtn->isPressed() ){ |
|---|
| 557 | m_pModeActionBtn->setToolTip( trUtf8( "stacked pattern mode") ); |
|---|
| 558 | } else { |
|---|
| 559 | m_pModeActionBtn->setToolTip( trUtf8( "single pattern mode") ); |
|---|
| 560 | } |
|---|
| 561 | Hydrogen::get_instance()->togglePlaysSelected(); |
|---|
| 562 | updateAll(); |
|---|
| 563 | } |
|---|
| 564 | |
|---|
| 565 | void SongEditorPanel::setModeActionBtn( bool mode ) |
|---|
| 566 | { |
|---|
| 567 | if( mode ){ |
|---|
| 568 | m_pModeActionBtn->setPressed( true ); |
|---|
| 569 | m_pModeActionBtn->setToolTip( trUtf8( "stacked pattern mode") ); |
|---|
| 570 | } else { |
|---|
| 571 | m_pModeActionBtn->setPressed( false ); |
|---|
| 572 | m_pModeActionBtn->setToolTip( trUtf8( "single pattern mode") ); |
|---|
| 573 | } |
|---|
| 574 | } |
|---|
| 575 | |
|---|
| 576 | void SongEditorPanel::zoomInBtnPressed( Button* pBtn ) |
|---|
| 577 | { |
|---|
| 578 | UNUSED( pBtn ); |
|---|
| 579 | unsigned width = m_pSongEditor->getGridWidth (); |
|---|
| 580 | --width; |
|---|
| 581 | m_pSongEditor->setGridWidth (width); |
|---|
| 582 | m_pPositionRuler->setGridWidth (width); |
|---|
| 583 | |
|---|
| 584 | updateAll(); |
|---|
| 585 | } |
|---|
| 586 | |
|---|
| 587 | |
|---|
| 588 | void SongEditorPanel::zoomOutBtnPressed( Button* pBtn ) |
|---|
| 589 | { |
|---|
| 590 | UNUSED( pBtn ); |
|---|
| 591 | unsigned width = m_pSongEditor->getGridWidth (); |
|---|
| 592 | ++width; |
|---|
| 593 | m_pSongEditor->setGridWidth (width); |
|---|
| 594 | m_pPositionRuler->setGridWidth (width); |
|---|
| 595 | updateAll(); |
|---|
| 596 | } |
|---|
| 597 | |
|---|
| 598 | |
|---|
| 599 | void SongEditorPanel::selectedPatternChangedEvent() |
|---|
| 600 | { |
|---|
| 601 | resyncExternalScrollBar(); |
|---|
| 602 | } |
|---|