diff options
Diffstat (limited to 'muse2')
-rw-r--r-- | muse2/muse/waveedit/waveview.cpp | 491 | ||||
-rw-r--r-- | muse2/muse/waveedit/waveview.h | 16 |
2 files changed, 0 insertions, 507 deletions
diff --git a/muse2/muse/waveedit/waveview.cpp b/muse2/muse/waveedit/waveview.cpp index df579a43..3e3ea057 100644 --- a/muse2/muse/waveedit/waveview.cpp +++ b/muse2/muse/waveedit/waveview.cpp @@ -526,497 +526,6 @@ void WaveView::range(int* s, int *e) *e = MusEGlobal::tempomap.tick2frame(pe); } -//--------------------------------------------------------- -// cmd -//--------------------------------------------------------- -void WaveView::cmd(int n) - { - int modifyoperation = -1; - double paramA = 0.0; - - switch(n) { - case WaveEdit::CMD_SELECT_ALL: - if (!editor->parts()->empty()) { - MusECore::iPart iBeg = editor->parts()->begin(); - MusECore::iPart iEnd = editor->parts()->end(); - iEnd--; - MusECore::WavePart* beg = (MusECore::WavePart*) iBeg->second; - MusECore::WavePart* end = (MusECore::WavePart*) iEnd->second; - selectionStart = beg->frame(); - selectionStop = end->frame() + end->lenFrame(); - redraw(); - } - break; - - case WaveEdit::CMD_EDIT_EXTERNAL: - modifyoperation = EDIT_EXTERNAL; - break; - - case WaveEdit::CMD_SELECT_NONE: - selectionStart = selectionStop = 0; - redraw(); - break; - case WaveEdit::CMD_EDIT_COPY: - modifyoperation = COPY; - break; - case WaveEdit::CMD_EDIT_CUT: - modifyoperation = CUT; - break; - case WaveEdit::CMD_EDIT_PASTE: - modifyoperation = PASTE; - break; - - case WaveEdit::CMD_MUTE: - modifyoperation = MUTE; - break; - - case WaveEdit::CMD_NORMALIZE: - modifyoperation = NORMALIZE; - break; - - case WaveEdit::CMD_FADE_IN: - modifyoperation = FADE_IN; - break; - - case WaveEdit::CMD_FADE_OUT: - modifyoperation = FADE_OUT; - break; - - case WaveEdit::CMD_REVERSE: - modifyoperation = REVERSE; - break; - - case WaveEdit::CMD_GAIN_FREE: { - EditGain* editGain = new EditGain(this, lastGainvalue); - if (editGain->exec() == QDialog::Accepted) { - lastGainvalue = editGain->getGain(); - modifyoperation = GAIN; - paramA = (double)lastGainvalue / 100.0; - } - delete editGain; - } - break; - - case WaveEdit::CMD_GAIN_200: - modifyoperation = GAIN; - paramA = 2.0; - break; - - case WaveEdit::CMD_GAIN_150: - modifyoperation = GAIN; - paramA = 1.5; - break; - - case WaveEdit::CMD_GAIN_75: - modifyoperation = GAIN; - paramA = 0.75; - break; - - case WaveEdit::CMD_GAIN_50: - modifyoperation = GAIN; - paramA = 0.5; - break; - - case WaveEdit::CMD_GAIN_25: - modifyoperation = GAIN; - paramA = 0.25; - break; - - default: - break; - } - - if (modifyoperation != -1) { - if (selectionStart == selectionStop && modifyoperation!=PASTE) { - printf("No selection. Ignoring\n"); //@!TODO: Disable menu options when no selection - QMessageBox::information(this, - QString("MusE"), - QWidget::tr("No selection. Ignoring")); - - return; - } - - //if(!modifyWarnedYet) - //{ - // modifyWarnedYet = true; - // if(QMessageBox::warning(this, QString("Muse"), - // tr("Warning! Muse currently operates directly on the sound file.\n" - // "Undo is supported, but NOT after exit, WITH OR WITHOUT A SAVE!\n" - // "If you are stuck, try deleting the associated .wca file and reloading."), tr("&Ok"), tr("&Cancel"), - // QString::null, 0, 1 ) != 0) - // return; - //} - modifySelection(modifyoperation, selectionStart, selectionStop, paramA); - } - } - - -//--------------------------------------------------------- -// getSelection -//--------------------------------------------------------- -MusECore::WaveSelectionList WaveView::getSelection(unsigned startpos, unsigned stoppos) - { - MusECore::WaveSelectionList selection; - - for (MusECore::iPart ip = editor->parts()->begin(); ip != editor->parts()->end(); ++ip) { - MusECore::WavePart* wp = (MusECore::WavePart*)(ip->second); - unsigned part_offset = wp->frame(); - - MusECore::EventList* el = wp->events(); - //printf("eventlist length=%d\n",el->size()); - - for (MusECore::iEvent e = el->begin(); e != el->end(); ++e) { - MusECore::Event event = e->second; - if (event.empty()) - continue; - MusECore::SndFileR file = event.sndFile(); - if (file.isNull()) - continue; - - unsigned event_offset = event.frame() + part_offset; - unsigned event_startpos = event.spos(); - unsigned event_length = event.lenFrame() + event.spos(); - unsigned event_end = event_offset + event_length; - //printf("startpos=%d stoppos=%d part_offset=%d event_offset=%d event_startpos=%d event_length=%d event_end=%d\n", startpos, stoppos, part_offset, event_offset, event_startpos, event_length, event_end); - - if (!(event_end <= startpos || event_offset > stoppos)) { - int tmp_sx = startpos - event_offset + event_startpos; - int tmp_ex = stoppos - event_offset + event_startpos; - unsigned sx; - unsigned ex; - - tmp_sx < (int)event_startpos ? sx = event_startpos : sx = tmp_sx; - tmp_ex > (int)event_length ? ex = event_length : ex = tmp_ex; - - //printf("Event data affected: %d->%d filename:%s\n", sx, ex, file.name().toLatin1().constData()); - MusECore::WaveEventSelection s; - s.file = file; - s.startframe = sx; - s.endframe = ex+1; - //printf("sx=%d ex=%d\n",sx,ex); - selection.push_back(s); - } - } - } - - return selection; - } - -//--------------------------------------------------------- -// modifySelection -//--------------------------------------------------------- -void WaveView::modifySelection(int operation, unsigned startpos, unsigned stoppos, double paramA) - { - MusEGlobal::song->startUndo(); - - if (operation == PASTE) { - // we need to redefine startpos and stoppos - if (copiedPart =="") - return; - MusECore::SndFile pasteFile(copiedPart); - pasteFile.openRead(); - startpos = pos[0]; - stoppos = startpos+ pasteFile.samples(); // possibly this is wrong if there are tempo changes - pasteFile.close(); - pos[0]=stoppos; - } - - MusECore::WaveSelectionList selection = getSelection(startpos, stoppos); - for (MusECore::iWaveSelection i = selection.begin(); i != selection.end(); i++) { - MusECore::WaveEventSelection w = *i; - MusECore::SndFileR& file = w.file; - unsigned sx = w.startframe; - unsigned ex = w.endframe; - unsigned file_channels = file.channels(); - - QString tmpWavFile = QString::null; - if (!MusEGlobal::getUniqueTmpfileName("tmp_musewav",".wav", tmpWavFile)) { - break; - } - - MusEGlobal::audio->msgIdle(true); // Not good with playback during operations - MusECore::SndFile tmpFile(tmpWavFile); - tmpFile.setFormat(file.format(), file_channels, file.samplerate()); - if (tmpFile.openWrite()) { - MusEGlobal::audio->msgIdle(false); - printf("Could not open temporary file...\n"); - break; - } - - // - // Write out data that will be changed to temp file - // - unsigned tmpdatalen = ex - sx; - off_t tmpdataoffset = sx; - float* tmpdata[file_channels]; - - for (unsigned i=0; i<file_channels; i++) { - tmpdata[i] = new float[tmpdatalen]; - } - file.seek(tmpdataoffset, 0); - file.readWithHeap(file_channels, tmpdata, tmpdatalen); - file.close(); - tmpFile.write(file_channels, tmpdata, tmpdatalen); - tmpFile.close(); - - switch(operation) - { - case MUTE: - muteSelection(file_channels, tmpdata, tmpdatalen); - break; - - case NORMALIZE: - normalizeSelection(file_channels, tmpdata, tmpdatalen); - break; - - case FADE_IN: - fadeInSelection(file_channels, tmpdata, tmpdatalen); - break; - - case FADE_OUT: - fadeOutSelection(file_channels, tmpdata, tmpdatalen); - break; - - case REVERSE: - reverseSelection(file_channels, tmpdata, tmpdatalen); - break; - - case GAIN: - applyGain(file_channels, tmpdata, tmpdatalen, paramA); - break; - case CUT: - copySelection(file_channels, tmpdata, tmpdatalen, true, file.format(), file.samplerate()); - break; - case COPY: - copySelection(file_channels, tmpdata, tmpdatalen, false, file.format(), file.samplerate()); - break; - case PASTE: - { - MusECore::SndFile pasteFile(copiedPart); - pasteFile.openRead(); - pasteFile.seek(tmpdataoffset, 0); - pasteFile.readWithHeap(file_channels, tmpdata, tmpdatalen); - } - break; - - case EDIT_EXTERNAL: - editExternal(file.format(), file.samplerate(), file_channels, tmpdata, tmpdatalen); - break; - - default: - printf("Error: Default state reached in modifySelection\n"); - break; - - } - - file.openWrite(); - file.seek(tmpdataoffset, 0); - file.write(file_channels, tmpdata, tmpdatalen); - file.update(); - file.close(); - file.openRead(); - - for (unsigned i=0; i<file_channels; i++) { - delete[] tmpdata[i]; - } - - // Undo handling - MusEGlobal::song->cmdChangeWave(file.dirPath() + "/" + file.name(), tmpWavFile, sx, ex); - MusEGlobal::audio->msgIdle(false); // Not good with playback during operations - } - MusEGlobal::song->endUndo(SC_CLIP_MODIFIED); - redraw(); - } - -//--------------------------------------------------------- -// copySelection -//--------------------------------------------------------- -void WaveView::copySelection(unsigned file_channels, float** tmpdata, unsigned length, bool blankData, unsigned format, unsigned sampleRate) -{ - if (copiedPart!="") { - QFile::remove(copiedPart); - } - if (!MusEGlobal::getUniqueTmpfileName("tmp_musewav",".wav", copiedPart)) { - return; - } - - MusECore::SndFile tmpFile(copiedPart); - tmpFile.setFormat(format, file_channels, sampleRate); - tmpFile.openWrite(); - tmpFile.write(file_channels, tmpdata, length); - tmpFile.close(); - - if (blankData) { - // Set everything to 0! - for (unsigned i=0; i<file_channels; i++) { - for (unsigned j=0; j<length; j++) { - tmpdata[i][j] = 0; - } - } - } -} - -//--------------------------------------------------------- -// muteSelection -//--------------------------------------------------------- -void WaveView::muteSelection(unsigned channels, float** data, unsigned length) - { - // Set everything to 0! - for (unsigned i=0; i<channels; i++) { - for (unsigned j=0; j<length; j++) { - data[i][j] = 0; - } - } - } - -//--------------------------------------------------------- -// normalizeSelection -//--------------------------------------------------------- -void WaveView::normalizeSelection(unsigned channels, float** data, unsigned length) - { - float loudest = 0.0; - for (unsigned i=0; i<channels; i++) { - for (unsigned j=0; j<length; j++) { - if (data[i][j] > loudest) - loudest = data[i][j]; - } - } - - double scale = 0.99 / (double)loudest; - - for (unsigned i=0; i<channels; i++) { - for (unsigned j=0; j<length; j++) { - data[i][j] = (float) ((double)data[i][j] * scale); - } - } - } - -//--------------------------------------------------------- -// fadeInSelection -//--------------------------------------------------------- -void WaveView::fadeInSelection(unsigned channels, float** data, unsigned length) - { - for (unsigned i=0; i<channels; i++) { - for (unsigned j=0; j<length; j++) { - double scale = (double) j / (double)length ; - data[i][j] = (float) ((double)data[i][j] * scale); - } - } - } - -//--------------------------------------------------------- -// fadeOutSelection -//--------------------------------------------------------- -void WaveView::fadeOutSelection(unsigned channels, float** data, unsigned length) - { - for (unsigned i=0; i<channels; i++) { - for (unsigned j=0; j<length; j++) { - double scale = (double) (length - j) / (double)length ; - data[i][j] = (float) ((double)data[i][j] * scale); - } - } - } - -//--------------------------------------------------------- -// reverseSelection -//--------------------------------------------------------- -void WaveView::reverseSelection(unsigned channels, float** data, unsigned length) - { - if(length <= 1) - return; - for (unsigned i=0; i<channels; i++) { - for (unsigned j=0; j<length/2; j++) { - float tmpl = data[i][j]; - float tmpr = data[i][length - j - 1]; - data[i][j] = tmpr; - data[i][length - j - 1] = tmpl; - } - } - } -//--------------------------------------------------------- -// applyGain -//--------------------------------------------------------- -void WaveView::applyGain(unsigned channels, float** data, unsigned length, double gain) - { - for (unsigned i=0; i<channels; i++) { - for (unsigned j=0; j<length; j++) { - data[i][j] = (float) ((double)data[i][j] * gain); - } - } - } - -//--------------------------------------------------------- -// editExternal -//--------------------------------------------------------- -void WaveView::editExternal(unsigned file_format, unsigned file_samplerate, unsigned file_channels, float** tmpdata, unsigned tmpdatalen) - { - // Create yet another tmp-file - QString exttmpFileName; - if (!MusEGlobal::getUniqueTmpfileName("tmp_musewav",".wav", exttmpFileName)) { - printf("Could not create temp file - aborting...\n"); - return; - } - - MusECore::SndFile exttmpFile(exttmpFileName); - exttmpFile.setFormat(file_format, file_channels, file_samplerate); - if (exttmpFile.openWrite()) { - printf("Could not open temporary file...\n"); - return; - } - // Write out change-data to this file: - exttmpFile.write(file_channels, tmpdata, tmpdatalen); - exttmpFile.close(); - - // Forkaborkabork - int pid = fork(); - if (pid == 0) { - if (execlp(MusEGlobal::config.externalWavEditor.toLatin1().constData(), MusEGlobal::config.externalWavEditor.toLatin1().constData(), exttmpFileName.toLatin1().constData(), NULL) == -1) { - perror("Failed to launch external editor"); - // Get out of here - - - // cannot report error through gui, we are in another fork! - //@!TODO: Handle unsuccessful attempts - exit(99); - } - exit(0); - } - else if (pid == -1) { - perror("fork failed"); - } - else { - int status; - waitpid(pid, &status, 0); - //printf ("status=%d\n",status); - if( WEXITSTATUS(status) != 0 ){ - QMessageBox::warning(this, tr("MusE - external editor failed"), - tr("MusE was unable to launch the external editor\ncheck if the editor setting in:\n" - "Global Settings->Audio:External Waveditor\nis set to a valid editor.")); - } - - if (exttmpFile.openRead()) { - printf("Could not reopen temporary file!\n"); - } - else { - // Re-read file again - exttmpFile.seek(0, 0); - size_t sz = exttmpFile.readWithHeap(file_channels, tmpdata, tmpdatalen); - if (sz != tmpdatalen) { - // File must have been shrunken - not good. Alert user. - QMessageBox::critical(this, tr("MusE - file size changed"), - tr("When editing in external editor - you should not change the filesize\nsince it must fit the selected region.\n\nMissing data is muted")); - for (unsigned i=0; i<file_channels; i++) { - for (unsigned j=sz; j<tmpdatalen; j++) { - tmpdata[i][j] = 0; - } - } - } - } - QDir dir = exttmpFile.dirPath(); - dir.remove(exttmpFileName); - dir.remove(exttmpFile.basename() + ".wca"); - } - } } // namespace MusECore diff --git a/muse2/muse/waveedit/waveview.h b/muse2/muse/waveedit/waveview.h index 6aa55120..68989aca 100644 --- a/muse2/muse/waveedit/waveview.h +++ b/muse2/muse/waveedit/waveview.h @@ -86,21 +86,6 @@ class WaveView : public View { MusECore::WaveSelectionList getSelection(unsigned startpos, unsigned stoppos); int lastGainvalue; //!< Stores the last used gainvalue when specifiying gain value in the editgain dialog - void modifySelection(int operation, unsigned startpos, unsigned stoppos, double paramA); //!< Modifies selection - - void muteSelection(unsigned channels, float** data, unsigned length); //!< Mutes selection - void normalizeSelection(unsigned channels, float** data, unsigned length); //!< Normalizes selection - void fadeInSelection(unsigned channels, float** data, unsigned length); //!< Linear fade in of selection - void fadeOutSelection(unsigned channels, float** data, unsigned length); //!< Linear fade out of selection - void reverseSelection(unsigned channels, float** data, unsigned length); //!< Reverse selection - void applyGain(unsigned channels, float** data, unsigned length, double gain); //!< Apply gain to selection - void copySelection(unsigned file_channels, float** tmpdata, unsigned tmpdatalen, bool blankData, unsigned format, unsigned sampleRate); - - void editExternal(unsigned file_format, unsigned file_samplerate, unsigned channels, float** data, unsigned length); - - //void applyLadspa(unsigned channels, float** data, unsigned length); //!< Apply LADSPA plugin on selection - - private slots: void setPos(int idx, unsigned val, bool adjustScrollbar); @@ -120,7 +105,6 @@ class WaveView : public View { WaveView(MidiEditor*, QWidget* parent, int xscale, int yscale); QString getCaption() const; void range(int*, int*); - void cmd(int n); MusECore::WavePart* part() { return curPart; } }; |