1 /*
2 TiMidity++ -- MIDI to WAVE converter and player
3 Copyright (C) 1999-2002 Masanao Izumo <mo@goice.co.jp>
4 Copyright (C) 1995 Tuukka Toivonen <tt@cgs.fi>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but 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 w32_gogo.c
21
22 Functions to use gogo.dll for mp3 gogo (Windows 95/98/NT).
23
24 Orignal source : stub.c by �o�d�m���l�����������b���� and �ւ��.
25
26 Modified by Daisuke Aoki <dai@y7.net>
27 */
28
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif /* HAVE_CONFIG_H */
32 #ifdef __POCC__
33 #include <sys/types.h>
34 #endif //for off_t
35 #include "interface.h"
36
37 #ifdef AU_GOGO_DLL
38
39 #include <stdio.h>
40
41 #ifdef __W32__
42 #include <stdlib.h>
43 #include <io.h>
44 #include <windows.h>
45 #include <process.h>
46 #include <windowsx.h>
47 #include <winuser.h>
48 #include <stdio.h>
49 #endif
50
51 #ifdef HAVE_UNISTD_H
52 #include <unistd.h>
53 #endif /* HAVE_UNISTD_H */
54
55 #ifndef NO_STRING_H
56 #include <string.h>
57 #else
58 #include <strings.h>
59 #endif
60 #include <fcntl.h>
61
62 /* #include <musenc.h> /* for gogo */
63 #include <gogo/gogo.h> /* for gogo */
64
65 #include "w32_gogo.h"
66
67 #include "gogo_a.h"
68
69 #include "timidity.h"
70 #include "common.h"
71 #include "output.h"
72 #include "controls.h"
73 #include "instrum.h"
74 #include "playmidi.h"
75 #include "readmidi.h"
76
77 static HINSTANCE hModule = NULL;
78 typedef MERET (*me_init)(void);
79 typedef MERET (*me_setconf)(UPARAM mode, UPARAM dwPara1, UPARAM dwPara2 );
80 typedef MERET (*me_getconf)(UPARAM mode, void *para1 );
81 typedef MERET (*me_detect)();
82 typedef MERET (*me_procframe)();
83 typedef MERET (*me_close)();
84 typedef MERET (*me_end)();
85 typedef MERET (*me_getver)( unsigned long *vercode, char *verstring );
86 typedef MERET (*me_haveunit)( unsigned long *unit );
87
88 static me_init mpge_init = NULL;
89 static me_setconf mpge_setconf = NULL;
90 static me_getconf mpge_getconf = NULL;
91 static me_detect mpge_detector = NULL;
92 static me_procframe mpge_processframe = NULL;
93 static me_close mpge_close = NULL;
94 static me_end mpge_end = NULL;
95 static me_getver mpge_getver = NULL;
96 static me_haveunit mpge_haveunit = NULL;
97
98 int MPGE_available = 0;
99
100 // DLL�̓ǂݍ���(�ŏ���1��ڂ̂�)�ƃ��[�N�G���A�̏��������s���܂��B
MPGE_initializeWork(void)101 MERET MPGE_initializeWork(void)
102 {
103 if( hModule == NULL ){
104 // (DLL���ǂݍ��܂�Ă��Ȃ��ꍇ)
105 // �J�����g�f�B���N�g���A�y��system�f�B���N�g����GOGO.DLL�̓ǂݍ���
106 hModule = LoadLibrary("gogo.dll");
107 if( hModule == NULL ){ // DLL��������Ȃ��ꍇ
108 #define Key HKEY_CURRENT_USER
109 #define SubKey "Software\\MarineCat\\GOGO_DLL"
110 HKEY hKey;
111 DWORD dwType, dwKeySize;
112 LONG lResult;
113 static char *szName = "INSTPATH";
114 char szPathName[ _MAX_PATH + 8];
115 dwKeySize = sizeof( szPathName );
116
117 // ���W�X�g�����ڂ� HEY_CURENT_USER\Software\MarineCat\GOGO_DLL�L�[�ȉ���
118 // INSTPATH (REG_SZ)���擾���܂��B
119 if( RegOpenKeyEx(
120 Key,
121 SubKey,
122 0,
123 KEY_ALL_ACCESS,
124 &hKey ) == ERROR_SUCCESS
125 ){
126 lResult = RegQueryValueEx(
127 hKey,
128 szName,
129 0,
130 &dwType,
131 (BYTE *)szPathName,
132 &dwKeySize);
133 RegCloseKey(hKey);
134 if( lResult == ERROR_SUCCESS && REG_SZ == dwType ){
135 // ���W�X�g������擾�����p�X�ōēxDLL�̓ǂݍ��݂����݂�
136 hModule = LoadLibrary( szPathName );
137 }
138 }
139 #undef Key
140 #undef SubKey
141 }
142 // DLL��������Ȃ�
143 if( hModule == NULL ){
144 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "can not find gogo.dll.");
145 return ME_INTERNALERROR;
146 // MessageBox( "DLL�̓ǂݍ��݂����s���܂����B\nDLL��EXE�t�@�C���Ɠ����f�B���N�g���֕��ʂ��Ă�������\n");
147 // fprintf( stderr,"DLL�̓ǂݍ��݂����s���܂����B\nDLL��EXE�t�@�C���Ɠ����f�B���N�g���֕��ʂ��Ă�������\n");
148 // exit( -1 );
149 }
150
151 // �G�N�X�|�[�g���̎擾
152 mpge_init = (me_init )GetProcAddress( hModule, "MPGE_initializeWork" );
153 mpge_setconf = (me_setconf )GetProcAddress( hModule, "MPGE_setConfigure" );
154 mpge_getconf = (me_getconf )GetProcAddress( hModule, "MPGE_getConfigure" );
155 mpge_detector = (me_detect )GetProcAddress( hModule, "MPGE_detectConfigure" );
156 mpge_processframe = (me_procframe )GetProcAddress( hModule, "MPGE_processFrame" );
157 mpge_close = (me_close )GetProcAddress( hModule, "MPGE_closeCoder" );
158 mpge_end = (me_end )GetProcAddress( hModule, "MPGE_endCoder" );
159 mpge_getver = (me_getver )GetProcAddress( hModule, "MPGE_getVersion" );
160 mpge_haveunit= (me_haveunit )GetProcAddress( hModule, "MPGE_getUnitStates" );
161 }
162
163 // ���ׂĂ̊������킩�m�F����
164 if( mpge_init && mpge_setconf && mpge_getconf &&
165 mpge_detector && mpge_processframe && mpge_end && mpge_getver && mpge_haveunit ){
166 MPGE_available = 1;
167 return (mpge_init)();
168 }
169
170 // �G���[
171 //fprintf( stderr, "DLL�̓��e�������ʂ��邱�Ƃ��o���܂���ł���\n");
172 FreeLibrary( hModule );
173 hModule = NULL;
174 MPGE_available = 0;
175 //exit( -1 );
176
177 return ME_NOERR;
178 }
179
MPGE_terminateWork(void)180 MERET MPGE_terminateWork(void) // �����I��
181 {
182 mpge_init = NULL;
183 mpge_setconf = NULL;
184 mpge_getconf = NULL;
185 mpge_detector = NULL;
186 mpge_processframe = NULL;
187 mpge_close = NULL;
188 mpge_end = NULL;
189 mpge_getver = NULL;
190 mpge_haveunit= NULL;
191 if(hModule)
192 FreeLibrary( hModule );
193 hModule = NULL;
194 MPGE_available = 0;
195
196 return ME_NOERR;
197 }
198
199
MPGE_setConfigure(UPARAM mode,UPARAM dwPara1,UPARAM dwPara2)200 MERET MPGE_setConfigure(UPARAM mode, UPARAM dwPara1, UPARAM dwPara2 )
201 {
202 if(!mpge_setconf)
203 return ME_INTERNALERROR;
204 return (mpge_setconf)( mode, dwPara1, dwPara2 );
205 }
206
MPGE_getConfigure(UPARAM mode,void * para1)207 MERET MPGE_getConfigure(UPARAM mode, void *para1 )
208 {
209 if(!mpge_getconf)
210 return ME_INTERNALERROR;
211 return (mpge_getconf)( mode, para1 );
212 }
213
MPGE_detectConfigure(void)214 MERET MPGE_detectConfigure(void)
215 {
216 if(!mpge_detector)
217 return ME_INTERNALERROR;
218 return (mpge_detector)();
219 }
220
MPGE_processFrame(void)221 MERET MPGE_processFrame(void)
222 {
223 if(!mpge_processframe)
224 return ME_INTERNALERROR;
225 return (mpge_processframe)();
226 }
227
MPGE_closeCoder(void)228 MERET MPGE_closeCoder(void)
229 {
230 if(!mpge_close)
231 return ME_INTERNALERROR;
232 return (mpge_close)();
233 }
234
MPGE_endCoder(void)235 MERET MPGE_endCoder(void)
236 {
237 MERET val;
238 if(!mpge_end)
239 return ME_INTERNALERROR;
240 val = (mpge_end)();
241 if( val == ME_NOERR ){
242 mpge_setconf = NULL;
243 mpge_getconf = NULL;
244 mpge_detector = NULL;
245 mpge_processframe = NULL;
246 mpge_close = NULL;
247 mpge_end = NULL;
248 mpge_getver = NULL;
249 mpge_haveunit= NULL;
250 FreeLibrary( hModule ); // DLL�J��
251 hModule = NULL;
252 MPGE_available = 0;
253 }
254 return val;
255 }
256
MPGE_getVersion(unsigned long * vercode,char * verstring)257 MERET MPGE_getVersion( unsigned long *vercode, char *verstring )
258 {
259 if(!mpge_getver)
260 return ME_INTERNALERROR;
261 return (mpge_getver)( vercode, verstring );
262 }
263
MPGE_getUnitStates(unsigned long * unit)264 MERET MPGE_getUnitStates( unsigned long *unit)
265 {
266 if(!mpge_haveunit)
267 return ME_INTERNALERROR;
268 return (mpge_haveunit)( unit );
269 }
270
gogo_dll_check(void)271 int gogo_dll_check(void)
272 {
273 HANDLE hDLL = NULL;
274 if(hModule)
275 return 1;
276 hDLL = LoadLibrary("gogo.dll");
277 if(hDLL){
278 FreeLibrary(hDLL);
279 return 1;
280 } else {
281 #define Key HKEY_CURRENT_USER
282 #define SubKey "Software\\MarineCat\\GOGO_DLL"
283 HKEY hKey;
284 DWORD dwType, dwKeySize;
285 LONG lResult;
286 static char *szName = "INSTPATH";
287 char szPathName[ _MAX_PATH + 8];
288 dwKeySize = sizeof( szPathName );
289 if( RegOpenKeyEx(Key,SubKey,0,KEY_ALL_ACCESS,&hKey ) == ERROR_SUCCESS ){
290 lResult = RegQueryValueEx(hKey,szName,0,&dwType,(BYTE *)szPathName,&dwKeySize);
291 RegCloseKey(hKey);
292 if( lResult == ERROR_SUCCESS && REG_SZ == dwType ){
293 hDLL = LoadLibrary( szPathName );
294 }
295 }
296 #undef Key
297 #undef SubKey
298 }
299 if(hDLL){
300 FreeLibrary(hDLL);
301 return 1;
302 }
303 return 0;
304 }
305
306 #endif /* AU_GOGO_DLL */
307