1 /*
2 * Copyright (C) 2002 - David W. Durham
3 *
4 * This file is part of ReZound, an audio editing application.
5 *
6 * ReZound is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published
8 * by the Free Software Foundation; either version 2 of the License,
9 * or (at your option) any later version.
10 *
11 * ReZound is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19 */
20
21 #include "CCopyCutDeleteEdit.h"
22
23 #include "../ASoundClipboard.h"
24
CCopyCutDeleteEdit(const AActionFactory * factory,const CActionSound * actionSound,CCDType _type)25 CCopyCutDeleteEdit::CCopyCutDeleteEdit(const AActionFactory *factory,const CActionSound *actionSound,CCDType _type) :
26 AAction(factory,actionSound),
27
28 type(_type)
29 {
30 }
31
~CCopyCutDeleteEdit()32 CCopyCutDeleteEdit::~CCopyCutDeleteEdit()
33 {
34 }
35
doActionSizeSafe(CActionSound * actionSound,bool prepareForUndo)36 bool CCopyCutDeleteEdit::doActionSizeSafe(CActionSound *actionSound,bool prepareForUndo)
37 {
38 if(actionSound->countChannels()<=0)
39 return(false); // no channels to do
40
41 // ??? cut could be optimized if the clipboard were abstracted in such a way that I could use moveData to move to a pool in the same pool file as the sound
42 if(type==ccdtCopy || type==ccdtCut)
43 {
44 const sample_pos_t start=actionSound->start;
45 const sample_pos_t selectionLength=actionSound->selectionLength();
46
47 if(AAction::clipboards[gWhichClipboard]->isReadOnly())
48 throw(EUserMessage((_("cannot copy/cut to clipboard: ")+AAction::clipboards[gWhichClipboard]->getDescription()).c_str()));
49
50 AAction::clipboards[gWhichClipboard]->copyFrom(actionSound->sound,actionSound->doChannel,start,selectionLength);
51 }
52
53 if(type==ccdtCut || type==ccdtDelete)
54 {
55 if(prepareForUndo)
56 moveSelectionToTempPools(actionSound,mmSelection);
57 else
58 actionSound->sound->removeSpace(actionSound->doChannel,actionSound->start,actionSound->selectionLength());
59
60 actionSound->stop=actionSound->start=actionSound->start-1;
61 }
62
63 return(true);
64 }
65
canUndo(const CActionSound * actionSound) const66 AAction::CanUndoResults CCopyCutDeleteEdit::canUndo(const CActionSound *actionSound) const
67 {
68 if(type==ccdtCut || type==ccdtDelete)
69 {
70 // should check some size constraint?
71 return(curYes);
72 }
73 else
74 return(curNA);
75 }
76
undoActionSizeSafe(const CActionSound * actionSound)77 void CCopyCutDeleteEdit::undoActionSizeSafe(const CActionSound *actionSound)
78 {
79 restoreSelectionFromTempPools(actionSound);
80 }
81
doesWarrantSaving() const82 bool CCopyCutDeleteEdit::doesWarrantSaving() const
83 {
84 return type!=ccdtCopy;
85 }
86
87
88 // ---------------------------------------------
89
CCopyEditFactory(AActionDialog * channelSelectDialog)90 CCopyEditFactory::CCopyEditFactory(AActionDialog *channelSelectDialog) :
91 AActionFactory(N_("Copy"),"",channelSelectDialog,NULL,false,false)
92 {
93 }
94
~CCopyEditFactory()95 CCopyEditFactory::~CCopyEditFactory()
96 {
97 }
98
manufactureAction(const CActionSound * actionSound,const CActionParameters * actionParameters) const99 CCopyCutDeleteEdit *CCopyEditFactory::manufactureAction(const CActionSound *actionSound,const CActionParameters *actionParameters) const
100 {
101 return(new CCopyCutDeleteEdit(this,actionSound,CCopyCutDeleteEdit::ccdtCopy));
102 }
103
104
105
106 // -----------------------------------
107
108
CCutEditFactory(AActionDialog * channelSelectDialog)109 CCutEditFactory::CCutEditFactory(AActionDialog *channelSelectDialog) :
110 AActionFactory(N_("Cut"),"",channelSelectDialog,NULL)
111 {
112 }
113
~CCutEditFactory()114 CCutEditFactory::~CCutEditFactory()
115 {
116 }
117
manufactureAction(const CActionSound * actionSound,const CActionParameters * actionParameters) const118 CCopyCutDeleteEdit *CCutEditFactory::manufactureAction(const CActionSound *actionSound,const CActionParameters *actionParameters) const
119 {
120 return(new CCopyCutDeleteEdit(this,actionSound,CCopyCutDeleteEdit::ccdtCut));
121 }
122
123
124
125 // -----------------------------------
126
127
CDeleteEditFactory(AActionDialog * channelSelectDialog)128 CDeleteEditFactory::CDeleteEditFactory(AActionDialog *channelSelectDialog) :
129 AActionFactory(N_("Delete"),"",channelSelectDialog,NULL)
130 {
131 }
132
~CDeleteEditFactory()133 CDeleteEditFactory::~CDeleteEditFactory()
134 {
135 }
136
manufactureAction(const CActionSound * actionSound,const CActionParameters * actionParameters) const137 CCopyCutDeleteEdit *CDeleteEditFactory::manufactureAction(const CActionSound *actionSound,const CActionParameters *actionParameters) const
138 {
139 return(new CCopyCutDeleteEdit(this,actionSound,CCopyCutDeleteEdit::ccdtDelete));
140 }
141
142
143