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 "CCopyCutToNewEdit.h"
22 
23 #include "../ASoundFileManager.h"
24 #include "../CActionParameters.h"
25 #include "../CLoadedSound.h"
26 
CCopyCutToNewEdit(const AActionFactory * factory,const CActionSound * actionSound,CCType _type,ASoundFileManager * _soundFileManager)27 CCopyCutToNewEdit::CCopyCutToNewEdit(const AActionFactory *factory,const CActionSound *actionSound,CCType _type,ASoundFileManager *_soundFileManager) :
28     AAction(factory,actionSound),
29 
30     type(_type),
31     soundFileManager(_soundFileManager)
32 {
33 }
34 
~CCopyCutToNewEdit()35 CCopyCutToNewEdit::~CCopyCutToNewEdit()
36 {
37 }
38 
doActionSizeSafe(CActionSound * actionSound,bool prepareForUndo)39 bool CCopyCutToNewEdit::doActionSizeSafe(CActionSound *actionSound,bool prepareForUndo)
40 {
41 	if(actionSound->countChannels()<=0)
42 		return false; // no channels to do
43 
44 	const sample_pos_t start=actionSound->start;
45 	const sample_pos_t selectionLength=actionSound->selectionLength();
46 
47 	CLoadedSound *newSound=soundFileManager->createNew(
48 		soundFileManager->getUntitledFilename(gPromptDialogDirectory,"rez"),
49 		actionSound->countChannels(),
50 		actionSound->sound->getSampleRate(),
51 		selectionLength);
52 
53 	{
54 		CSoundLocker sl(newSound->sound, false);
55 
56 		unsigned k=0;
57 		for(unsigned t=0;t<actionSound->sound->getChannelCount();t++)
58 		{
59 			if(actionSound->doChannel[t])
60 				newSound->sound->mixSound(k++,0,actionSound->sound->getAudio(t),start,actionSound->sound->getSampleRate(),selectionLength,mmOverwrite,sftNone,false,true);
61 		}
62 	}
63 
64 	if(type==cctCutToNew)
65 	{
66 		if(prepareForUndo)
67 			moveSelectionToTempPools(actionSound,mmSelection);
68 		else
69 			actionSound->sound->removeSpace(actionSound->doChannel,actionSound->start,actionSound->selectionLength());
70 
71 		actionSound->stop=actionSound->start=actionSound->start-1;
72 	}
73 
74 	return true;
75 }
76 
canUndo(const CActionSound * actionSound) const77 AAction::CanUndoResults CCopyCutToNewEdit::canUndo(const CActionSound *actionSound) const
78 {
79 	if(type==cctCutToNew)
80 		return curYes;
81 	else
82 		return curNA;
83 }
84 
undoActionSizeSafe(const CActionSound * actionSound)85 void CCopyCutToNewEdit::undoActionSizeSafe(const CActionSound *actionSound)
86 {
87 	restoreSelectionFromTempPools(actionSound);
88 }
89 
doesWarrantSaving() const90 bool CCopyCutToNewEdit::doesWarrantSaving() const
91 {
92 	return type==cctCutToNew;
93 }
94 
95 
96 // ---------------------------------------------
97 
CCopyToNewEditFactory(AActionDialog * channelSelectDialog)98 CCopyToNewEditFactory::CCopyToNewEditFactory(AActionDialog *channelSelectDialog) :
99 	AActionFactory(N_("Copy to New"),_("Copy to Selection to a Newly Created Sound Window"),channelSelectDialog,NULL,false,false)
100 {
101 }
102 
~CCopyToNewEditFactory()103 CCopyToNewEditFactory::~CCopyToNewEditFactory()
104 {
105 }
106 
manufactureAction(const CActionSound * actionSound,const CActionParameters * actionParameters) const107 CCopyCutToNewEdit *CCopyToNewEditFactory::manufactureAction(const CActionSound *actionSound,const CActionParameters *actionParameters) const
108 {
109 	return new CCopyCutToNewEdit(this,actionSound,CCopyCutToNewEdit::cctCopyToNew,actionParameters->getSoundFileManager());
110 }
111 
112 
113 
114 // -----------------------------------
115 
116 
CCutToNewEditFactory(AActionDialog * channelSelectDialog)117 CCutToNewEditFactory::CCutToNewEditFactory(AActionDialog *channelSelectDialog) :
118 	AActionFactory(N_("Cut to New"),_("Cut and Move the Selection to a Newly Created Sound Window"),channelSelectDialog,NULL)
119 {
120 }
121 
~CCutToNewEditFactory()122 CCutToNewEditFactory::~CCutToNewEditFactory()
123 {
124 }
125 
manufactureAction(const CActionSound * actionSound,const CActionParameters * actionParameters) const126 CCopyCutToNewEdit *CCutToNewEditFactory::manufactureAction(const CActionSound *actionSound,const CActionParameters *actionParameters) const
127 {
128 	return new CCopyCutToNewEdit(this,actionSound,CCopyCutToNewEdit::cctCutToNew,actionParameters->getSoundFileManager());
129 }
130 
131 
132