Pattern* Pattern::load_from( XMLNode* node, InstrumentList* instruments ) { Pattern* pattern = new Pattern( node->read_string( "name", NULL, false, false ), node->read_string( "info", "", false, false ), node->read_string( "category", "unknown", false, false ), node->read_int( "size", -1, false, false ) ); // FIXME support legacy xml element pattern_name, should once be removed if ( pattern->get_name().isEmpty() ) { pattern->set_name( node->read_string( "pattern_name", "unknown", false, false ) ); } XMLNode note_list_node = node->firstChildElement( "noteList" ); if ( !note_list_node.isNull() ) { XMLNode note_node = note_list_node.firstChildElement( "note" ); while ( !note_node.isNull() ) { Note* note = Note::load_from( ¬e_node, instruments ); if( note ) { pattern->insert_note( note ); } note_node = note_node.nextSiblingElement( "note" ); } } return pattern; }
void MainForm::action_file_export_pattern_as() { if ( ( Hydrogen::get_instance()->getState() == STATE_PLAYING ) ) { Hydrogen::get_instance()->sequencer_stop(); } Hydrogen *engine = Hydrogen::get_instance(); int selectedpattern = engine->getSelectedPatternNumber(); Song *song = engine->getSong(); Pattern *pat = song->get_pattern_list()->get ( selectedpattern ); Instrument *instr = song->get_instrument_list()->get ( 0 ); assert ( instr ); QDir dir = Preferences::get_instance()->__lastspatternDirectory; QFileDialog fd(this); fd.setFileMode ( QFileDialog::AnyFile ); fd.setFilter ( trUtf8 ( "Hydrogen Pattern (*.h2pattern)" ) ); fd.setAcceptMode ( QFileDialog::AcceptSave ); fd.setWindowTitle ( trUtf8 ( "Save Pattern as ..." ) ); fd.setDirectory ( dir ); fd.setSidebarUrls( fd.sidebarUrls() << QUrl::fromLocalFile( Filesystem::patterns_dir() ) ); QString defaultPatternname = QString ( pat->get_name() ); fd.selectFile ( defaultPatternname ); LocalFileMng fileMng; QString filename; if ( fd.exec() == QDialog::Accepted ) { filename = fd.selectedFiles().first(); QString tmpfilename = filename; QString toremove = tmpfilename.section( '/', -1 ); QString newdatapath = tmpfilename.replace( toremove, "" ); Preferences::get_instance()->__lastspatternDirectory = newdatapath; } if ( !filename.isEmpty() ) { QString sNewFilename = filename; if(sNewFilename.endsWith( ".h2pattern" ) ){ sNewFilename += ""; } else{ sNewFilename += ".h2pattern"; } QString patternname = sNewFilename; QString realpatternname = filename; QString realname = realpatternname.mid( realpatternname.lastIndexOf( "/" ) + 1 ); if ( realname.endsWith( ".h2pattern" ) ) realname.replace( ".h2pattern", "" ); pat->set_name(realname); HydrogenApp::get_instance()->getSongEditorPanel()->updateAll(); int err = fileMng.savePattern ( song, engine->getCurrentDrumkitname(), selectedpattern, patternname, realname, 2 ); if ( err != 0 ) { QMessageBox::warning( this, "Hydrogen", trUtf8("Could not export pattern.") ); _ERRORLOG ( "Error saving the pattern" ); } } h2app->setStatusBarMessage ( trUtf8 ( "Pattern saved." ), 10000 ); //update SoundlibraryPanel HydrogenApp::get_instance()->getInstrumentRack()->getSoundLibraryPanel()->test_expandedItems(); HydrogenApp::get_instance()->getInstrumentRack()->getSoundLibraryPanel()->updateDrumkitList(); }