📄 audiomanagerdialog.cpp
字号:
// set pixmap // childItem->setPixmap(2, *audioPixmap); // set segment // childItem->setSegment(*iit); if (findSelection && lastSegment == (*iit)) { m_fileList->setSelected(childItem, true); findSelection = false; foundSelection = true; } // Add children } } } updateActionState(foundSelection); if (wrongSampleRates) { m_wrongSampleRates->show(); } else { m_wrongSampleRates->hide(); } m_fileList->blockSignals(false);}AudioFile*AudioManagerDialog::getCurrentSelection(){ // try and get the selected item AudioListItem *item = dynamic_cast<AudioListItem*>(m_fileList->selectedItem()); if (item == 0) return 0; std::vector<AudioFile*>::const_iterator it; for (it = m_doc->getAudioFileManager().begin(); it != m_doc->getAudioFileManager().end(); ++it) { // If we match then return the valid AudioFile // if (item->getId() == (*it)->getId()) return (*it); } return 0;}voidAudioManagerDialog::slotExportAudio(){ WAVAudioFile *sourceFile = dynamic_cast<WAVAudioFile*>(getCurrentSelection()); AudioListItem *item = dynamic_cast<AudioListItem*>(m_fileList->selectedItem()); Segment *segment = item->getSegment(); QString saveFile = KFileDialog::getSaveFileName(":WAVS", i18n("*.wav|WAV files (*.wav)"), this, i18n("Choose a name to save this file as")); if (sourceFile == 0 || item == 0 || saveFile.isEmpty()) return ; // Check for a dot extension and append ".wav" if not found // if (saveFile.contains(".") == 0) saveFile += ".wav"; ProgressDialog progressDlg(i18n("Exporting audio file..."), 100, this); progressDlg.progressBar()->setProgress(0); RealTime clipStartTime = RealTime::zeroTime; RealTime clipDuration = sourceFile->getLength(); if (segment) { clipStartTime = segment->getAudioStartTime(); clipDuration = segment->getAudioEndTime() - clipStartTime; } WAVAudioFile *destFile = new WAVAudioFile(qstrtostr(saveFile), sourceFile->getChannels(), sourceFile->getSampleRate(), sourceFile->getBytesPerSecond(), sourceFile->getBytesPerFrame(), sourceFile->getBitsPerSample()); if (sourceFile->open() == false) { delete destFile; return ; } destFile->write(); sourceFile->scanTo(clipStartTime); destFile->appendSamples(sourceFile->getSampleFrameSlice(clipDuration)); destFile->close(); sourceFile->close(); delete destFile; progressDlg.progressBar()->setProgress(100);}voidAudioManagerDialog::slotRemove(){ AudioFile *audioFile = getCurrentSelection(); AudioListItem *item = dynamic_cast<AudioListItem*>(m_fileList->selectedItem()); if (audioFile == 0 || item == 0) return ; // If we're on a Segment then delete it at the Composition // and refresh the list. // if (item->getSegment()) { // Get the next item to highlight // QListViewItem *newItem = item->itemBelow(); // Or try above // if (newItem == 0) newItem = item->itemAbove(); // Or the parent // if (newItem == 0) newItem = item->parent(); // Get the id and segment of the next item so that we can // match against it // AudioFileId id = 0; Segment *segment = 0; AudioListItem *aItem = dynamic_cast<AudioListItem*>(newItem); if (aItem) { segment = aItem->getSegment(); id = aItem->getId(); } // Jump to new selection // if (newItem) setSelected(id, segment, true); // propagate // Do it - will force update // SegmentSelection selection; selection.insert(item->getSegment()); emit deleteSegments(selection); return ; } // remove segments along with audio file // AudioFileId id = audioFile->getId(); SegmentSelection selection; Composition &comp = m_doc->getComposition(); bool haveSegments = false; for (Composition::iterator it = comp.begin(); it != comp.end(); ++it) { if ((*it)->getType() == Segment::Audio && (*it)->getAudioFileId() == id) { haveSegments = true; break; } } if (haveSegments) { QString question = i18n("This will unload audio file \"%1\" and remove all associated segments. Are you sure?") .arg(QString(audioFile->getFilename().c_str())); // Ask the question int reply = KMessageBox::warningContinueCancel(this, question); if (reply != KMessageBox::Continue) return ; } for (Composition::iterator it = comp.begin(); it != comp.end(); ++it) { if ((*it)->getType() == Segment::Audio && (*it)->getAudioFileId() == id) selection.insert(*it); } emit deleteSegments(selection); m_doc->notifyAudioFileRemoval(id); m_doc->getAudioFileManager().removeFile(id); // tell the sequencer emit deleteAudioFile(id); // repopulate slotPopulateFileList();}voidAudioManagerDialog::slotPlayPreview(){ AudioFile *audioFile = getCurrentSelection(); AudioListItem *item = dynamic_cast<AudioListItem*>(m_fileList->selectedItem()); if (item == 0 || audioFile == 0) return ; // store the audio file we're playing m_playingAudioFile = audioFile->getId(); // tell the sequencer emit playAudioFile(audioFile->getId(), item->getStartTime(), item->getDuration()); // now open up the playing dialog // m_audioPlayingDialog = new AudioPlayingDialog(this, QString(audioFile->getFilename().c_str())); // Setup timer to pop down dialog after file has completed // int msecs = item->getDuration().sec * 1000 + item->getDuration().nsec / 1000000; m_playTimer->start(msecs, true); // single shot // just execute // if (m_audioPlayingDialog->exec() == QDialog::Rejected) emit cancelPlayingAudioFile(m_playingAudioFile); delete m_audioPlayingDialog; m_audioPlayingDialog = 0; m_playTimer->stop();}voidAudioManagerDialog::slotCancelPlayingAudio(){ //std::cout << "AudioManagerDialog::slotCancelPlayingAudio" << std::endl; if (m_audioPlayingDialog) { m_playTimer->stop(); delete m_audioPlayingDialog; m_audioPlayingDialog = 0; }}voidAudioManagerDialog::slotAdd(){ QString extensionList = i18n("*.wav|WAV files (*.wav)\n*.*|All files"); if (RosegardenGUIApp::self()->haveAudioImporter()) { //!!! This list really needs to come from the importer helper program // (which has an option to supply it -- we just haven't recorded it) extensionList = i18n("*.wav *.flac *.ogg *.mp3|Audio files (*.wav *.flac *.ogg *.mp3)\n*.wav|WAV files (*.wav)\n*.flac|FLAC files (*.flac)\n*.ogg|Ogg files (*.ogg)\n*.mp3|MP3 files (*.mp3)\n*.*|All files"); } KURL::List kurlList = KFileDialog::getOpenURLs(":WAVS", extensionList, // i18n("*.wav|WAV files (*.wav)\n*.mp3|MP3 files (*.mp3)"), this, i18n("Select one or more audio files")); KURL::List::iterator it; for (it = kurlList.begin(); it != kurlList.end(); ++it) addFile(*it);}voidAudioManagerDialog::updateActionState(bool haveSelection){ if (m_doc->getAudioFileManager().begin() == m_doc->getAudioFileManager().end()) { stateChanged("have_audio_files", KXMLGUIClient::StateReverse); } else { stateChanged("have_audio_files", KXMLGUIClient::StateNoReverse); } if (haveSelection) { stateChanged("have_audio_selected", KXMLGUIClient::StateNoReverse); if (m_audiblePreview) { stateChanged("have_audible_preview", KXMLGUIClient::StateNoReverse); } else { stateChanged("have_audible_preview", KXMLGUIClient::StateReverse); } if (isSelectedTrackAudio()) { stateChanged("have_audio_insertable", KXMLGUIClient::StateNoReverse); } else { stateChanged("have_audio_insertable", KXMLGUIClient::StateReverse); } } else { stateChanged("have_audio_selected", KXMLGUIClient::StateReverse); stateChanged("have_audio_insertable", KXMLGUIClient::StateReverse); stateChanged("have_audible_preview", KXMLGUIClient::StateReverse); }}voidAudioManagerDialog::slotInsert(){ AudioFile *audioFile = getCurrentSelection(); if (audioFile == 0) return ; RG_DEBUG << "AudioManagerDialog::slotInsert\n"; emit insertAudioSegment(audioFile->getId(), RealTime::zeroTime, audioFile->getLength());}voidAudioManagerDialog::slotRemoveAll(){ QString question = i18n("This will unload all audio files and remove their associated segments.\nThis action cannot be undone, and associations with these files will be lost.\nFiles will not be removed from your disk.\nAre you sure?"); int reply = KMessageBox::warningContinueCancel(this, question); if (reply != KMessageBox::Continue) return ; SegmentSelection selection; Composition &comp = m_doc->getComposition(); for (Composition::iterator it = comp.begin(); it != comp.end(); ++it) { if ((*it)->getType() == Segment::Audio) selection.insert(*it); } // delete segments emit deleteSegments(selection); for (std::vector<AudioFile*>::const_iterator aIt = m_doc->getAudioFileManager().begin(); aIt != m_doc->getAudioFileManager().end(); ++aIt) { m_doc->notifyAudioFileRemoval((*aIt)->getId()); } m_doc->getAudioFileManager().clear(); // and now the audio files emit deleteAllAudioFiles(); // clear the file list m_fileList->clear(); slotPopulateFileList();}voidAudioManagerDialog::slotRemoveAllUnused(){ QString question = i18n("This will unload all audio files that are not associated with any segments in this composition.\nThis action cannot be undone, and associations with these files will be lost.\nFiles will not be removed from your disk.\nAre you sure?"); int reply = KMessageBox::warningContinueCancel(this, question); if (reply != KMessageBox::Continue) return ; 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<AudioFileId> toDelete; 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((*aIt)->getId()); } // Delete the audio files from the AFM // for (std::vector<AudioFileId>::iterator dIt = toDelete.begin(); dIt != toDelete.end(); ++dIt) { m_doc->notifyAudioFileRemoval(*dIt); m_doc->getAudioFileManager().removeFile(*dIt); emit deleteAudioFile(*dIt); } // clear the file list m_fileList->clear(); slotPopulateFileList();}voidAudioManagerDialog::slotDeleteUnused()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -