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 "CChannelSelectDialog.h"
22
23 #include <istring>
24
25 #include "../backend/CSound.h"
26
27
28 CChannelSelectDialog *gChannelSelectDialog=NULL;
29
30
31 FXDEFMAP(CChannelSelectDialog) CChannelSelectDialogMap[]=
32 {
33 // Message_Type ID Message_Handler
34 FXMAPFUNC(SEL_COMMAND, CChannelSelectDialog::ID_DEFAULT_BUTTON, CChannelSelectDialog::onDefaultButton),
35 FXMAPFUNC(SEL_COMMAND, CChannelSelectDialog::ID_CLEAR_BUTTON, CChannelSelectDialog::onClearButton),
36 };
37
38
FXIMPLEMENT(CChannelSelectDialog,FXModalDialogBox,CChannelSelectDialogMap,ARRAYNUMBER (CChannelSelectDialogMap))39 FXIMPLEMENT(CChannelSelectDialog,FXModalDialogBox,CChannelSelectDialogMap,ARRAYNUMBER(CChannelSelectDialogMap))
40
41
42
43 // ----------------------------------------
44
45 CChannelSelectDialog::CChannelSelectDialog(FXWindow *mainWindow) :
46 /*
47 * having the title be translated is fine, except the fact that I use them in preset names
48 * what I need to do is avoid ever calling getTitle() on a fox widget
49 * I need to implement something like a getOrigTitle() which stores the original value of
50 * the title. I should use N_(...) when passing a string to be the title except _(...) when
51 * actually giving that string to FOX so it can render the translated title, and I should save
52 * the original in origTitle for getOrigTitle to return and use in presets
53 *
54 * this goes for derivations of FXModalWindow and all action param value widgetso
55 *
56 * ??? I *think* I can make this _() instead of N_() on the title.. I don't call getTitle() anywhere
57 */
58 FXModalDialogBox(mainWindow,N_("Channel Select"),100,100,FXModalDialogBox::ftVertical,FXModalDialogBox::stShrinkWrap),
59
60 label(new FXLabel(getFrame(),_("Channels to Which This Action Should Apply:"),NULL,LAYOUT_CENTER_X))
61 {
62 ASSURE_WIDTH(getFrame(),300);
63 getFrame()->setVSpacing(1);
64 getFrame()->setHSpacing(1);
65
66 for(unsigned t=0;t<MAX_CHANNELS;t++) // ??? could map it to some name like "Left, Right, Center, Bass... etc"
67 checkBoxes[t]=new FXCheckButton(getFrame(),(_("Channel ")+istring(t)).c_str(),NULL,0,CHECKBUTTON_NORMAL | LAYOUT_CENTER_X);
68
69 FXPacker *buttonPacker=new FXHorizontalFrame((/*this cast might cause a problem in the future*/FXComposite *)(getFrame()->getParent()),LAYOUT_FILL_X | FRAME_RAISED|FRAME_THICK);
70 new FXButton(buttonPacker,_("Default"),NULL,this,ID_DEFAULT_BUTTON,BUTTON_NORMAL);
71 new FXButton(buttonPacker,_("Clear"),NULL,this,ID_CLEAR_BUTTON,BUTTON_NORMAL);
72 }
73
~CChannelSelectDialog()74 CChannelSelectDialog::~CChannelSelectDialog()
75 {
76 }
77
show(CActionSound * actionSound,CActionParameters * actionParameters)78 bool CChannelSelectDialog::show(CActionSound *actionSound,CActionParameters *actionParameters)
79 {
80 this->actionSound=actionSound;
81
82 // don't show the dialog if there is only one channel
83 if(actionSound->sound->getChannelCount()<=1)
84 {
85 actionSound->doChannel[0]=true;
86 return(true);
87 }
88
89 // uncheck all check boxes
90 // only enable the check boxes that there are channels for
91 for(unsigned t=0;t<MAX_CHANNELS;t++)
92 {
93 checkBoxes[t]->setCheck(FALSE);
94 if(t<actionSound->sound->getChannelCount())
95 checkBoxes[t]->show();
96 else
97 checkBoxes[t]->hide();
98 }
99
100 for(unsigned t=0;t<actionSound->sound->getChannelCount();t++)
101 checkBoxes[t]->setCheck(actionSound->doChannel[t] ? TRUE : FALSE);
102
103 // when the number of shown or hidden widgets changes the frame needs to be told to recalc
104 getFrame()->recalc();
105
106 if(execute(PLACEMENT_CURSOR))
107 {
108 bool ret=false; // or all the checks together... if it's false, then it's like hitting cancel
109 for(unsigned t=0;t<MAX_CHANNELS;t++)
110 {
111 actionSound->doChannel[t]=checkBoxes[t]->getCheck()==TRUE ? true : false;
112 ret|=actionSound->doChannel[t];
113 }
114
115 return(ret);
116 }
117 return(false);
118
119 }
120
hide()121 void CChannelSelectDialog::hide()
122 {
123 FXModalDialogBox::hide();
124 }
125
onDefaultButton(FXObject * sender,FXSelector sel,void * ptr)126 long CChannelSelectDialog::onDefaultButton(FXObject *sender,FXSelector sel,void *ptr)
127 {
128 for(unsigned x=0;x<MAX_CHANNELS;x++)
129 checkBoxes[x]->setCheck(FALSE);
130
131 for(unsigned x=0;x<actionSound->sound->getChannelCount();x++)
132 checkBoxes[x]->setCheck(actionSound->doChannel[x] ? TRUE : FALSE);
133
134 return 1;
135 }
136
onClearButton(FXObject * sender,FXSelector sel,void * ptr)137 long CChannelSelectDialog::onClearButton(FXObject *sender,FXSelector sel,void *ptr)
138 {
139 for(unsigned x=0;x<MAX_CHANNELS;x++)
140 checkBoxes[x]->setCheck(FALSE);
141 return 1;
142 }
143
144