OSDN Git Service

Enable SJIS support of GCC
[timidity41/timidity41.git] / timdrvsetup / timdrvsetup.c
1
2
3
4 #include "timidity.c"
5
6 #include <tchar.h>
7 #include "w32g.h"
8 #include "w32g_res.h"
9 #include "w32g_utl.h"
10 #include "w32g_pref.h"
11
12
13 // \83G\83\89\81[\89ñ\94ð\97p (w32g_c.c, w32g_i.c, w32g_ut2.c \93\99\82Ì\91ã\91Ö
14 int PlayerLanguage = LANGUAGE_JAPANESE; //LANGUAGE_ENGLISH;
15 int IniFileAutoSave = 1;
16 char *IniFile;
17 char *ConfigFile;
18 char *PlaylistFile;
19 char *PlaylistHistoryFile;
20 char *MidiFileOpenDir;
21 char *ConfigFileOpenDir;
22 char *PlaylistFileOpenDir;
23 int SecondMode = 0;
24 BOOL PosSizeSave = TRUE;
25 int DocMaxSize;
26 char *DocFileExt;
27 int AutoloadPlaylist = 0;
28 int AutosavePlaylist = 0;
29 int SeachDirRecursive = 0;
30 int DocWndIndependent = 0;
31 int DocWndAutoPopup = 0;
32 int TraceGraphicFlag;
33 int PlayerThreadPriority;
34 int MidiPlayerThreadPriority;
35 int MainThreadPriority;
36 int GUIThreadPriority;
37 int TracerThreadPriority;
38 int WrdThreadPriority;
39 int SubWindowMax = 6;
40 int InitMinimizeFlag = 0;
41 int main_panel_update_time = 10;
42 int DebugWndStartFlag = 1;
43 int ConsoleWndStartFlag = 0;
44 int ListWndStartFlag = 0;
45 int TracerWndStartFlag = 0;
46 int DocWndStartFlag = 0;
47 int WrdWndStartFlag = 0;
48 int SoundSpecWndStartFlag = 0;
49 int DebugWndFlag = 1;
50 int ConsoleWndFlag = 1;
51 int ListWndFlag = 1;
52 int TracerWndFlag = 0;
53 int DocWndFlag = 1;
54 int WrdWndFlag = 0;
55 int SoundSpecWndFlag = 0;
56 int WrdGraphicFlag;
57 int TraceGraphicFlag;
58 char *w32g_output_dir = NULL;
59 int w32g_auto_output_mode = 0;
60 int w32g_lock_open_file = 0;
61 WRDTracer w32g_wrdt_mode;
62 int playlist_max = 1;
63 int playlist_max_ini = 1;
64 int ConsoleClearFlag = 0;
65
66 extern char *opt_reduce_voice_threshold;
67 extern char *opt_reduce_quality_threshold;
68 extern char *opt_reduce_polyphony_threshold;
69
70
71
72 // HWND
73 HWND hMainWnd = 0;
74 HWND hDebugWnd = 0;
75 HWND hConsoleWnd = 0;
76 HWND hTracerWnd = 0;
77 HWND hDocWnd = 0;
78 HWND hListWnd = 0;
79 HWND hWrdWnd = 0;
80 HWND hSoundSpecWnd = 0;
81 HWND hDebugEditWnd = 0;
82 HWND hDocEditWnd = 0;
83 HWND hUrlWnd = 0;
84 // Process.
85 HANDLE hProcess = 0;
86 // Main Thread.
87 HANDLE hMainThread = 0;
88 HANDLE hPlayerThread = 0;
89 HANDLE hMainThreadInfo = 0;
90 DWORD dwMainThreadID = 0;
91
92 void TracerWndApplyQuietChannel(ChannelBitMask quietchannels_){}
93 void w32g_restart(void){}
94 void w32g_send_rc(int rc, ptr_size_t value){}
95 void w32g_i_init(void){}
96 void w32g_ext_control_main_thread(int rc, ptr_size_t value){}
97
98 // Control funcitons
99 static int ctl_open(int using_stdin, int using_stdout){}
100 static void ctl_close(void){}
101 static int ctl_pass_playing_list(int number_of_files, char *list_of_files[]){}
102 static void ctl_event(CtlEvent *e){}
103 static int ctl_read(ptr_size_t *valp){}
104 static int cmsg(int type, int verbosity_level, char *fmt, ...){}
105 #define ctl w32gui_control_mode
106 #define CTL_STATUS_UPDATE -98
107 ControlMode ctl=
108 {
109     "Win32 GUI interface", 'w',
110     "w32gui",
111     1,1,0,
112     CTLF_AUTOSTART | CTLF_DRAG_START,
113     ctl_open,
114     ctl_close,
115     ctl_pass_playing_list,
116     ctl_read,
117     NULL,
118     cmsg,
119     ctl_event
120 };
121
122
123 // \82±\82±\82©\82çsetup\82Ì\83\81\83C\83\93\95\94\95ª
124
125 char IniPath[FILEPATH_MAX] = "";
126
127
128 // w32_utl.c \82Å\8eg\97p
129 void get_ini_path(char *ini)
130 {
131         if(ini)
132                 strcpy(ini, (const char *)&IniPath);
133 }
134
135 // timidity_start_initialize()
136 void config_gui_start_initialize(void)
137 {
138         int i;
139     static int drums[] = DEFAULT_DRUMCHANNELS;
140     static int is_first = 1;
141
142 #if defined(__FreeBSD__) && !defined(__alpha__)
143     fp_except_t fpexp;
144 #elif defined(__NetBSD__) || defined(__OpenBSD__)
145     fp_except fpexp;
146 #endif
147 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
148     fpexp = fpgetmask();
149     fpsetmask(fpexp & ~(FP_X_INV|FP_X_DZ));
150 #endif
151     if(!output_text_code)
152                 output_text_code = safe_strdup(OUTPUT_TEXT_CODE);
153     if(!opt_aq_max_buff)
154                 opt_aq_max_buff = safe_strdup("5.0");
155     if(!opt_aq_fill_buff)
156                 opt_aq_fill_buff = safe_strdup("100%"); 
157     if(!opt_reduce_voice_threshold)
158                 opt_reduce_voice_threshold = safe_strdup("75%");
159     if(!opt_reduce_quality_threshold)
160                 opt_reduce_quality_threshold = safe_strdup("99%");
161     if(!opt_reduce_polyphony_threshold)
162                 opt_reduce_polyphony_threshold = safe_strdup("85%");
163
164     /* Check the byte order */
165     i = 1;
166 #ifdef LITTLE_ENDIAN
167     if(*(char *)&i != 1)
168 #else
169     if(*(char *)&i == 1)
170 #endif
171     {
172                 fprintf(stderr, "Byte order is miss configured.\n");
173                 exit(1);
174     }
175     for(i = 0; i < MAX_CHANNELS; i++)
176                 memset(&(channel[i]), 0, sizeof(Channel));
177     CLEAR_CHANNELMASK(quietchannels);
178     CLEAR_CHANNELMASK(default_drumchannels);
179     for(i = 0; drums[i] > 0; i++)
180                 SET_CHANNELMASK(default_drumchannels, drums[i] - 1);
181 #if MAX_CHANNELS > 16
182     for(i = 16; i < MAX_CHANNELS; i++)
183                 if(IS_SET_CHANNELMASK(default_drumchannels, i & 0xF))
184                         SET_CHANNELMASK(default_drumchannels, i);
185 #endif
186     if(program_name == NULL)
187                 program_name = "TiMidity";
188     uudecode_unquote_html = 1;
189     for(i = 0; i < MAX_CHANNELS; i++){
190                 default_program[i] = DEFAULT_PROGRAM;
191                 special_program[i] = -1;
192                 memset(channel[i].drums, 0, sizeof(channel[i].drums));
193     }
194     if(play_mode == NULL)
195                 play_mode = &null_play_mode;
196 }
197
198 // void timidity_init_player()  
199 void config_gui_init_player(void)       
200 {
201  //   initialize_resampler_coeffs();
202     /* Allocate voice[] */
203  //   free_voices();
204  //   safe_free(voice);
205  //   voice = (Voice*) safe_calloc(max_voices, sizeof(Voice));
206         //memset(voice, 0, sizeof(voice));
207     /* Set play mode parameters */
208     if(opt_output_rate != 0)
209                 play_mode->rate = opt_output_rate;
210     else if(play_mode->rate == 0)
211                 play_mode->rate = DEFAULT_RATE;
212     /* save defaults */
213     COPY_CHANNELMASK(drumchannels, default_drumchannels);
214     COPY_CHANNELMASK(drumchannel_mask, default_drumchannel_mask);
215     if(opt_buffer_fragments != -1)
216     {
217                 if(play_mode->flag & PF_BUFF_FRAGM_OPT)
218                         play_mode->extra_param[0] = opt_buffer_fragments;
219     }
220         else
221                 opt_buffer_fragments = 64;
222     if(opt_audio_buffer_bits != -1)
223         audio_buffer_bits = opt_audio_buffer_bits;
224     else
225         opt_audio_buffer_bits = audio_buffer_bits;
226
227     if(opt_compute_buffer_bits != -128)
228         compute_buffer_bits = opt_compute_buffer_bits;
229     else
230         opt_compute_buffer_bits = compute_buffer_bits;
231         init_output(); // div_playmode_rate
232         init_playmidi();
233 }
234
235 // main()
236 void config_gui_main(void)
237 {
238     int err = 0;
239         timdrvOverrideSFSettingLoad();
240 #if defined(VST_LOADER_ENABLE)
241         if (hVSTHost == NULL) {         
242                 // ini\82Ì\83f\83B\83\8c\83N\83g\83\8a\82É\82 \82é timvstwrap.dll
243                 int i, last = 0;
244                 char WrapPath[FILEPATH_MAX] = "";
245                 for(i = 0; i < FILEPATH_MAX; i++){
246                         if(IniPath[i] == '\0')
247                                 break;
248                         else if(IniPath[i] == '\\')
249                                 last = i;
250                 }
251                 if(last){
252                         int j = 0;
253                         for(i = 0; i < last; i++){
254                                 WrapPath[j++] = IniPath[i];
255                         }
256                         WrapPath[j] = '\0';
257 #ifdef _WIN64
258                         strcat(WrapPath, "\\timvstwrap_x64.dll\0");
259 #else
260                         strcat(WrapPath, "\\timvstwrap.dll\0");
261 #endif
262                 }
263                 if(WrapPath[0] != 0)
264                         hVSTHost = LoadLibrary(WrapPath);
265                 if (hVSTHost == NULL){
266 #ifdef _WIN64
267                         hVSTHost = LoadLibrary("timvstwrap_x64.dll");
268 #else
269                         hVSTHost = LoadLibrary("timvstwrap.dll");
270 #endif
271                 }
272                 if (hVSTHost != NULL) {
273                         ((vst_open)GetProcAddress(hVSTHost, "vstOpen"))();
274                 }
275         }
276 #endif  
277         // timidity_start_initialize()
278         config_gui_start_initialize();
279     timidity_post_load_configuration();
280         config_gui_init_player();
281 }
282
283 // main() end
284 void config_gui_main_close(void)
285 {
286         int i;
287         
288         safe_free(play_mode->name);
289         play_mode->name = NULL;
290 #ifdef SUPPORT_SOCKET
291         safe_free(url_user_agent);
292         url_user_agent = NULL;
293         safe_free(url_http_proxy_host);
294         url_http_proxy_host = NULL;
295         safe_free(url_ftp_proxy_host);
296         url_ftp_proxy_host = NULL;
297         safe_free(user_mailaddr);
298         user_mailaddr = NULL;
299 #endif
300 #ifdef IA_DYNAMIC
301         safe_free(dynamic_lib_root);
302         dynamic_lib_root = NULL;
303 #endif
304         safe_free(pcm_alternate_file);
305         pcm_alternate_file = NULL;
306         safe_free(opt_output_name);
307         opt_output_name = NULL;
308         safe_free(opt_aq_max_buff);
309         opt_aq_max_buff = NULL;
310         safe_free(opt_aq_fill_buff);
311         opt_aq_fill_buff = NULL;
312         safe_free(opt_reduce_voice_threshold);
313         opt_reduce_voice_threshold = NULL;
314         safe_free(opt_reduce_quality_threshold);
315         opt_reduce_quality_threshold = NULL;
316         safe_free(opt_reduce_polyphony_threshold);
317         opt_reduce_polyphony_threshold = NULL;
318         safe_free(output_text_code);
319         output_text_code = NULL;
320         safe_free(wrdt_open_opts);
321         wrdt_open_opts = NULL;
322         free_soft_queue();
323         free_audio_bucket();
324         free_instruments(0);
325         free_soundfonts();
326         free_cache_data();
327         free_freq_data();
328         free_wrd();
329         free_readmidi();
330         free_playmidi();
331         free_mix_c();
332         free_global_mblock();
333         tmdy_free_config();
334         //free_reverb_buffer();
335         free_effect_buffers();
336 #ifdef INT_SYNTH
337         free_int_synth();
338 #endif // INT_SYNTH
339         free_voices();
340         uninitialize_resampler_coeffs();
341         for (i = 0; i < MAX_CHANNELS; i++)
342                 free_drum_effect(i);
343 #ifdef VST_LOADER_ENABLE
344         if (hVSTHost != NULL) {
345                 ((vst_close)GetProcAddress(hVSTHost,"vstClose"))();
346                 FreeLibrary(hVSTHost);
347                 hVSTHost = NULL;
348         }
349 #endif
350 }
351
352 HINSTANCE hInst = NULL;
353 HWND hConfigWnd = NULL;
354
355 void set_config_hwnd(HWND hwnd)
356 {
357         if(hwnd)
358                 hConfigWnd = hwnd;
359 }
360
361 // Create Window
362 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
363 {
364         HICON *hIcon;
365         
366 #if defined(TIMIDITY_LEAK_CHECK)
367         _CrtSetDbgFlag(CRTDEBUGFLAGS);
368 #endif  
369         hInst = hInstance;
370         hIcon = (HICON *)LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON_TIMIDITY), IMAGE_ICON, 16, 16, 0);
371         if ( hConfigWnd != NULL ) {
372                 DestroyWindow ( hConfigWnd );
373                 hConfigWnd = NULL;
374         }       
375         // Create Window
376         PrefWndCreate(NULL, 0); // set hConfigWnd       
377         if (hIcon!=NULL)
378                 SendMessage(hConfigWnd, WM_SETICON,FALSE, (LPARAM)hIcon);
379         {  // Set the title of the main window again.
380                 char buffer[256];
381                 SendMessage( hConfigWnd, WM_GETTEXT, (WPARAM)255, (LPARAM)buffer);
382                 SendMessage( hConfigWnd, WM_SETTEXT, (WPARAM)0, (LPARAM)buffer);
383         }
384         if (!hConfigWnd)
385                 return FALSE;
386         ShowWindow(hConfigWnd, nCmdShow);
387         UpdateWindow(hConfigWnd);
388         return TRUE;
389 }
390
391 int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
392 {
393         static int init_flg = 0;
394         MSG msg;
395         HACCEL hAccelTable;
396         
397         if(init_flg)
398                 return FALSE;
399         init_flg = 1;
400         // ini_path     
401         {               
402                 char buffer[FILEPATH_MAX] = {0};
403                 GetWindowsDirectory(buffer, FILEPATH_MAX - 1);
404                 if (IS_PATH_SEP(buffer[strlen(buffer) - 1]))
405                         buffer[strlen(buffer) - 1] = 0;
406                 strlcat(buffer, "\\", FILEPATH_MAX);
407                 strlcat(buffer, "timdrv_soundfont.ini", FILEPATH_MAX);          
408                 strncpy(IniPath, buffer, FILEPATH_MAX);
409         }
410         if (!InitInstance (hInstance, nCmdShow)) // Create Window
411                 return FALSE;
412         hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_CONFIG_GUI));     
413         while (GetMessage(&msg, NULL, 0, 0)){ // message loop
414                 if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)){
415                         TranslateMessage(&msg);
416                         DispatchMessage(&msg);
417                 }
418         }
419         return (int) msg.wParam;
420 }
421
422