diff options
-rw-r--r-- | muse2/ChangeLog | 2 | ||||
-rw-r--r-- | muse2/muse/waveedit/waveedit.cpp | 25 | ||||
-rw-r--r-- | muse2/muse/waveedit/waveedit.h | 6 | ||||
-rw-r--r-- | muse2/muse/waveedit/waveview.cpp | 66 | ||||
-rw-r--r-- | muse2/muse/waveedit/waveview.h | 4 |
5 files changed, 101 insertions, 2 deletions
diff --git a/muse2/ChangeLog b/muse2/ChangeLog index 9928262c..a0dd731c 100644 --- a/muse2/ChangeLog +++ b/muse2/ChangeLog @@ -1,3 +1,5 @@ +10.02.2011: + - added cut/copy/paste and keyboard shortcuts to wave editor (rj) 09.02.2011: - fixed regression with Bounce to File and Bounce to Track (rj) [[[ By Tim. Marked as p4.0.15 ... diff --git a/muse2/muse/waveedit/waveedit.cpp b/muse2/muse/waveedit/waveedit.cpp index a6251503..89e7fb78 100644 --- a/muse2/muse/waveedit/waveedit.cpp +++ b/muse2/muse/waveedit/waveedit.cpp @@ -100,6 +100,19 @@ WaveEdit::WaveEdit(PartList* pl) menuFunctions->addSeparator(); + copyAction = menuEdit->addAction(tr("&Copy")); + mapper->setMapping(copyAction, CMD_EDIT_COPY); + connect(copyAction, SIGNAL(triggered()), mapper, SLOT(map())); + + cutAction = menuEdit->addAction(tr("C&ut")); + mapper->setMapping(cutAction, CMD_EDIT_CUT); + connect(cutAction, SIGNAL(triggered()), mapper, SLOT(map())); + + pasteAction = menuEdit->addAction(tr("&Paste")); + mapper->setMapping(pasteAction, CMD_EDIT_PASTE); + connect(pasteAction, SIGNAL(triggered()), mapper, SLOT(map())); + + act = menuEdit->addAction(tr("Edit in E&xternal Editor")); mapper->setMapping(act, CMD_EDIT_EXTERNAL); connect(act, SIGNAL(triggered()), mapper, SLOT(map())); @@ -226,6 +239,9 @@ WaveEdit::WaveEdit(PartList* pl) connect(hscroll, SIGNAL(scaleChanged(int)), SLOT(updateHScrollRange())); connect(song, SIGNAL(songChanged(int)), SLOT(songChanged1(int))); + + + initShortcuts(); updateHScrollRange(); configChanged(); @@ -237,6 +253,15 @@ WaveEdit::WaveEdit(PartList* pl) } } +void WaveEdit::initShortcuts() + { + cutAction->setShortcut(shortcuts[SHRT_CUT].key); + copyAction->setShortcut(shortcuts[SHRT_COPY].key); + pasteAction->setShortcut(shortcuts[SHRT_PASTE].key); + selectAllAction->setShortcut(shortcuts[SHRT_SELECT_ALL].key); + selectNoneAction->setShortcut(shortcuts[SHRT_SELECT_NONE].key); + } + //--------------------------------------------------------- // configChanged //--------------------------------------------------------- diff --git a/muse2/muse/waveedit/waveedit.h b/muse2/muse/waveedit/waveedit.h index 79102410..67230897 100644 --- a/muse2/muse/waveedit/waveedit.h +++ b/muse2/muse/waveedit/waveedit.h @@ -40,6 +40,9 @@ class WaveEdit : public MidiEditor { PosLabel* pos2; QAction* selectAllAction; QAction* selectNoneAction; + QAction* cutAction; + QAction* copyAction; + QAction* pasteAction; static int _widthInit, _heightInit; @@ -50,6 +53,8 @@ class WaveEdit : public MidiEditor { QMenu* menuFunctions, *select, *menuGain; + void initShortcuts(); + private slots: void cmd(int); void setTime(unsigned t); @@ -75,6 +80,7 @@ class WaveEdit : public MidiEditor { enum { CMD_MUTE=0, CMD_NORMALIZE, CMD_FADE_IN, CMD_FADE_OUT, CMD_REVERSE, CMD_GAIN_FREE, CMD_GAIN_200, CMD_GAIN_150, CMD_GAIN_75, CMD_GAIN_50, CMD_GAIN_25, + CMD_EDIT_COPY, CMD_EDIT_CUT, CMD_EDIT_PASTE, CMD_EDIT_EXTERNAL, CMD_SELECT_ALL, CMD_SELECT_NONE }; }; diff --git a/muse2/muse/waveedit/waveview.cpp b/muse2/muse/waveedit/waveview.cpp index 668d8bea..fab731ba 100644 --- a/muse2/muse/waveedit/waveview.cpp +++ b/muse2/muse/waveedit/waveview.cpp @@ -14,6 +14,7 @@ #include <QFileInfo> #include <QMessageBox> #include <QMouseEvent> +#include <QFile> #include "editgain.h" #include "globals.h" @@ -499,6 +500,15 @@ void WaveView::cmd(int n) 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; @@ -561,7 +571,7 @@ void WaveView::cmd(int n) } if (modifyoperation != -1) { - if (selectionStart == selectionStop) { + if (selectionStart == selectionStop && modifyoperation!=PASTE) { printf("No selection. Ignoring\n"); //@!TODO: Disable menu options when no selection QMessageBox::information(this, QString("MusE"), @@ -643,6 +653,18 @@ void WaveView::modifySelection(int operation, unsigned startpos, unsigned stoppo { song->startUndo(); + if (operation == PASTE) { + // we need to redefine startpos and stoppos + if (copiedPart =="") + return; + 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; + } + WaveSelectionList selection = getSelection(startpos, stoppos); for (iWaveSelection i = selection.begin(); i != selection.end(); i++) { WaveEventSelection w = *i; @@ -706,6 +728,20 @@ void WaveView::modifySelection(int operation, unsigned startpos, unsigned stoppo 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: + { + 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); @@ -737,6 +773,34 @@ void WaveView::modifySelection(int operation, unsigned startpos, unsigned stoppo } //--------------------------------------------------------- +// copySelection +//--------------------------------------------------------- +void WaveView::copySelection(unsigned file_channels, float** tmpdata, unsigned length, bool blankData, unsigned format, unsigned sampleRate) +{ + if (copiedPart!="") { + QFile::remove(copiedPart); + } + if (!getUniqueTmpfileName(copiedPart)) { + return; + } + + 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) diff --git a/muse2/muse/waveedit/waveview.h b/muse2/muse/waveedit/waveview.h index d1f247b3..53b0c76f 100644 --- a/muse2/muse/waveedit/waveview.h +++ b/muse2/muse/waveedit/waveview.h @@ -42,10 +42,11 @@ class WaveView : public View { int endSample; WavePart* curPart; + QString copiedPart; int curPartId; enum { NORMAL, DRAG } mode; - enum { MUTE = 0, NORMALIZE, FADE_IN, FADE_OUT, REVERSE, GAIN, EDIT_EXTERNAL }; //!< Modify operations + enum { MUTE = 0, NORMALIZE, FADE_IN, FADE_OUT, REVERSE, GAIN, EDIT_EXTERNAL, CUT, COPY, PASTE }; //!< Modify operations unsigned selectionStart, selectionStop, dragstartx; @@ -69,6 +70,7 @@ class WaveView : public View { 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); |