📄 audiomanagerdialog.cpp
字号:
{ std::set <AudioFileId> audioFiles; Composition &comp = m_doc->getComposition(); for (Composition::iterator it = comp.begin(); it != comp.end(); ++it) { if ((*it)->getType() == Segment::Audio) audioFiles.insert((*it)->getAudioFileId()); } std::vector<QString> toDelete; std::map<QString, AudioFileId> nameMap; for (std::vector<AudioFile*>::const_iterator aIt = m_doc->getAudioFileManager().begin(); aIt != m_doc->getAudioFileManager().end(); ++aIt) { if (audioFiles.find((*aIt)->getId()) == audioFiles.end()) { toDelete.push_back(strtoqstr((*aIt)->getFilename())); nameMap[strtoqstr((*aIt)->getFilename())] = (*aIt)->getId(); } } UnusedAudioSelectionDialog *dialog = new UnusedAudioSelectionDialog (this, i18n("The following audio files are not used in the current composition.\n\nPlease select the ones you wish to delete permanently from the hard disk.\n"), toDelete); if (dialog->exec() == QDialog::Accepted) { std::vector<QString> names = dialog->getSelectedAudioFileNames(); if (names.size() > 0) { QString question = i18n("About to delete 1 audio file permanently from the hard disk.\nThis action cannot be undone, and there will be no way to recover this file.\nAre you sure?", "About to delete %n audio files permanently from the hard disk.\nThis action cannot be undone, and there will be no way to recover these files.\nAre you sure?", names.size()); int reply = KMessageBox::warningContinueCancel(this, question); if (reply != KMessageBox::Continue) { delete dialog; return ; } for (int i = 0; i < names.size(); ++i) { std::cerr << i << ": " << names[i] << std::endl; QFile file(names[i]); if (!file.remove()) { KMessageBox::error(this, i18n("File %1 could not be deleted.").arg(names[i])); } else { if (nameMap.find(names[i]) != nameMap.end()) { m_doc->getAudioFileManager().removeFile(nameMap[names[i]]); emit deleteAudioFile(nameMap[names[i]]); } else { std::cerr << "WARNING: Audio file name " << names[i] << " not in name map" << std::endl; } QFile peakFile(QString("%1.pk").arg(names[i])); peakFile.remove(); } } } } m_fileList->clear(); slotPopulateFileList(); delete dialog;}voidAudioManagerDialog::slotRename(){ AudioFile *audioFile = getCurrentSelection(); if (audioFile == 0) return ; bool ok = false; QString newText = KLineEditDlg::getText( i18n("Change Audio File label"), i18n("Enter new label"), QString(audioFile->getName().c_str()), &ok, this); if ( ok && !newText.isEmpty() ) audioFile->setName(qstrtostr(newText)); slotPopulateFileList();}voidAudioManagerDialog::slotSelectionChanged(QListViewItem *item){ AudioListItem *aItem = dynamic_cast<AudioListItem*>(item); // If we're on a segment then send a "select" signal // and enable appropriate buttons. // if (aItem && aItem->getSegment()) { SegmentSelection selection; selection.insert(aItem->getSegment()); emit segmentsSelected(selection); } updateActionState(aItem != 0);}voidAudioManagerDialog::setSelected(AudioFileId id, const Segment *segment, bool propagate){ QListViewItem *it = m_fileList->firstChild(); QListViewItem *chIt = 0; AudioListItem *aItem; while (it) { // If we're looking for a top level audio file if (segment == 0) { aItem = dynamic_cast<AudioListItem*>(it); if (aItem->getId() == id) { selectFileListItemNoSignal(it); return ; } } else // look for a child { if (it->childCount() > 0) chIt = it->firstChild(); while (chIt) { aItem = dynamic_cast<AudioListItem*>(chIt); if (aItem) { if (aItem->getId() == id && aItem->getSegment() == segment) { selectFileListItemNoSignal(chIt); // Only propagate to segmentcanvas if asked to if (propagate) { SegmentSelection selection; selection.insert(aItem->getSegment()); emit segmentsSelected(selection); } return ; } } chIt = chIt->nextSibling(); } } it = it->nextSibling(); }}voidAudioManagerDialog::selectFileListItemNoSignal(QListViewItem* it){ m_fileList->blockSignals(true); if (it) { m_fileList->ensureItemVisible(it); m_fileList->setSelected(it, true); } else { m_fileList->clearSelection(); } m_fileList->blockSignals(false);}MultiViewCommandHistory*AudioManagerDialog::getCommandHistory(){ return m_doc->getCommandHistory();}voidAudioManagerDialog::slotCommandExecuted(KCommand*){ slotPopulateFileList();}voidAudioManagerDialog::slotSegmentSelection( const SegmentSelection &segments){ const Segment *segment = 0; for (SegmentSelection::const_iterator it = segments.begin(); it != segments.end(); ++it) { if ((*it)->getType() == Segment::Audio) { // Only get one audio segment if (segment == 0) segment = *it; else segment = 0; } } if (segment) { // We don't propagate this segment setting to the canvas // as we probably got called from there. // setSelected(segment->getAudioFileId(), segment, false); } else { selectFileListItemNoSignal(0); }}voidAudioManagerDialog::slotCancelPlayingAudioFile(){ emit cancelPlayingAudioFile(m_playingAudioFile);}voidAudioManagerDialog::closePlayingDialog(AudioFileId id){ //std::cout << "AudioManagerDialog::closePlayingDialog" << std::endl; if (m_audioPlayingDialog && id == m_playingAudioFile) { m_playTimer->stop(); delete m_audioPlayingDialog; m_audioPlayingDialog = 0; }}boolAudioManagerDialog::addFile(const KURL& kurl){ AudioFileId id = 0; AudioFileManager &aFM = m_doc->getAudioFileManager(); if (!kurl.isLocalFile()) { if (!RosegardenGUIApp::self()->testAudioPath("importing a remote audio file")) return false; } else if (aFM.fileNeedsConversion(qstrtostr(kurl.path()), m_sampleRate)) { if (!RosegardenGUIApp::self()->testAudioPath("importing an audio file that needs to be converted or resampled")) return false; } ProgressDialog progressDlg(i18n("Adding audio file..."), 100, this); CurrentProgressDialog::set(&progressDlg); progressDlg.progressBar()->hide(); progressDlg.show(); // Connect the progress dialog // connect(&aFM, SIGNAL(setProgress(int)), progressDlg.progressBar(), SLOT(setValue(int))); connect(&aFM, SIGNAL(setOperationName(QString)), &progressDlg, SLOT(slotSetOperationName(QString))); connect(&progressDlg, SIGNAL(cancelClicked()), &aFM, SLOT(slotStopImport())); try { id = aFM.importURL(kurl, m_sampleRate); } catch (AudioFileManager::BadAudioPathException e) { CurrentProgressDialog::freeze(); QString errorString = i18n("Failed to add audio file. ") + strtoqstr(e.getMessage()); KMessageBox::sorry(this, errorString); return false; } catch (SoundFile::BadSoundFileException e) { CurrentProgressDialog::freeze(); QString errorString = i18n("Failed to add audio file. ") + strtoqstr(e.getMessage()); KMessageBox::sorry(this, errorString); return false; } disconnect(&progressDlg, SIGNAL(cancelClicked()), &aFM, SLOT(slotStopImport())); connect(&progressDlg, SIGNAL(cancelClicked()), &aFM, SLOT(slotStopPreview())); progressDlg.progressBar()->show(); progressDlg.slotSetOperationName(i18n("Generating audio preview...")); try { aFM.generatePreview(id); } catch (Exception e) { CurrentProgressDialog::freeze(); QString message = strtoqstr(e.getMessage()) + "\n\n" + i18n("Try copying this file to a directory where you have write permission and re-add it"); KMessageBox::information(this, message); } disconnect(&progressDlg, SIGNAL(cancelClicked()), &aFM, SLOT(slotStopPreview())); slotPopulateFileList(); // tell the sequencer emit addAudioFile(id); return true;}voidAudioManagerDialog::slotDropped(QDropEvent *event, QListViewItem*){ QStrList uri; // see if we can decode a URI.. if not, just ignore it if (QUriDrag::decode(event, uri)) { // okay, we have a URI.. process it for (QString url = uri.first(); url; url = uri.next()) { RG_DEBUG << "AudioManagerDialog::dropEvent() : got " << url << endl; addFile(KURL(url)); } }}voidAudioManagerDialog::closeEvent(QCloseEvent *e){ RG_DEBUG << "AudioManagerDialog::closeEvent()\n"; emit closing(); KMainWindow::closeEvent(e);}voidAudioManagerDialog::slotClose(){ emit closing(); close(); //KDockMainWindow::slotClose(); // delete this;}voidAudioManagerDialog::setAudioSubsystemStatus(bool ok){ // We can do something more fancy in the future but for the moment // this will suffice. // m_audiblePreview = ok;}boolAudioManagerDialog::addAudioFile(const QString &filePath){ return addFile(QFileInfo(filePath).absFilePath());}boolAudioManagerDialog::isSelectedTrackAudio(){ Composition &comp = m_doc->getComposition(); Studio &studio = m_doc->getStudio(); TrackId currentTrackId = comp.getSelectedTrack(); Track *track = comp.getTrackById(currentTrackId); if (track) { InstrumentId ii = track->getInstrument(); Instrument *instrument = studio.getInstrumentById(ii); if (instrument && instrument->getType() == Instrument::Audio) return true; } return false;}voidAudioManagerDialog::slotDistributeOnMidiSegment(){ RG_DEBUG << "AudioManagerDialog::slotDistributeOnMidiSegment" << endl; //Composition &comp = m_doc->getComposition(); QList<RosegardenGUIView>& viewList = m_doc->getViewList(); RosegardenGUIView *w = 0; SegmentSelection selection; for (w = viewList.first(); w != 0; w = viewList.next()) { selection = w->getSelection(); } // Store the insert times in a local vector // std::vector<timeT> insertTimes; for (SegmentSelection::iterator i = selection.begin(); i != selection.end(); ++i) { // For MIDI (Internal) Segments only of course // if ((*i)->getType() == Segment::Internal) { for (Segment::iterator it = (*i)->begin(); it != (*i)->end(); ++it) { if ((*it)->isa(Note::EventType)) insertTimes.push_back((*it)->getAbsoluteTime()); } } } for (unsigned int i = 0; i < insertTimes.size(); ++i) { RG_DEBUG << "AudioManagerDialog::slotDistributeOnMidiSegment - " << "insert audio segment at " << insertTimes[i] << endl; }}}#include "AudioManagerDialog.moc"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -