-
Notifications
You must be signed in to change notification settings - Fork 0
/
CamdMUI.c
326 lines (257 loc) · 7.7 KB
/
CamdMUI.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
#ifdef __STORM__
int main( int argc, char *argv[] );
void wbmain(struct WBStartup* wb)
{ main(0, (char **) wb);
}
#endif
#include "RaspMidi.h"
//GLOBALS
BYTE midisig = -1;
UBYTE UserMidiPort[MAXINFOCHARS];
UBYTE CurrentBank = 0;
static struct NewMenu MenuData[] =
{
{ NM_TITLE, "RaspMIDI" ,"P",0 ,0 ,(APTR)MEN_PROJECT },
{ NM_ITEM , "About" ,"?",0 ,0 ,(APTR)MEN_ABOUT },
{ NM_ITEM , "Quit" ,"Q",0 ,0 ,(APTR)MEN_QUIT },
{ NM_END,NULL,0,0,0,(APTR)0 },
};
//Estructura para lanzar mensajes en requester
struct EasyStruct ShowRequester = {
sizeof(struct EasyStruct),
0,
"",
"%s",
"Ok"
};
struct TagItem MidiItems[] =
{
MIDI_Name, (LONG)"RaspMIDI Node",
MIDI_MsgQueue, 6048L,
MIDI_SysExSize, 10000L,
MIDI_RecvSignal, midisig,
TAG_DONE, NULL
};
struct TagItem MidiLinkTags[] =
{
MLINK_Location, (LONG)UserMidiPort,
TAG_DONE, NULL
};
//MAIN
int main(int argc, char *argv[] )
{
ULONG signals;
BOOL running = TRUE;
struct DiskObject *DiskObj;
STRPTR temp;
BPTR oldlock;
strcpy( UserMidiPort, DEFAULTMIDIPORT);
//LEE LOS TOOLTYPES
if(argc == 0)
{
struct WBStartup *WbStartup = (struct WBStartup *) argv;
struct WBArg *Args = WbStartup->sm_ArgList;
if(WbStartup == NULL) CleanOut("No wbstartup\n");
oldlock = CurrentDir(Args[0].wa_Lock);
DiskObj = GetDiskObject((char *)Args[0].wa_Name);
temp = FindToolType(DiskObj->do_ToolTypes , "MIDIPORT");
if(temp != NULL) strcpy( UserMidiPort, temp );
CurrentDir(oldlock);
}
CreateSysExMsg();
//Si no tenemos las libs salimos
if(OpenLib() == FALSE) return 1;
//señales para el midi
midisig = AllocSignal(-1);
if(midisig == -1) CleanOut("Cant get a signal");
// MIDI Node
ournode = CreateMidiA(&MidiItems[0]);
if(!ournode) CleanOut("Can't Create MidiNode");
// MIDI Link
outLink = AddMidiLinkA(ournode, MLTYPE_Sender, &MidiLinkTags[0]);
if(!outLink) CleanOut("Can't Add Output Link");
//Creamos App y ventana
app = ApplicationObject,
MUIA_Application_Title, "RaspMIDI",
MUIA_Application_Author, "tolkien/goblins",
MUIA_Application_Version, ver,
MUIA_Application_Window, window = WindowObject,
MUIA_Window_Title, "RaspMIDI tolkien/goblins",
MUIA_Window_ID, MAKE_ID('M','I','D','1'),
MUIA_Window_Menustrip, menu = MUI_MakeObject(MUIO_MenustripNM,MenuData,MUIO_MenustripNM_CommandKeyCheck),
MUIA_Window_Activate, TRUE,
MUIA_Window_Width, 150,
MUIA_Window_Height, 100,
MUIA_Window_CloseGadget, TRUE,
MUIA_Window_DepthGadget, TRUE,
MUIA_Window_SizeGadget, TRUE,
WindowContents, VGroup,
Child, BTreboot = SimpleButton("Reboot"),
Child, VGroup, GroupFrameT("MT-32"),
Child, BTmt32mode = SimpleButton("MT-32 mode"),
Child, HGroup, GroupFrameT("Rom type"),
Child, BTmt32old = SimpleButton("MT-32 old"),
Child, BTmt32new = SimpleButton("MT-32 new"),
Child, BTcm32l = SimpleButton("CM-32l"),
End,
End,
Child, VGroup, GroupFrameT("SoundFont"),
Child, BTsfmode = SimpleButton("SoundFont mode"),
Child, HGroup, GroupFrameT("SoundFont bank"),
Child, BTsfless = SimpleButton("<"),
Child, BTsfbank = Label2(" 0 "),
Child, BTsfmore = SimpleButton(">"),
End,
End,
End,
End,
End;
if (!app)
{
Show("Cant create MUI app", "What a fucking fail!");
CleanOut(NULL);
return 2;
}
//METHODS
DoMethod(window,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,
app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
DoMethod(BTreboot, MUIM_Notify, MUIA_Pressed, FALSE, app, 2, MUIM_Application_ReturnID, IDreboot);
DoMethod(BTmt32mode, MUIM_Notify, MUIA_Pressed, FALSE, app, 2, MUIM_Application_ReturnID, IDmt32mode);
DoMethod(BTmt32old, MUIM_Notify, MUIA_Pressed, FALSE, app, 2, MUIM_Application_ReturnID, IDmt32old);
DoMethod(BTmt32new, MUIM_Notify, MUIA_Pressed, FALSE, app, 2, MUIM_Application_ReturnID, IDmt32new);
DoMethod(BTcm32l, MUIM_Notify, MUIA_Pressed, FALSE, app, 2, MUIM_Application_ReturnID, IDcm32l);
DoMethod(BTsfmode, MUIM_Notify, MUIA_Pressed, FALSE, app, 2, MUIM_Application_ReturnID, IDsfmode);
DoMethod(BTsfless, MUIM_Notify, MUIA_Pressed, FALSE, app, 2, MUIM_Application_ReturnID, IDsfless);
DoMethod(BTsfmore, MUIM_Notify, MUIA_Pressed, FALSE, app, 2, MUIM_Application_ReturnID, IDsfmore);
set(window,MUIA_Window_Open,TRUE);
//main loop
while(running)
{
ULONG id = DoMethod(app, MUIM_Application_Input, &signals);
switch(id)
{
case MEN_QUIT:
case MUIV_Application_ReturnID_Quit:
running = FALSE;
break;
case MEN_ABOUT:
//MUI_Request(app, window, 0, NULL, "Ok", "RaspMIDI 1.0 \ntolkien/goblins");
MUI_Request(app, window, 0, NULL, "Ok", about);
break;
}
//los menus tiene ID >= 50
//los botones del 1 en adelante
if(id >=1 && id <= 6)
{
SendSysExMsg(id);
}
//comprobamos el cambio de bancos
if(id >= IDsfless && id <=IDsfmore ) ChangeBank(id);
if(signals)
{
signals = Wait(signals | SIGBREAKF_CTRL_C);
if(signals & SIGBREAKF_CTRL_C) running = FALSE;
}
}
set(window,MUIA_Window_Open,FALSE);
//Cerramos librerias
CleanOut(NULL);
return 0;
}
//FUNCIONES
void Show(APTR titulo, APTR cuerpo)
{
ULONG iflags = 0;
ShowRequester.es_Title = titulo;
EasyRequest(NULL, &ShowRequester, &iflags, cuerpo);
}
int OpenLib()
{
MUIMasterBase = OpenLibrary(MUIMASTER_NAME, MUIMASTER_VMIN);
if(!MUIMasterBase) CleanOut("Cant open MUI library\n");
CamdBase = OpenLibrary("camd.library", 36L);
if(!CamdBase) CleanOut("Cant open CAMD library\n");
if(!MUIMasterBase || !CamdBase) return FALSE;
return TRUE;
}
void CleanOut(BYTE *txt)
{
if(txt) Show("Error", txt);
if (outLink) RemoveMidiLink(outLink);
if (ournode) DeleteMidi(ournode);
if (midisig != -1) FreeSignal(midisig);
if(app) MUI_DisposeObject(app);
if(MUIMasterBase) CloseLibrary(MUIMasterBase);
if(CamdBase) CloseLibrary(CamdBase);
}
void SendSysExMsg(int ID)
{
ID--; //para que empiece a contar de 0
PutSysEx(outLink, (UBYTE*)&sysexmsg[ID].msg);
}
void CreateSysExMsg()
{
//REBOOT
sysexmsg[0].msg[0] = 0xf0;
sysexmsg[0].msg[1] = 0x7d;
sysexmsg[0].msg[2] = 0x00;
sysexmsg[0].msg[3] = 0xf7;
sysexmsg[0].name = "REBOOT sysexmsg";
//MT32 MODE
sysexmsg[1].msg[0] = 0xf0;
sysexmsg[1].msg[1] = 0x7d;
sysexmsg[1].msg[2] = 0x03;
sysexmsg[1].msg[3] = 0x00;
sysexmsg[1].msg[4] = 0xf7;
sysexmsg[1].name = "MT-32 mode";
//MT32 MODE (old)
sysexmsg[2].msg[0] = 0xf0;
sysexmsg[2].msg[1] = 0x7d;
sysexmsg[2].msg[2] = 0x01;
sysexmsg[2].msg[3] = 0x00;
sysexmsg[2].msg[4] = 0xf7;
sysexmsg[2].name = "MT-32 old rom";
//MT32 MODE (new)
sysexmsg[3].msg[0] = 0xf0;
sysexmsg[3].msg[1] = 0x7d;
sysexmsg[3].msg[2] = 0x01;
sysexmsg[3].msg[3] = 0x01;
sysexmsg[3].msg[4] = 0xf7;
sysexmsg[3].name = "MT-32 new rom";
//CM32 MODE
sysexmsg[4].msg[0] = 0xf0;
sysexmsg[4].msg[1] = 0x7d;
sysexmsg[4].msg[2] = 0x01;
sysexmsg[4].msg[3] = 0x02;
sysexmsg[4].msg[4] = 0xf7;
sysexmsg[4].name = "CM-32l rom";
//SOUNDFONT MODE
sysexmsg[5].msg[0] = 0xf0;
sysexmsg[5].msg[1] = 0x7d;
sysexmsg[5].msg[2] = 0x03;
sysexmsg[5].msg[3] = 0x01;
sysexmsg[5].msg[4] = 0xf7;
sysexmsg[5].name = "SoundFont mode";
//SOUNDFONT BANK
sysexmsg[6].msg[0] = 0xf0;
sysexmsg[6].msg[1] = 0x7d;
sysexmsg[6].msg[2] = 0x02;
sysexmsg[6].msg[3] = 0x00;
sysexmsg[6].msg[4] = 0xf7;
sysexmsg[6].name = "SoundFont bank";
}
void ChangeBank(LONG id)
{
//f0 7d 02 xx f7 Soundfont Bank xx=00 To ??
UBYTE temp = CurrentBank;
UBYTE tonum[4];
if(id == IDsfless && CurrentBank > 0) CurrentBank--;
if(id == IDsfmore && CurrentBank < 127) CurrentBank++;
sprintf(tonum, "%d", CurrentBank);
if(temp != CurrentBank)
{
sysexmsg[6].msg[3] = CurrentBank;
set(BTsfbank, MUIA_Text_Contents, tonum);
SendSysExMsg(7);
}
}