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 #ifndef __CSelectionEdit_H__
22 #define __CSelectionEdit_H__
23 
24 #include "../../../config/common.h"
25 
26 
27 #include "../AAction.h"
28 
29 enum Selections
30 {
31 	sSelectAll=0,			// select everything
32 	sSelectToBeginning=1,		// make start selection position move to the beginning
33 	sSelectToEnd=2,			// make stop selection position move to the end
34 	sFlopToBeginning=3,		// move the stop position to the start position and then the start position to the beginning
35 	sFlopToEnd=4,			// move the start position to the stop position and then the stop position to the end
36 	sSelectToSelectStart=5,		// move the start position forward to the stop position
37 	sSelectToSelectStop=6,		// move the stop position backward to the start position
38 		// !!! If I add more... change gSelectionNames AND gSelectionDescriptions in CSelectionEdit.cpp !!!
39 
40 
41 	// --- and below no need to change gSelectionNames or gSelectiondescriptions --------------
42 
43 	sSetSelectionPositions,
44 
45 	sGrowSelectionToTheLeft,
46 	sGrowSelectionToTheRight,
47 	sGrowSelectionInBothDirections,
48 	sSlideSelectionToTheLeft,
49 	sSlideSelectionToTheRight
50 };
51 
52 
53 class CSelectionEdit : public AAction
54 {
55 public:
56 	/*
57 		For selection changes, actionSound is to have the undoPositions
58 		and the new positions are passed in as parameters or a predefined
59 		selection.
60 	*/
61 	CSelectionEdit(const AActionFactory *factory,const CActionSound *actionSound,Selections selection);
62 	CSelectionEdit(const AActionFactory *factory,const CActionSound *actionSound,Selections selection,const double amount);
63 	CSelectionEdit(const AActionFactory *factory,const CActionSound *actionSound,sample_pos_t selectStart,sample_pos_t selectStop);
64 	virtual ~CSelectionEdit();
65 
66 
67 protected:
68 	bool doActionSizeSafe(CActionSound *actionSound,bool prepareForUndo);
69 	void undoActionSizeSafe(const CActionSound *actionSound);
70 	CanUndoResults canUndo(const CActionSound *actionSound) const;
71 
72 	bool doesWarrantSaving() const;
73 
74 private:
75 
76 	Selections selection;
77 	const double amount; // used if seleciton is sGrow... or sSlide...
78 	sample_pos_t selectStart,selectStop;
79 
80 };
81 
82 /*
83  * Here the factory has a parameter of how to construct the action before
84  * it's performed.  This is because a selection edit is fairly simple and
85  * I didn't want to create a differen AAction derivation for each type of
86  * selection change
87  */
88 
89 class CSelectionEditFactory : public AActionFactory
90 {
91 public:
92 	CSelectionEditFactory(Selections selection);
93 	virtual ~CSelectionEditFactory();
94 
95 	CSelectionEdit *manufactureAction(const CActionSound *actionSound,const CActionParameters *actionParameters) const;
96 
97 private:
98 	Selections selection;
99 };
100 
101 /*
102  * Here is another factory for the same CSelectionAction which has specific
103  * positions to use for the selection change
104  */
105 class CSelectionEditPositionFactory : public AActionFactory
106 {
107 public:
108 	CSelectionEditPositionFactory();
109 	virtual ~CSelectionEditPositionFactory();
110 
111 	CSelectionEdit *manufactureAction(const CActionSound *actionSound,const CActionParameters *actionParameters) const;
112 
113 	sample_pos_t selectStart,selectStop;
114 };
115 
116 
117 class CGrowOrSlideSelectionEditFactory : public AActionFactory
118 {
119 public:
120 	CGrowOrSlideSelectionEditFactory(AActionDialog *normalDialog); // selection will be sGrow... or sSlide
121 	virtual ~CGrowOrSlideSelectionEditFactory();
122 
123 	CSelectionEdit *manufactureAction(const CActionSound *actionSound,const CActionParameters *actionParameters) const;
124 };
125 
126 
127 #endif
128