void SongEditorPatternList::patternPopup_copy() { Engine *pEngine = g_engine; T<Song>::shared_ptr pSong = pEngine->getSong(); PatternList *pPatternList = pSong->get_pattern_list(); int nSelectedPattern = pEngine->getSelectedPatternNumber(); T<Tritium::Pattern>::shared_ptr pPattern = pPatternList->get( nSelectedPattern ); T<Tritium::Pattern>::shared_ptr pNewPattern = pPattern->copy(); pPatternList->add( pNewPattern ); // rename the copied pattern PatternPropertiesDialog *dialog = new PatternPropertiesDialog( this, pNewPattern, true ); if ( dialog->exec() == QDialog::Accepted ) { pSong->set_modified( true ); pEngine->setSelectedPatternNumber(pPatternList->get_size() - 1); // select the last pattern (the copied one) if (pSong->get_mode() == Song::PATTERN_MODE) { pEngine->sequencer_setNextPattern( pPatternList->get_size() - 1, false, false ); // select the last pattern (the new copied pattern) } } else { pPatternList->del( pNewPattern ); pNewPattern.reset(); } delete dialog; 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(); }
void MainForm::action_file_openPattern() { Hydrogen *engine = Hydrogen::get_instance(); Song *song = engine->getSong(); PatternList *pPatternList = song->get_pattern_list(); Instrument *instr = song->get_instrument_list()->get ( 0 ); assert ( instr ); QDir dirPattern( Preferences::get_instance()->getDataDirectory() + "/patterns" ); QFileDialog fd(this); 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(); } QString patternname = filename; LocalFileMng mng; LocalFileMng fileMng; Pattern* err = fileMng.loadPattern ( patternname ); if ( err == 0 ) { _ERRORLOG( "Error loading the pattern" ); _ERRORLOG( patternname ); } else { H2Core::Pattern *pNewPattern = err; pPatternList->add ( pNewPattern ); song->__is_modified = true; } HydrogenApp::get_instance()->getSongEditorPanel()->updateAll(); }
void SoundLibraryPanel::on_patternLoadAction() { LocalFileMng mng; QString patternName = __sound_library_tree->currentItem()->text( 0 ) + ".h2pattern"; QString drumkitname = __sound_library_tree->currentItem()->toolTip ( 0 ); Hydrogen *engine = Hydrogen::get_instance(); Song *song = engine->getSong(); PatternList *pPatternList = song->get_pattern_list(); QString sDirectory; std::vector<QString> patternDirList = mng.getPatternDirList(); for (uint i = 0; i < patternDirList.size(); ++i) { QString absPath = patternDirList[i]; mng.getPatternList( absPath ); } std::vector<QString> allPatternDirList = mng.getallPatternList(); for (uint i = 0; i < allPatternDirList.size(); ++i) { QString testName = allPatternDirList[i]; if( testName.contains( patternName ) && testName.contains( drumkitname )){ sDirectory = allPatternDirList[i]; } } Pattern* err = mng.loadPattern (sDirectory ); if ( err == 0 ) { ERRORLOG( "Error loading the pattern" ); } else { H2Core::Pattern *pNewPattern = err; pPatternList->add ( pNewPattern ); song->__is_modified = true; } HydrogenApp::get_instance()->getSongEditorPanel()->updateAll(); }
void SongEditorPatternList::patternPopup_delete() { Engine *pEngine = g_engine; // int state = engine->get_transport()->get_state(); // // per ora non lascio possibile la cancellazione del pattern durante l'esecuzione // // da togliere quando correggo il bug // if (state == PLAYING) { // QMessageBox::information( this, "Composite", trUtf8("Can't delete the pattern while the audio engine is playing")); // return; // } if ( pEngine->getSong()->get_mode() == Song::PATTERN_MODE ) { pEngine->sequencer_setNextPattern( -1, false, false ); // reimposto il prossimo pattern a NULL, altrimenti viene scelto quello che sto distruggendo ora... } // pEngine->sequencer_stop(); // "lock engine" I am not sure, but think this is unnecessarily. -wolke- // g_engine->lock( RIGHT_HERE ); T<Song>::shared_ptr song = pEngine->getSong(); PatternList *pSongPatternList = song->get_pattern_list(); T<Pattern>::shared_ptr pattern = pSongPatternList->get( pEngine->getSelectedPatternNumber() ); DEBUGLOG( QString("[patternPopup_delete] Delete pattern: %1 @%2").arg(pattern->get_name()).arg( (long)pattern.get() ) ); pSongPatternList->del(pattern); T<Song::pattern_group_t>::shared_ptr patternGroupVect = song->get_pattern_group_vector(); uint i = 0; while (i < patternGroupVect->size() ) { T<PatternList>::shared_ptr list = (*patternGroupVect)[i]; uint j = 0; while ( j < list->get_size() ) { T<Tritium::Pattern>::shared_ptr pOldPattern = list->get( j ); if (pOldPattern == pattern ) { list->del( j ); continue; } j++; } // for (uint j = 0; j < list->get_size(); j++) { // Pattern *pOldPattern = list->get( j ); // if (pOldPattern == pattern ) { // list->del( j ); // } // } /* if (list->get_size() == 0 ) { patternGroupVect->erase( patternGroupVect->begin() + i ); delete list; list = NULL; } else { */ i++; // } } T<PatternList>::shared_ptr list = pEngine->getCurrentPatternList(); list->del( pattern ); // se esiste, seleziono il primo pattern if ( pSongPatternList->get_size() > 0 ) { T<Tritium::Pattern>::shared_ptr pFirstPattern = pSongPatternList->get( 0 ); list->add( pFirstPattern ); // Cambio due volte...cosi' il pattern editor viene costretto ad aggiornarsi pEngine->setSelectedPatternNumber( -1 ); pEngine->setSelectedPatternNumber( 0 ); } else { // there's no patterns.. T<Pattern>::shared_ptr emptyPattern = Pattern::get_empty_pattern(); emptyPattern->set_name( trUtf8("Pattern 1") ); emptyPattern->set_category( trUtf8("not_categorized") ); pSongPatternList->add( emptyPattern ); pEngine->setSelectedPatternNumber( -1 ); pEngine->setSelectedPatternNumber( 0 ); } pattern.reset(); song->set_modified( true ); // "unlock" I am not sure, but think this is unnecessarily. -wolke- // g_engine->unlock(); ( CompositeApp::get_instance() )->getSongEditorPanel()->updateAll(); }