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 "CMIDIDumpSampleIdDialog.h"
22 
23 #include "CStatusComm.h"
24 
25 #include <stdlib.h>
26 
27 #include <istring>
28 
29 
30 FXDEFMAP(CMIDIDumpSampleIdDialog) CMIDIDumpSampleIdDialogMap[]=
31 {
32 //	Message_Type			ID						Message_Handler
33 	FXMAPFUNC(SEL_COMMAND,		CMIDIDumpSampleIdDialog::ID_WAIT_CHECKBUTTON,	CMIDIDumpSampleIdDialog::onWaitCheckButton),
34 };
35 
36 
FXIMPLEMENT(CMIDIDumpSampleIdDialog,FXModalDialogBox,CMIDIDumpSampleIdDialogMap,ARRAYNUMBER (CMIDIDumpSampleIdDialogMap))37 FXIMPLEMENT(CMIDIDumpSampleIdDialog,FXModalDialogBox,CMIDIDumpSampleIdDialogMap,ARRAYNUMBER(CMIDIDumpSampleIdDialogMap))
38 
39 
40 
41 // ----------------------------------------
42 
43 
44 CMIDIDumpSampleIdDialog::CMIDIDumpSampleIdDialog(FXWindow *mainWindow) :
45 	FXModalDialogBox(mainWindow,N_("MIDI Sample Dump"),0,0,FXModalDialogBox::ftVertical,FXModalDialogBox::stShrinkWrap)
46 {
47 	FXComposite *t;
48 
49 	waitCheckButton=new FXCheckButton(getFrame(),_("Wait for Dump"),this,ID_WAIT_CHECKBUTTON);
50 
51 	t=new FXHorizontalFrame(getFrame());
52 		new FXLabel(t,_("Sample ID"));
53 		waveformIdEdit=new FXTextField(t,10,NULL,0,TEXTFIELD_NORMAL|TEXTFIELD_INTEGER | LAYOUT_FILL_X);
54 		waveformIdEdit->setText("0");
55 
56 	t=new FXHorizontalFrame(getFrame());
57 		new FXLabel(t,_("SysEx Channel"));
58 		sysExChannelSpinner=new FXSpinner(t,4,NULL,0,SPIN_NORMAL | SPIN_CYCLIC | FRAME_SUNKEN|FRAME_THICK);
59 		sysExChannelSpinner->setRange(0,127);
60 
61 	loopTypeFrame=t=new FXHorizontalFrame(getFrame());
62 		new FXLabel(t,_("Loop Type"));
63 		loopTypeEdit=new FXTextField(t,10,NULL,0,TEXTFIELD_NORMAL|TEXTFIELD_INTEGER | LAYOUT_FILL_X);
64 		loopTypeEdit->setText("0");
65 }
66 
~CMIDIDumpSampleIdDialog()67 CMIDIDumpSampleIdDialog::~CMIDIDumpSampleIdDialog()
68 {
69 }
70 
showForOpen(int & sysExChannel,int & waveformId)71 bool CMIDIDumpSampleIdDialog::showForOpen(int &sysExChannel,int &waveformId)
72 {
73 	waitCheckButton->setCheck(waveformId<0);
74 	waitCheckButton->show();
75 
76 	if(waveformId>=0)
77 		waveformIdEdit->setText(istring(waveformId).c_str());
78 
79 	if(sysExChannel>=0)
80 		sysExChannelSpinner->setValue(sysExChannel);
81 
82 	loopTypeFrame->hide();
83 
84 	onWaitCheckButton(NULL,0,NULL);
85 
86 	recalc();
87 
88 	redo:
89 	if(execute(PLACEMENT_SCREEN))
90 	{
91 
92 		if(waitCheckButton->getCheck())
93 		{
94 			waveformId=-1;
95 			sysExChannel=-1;
96 		}
97 		else
98 		{
99 			waveformId=atoi(waveformIdEdit->getText().text());
100 			if(waveformId<0 || waveformId>16384)
101 			{
102 				Error(_("Waveform IDs must be from 0 to 16384"));
103 				goto redo;
104 			}
105 
106 			sysExChannel=sysExChannelSpinner->getValue();
107 		}
108 		return true;
109 	}
110 	return false;
111 }
112 
showForSave(int & sysExChannel,int & waveformId,int & loopType)113 bool CMIDIDumpSampleIdDialog::showForSave(int &sysExChannel,int &waveformId,int &loopType)
114 {
115 	waitCheckButton->setCheck(false);
116 	waitCheckButton->hide();
117 
118 	if(waveformId>=0)
119 		waveformIdEdit->setText(istring(waveformId).c_str());
120 
121 	if(sysExChannel>=0)
122 		sysExChannelSpinner->setValue(sysExChannel);
123 
124 	if(loopType>=0)
125 		loopTypeEdit->setText(istring(loopType).c_str());
126 	loopTypeFrame->show();
127 
128 	onWaitCheckButton(NULL,0,NULL);
129 
130 	recalc();
131 
132 
133 	redo:
134 	if(execute(PLACEMENT_SCREEN))
135 	{
136 		waveformId=atoi(waveformIdEdit->getText().text());
137 		if(waveformId<0 || waveformId>16384)
138 		{
139 			Error(_("Waveform IDs must be from 0 to 16384"));
140 			goto redo;
141 		}
142 
143 		sysExChannel=sysExChannelSpinner->getValue();
144 
145 		loopType=atoi(loopTypeEdit->getText().text());
146 		if(loopType<0 || loopType>127)
147 		{
148 			Error(_("Loop type must be from 0 to 127"));
149 			goto redo;
150 		}
151 
152 		return true;
153 	}
154 	return false;
155 }
156 
onWaitCheckButton(FXObject * sender,FXuint sel,void * ptr)157 long CMIDIDumpSampleIdDialog::onWaitCheckButton(FXObject *sender,FXuint sel,void *ptr)
158 {
159 	if(waitCheckButton->getCheck())
160 	{
161 		waveformIdEdit->disable();
162 		sysExChannelSpinner->disable();
163 	}
164 	else
165 	{
166 		waveformIdEdit->enable();
167 		sysExChannelSpinner->enable();
168 	}
169 
170 	return 1;
171 }
172 
173