void SongEditorPatternList::movePatternLine( int nSourcePattern , int nTargetPattern ) { Engine *engine = g_engine; T<Song>::shared_ptr pSong = engine->getSong(); PatternList *pPatternList = pSong->get_pattern_list(); // move instruments... T<Tritium::Pattern>::shared_ptr pSourcePattern = pPatternList->get( nSourcePattern );//Instrument *pSourceInstr = pPatternList->get(nSourcePattern); if ( nSourcePattern < nTargetPattern) { for (int nPatr = nSourcePattern; nPatr < nTargetPattern; nPatr++) { T<Tritium::Pattern>::shared_ptr pPattern = pPatternList->get(nPatr + 1); pPatternList->replace( pPattern, nPatr ); } pPatternList->replace( pSourcePattern, nTargetPattern ); } else { for (int nPatr = nSourcePattern; nPatr >= nTargetPattern; nPatr--) { T<Tritium::Pattern>::shared_ptr pPattern = pPatternList->get(nPatr - 1); pPatternList->replace( pPattern, nPatr ); } pPatternList->replace( pSourcePattern, nTargetPattern ); } engine->setSelectedPatternNumber( nTargetPattern ); CompositeApp::get_instance()->getSongEditorPanel()->updateAll(); }
void SongEditorPatternList::dropEvent(QDropEvent *event) { QString sText = event->mimeData()->text(); if( sText.startsWith("Songs:") || sText.startsWith("move instrument:") ){ event->acceptProposedAction(); return; } if (sText.startsWith("move pattern:")) { Engine *engine = g_engine; int nSourcePattern = engine->getSelectedPatternNumber(); int nTargetPattern = event->pos().y() / m_nGridHeight; if ( nSourcePattern == nTargetPattern ) { event->acceptProposedAction(); return; } movePatternLine( nSourcePattern , nTargetPattern ); event->acceptProposedAction(); }else { PatternList *pPatternList = g_engine->getSong()->get_pattern_list(); QStringList tokens = sText.split( "::" ); QString sPatternName = tokens.at( 1 ); int nTargetPattern = event->pos().y() / m_nGridHeight; LocalFileMng mng(g_engine); T<Pattern>::shared_ptr err = mng.loadPattern( sPatternName ); if ( err == 0 ) { ERRORLOG( "Error loading the pattern" ); }else{ T<Pattern>::shared_ptr pNewPattern = err; pPatternList->add( pNewPattern ); for (int nPatr = pPatternList->get_size() +1 ; nPatr >= nTargetPattern; nPatr--) { T<Tritium::Pattern>::shared_ptr pPattern = pPatternList->get(nPatr - 1); pPatternList->replace( pPattern, nPatr ); } pPatternList->replace( pNewPattern, nTargetPattern ); g_engine->getSong()->set_modified( true ); createBackground(); update(); } CompositeApp::get_instance()->getSongEditorPanel()->updateAll(); event->acceptProposedAction(); } }
void SongEditorPatternList::patternPopup_load() { Engine *engine = g_engine; int tmpselectedpatternpos = engine->getSelectedPatternNumber(); T<Song>::shared_ptr song = engine->getSong(); PatternList *pPatternList = song->get_pattern_list(); T<Instrument>::shared_ptr instr = engine->get_sampler()->get_instrument_list()->get( 0 ); assert( instr ); QDir dirPattern( g_engine->get_preferences()->getDataDirectory() + "/patterns" ); std::auto_ptr<QFileDialog> fd( new QFileDialog ); fd->setFileMode(QFileDialog::ExistingFile); fd->setFilter( trUtf8("Hydrogen Pattern (*.h2pattern)") ); fd->setDirectory(dirPattern ); fd->setWindowTitle( trUtf8( "Open Pattern" ) ); QString filename; if (fd->exec() == QDialog::Accepted) { filename = fd->selectedFiles().first(); } else { return; } LocalFileMng mng(g_engine); LocalFileMng fileMng(g_engine); T<Pattern>::shared_ptr err = fileMng.loadPattern( filename ); if ( err == 0 ) { ERRORLOG( "Error loading the pattern" ); }else{ T<Pattern>::shared_ptr pNewPattern = err; pPatternList->add( pNewPattern ); song->set_modified( true ); createBackground(); update(); } int listsize = pPatternList->get_size(); engine->setSelectedPatternNumber( listsize -1 ); T<Pattern>::shared_ptr pTemp = pPatternList->get( engine->getSelectedPatternNumber() ); pPatternList->replace( pPatternList->get( tmpselectedpatternpos ), listsize -1); pPatternList->replace( pTemp, tmpselectedpatternpos ); listsize = pPatternList->get_size(); engine->setSelectedPatternNumber( listsize -1 ); patternPopup_delete(); engine->setSelectedPatternNumber( tmpselectedpatternpos ); CompositeApp::get_instance()->getSongEditorPanel()->updateAll(); }