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 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865
|
/*
TiMidity++ -- MIDI to WAVE converter and player
Copyright (C) 1999-2004 Masanao Izumo <iz@onicos.co.jp>
Copyright (C) 1995 Tuukka Toivonen <tt@cgs.fi>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
w32g_syn.c: Written by Daisuke Aoki <dai@y7.net>
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include "interface.h"
#include <stdio.h>
#include <stdlib.h>
#include <process.h>
#include <stddef.h>
#include <windows.h>
#undef RC_NONE
#include <shlobj.h>
#if defined(__CYGWIN32__) || defined(__MINGW32__)
#ifndef HAVE_NEW_MMSYSTEM
#include <commdlg.h>
#ifndef TPM_TOPALIGN
#define TPM_TOPALIGN 0x0000L /* for old version of cygwin */
#endif
#define TIME_ONESHOT 0
#define TIME_PERIODIC 1
int WINAPI timeSetEvent(UINT uDelay, UINT uResolution,
void *fptc, DWORD dwUser, UINT fuEvent);
int WINAPI timeKillEvent(UINT uTimerID);
#endif
#else
#include <commctrl.h>
#endif /* __CYGWIN32__ */
#include <commctrl.h>
#ifndef NO_STRING_H
#include <string.h>
#else
#include <strings.h>
#endif
#include <shlobj.h>
#include <windowsx.h> /* There is no <windowsx.h> on CYGWIN.
* Edit_* and ListBox_* are defined in
* <windowsx.h>
*/
#ifdef TWSYNSRV
#include <winsvc.h>
//#include <lmcons.h>
#include <stdarg.h>
#endif
#include "timidity.h"
#include "common.h"
#include "instrum.h"
#include "playmidi.h"
#include "readmidi.h"
#include "output.h"
#include "controls.h"
#if defined(__CYGWIN32__) || defined(__MINGW32__)
#define WIN32GCC
WINAPI void InitCommonControls(void);
#endif
#include "w32g.h"
#include "w32g_utl.h"
#include "w32g_pref.h"
#include "w32g_res.h"
#ifdef IA_W32G_SYN
typedef struct w32g_syn_t_ {
UINT nid_uID;
#ifndef TWSYNSRV
HWND nid_hWnd;
HICON hIcon;
#endif
int argc;
char **argv;
HANDLE gui_hThread;
DWORD gui_dwThreadId;
HANDLE syn_hThread;
DWORD syn_dwThreadId;
// int syn_ThreadPriority;
HANDLE hMutex;
int volatile quit_state;
} w32g_syn_t;
static w32g_syn_t w32g_syn;
// eϐ (^^;;;
HINSTANCE hInst = NULL;
int PlayerLanguage = LANGUAGE_ENGLISH;
int IniFileAutoSave = 1;
char *IniFile;
char *ConfigFile;
char *PlaylistFile;
char *PlaylistHistoryFile;
char *MidiFileOpenDir;
char *ConfigFileOpenDir;
char *PlaylistFileOpenDir;
int SecondMode = 0;
BOOL PosSizeSave = TRUE;
int DocMaxSize;
char *DocFileExt;
int AutoloadPlaylist = 0;
int AutosavePlaylist = 0;
int SeachDirRecursive = 0;
int DocWndIndependent = 0;
int DocWndAutoPopup = 0;
int TraceGraphicFlag;
int PlayerThreadPriority;
int MidiPlayerThreadPriority;
int MainThreadPriority;
int GUIThreadPriority;
int TracerThreadPriority;
int WrdThreadPriority;
int SubWindowMax = 5;
int InitMinimizeFlag = 0;
int DebugWndStartFlag = 1;
int ConsoleWndStartFlag = 0;
int ListWndStartFlag = 0;
int TracerWndStartFlag = 0;
int DocWndStartFlag = 0;
int WrdWndStartFlag = 0;
int DebugWndFlag = 1;
int ConsoleWndFlag = 1;
int ListWndFlag = 1;
int TracerWndFlag = 0;
int DocWndFlag = 1;
int WrdWndFlag = 0;
int SoundSpecWndFlag = 0;
int WrdGraphicFlag;
int TraceGraphicFlag;
int w32g_auto_output_mode = 0;
char *w32g_output_dir = NULL;
extern void CmdLineToArgv(LPSTR lpCmdLine, int *argc, CHAR ***argv);
static int start_syn_thread ( void );
static void WINAPI syn_thread ( void );
#ifndef TWSYNSRV
// Task tray version here
static LRESULT CALLBACK SynWinProc ( HWND hwnd, UINT uMess, WPARAM wParam, LPARAM lParam );
static void VersionWnd(HWND hParentWnd);
static void TiMidityWnd(HWND hParentWnd);
static int w32g_syn_create_win ( void );
#define HAVE_SYN_CONSOLE
#define MYWM_NOTIFYICON (WM_USER+501)
#define MYWM_QUIT (WM_USER+502)
#define W32G_SYNWIN_CLASSNAME "TWSYNTH GUI"
#define W32G_SYN_TIP "TWSYNTH GUI"
// |bvAbvj[
#define IDM_NOTHING 100
#define IDM_QUIT 101
#define IDM_START 102
// #define IDM_STOP 103
#define IDM_SYSTEM_RESET 104
#define IDM_GM_SYSTEM_RESET 105
#define IDM_GS_SYSTEM_RESET 106
#define IDM_XG_SYSTEM_RESET 107
#define IDM_CHANGE_GM_SYSTEM 108
#define IDM_CHANGE_GS_SYSTEM 109
#define IDM_CHANGE_XG_SYSTEM 110
#define IDM_CHANGE_DEFAULT_SYSTEM 111
#define IDM_PREFERENCE 112
#define IDM_CONSOLE_WND 113
#define IDM_PROCESS_PRIORITY_LOWEST 131
#define IDM_PROCESS_PRIORITY_BELOW_NORMAL 132
#define IDM_PROCESS_PRIORITY_NORMAL 133
#define IDM_PROCESS_PRIORITY_ABOVE_NORMAL 134
#define IDM_PROCESS_PRIORITY_HIGHEST 135
#define IDM_PROCESS_PRIORITY_REALTIME 136
#define IDM_SYN_THREAD_PRIORITY_LOWEST 121
#define IDM_SYN_THREAD_PRIORITY_BELOW_NORMAL 122
#define IDM_SYN_THREAD_PRIORITY_NORMAL 123
#define IDM_SYN_THREAD_PRIORITY_ABOVE_NORMAL 124
#define IDM_SYN_THREAD_PRIORITY_HIGHEST 125
#define IDM_SYN_THREAD_PRIORITY_TIMECRITICAL 137
#define IDM_VERSION 126
#define IDM_TIMIDITY 127
#ifdef HAVE_SYN_CONSOLE
static HWND hConsoleWnd;
void InitConsoleWnd(HWND hParentWnd);
#endif // HAVE_SYN_CONSOLE
#else // !TWSYNSRV
// Windows service version here
#undef HAVE_SYN_CONSOLE
static SERVICE_STATUS_HANDLE serviceStatusHandle;
static DWORD currentServiceStatus;
static const char *serviceName = "Timidity";
static const char *serviceDescription = "Realtime synthesize midi message";
static const char *regKeyTwSynSrv = "SYSTEM\\CurrentControlSet\\Services\\Timidity";
static BOOL InstallService();
static BOOL UninstallService();
#endif // !TWSYNSRV
#define W32G_SYN_NID_UID 12301
#define W32G_MUTEX_NAME "TWSYNTH MUTEX"
#define W32G_SYN_MESSAGE_MAX 100
#define W32G_SYN_NONE 0
#define W32G_SYN_QUIT 10
#define W32G_SYN_START 11 // tԂֈڍs
#define W32G_SYN_STOP 12 // t~Ԃֈڍs
#define W32G_SYN_GS_SYSTEM_RESET 21
#define W32G_SYN_XG_SYSTEM_RESET 22
#define W32G_SYN_SYSTEM_RESET 23
#define W32G_SYN_GM_SYSTEM_RESET 24
#define W32G_SYN_CHANGE_GS_SYSTEM 25
#define W32G_SYN_CHANGE_XG_SYSTEM 26
#define W32G_SYN_CHANGE_GM_SYSTEM 27
#define W32G_SYN_CHANGE_DEFAULT_SYSTEM 28
typedef struct w32g_syn_message_t_ {
int cmd;
} w32g_syn_message_t;
static volatile enum { stop, run, quit, none } w32g_syn_status, w32g_syn_status_prev;
#ifndef MAX_PORT
#define MAX_PORT 4
#endif
int w32g_syn_id_port[MAX_PORT];
int w32g_syn_port_num = 2;
extern int win_main(int argc, char **argv);
extern int ctl_pass_playing_list2(int n, char *args[]);
extern void winplaymidi(void);
w32g_syn_message_t msg_loopbuf[W32G_SYN_MESSAGE_MAX];
int msg_loopbuf_start = -1;
int msg_loopbuf_end = -1;
extern int rtsyn_system_mode;
HANDLE msg_loopbuf_hMutex = NULL; // rp
int syn_AutoStart; // VZN
DWORD processPriority; // vZX̃vCIeB
DWORD syn_ThreadPriority; // VZXbh̃vCIeB
extern int volatile stream_max_compute; // play_event() compute_data() ŌvZő厞ԁB
static int w32g_syn_main ( void );
static int start_syn_thread ( void );
static void WINAPI syn_thread ( void );
static void terminate_syn_thread ( void );
static int wait_for_termination_of_syn_thread ( void );
int w32g_message_set ( int cmd );
int w32g_message_get ( w32g_syn_message_t *msg );
void w32g_syn_ctl_pass_playing_list ( int n_, char *args_[] );
int w32g_syn_do_before_pref_apply ( void );
int w32g_syn_do_after_pref_apply ( void );
/*
\
@CXbhFGUĨbZ[W[v
@VZTCU[XbhF
*/
int WINAPI
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
HANDLE hMutex;
int i;
// ̂ƂQdN͂łȂ悤ɂƂB
hMutex = OpenMutex ( 0, FALSE, W32G_MUTEX_NAME );
if ( hMutex != NULL ) {
CloseHandle ( hMutex );
return 0;
}
w32g_syn.hMutex = CreateMutex ( NULL, TRUE, W32G_MUTEX_NAME );
if ( w32g_syn.hMutex == NULL ) {
return 0;
}
CmdLineToArgv(lpCmdLine, &w32g_syn.argc, &w32g_syn.argv);
#ifdef TWSYNSRV
// Service install and uninstall handling
for (i = 1; i < w32g_syn.argc; i++)
{
if (stricmp(w32g_syn.argv[i], "/INSTALL") == 0)
{
InstallService();
ReleaseMutex ( w32g_syn.hMutex );
CloseHandle ( w32g_syn.hMutex );
return 0;
}
else if (stricmp(w32g_syn.argv[i], "/UNINSTALL") == 0)
{
UninstallService();
ReleaseMutex ( w32g_syn.hMutex );
CloseHandle ( w32g_syn.hMutex );
return 0;
}
}
#endif
// wrdt=wrdt_list[0];
hInst = hInstance;
w32g_syn.gui_hThread = GetCurrentThread();
w32g_syn.gui_dwThreadId = GetCurrentThreadId();
w32g_syn.quit_state = 0;
w32g_syn_main ();
ReleaseMutex ( w32g_syn.hMutex );
CloseHandle ( w32g_syn.hMutex );
return 0;
}
#ifndef TWSYNSRV
// Task tray version here
static int w32g_syn_create_win ( void )
{
WNDCLASSEX wndclass ;
wndclass.cbSize = sizeof(WNDCLASSEX);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = SynWinProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInst ;
wndclass.hIcon = w32g_syn.hIcon;
wndclass.hIconSm = w32g_syn.hIcon;
wndclass.hCursor = LoadCursor(0,IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH)(COLOR_SCROLLBAR + 1);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = W32G_SYNWIN_CLASSNAME;
RegisterClassEx(&wndclass);
w32g_syn.nid_hWnd = CreateWindowEx ( WS_EX_TOOLWINDOW, W32G_SYNWIN_CLASSNAME, 0,
WS_CLIPCHILDREN,
CW_USEDEFAULT,0, 10, 10,0,0,hInst,0 );
if ( w32g_syn.nid_hWnd == NULL ) {
return -1;
}
ShowWindow ( w32g_syn.nid_hWnd, SW_HIDE );
UpdateWindow ( w32g_syn.nid_hWnd ); // KvȂƎvǁB
return 0;
}
// return
// 0 : OK
// -1 : FATAL ERROR
static int w32g_syn_main ( void )
{
int i;
MSG msg;
InitCommonControls();
w32g_syn.nid_uID = W32G_SYN_NID_UID;
w32g_syn.nid_hWnd = NULL;
w32g_syn.hIcon = LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON_TIMIDITY), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
processPriority = NORMAL_PRIORITY_CLASS;
syn_ThreadPriority = THREAD_PRIORITY_NORMAL;
for ( i = 0; i <= MAX_PORT; i ++ ) {
w32g_syn_id_port[i] = i + 1;
}
if ( w32g_syn_create_win() ) {
MessageBox ( NULL, "Fatal Error", "ERROR", MB_OK );
return -1;
}
while( GetMessage(&msg,NULL,0,0) ){
if ( msg.message == MYWM_QUIT ) {
if ( w32g_syn.quit_state < 1 ) w32g_syn.quit_state = 1;
if ( hConsoleWnd != NULL ) {
DestroyWindow ( hConsoleWnd );
hConsoleWnd = NULL;
}
DestroyWindow ( w32g_syn.nid_hWnd );
w32g_syn.nid_hWnd = NULL;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
while ( w32g_syn.quit_state < 2 ) {
Sleep ( 300 );
}
return 0;
}
static VOID CALLBACK forced_exit ( HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime )
{
exit ( 0 );
}
// Add the icon into the status area of the task bar.
BOOL AddTasktrayIcon(HWND hwnd)
{
BOOL bRes;
NOTIFYICONDATA nid;
nid.cbSize = sizeof ( NOTIFYICONDATA );
nid.hWnd = w32g_syn.nid_hWnd = hwnd;
nid.uID = w32g_syn.nid_uID;
nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
nid.uCallbackMessage = MYWM_NOTIFYICON;
nid.hIcon = w32g_syn.hIcon;
strcpy ( nid.szTip, W32G_SYN_TIP );
bRes = Shell_NotifyIcon ( NIM_ADD, &nid );
return bRes;
}
// Delete the icon from the status area of the task bar.
void DeleteTasktrayIcon(HWND hwnd)
{
BOOL bRes;
NOTIFYICONDATA nid;
int i;
nid.cbSize = sizeof ( NOTIFYICONDATA );
nid.hWnd = w32g_syn.nid_hWnd;
nid.uID = w32g_syn.nid_uID;
for ( i = 1; i <= 10; i ++ ) {
bRes = Shell_NotifyIcon ( NIM_DELETE, &nid );
if ( bRes == TRUE )
break;
if ( i >= 10 ) {
MessageBox ( NULL, "Fatal Error", "ERROR", MB_OK );
}
}
}
static LRESULT CALLBACK
SynWinProc(HWND hwnd, UINT uMess, WPARAM wParam, LPARAM lParam)
{
static int have_popupmenu = 0;
switch (uMess) {
case WM_CREATE:
if ( AddTasktrayIcon(hwnd) == FALSE ) {
MessageBox ( NULL, "Fatal Error", "ERROR", MB_OK );
DestroyWindow ( hwnd );
PostQuitMessage ( 0 );
return -1;
}
start_syn_thread ();
break;
case WM_DESTROY:
{
int i;
terminate_syn_thread();
for ( i = 0; i < 4; i ++ ) {
if ( wait_for_termination_of_syn_thread() )
break;
}
}
DeleteTasktrayIcon(hwnd);
PostQuitMessage ( 0 );
break;
case MYWM_NOTIFYICON:
{
if ( (UINT)wParam == w32g_syn.nid_uID ) {
if ( (UINT)lParam == WM_RBUTTONDOWN || (UINT)lParam == WM_LBUTTONDOWN) {
int priority_flag[2][6];
POINT point;
HMENU hMenu, hMenuReset, hMenuChange, hMenuProcessPriority, hMenuSynPriority;
if ( have_popupmenu )
break;
have_popupmenu = 1;
// Process priority check
if ( processPriority == IDLE_PRIORITY_CLASS )
priority_flag[0][0] = MF_CHECKED;
else
priority_flag[0][0] = 0;
if ( processPriority == BELOW_NORMAL_PRIORITY_CLASS )
priority_flag[0][1] = MF_CHECKED;
else
priority_flag[0][1] = 0;
if ( processPriority == NORMAL_PRIORITY_CLASS )
priority_flag[0][2] = MF_CHECKED;
else
priority_flag[0][2] = 0;
if ( processPriority == ABOVE_NORMAL_PRIORITY_CLASS )
priority_flag[0][3] = MF_CHECKED;
else
priority_flag[0][3] = 0;
if ( processPriority == HIGH_PRIORITY_CLASS )
priority_flag[0][4] = MF_CHECKED;
else
priority_flag[0][4] = 0;
if ( processPriority == REALTIME_PRIORITY_CLASS )
priority_flag[0][5] = MF_CHECKED;
else
priority_flag[0][5] = 0;
// Thread priority check
if ( syn_ThreadPriority == THREAD_PRIORITY_LOWEST )
priority_flag[1][0] = MF_CHECKED;
else
priority_flag[1][0] = 0;
if ( syn_ThreadPriority == THREAD_PRIORITY_BELOW_NORMAL )
priority_flag[1][1] = MF_CHECKED;
else
priority_flag[1][1] = 0;
if ( syn_ThreadPriority == THREAD_PRIORITY_NORMAL )
priority_flag[1][2] = MF_CHECKED;
else
priority_flag[1][2] = 0;
if ( syn_ThreadPriority == THREAD_PRIORITY_ABOVE_NORMAL )
priority_flag[1][3] = MF_CHECKED;
else
priority_flag[1][3] = 0;
if ( syn_ThreadPriority == THREAD_PRIORITY_HIGHEST )
priority_flag[1][4] = MF_CHECKED;
else
priority_flag[1][4] = 0;
if ( syn_ThreadPriority == THREAD_PRIORITY_TIME_CRITICAL )
priority_flag[1][5] = MF_CHECKED;
else
priority_flag[1][5] = 0;
hMenu = CreatePopupMenu ();
hMenuReset = CreateMenu ();
hMenuChange = CreateMenu ();
hMenuProcessPriority = CreateMenu ();
hMenuSynPriority = CreateMenu ();
if (PlayerLanguage == LANGUAGE_JAPANESE) {
if ( w32g_syn_status == run ) {
AppendMenu ( hMenu, MF_STRING, IDM_STOP, "VZ~");
} else if ( w32g_syn_status == stop ) {
AppendMenu ( hMenu, MF_STRING, IDM_START, "VZJn");
} else if ( w32g_syn_status == quit ) {
AppendMenu ( hMenu, MF_STRING | MF_GRAYED, IDM_START, "Icc");
}
AppendMenu ( hMenu, MF_STRING, IDM_SYSTEM_RESET, "VXeZbg");
switch ( rtsyn_system_mode ) {
case GM_SYSTEM_MODE:
AppendMenu ( hMenuReset, MF_STRING | MF_CHECKED, IDM_GM_SYSTEM_RESET, "GM Zbg");
AppendMenu ( hMenuReset, MF_STRING, IDM_GS_SYSTEM_RESET, "GS Zbg");
AppendMenu ( hMenuReset, MF_STRING, IDM_XG_SYSTEM_RESET, "XG Zbg");
AppendMenu ( hMenuChange, MF_STRING | MF_CHECKED, IDM_CHANGE_GM_SYSTEM, "GM VXe֕ύX");
AppendMenu ( hMenuChange, MF_STRING, IDM_CHANGE_GS_SYSTEM, "GS VXe֕ύX");
AppendMenu ( hMenuChange, MF_STRING, IDM_CHANGE_XG_SYSTEM, "XG VXe֕ύX");
AppendMenu ( hMenuChange, MF_STRING, IDM_CHANGE_DEFAULT_SYSTEM, "ftHg̃VXe֕ύX");
break;
case GS_SYSTEM_MODE:
AppendMenu ( hMenuReset, MF_STRING, IDM_GM_SYSTEM_RESET, "GM Zbg");
AppendMenu ( hMenuReset, MF_STRING | MF_CHECKED, IDM_GS_SYSTEM_RESET, "GS Zbg");
AppendMenu ( hMenuReset, MF_STRING, IDM_XG_SYSTEM_RESET, "XG Zbg");
AppendMenu ( hMenuChange, MF_STRING, IDM_CHANGE_GM_SYSTEM, "GM VXe֕ύX");
AppendMenu ( hMenuChange, MF_STRING | MF_CHECKED, IDM_CHANGE_GS_SYSTEM, "GS VXe֕ύX");
AppendMenu ( hMenuChange, MF_STRING, IDM_CHANGE_XG_SYSTEM, "XG VXe֕ύX");
AppendMenu ( hMenuChange, MF_STRING, IDM_CHANGE_DEFAULT_SYSTEM, "ftHg̃VXe֕ύX");
break;
case XG_SYSTEM_MODE:
AppendMenu ( hMenuReset, MF_STRING, IDM_GM_SYSTEM_RESET, "GM Zbg");
AppendMenu ( hMenuReset, MF_STRING, IDM_GS_SYSTEM_RESET, "GS Zbg");
AppendMenu ( hMenuReset, MF_STRING | MF_CHECKED, IDM_XG_SYSTEM_RESET, "XG Zbg");
AppendMenu ( hMenuChange, MF_STRING, IDM_CHANGE_GM_SYSTEM, "GM VXe֕ύX");
AppendMenu ( hMenuChange, MF_STRING, IDM_CHANGE_GS_SYSTEM, "GS VXe֕ύX");
AppendMenu ( hMenuChange, MF_STRING | MF_CHECKED, IDM_CHANGE_XG_SYSTEM, "XG VXe֕ύX");
AppendMenu ( hMenuChange, MF_STRING, IDM_CHANGE_DEFAULT_SYSTEM, "ftHg̃VXe֕ύX");
break;
default:
case DEFAULT_SYSTEM_MODE:
AppendMenu ( hMenuReset, MF_STRING, IDM_GM_SYSTEM_RESET, "GM Zbg");
AppendMenu ( hMenuReset, MF_STRING, IDM_GS_SYSTEM_RESET, "GS Zbg");
AppendMenu ( hMenuReset, MF_STRING, IDM_XG_SYSTEM_RESET, "XG Zbg");
AppendMenu ( hMenuChange, MF_STRING, IDM_CHANGE_GM_SYSTEM, "GM VXe֕ύX");
AppendMenu ( hMenuChange, MF_STRING, IDM_CHANGE_GS_SYSTEM, "GS VXe֕ύX");
AppendMenu ( hMenuChange, MF_STRING, IDM_CHANGE_XG_SYSTEM, "XG VXe֕ύX");
AppendMenu ( hMenuChange, MF_STRING | MF_CHECKED, IDM_CHANGE_DEFAULT_SYSTEM, "ftHg̃VXe֕ύX");
break;
}
AppendMenu ( hMenuProcessPriority, MF_STRING | priority_flag[0][0], IDM_PROCESS_PRIORITY_LOWEST, "Ⴂ");
AppendMenu ( hMenuProcessPriority, MF_STRING | priority_flag[0][1], IDM_PROCESS_PRIORITY_BELOW_NORMAL, "Ⴂ");
AppendMenu ( hMenuProcessPriority, MF_STRING | priority_flag[0][2], IDM_PROCESS_PRIORITY_NORMAL, "");
AppendMenu ( hMenuProcessPriority, MF_STRING | priority_flag[0][3], IDM_PROCESS_PRIORITY_ABOVE_NORMAL, "");
AppendMenu ( hMenuProcessPriority, MF_STRING | priority_flag[0][4], IDM_PROCESS_PRIORITY_HIGHEST, "");
AppendMenu ( hMenuProcessPriority, MF_SEPARATOR, 0, 0 );
AppendMenu ( hMenuProcessPriority, MF_STRING | priority_flag[0][5], IDM_PROCESS_PRIORITY_REALTIME, "A^C");
AppendMenu ( hMenuSynPriority, MF_STRING | priority_flag[1][0], IDM_SYN_THREAD_PRIORITY_LOWEST, "Ⴂ");
AppendMenu ( hMenuSynPriority, MF_STRING | priority_flag[1][1], IDM_SYN_THREAD_PRIORITY_BELOW_NORMAL, "Ⴂ");
AppendMenu ( hMenuSynPriority, MF_STRING | priority_flag[1][2], IDM_SYN_THREAD_PRIORITY_NORMAL, "");
AppendMenu ( hMenuSynPriority, MF_STRING | priority_flag[1][3], IDM_SYN_THREAD_PRIORITY_ABOVE_NORMAL, "");
AppendMenu ( hMenuSynPriority, MF_STRING | priority_flag[1][4], IDM_SYN_THREAD_PRIORITY_HIGHEST, "");
AppendMenu ( hMenuSynPriority, MF_SEPARATOR, 0, 0 );
AppendMenu ( hMenuSynPriority, MF_STRING | priority_flag[1][5], IDM_SYN_THREAD_PRIORITY_TIMECRITICAL, "^CNeBJ");
AppendMenu ( hMenu, MF_SEPARATOR, 0, 0 );
AppendMenu ( hMenu, MF_POPUP, (UINT)hMenuReset, "eVXeZbg" );
AppendMenu ( hMenu, MF_POPUP, (UINT)hMenuChange, "̃VXe֕ύX" );
AppendMenu ( hMenu, MF_SEPARATOR, 0, 0 );
AppendMenu ( hMenu, MF_POPUP, (UINT)hMenuProcessPriority, "vZXvCIeBݒ" );
AppendMenu ( hMenu, MF_POPUP, (UINT)hMenuSynPriority, "VZXbhvCIeBݒ" );
AppendMenu ( hMenu, MF_SEPARATOR, 0, 0 );
AppendMenu ( hMenu, MF_STRING, IDM_PREFERENCE, "ݒ");
AppendMenu ( hMenu, MF_STRING, IDM_CONSOLE_WND, "R\[");
AppendMenu ( hMenu, MF_SEPARATOR, 0, 0 );
AppendMenu ( hMenu, MF_STRING, IDM_VERSION, "o[W");
AppendMenu ( hMenu, MF_STRING, IDM_TIMIDITY, "TiMidity++ ɂ");
AppendMenu ( hMenu, MF_SEPARATOR, 0, 0 );
AppendMenu ( hMenu, MF_STRING, IDM_QUIT, "I");
} else {
if ( w32g_syn_status == run ) {
AppendMenu ( hMenu, MF_STRING, IDM_STOP, "Stop synthesizer");
} else if ( w32g_syn_status == stop ) {
AppendMenu ( hMenu, MF_STRING, IDM_START, "Start synthesizer");
} else if ( w32g_syn_status == quit ) {
AppendMenu ( hMenu, MF_STRING | MF_GRAYED, IDM_START, "Quitting...");
}
AppendMenu ( hMenu, MF_STRING, IDM_SYSTEM_RESET, "System Reset");
switch ( rtsyn_system_mode ) {
case GM_SYSTEM_MODE:
AppendMenu ( hMenuReset, MF_STRING | MF_CHECKED, IDM_GM_SYSTEM_RESET, "GM Reset");
AppendMenu ( hMenuReset, MF_STRING, IDM_GS_SYSTEM_RESET, "GS Reset");
AppendMenu ( hMenuReset, MF_STRING, IDM_XG_SYSTEM_RESET, "XG Reset");
AppendMenu ( hMenuChange, MF_STRING | MF_CHECKED, IDM_CHANGE_GM_SYSTEM, "Change GM system");
AppendMenu ( hMenuChange, MF_STRING, IDM_CHANGE_GS_SYSTEM, "Change GS system");
AppendMenu ( hMenuChange, MF_STRING, IDM_CHANGE_XG_SYSTEM, "Change XG system");
AppendMenu ( hMenuChange, MF_STRING, IDM_CHANGE_DEFAULT_SYSTEM, "Change default system");
break;
case GS_SYSTEM_MODE:
AppendMenu ( hMenuReset, MF_STRING, IDM_GM_SYSTEM_RESET, "GM Reset");
AppendMenu ( hMenuReset, MF_STRING | MF_CHECKED, IDM_GS_SYSTEM_RESET, "GS Reset");
AppendMenu ( hMenuReset, MF_STRING, IDM_XG_SYSTEM_RESET, "XG Reset");
AppendMenu ( hMenuChange, MF_STRING, IDM_CHANGE_GM_SYSTEM, "Change GM system");
AppendMenu ( hMenuChange, MF_STRING | MF_CHECKED, IDM_CHANGE_GS_SYSTEM, "Change GS system");
AppendMenu ( hMenuChange, MF_STRING, IDM_CHANGE_XG_SYSTEM, "Change XG system");
AppendMenu ( hMenuChange, MF_STRING, IDM_CHANGE_DEFAULT_SYSTEM, "Change default system");
break;
case XG_SYSTEM_MODE:
AppendMenu ( hMenuReset, MF_STRING, IDM_GM_SYSTEM_RESET, "GM Reset");
AppendMenu ( hMenuReset, MF_STRING, IDM_GS_SYSTEM_RESET, "GS Reset");
AppendMenu ( hMenuReset, MF_STRING | MF_CHECKED, IDM_XG_SYSTEM_RESET, "XG Reset");
AppendMenu ( hMenuChange, MF_STRING, IDM_CHANGE_GM_SYSTEM, "Change GM system");
AppendMenu ( hMenuChange, MF_STRING, IDM_CHANGE_GS_SYSTEM, "Change GS system");
AppendMenu ( hMenuChange, MF_STRING | MF_CHECKED, IDM_CHANGE_XG_SYSTEM, "Change XG system");
AppendMenu ( hMenuChange, MF_STRING, IDM_CHANGE_DEFAULT_SYSTEM, "Change default system");
break;
default:
case DEFAULT_SYSTEM_MODE:
AppendMenu ( hMenuReset, MF_STRING, IDM_GM_SYSTEM_RESET, "GM Reset");
AppendMenu ( hMenuReset, MF_STRING, IDM_GS_SYSTEM_RESET, "GS Reset");
AppendMenu ( hMenuReset, MF_STRING, IDM_XG_SYSTEM_RESET, "XG Reset");
AppendMenu ( hMenuChange, MF_STRING, IDM_CHANGE_GM_SYSTEM, "Change GM system");
AppendMenu ( hMenuChange, MF_STRING, IDM_CHANGE_GS_SYSTEM, "Change GS system");
AppendMenu ( hMenuChange, MF_STRING, IDM_CHANGE_XG_SYSTEM, "Change XG system");
AppendMenu ( hMenuChange, MF_STRING | MF_CHECKED, IDM_CHANGE_DEFAULT_SYSTEM, "Change default system");
break;
}
AppendMenu ( hMenuProcessPriority, MF_STRING | priority_flag[0][0], IDM_PROCESS_PRIORITY_LOWEST, "lowest");
AppendMenu ( hMenuProcessPriority, MF_STRING | priority_flag[0][1], IDM_PROCESS_PRIORITY_BELOW_NORMAL, "below normal");
AppendMenu ( hMenuProcessPriority, MF_STRING | priority_flag[0][2], IDM_PROCESS_PRIORITY_NORMAL, "normal");
AppendMenu ( hMenuProcessPriority, MF_STRING | priority_flag[0][3], IDM_PROCESS_PRIORITY_ABOVE_NORMAL, "above normal");
AppendMenu ( hMenuProcessPriority, MF_STRING | priority_flag[0][4], IDM_PROCESS_PRIORITY_HIGHEST, "highest");
AppendMenu ( hMenuProcessPriority, MF_SEPARATOR, 0, 0 );
AppendMenu ( hMenuProcessPriority, MF_STRING | priority_flag[0][5], IDM_PROCESS_PRIORITY_REALTIME, "realtime");
AppendMenu ( hMenuSynPriority, MF_STRING | priority_flag[1][0], IDM_SYN_THREAD_PRIORITY_LOWEST, "lowest");
AppendMenu ( hMenuSynPriority, MF_STRING | priority_flag[1][1], IDM_SYN_THREAD_PRIORITY_BELOW_NORMAL, "below normal");
AppendMenu ( hMenuSynPriority, MF_STRING | priority_flag[1][2], IDM_SYN_THREAD_PRIORITY_NORMAL, "normal");
AppendMenu ( hMenuSynPriority, MF_STRING | priority_flag[1][3], IDM_SYN_THREAD_PRIORITY_ABOVE_NORMAL, "above normal");
AppendMenu ( hMenuSynPriority, MF_STRING | priority_flag[1][4], IDM_SYN_THREAD_PRIORITY_HIGHEST, "highest");
AppendMenu ( hMenuSynPriority, MF_SEPARATOR, 0, 0 );
AppendMenu ( hMenuSynPriority, MF_STRING | priority_flag[1][5], IDM_SYN_THREAD_PRIORITY_TIMECRITICAL, "time critical");
AppendMenu ( hMenu, MF_SEPARATOR, 0, 0 );
AppendMenu ( hMenu, MF_POPUP, (UINT)hMenuReset, "Specific system reset" );
AppendMenu ( hMenu, MF_POPUP, (UINT)hMenuChange, "Change Specific system" );
AppendMenu ( hMenu, MF_SEPARATOR, 0, 0 );
AppendMenu ( hMenu, MF_POPUP, (UINT)hMenuProcessPriority, "Change process priority" );
AppendMenu ( hMenu, MF_POPUP, (UINT)hMenuSynPriority, "Change synthesizer thread priority" );
AppendMenu ( hMenu, MF_SEPARATOR, 0, 0 );
AppendMenu ( hMenu, MF_STRING, IDM_PREFERENCE, "Preference");
AppendMenu ( hMenu, MF_STRING, IDM_CONSOLE_WND, "Console");
AppendMenu ( hMenu, MF_SEPARATOR, 0, 0 );
AppendMenu ( hMenu, MF_STRING, IDM_VERSION, "Version Info");
AppendMenu ( hMenu, MF_STRING, IDM_TIMIDITY, "About TiMidity++");
AppendMenu ( hMenu, MF_SEPARATOR, 0, 0 );
AppendMenu ( hMenu, MF_STRING, IDM_QUIT, "Quit");
}
GetCursorPos ( &point );
// |bvAbvj[Ə邽߂̑B
// http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q135788& Q
#if 0 // Win 98/2000 ȍ~pH
{
DWORD dwThreadID = GetWindowThreadProcessId ( hwnd, NULL );
if ( dwThreadID != w32g_syn.gui_dwThreadId ) {
AttachThreadInput ( w32g_syn.gui_dwThreadId, dwThreadID, TRUE );
SetForegroundWindow ( hwnd );
AttachThreadInput ( w32g_syn.gui_dwThreadId, dwThreadID, FALSE );
} else {
SetForegroundWindow ( hwnd );
}
}
#else // ł炵H
SetForegroundWindow ( hwnd );
#endif
TrackPopupMenu ( hMenu, TPM_TOPALIGN | TPM_LEFTALIGN,
point.x, point.y, 0, hwnd, NULL );
PostMessage ( hwnd, WM_NULL, 0, 0 ); // |bvAbvj[̃eNjbN炵B
DestroyMenu ( hMenu );
have_popupmenu = 0;
return 0;
}
}
}
break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDM_QUIT:
#if 1/* I */
SetTimer ( NULL, 0, 20000, forced_exit );
#endif
w32g_message_set (W32G_SYN_QUIT);
break;
case IDM_START:
w32g_message_set (W32G_SYN_START);
break;
case IDM_STOP:
w32g_message_set (W32G_SYN_STOP);
break;
case IDM_SYSTEM_RESET:
w32g_message_set (W32G_SYN_SYSTEM_RESET);
break;
case IDM_GM_SYSTEM_RESET:
w32g_message_set (W32G_SYN_GM_SYSTEM_RESET);
break;
case IDM_GS_SYSTEM_RESET:
w32g_message_set (W32G_SYN_GS_SYSTEM_RESET);
break;
case IDM_XG_SYSTEM_RESET:
w32g_message_set (W32G_SYN_XG_SYSTEM_RESET);
break;
case IDM_CHANGE_GM_SYSTEM:
w32g_message_set (W32G_SYN_CHANGE_GM_SYSTEM);
break;
case IDM_CHANGE_GS_SYSTEM:
w32g_message_set (W32G_SYN_CHANGE_GS_SYSTEM);
break;
case IDM_CHANGE_XG_SYSTEM:
w32g_message_set (W32G_SYN_CHANGE_XG_SYSTEM);
break;
case IDM_CHANGE_DEFAULT_SYSTEM:
w32g_message_set (W32G_SYN_CHANGE_DEFAULT_SYSTEM);
break;
case IDM_PREFERENCE:
PrefWndCreate ( w32g_syn.nid_hWnd );
break;
case IDM_VERSION:
VersionWnd ( w32g_syn.nid_hWnd );
break;
case IDM_TIMIDITY:
TiMidityWnd ( w32g_syn.nid_hWnd );
break;
case IDM_PROCESS_PRIORITY_LOWEST:
processPriority = IDLE_PRIORITY_CLASS;
if ( w32g_syn_status == run ) {
SetPriorityClass(GetCurrentProcess(), processPriority);
}
break;
case IDM_PROCESS_PRIORITY_BELOW_NORMAL:
processPriority = BELOW_NORMAL_PRIORITY_CLASS;
if ( w32g_syn_status == run ) {
SetPriorityClass(GetCurrentProcess(), processPriority);
}
break;
case IDM_PROCESS_PRIORITY_NORMAL:
processPriority = NORMAL_PRIORITY_CLASS;
if ( w32g_syn_status == run ) {
SetPriorityClass(GetCurrentProcess(), processPriority);
}
break;
case IDM_PROCESS_PRIORITY_ABOVE_NORMAL:
processPriority = ABOVE_NORMAL_PRIORITY_CLASS;
if ( w32g_syn_status == run ) {
SetPriorityClass(GetCurrentProcess(), processPriority);
}
break;
case IDM_PROCESS_PRIORITY_HIGHEST:
processPriority = HIGH_PRIORITY_CLASS;
if ( w32g_syn_status == run ) {
SetPriorityClass(GetCurrentProcess(), processPriority);
}
break;
case IDM_PROCESS_PRIORITY_REALTIME:
processPriority = REALTIME_PRIORITY_CLASS;
if ( w32g_syn_status == run ) {
SetPriorityClass(GetCurrentProcess(), processPriority);
}
break;
case IDM_SYN_THREAD_PRIORITY_LOWEST:
syn_ThreadPriority = THREAD_PRIORITY_LOWEST;
if ( w32g_syn_status == run ) {
SetThreadPriority ( w32g_syn.syn_hThread, syn_ThreadPriority );
}
break;
case IDM_SYN_THREAD_PRIORITY_BELOW_NORMAL:
syn_ThreadPriority = THREAD_PRIORITY_BELOW_NORMAL;
if ( w32g_syn_status == run ) {
SetThreadPriority ( w32g_syn.syn_hThread, syn_ThreadPriority );
}
break;
case IDM_SYN_THREAD_PRIORITY_NORMAL:
syn_ThreadPriority = THREAD_PRIORITY_NORMAL;
if ( w32g_syn_status == run ) {
SetThreadPriority ( w32g_syn.syn_hThread, syn_ThreadPriority );
}
break;
case IDM_SYN_THREAD_PRIORITY_ABOVE_NORMAL:
syn_ThreadPriority = THREAD_PRIORITY_ABOVE_NORMAL;
if ( w32g_syn_status == run ) {
SetThreadPriority ( w32g_syn.syn_hThread, syn_ThreadPriority );
}
break;
case IDM_SYN_THREAD_PRIORITY_HIGHEST:
syn_ThreadPriority = THREAD_PRIORITY_HIGHEST;
if ( w32g_syn_status == run ) {
SetThreadPriority ( w32g_syn.syn_hThread, syn_ThreadPriority );
}
break;
case IDM_SYN_THREAD_PRIORITY_TIMECRITICAL:
syn_ThreadPriority = THREAD_PRIORITY_TIME_CRITICAL;
if ( w32g_syn_status == run ) {
SetThreadPriority ( w32g_syn.syn_hThread, syn_ThreadPriority );
}
break;
#ifdef HAVE_SYN_CONSOLE
case IDM_CONSOLE_WND:
if ( hConsoleWnd == NULL ) {
InitConsoleWnd ( w32g_syn.nid_hWnd );
}
if ( IsWindowVisible ( hConsoleWnd ) )
ShowWindow ( hConsoleWnd, SW_HIDE );
else
ShowWindow ( hConsoleWnd, SW_SHOW );
break;
#endif
default:
break;
}
break;
default:
if (uMess == RegisterWindowMessage("TaskbarCreated")) {
AddTasktrayIcon(hwnd);
return 0;
}
return DefWindowProc ( hwnd, uMess, wParam, lParam );
}
return 0L;
}
static int volatile syn_thread_started = 0;
static int start_syn_thread ( void )
{
w32g_syn.syn_hThread = crt_beginthreadex ( NULL, 0,
(LPTHREAD_START_ROUTINE) syn_thread,
NULL, 0, & w32g_syn.syn_dwThreadId );
if ( w32g_syn.syn_hThread == NULL ) {
return -1;
}
for (;;) {
if ( syn_thread_started == 1 )
break;
if ( syn_thread_started == 2 )
return -1;
Sleep ( 200 );
}
if ( syn_thread_started == 2 )
return -1;
return 0;
}
static void WINAPI syn_thread ( void )
{
syn_thread_started = 1;
win_main ( w32g_syn.argc, w32g_syn.argv );
syn_thread_started = 2;
}
static void terminate_syn_thread ( void )
{
w32g_message_set ( W32G_SYN_QUIT );
}
static int wait_for_termination_of_syn_thread ( void )
{
int i;
int ok = 0;
for ( i = 0; i < 10; i++ ) {
if ( WaitForSingleObject ( w32g_syn.syn_hThread, 200 ) == WAIT_TIMEOUT ) {
w32g_message_set ( W32G_SYN_QUIT );
} else {
ok = 1;
break;
}
}
return ok;
}
#else // !TWSYNSRV
// Windows service version here
// To debug output (Require attached debugger)
static void OutputString(char *format, ...)
{
char temp[256];
va_list va;
va_start(va, format);
vsnprintf(temp, sizeof(temp), format, va);
OutputDebugString(temp);
va_end(va);
}
void PutsConsoleWnd(char *str)
{
OutputString("%s", str);
}
// To MessageBox Window (Require grant access windowstation)
static void OutputWindow(char *format, ...)
{
char temp[256];
va_list va;
va_start(va, format);
vsnprintf(temp, sizeof(temp), format, va);
MessageBox(NULL, temp, serviceName, MB_OK | MB_ICONEXCLAMATION);
va_end(va);
}
static void OutputLastError(char *message)
{
LPVOID buffer;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&buffer, 0, NULL);
OutputDebugString(message);
OutputDebugString(" : ");
OutputDebugString(buffer);
OutputDebugString("\n");
LocalFree(buffer);
}
static void OutputWindowLastError(char *message)
{
LPVOID buffer;
char *temp;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&buffer, 0, NULL);
temp = (char *)malloc(strlen((const char *)buffer) + strlen(message) + 10);
sprintf(temp, "%s : %s\n", message, buffer);
MessageBox(NULL, temp, serviceName, MB_OK | MB_ICONEXCLAMATION);
free(temp);
LocalFree(buffer);
}
// Report service status to service control manager
static BOOL ReportStatusToSCM(DWORD newServiceStatus, DWORD checkPoint, DWORD waitHint,
DWORD win32ExitCode, DWORD serviceSpecificExitCode)
{
BOOL result;
SERVICE_STATUS serviceStatus;
serviceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
currentServiceStatus = newServiceStatus;
serviceStatus.dwCurrentState = newServiceStatus;
serviceStatus.dwCheckPoint = checkPoint;
serviceStatus.dwWaitHint = waitHint;
serviceStatus.dwWin32ExitCode = win32ExitCode;
serviceStatus.dwServiceSpecificExitCode = serviceSpecificExitCode;
if (newServiceStatus == SERVICE_START_PENDING)
{
serviceStatus.dwControlsAccepted = 0;
}
else
{
serviceStatus.dwControlsAccepted =
SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_PAUSE_CONTINUE | SERVICE_ACCEPT_PARAMCHANGE;
}
result = SetServiceStatus(serviceStatusHandle, &serviceStatus);
if (result == FALSE)
{
OutputLastError("ReportStatusToSCM() == FALSE");
}
return result;
}
// Report service status to service control manager (Alternate version)
static BOOL PingStatusToSCM(DWORD checkPoint, DWORD waitHint)
{
return ReportStatusToSCM(currentServiceStatus, checkPoint, waitHint, NO_ERROR, NO_ERROR);
}
// Service control message from management interface (Callback from SCM)
static void WINAPI ServiceCtrlHandler(DWORD state)
{
switch (state)
{
case SERVICE_CONTROL_STOP:
ReportStatusToSCM(SERVICE_STOP_PENDING, 1, 0, NO_ERROR, NO_ERROR);
w32g_message_set(W32G_SYN_QUIT);
break;
case SERVICE_CONTROL_PAUSE:
ReportStatusToSCM(SERVICE_PAUSE_PENDING, 1, 0, NO_ERROR, NO_ERROR);
w32g_message_set(W32G_SYN_STOP);
ReportStatusToSCM(SERVICE_PAUSED, 1, 0, NO_ERROR, NO_ERROR);
break;
case SERVICE_CONTROL_CONTINUE:
ReportStatusToSCM(SERVICE_CONTINUE_PENDING, 1, 0, NO_ERROR, NO_ERROR);
w32g_message_set(W32G_SYN_START);
ReportStatusToSCM(SERVICE_RUNNING, 1, 0, NO_ERROR, NO_ERROR);
break;
case SERVICE_CONTROL_INTERROGATE:
OutputString("ServiceCtrlHandler(), SERVICE_CONTROL_INTERROGATE : oops.\n");
break;
case SERVICE_CONTROL_SHUTDOWN:
OutputString("ServiceCtrlHandler(), SERVICE_CONTROL_SHUTDOWN : oops.\n");
break;
default:
OutputString("ServiceCtrlHandler(), default handler (%d) : oops.\n", state);
break;
}
PingStatusToSCM(0, 0);
}
// Register service control handler
static SERVICE_STATUS_HANDLE RegisterCtrlHandler()
{
SERVICE_STATUS_HANDLE ssh = RegisterServiceCtrlHandler(
serviceName, ServiceCtrlHandler);
if (ssh == 0)
{
OutputLastError("RegisterServiceCtrlHandler() == 0");
return NULL;
}
return ssh;
}
// Service entry function (Callback from SCM)
static void WINAPI ServiceMain(DWORD argc, LPTSTR *argv)
{
serviceStatusHandle = RegisterCtrlHandler();
ReportStatusToSCM(SERVICE_RUNNING, 1, 0, NO_ERROR, NO_ERROR);
w32g_syn.syn_hThread = GetCurrentThread();
win_main(w32g_syn.argc, w32g_syn.argv);
ReportStatusToSCM(SERVICE_STOPPED, 1, 0, NO_ERROR, NO_ERROR);
}
// return
// 0 : OK
// -1 : FATAL ERROR
static int w32g_syn_main ( void )
{
int i;
BOOL result;
SERVICE_TABLE_ENTRY ServiceTable[2];
w32g_syn.nid_uID = W32G_SYN_NID_UID;
processPriority = NORMAL_PRIORITY_CLASS;
syn_ThreadPriority = THREAD_PRIORITY_NORMAL;
for ( i = 0; i <= MAX_PORT; i ++ ) {
w32g_syn_id_port[i] = i + 1;
}
ServiceTable[0].lpServiceName = (LPSTR)serviceName;
ServiceTable[0].lpServiceProc = ServiceMain;
ServiceTable[1].lpServiceName = 0;
ServiceTable[1].lpServiceProc = 0;
result = StartServiceCtrlDispatcher(ServiceTable);
if (result == FALSE)
{
#if 0
// OutputLastError("StartServiceCtrlDispatcher() == FALSE");
OutputWindowLastError("StartServiceCtrlDispatcher() == FALSE");
#else
ServiceMain(0, 0);
#endif
return -1;
}
return 0;
}
// Service installer
static BOOL InstallService()
{
char twSynSrvPath[_MAX_PATH], serviceLongName[40];
SC_HANDLE scm, sv;
HKEY srvKey;
GetModuleFileName(NULL, twSynSrvPath, _MAX_PATH);
scm = OpenSCManager(
NULL, SERVICES_ACTIVE_DATABASE, SC_MANAGER_CREATE_SERVICE);
if (scm == NULL)
{
OutputWindowLastError("OpenSCManager() == NULL");
return FALSE;
}
strcpy(serviceLongName, serviceName);
strcat(serviceLongName, (strcmp(timidity_version, "current"))
? " version " : " ");
strcat(serviceLongName, timidity_version);
sv = CreateService(scm, serviceName, serviceLongName,
0, SERVICE_WIN32_OWN_PROCESS, SERVICE_DEMAND_START,
SERVICE_ERROR_IGNORE, twSynSrvPath, NULL, NULL, NULL, NULL, NULL);
if (sv == NULL)
{
OutputWindowLastError("CreateService() == NULL");
CloseServiceHandle(scm);
return FALSE;
}
CloseServiceHandle(sv);
CloseServiceHandle(scm);
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, regKeyTwSynSrv,
0, KEY_WRITE | KEY_READ, &srvKey) == ERROR_SUCCESS)
{
if (RegSetValueEx(srvKey, "Description", NULL, REG_SZ,
(const BYTE *)serviceDescription, strlen(serviceDescription)) != ERROR_SUCCESS)
{
OutputWindowLastError("RegSetValueEx() != ERROR_SUCCESS");
RegCloseKey(srvKey);
return FALSE;
}
RegCloseKey(srvKey);
}
OutputWindow("%s : Service install successful.", serviceLongName);
return TRUE;
}
// Service uninstaller
static BOOL UninstallService()
{
char serviceLongName[40];
SC_HANDLE scm, sv;
scm = OpenSCManager(
NULL, SERVICES_ACTIVE_DATABASE, SC_MANAGER_CONNECT);
if (scm == NULL)
{
OutputWindowLastError("OpenSCManager() == NULL");
return FALSE;
}
sv = OpenService(scm, serviceName, DELETE | SERVICE_STOP | SERVICE_QUERY_STATUS);
if (sv == NULL)
{
OutputWindowLastError("OpenService() == NULL");
CloseServiceHandle(scm);
return FALSE;
}
if (DeleteService(sv) == FALSE)
{
OutputWindowLastError("DeleteService() == FALSE");
CloseServiceHandle(sv);
CloseServiceHandle(scm);
return FALSE;
}
CloseServiceHandle(sv);
CloseServiceHandle(scm);
strcpy(serviceLongName, serviceName);
strcat(serviceLongName, (strcmp(timidity_version, "current"))
? " version " : " ");
strcat(serviceLongName, timidity_version);
OutputWindow("%s : Service uninstall successful.", serviceLongName);
return TRUE;
}
#endif // !TWSYNSRV
// ϒɂ\cc
// 0: A1: ljłȂ
int w32g_message_set ( int cmd )
{
int res = 0;
if ( msg_loopbuf_hMutex == NULL ) {
msg_loopbuf_hMutex = CreateMutex ( NULL, TRUE, NULL );
} else {
WaitForSingleObject ( msg_loopbuf_hMutex, INFINITE );
}
if ( cmd == W32G_SYN_QUIT || cmd == W32G_SYN_START || cmd == W32G_SYN_STOP ) { // D悷郁bZ[WB
msg_loopbuf_start = 0;
msg_loopbuf_end = 0;
msg_loopbuf[msg_loopbuf_end].cmd = cmd;
ReleaseMutex ( msg_loopbuf_hMutex );
return res;
} else if ( cmd != W32G_SYN_NONE ) {
if ( msg_loopbuf_end < 0 ) {
msg_loopbuf_start = 0;
msg_loopbuf_end = 0;
} else if ( msg_loopbuf_start <= msg_loopbuf_end ) {
if ( msg_loopbuf_end < W32G_SYN_MESSAGE_MAX - 1)
msg_loopbuf_end ++;
else
res = 1;
} else if ( msg_loopbuf_end < msg_loopbuf_start - 1 ) {
msg_loopbuf_end ++;
} else {
res = 1;
}
if ( res == 0 ) {
msg_loopbuf[msg_loopbuf_end].cmd = cmd;
}
}
ReleaseMutex ( msg_loopbuf_hMutex );
Sleep ( 100 );
return res;
}
int w32g_message_get ( w32g_syn_message_t *msg )
{
int have_msg = 0;
if ( msg_loopbuf_hMutex == NULL ) {
msg_loopbuf_hMutex = CreateMutex ( NULL, TRUE, NULL );
} else {
WaitForSingleObject ( msg_loopbuf_hMutex, INFINITE );
}
if ( msg_loopbuf_start >= 0 ) {
memcpy ( msg, &msg_loopbuf[msg_loopbuf_start], sizeof ( w32g_syn_message_t ) );
have_msg = 1;
msg_loopbuf_start ++;
if ( msg_loopbuf_end < msg_loopbuf_start ) {
msg_loopbuf_start = msg_loopbuf_end = -1;
} else if ( msg_loopbuf_start >= W32G_SYN_MESSAGE_MAX ) {
msg_loopbuf_start = 0;
}
}
ReleaseMutex ( msg_loopbuf_hMutex );
return have_msg;
}
extern int seq_quit;
extern void rtsyn_play_event(MidiEvent *);
void w32g_syn_doit(void)
{
w32g_syn_message_t msg;
MidiEvent ev;
DWORD sleep_time;
while(seq_quit==0) {
int have_msg = 0;
sleep_time = 0;
have_msg = w32g_message_get ( &msg );
if ( have_msg ) {
switch ( msg.cmd ) {
case W32G_SYN_QUIT:
seq_quit=~0;
w32g_syn_status = quit;
sleep_time = 100;
break;
case W32G_SYN_START:
seq_quit=~0;
w32g_syn_status = run;
sleep_time = 100;
break;
case W32G_SYN_STOP:
seq_quit=~0;
w32g_syn_status = stop;
sleep_time = 100;
break;
case W32G_SYN_GM_SYSTEM_RESET:
rtsyn_server_reset();
ev.type=ME_RESET;
ev.a=GM_SYSTEM_MODE;
rtsyn_play_event(&ev);
sleep_time = 100;
break;
case W32G_SYN_GS_SYSTEM_RESET:
rtsyn_server_reset();
ev.type=ME_RESET;
ev.a=GS_SYSTEM_MODE;
rtsyn_play_event(&ev);
sleep_time = 100;
break;
case W32G_SYN_XG_SYSTEM_RESET:
rtsyn_server_reset();
ev.type=ME_RESET;
ev.a=XG_SYSTEM_MODE;
rtsyn_play_event(&ev);
sleep_time = 100;
break;
case W32G_SYN_SYSTEM_RESET:
rtsyn_server_reset();
ev.type=ME_RESET;
ev.a=rtsyn_system_mode;
rtsyn_play_event(&ev);
sleep_time = 100;
break;
case W32G_SYN_CHANGE_GM_SYSTEM:
rtsyn_system_mode=GM_SYSTEM_MODE;
rtsyn_server_reset();
ev.type=ME_RESET;
ev.a=GM_SYSTEM_MODE;
rtsyn_play_event(&ev);
change_system_mode(rtsyn_system_mode);
sleep_time = 100;
break;
case W32G_SYN_CHANGE_GS_SYSTEM:
rtsyn_system_mode=GS_SYSTEM_MODE;
rtsyn_server_reset();
ev.type=ME_RESET;
ev.a=GS_SYSTEM_MODE;
rtsyn_play_event(&ev);
change_system_mode(rtsyn_system_mode);
sleep_time = 100;
break;
case W32G_SYN_CHANGE_XG_SYSTEM:
rtsyn_system_mode=XG_SYSTEM_MODE;
rtsyn_server_reset();
ev.type=ME_RESET;
ev.a=XG_SYSTEM_MODE;
rtsyn_play_event(&ev);
change_system_mode(rtsyn_system_mode);
sleep_time = 100;
break;
case W32G_SYN_CHANGE_DEFAULT_SYSTEM:
rtsyn_system_mode=DEFAULT_SYSTEM_MODE;
rtsyn_server_reset();
ev.type=ME_RESET;
ev.a=GS_SYSTEM_MODE;
rtsyn_play_event(&ev);
change_system_mode(rtsyn_system_mode);
sleep_time = 100;
break;
default:
break;
}
}
winplaymidi();
Sleep ( sleep_time );
}
}
void w32g_syn_ctl_pass_playing_list ( int n_, char *args_[] )
{
int i;
#ifndef TWSYNSRV
w32g_syn_status = syn_AutoStart ? run : stop;
#else
w32g_syn_status = run;
#endif
for (;;) {
int breakflag = 0;
switch ( w32g_syn_status ) {
default:
case quit:
breakflag = 1;
break;
case run:
{
int result;
char args_[MAX_PORT][10];
char *args[MAX_PORT];
if ( w32g_syn_port_num <= 0 ) {
w32g_syn_status = stop;
break;
} else if ( w32g_syn_port_num > MAX_PORT ) {
w32g_syn_port_num = MAX_PORT;
}
for ( i = 0; i < MAX_PORT; i ++ ) {
args[i] = args_[i];
sprintf ( args[i], "%d", w32g_syn_id_port[i] );
}
SetPriorityClass ( GetCurrentProcess(), processPriority );
SetThreadPriority ( w32g_syn.syn_hThread, syn_ThreadPriority );
result = ctl_pass_playing_list2 ( w32g_syn_port_num, args );
SetPriorityClass ( GetCurrentProcess(), NORMAL_PRIORITY_CLASS );
SetThreadPriority ( w32g_syn.syn_hThread, THREAD_PRIORITY_NORMAL );
if ( result == 2 ) {
w32g_syn_status = stop;
}
}
break;
case stop:
{
w32g_syn_message_t msg;
if ( w32g_message_get ( &msg ) ) {
if ( msg.cmd == W32G_SYN_START ) {
w32g_syn_status = run;
break;
} else {
if ( msg.cmd == W32G_SYN_QUIT ) {
w32g_syn_status = quit;
break;
}
}
}
Sleep ( 500 );
}
break;
}
if ( breakflag )
break;
}
#ifndef TWSYNSRV
while ( w32g_syn.quit_state < 1 ) {
PostThreadMessage ( w32g_syn.gui_dwThreadId, MYWM_QUIT, 0, 0 );
Sleep ( 300 );
}
#endif
if ( w32g_syn.quit_state < 2 ) w32g_syn.quit_state = 2;
}
int w32g_syn_do_before_pref_apply ( void )
{
w32g_syn_status_prev = none;
for (;;) {
if ( w32g_syn_status == quit )
return -1;
if ( msg_loopbuf_hMutex == NULL ) {
msg_loopbuf_hMutex = CreateMutex ( NULL, TRUE, NULL );
} else {
WaitForSingleObject ( msg_loopbuf_hMutex, INFINITE );
}
if ( w32g_syn_status_prev == none )
w32g_syn_status_prev = w32g_syn_status;
if ( w32g_syn_status == stop ) {
return 0;
}
ReleaseMutex ( msg_loopbuf_hMutex );
w32g_message_set ( W32G_SYN_STOP );
Sleep ( 100 );
}
}
int w32g_syn_do_after_pref_apply ( void )
{
ReleaseMutex ( msg_loopbuf_hMutex );
if ( w32g_syn_status_prev == run ) {
w32g_message_set ( W32G_SYN_START );
Sleep ( 100 );
}
return 0;
}
#ifdef HAVE_SYN_CONSOLE
// ****************************************************************************
// Edit Ctl.
void VprintfEditCtlWnd(HWND hwnd, char *fmt, va_list argList)
{
char buffer[BUFSIZ], out[BUFSIZ];
char *in;
int i;
if(!IsWindow(hwnd))
return;
vsnprintf(buffer, sizeof(buffer), fmt, argList);
in = buffer;
i = 0;
for(;;){
if(*in == '\0' || i>sizeof(out)-3){
out[i] = '\0';
break;
}
if(*in=='\n'){
out[i] = 13;
out[i+1] = 10;
in++;
i += 2;
continue;
}
out[i] = *in;
in++;
i++;
}
Edit_SetSel(hwnd,-1,-1);
Edit_ReplaceSel(hwnd,out);
}
void PrintfEditCtlWnd(HWND hwnd, char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
VprintfEditCtlWnd(hwnd,fmt,ap);
va_end(ap);
}
#if 1
void PutsEditCtlWnd(HWND hwnd, char *str)
{
char *in = str;
int i;
char out[BUFSIZ];
i = 0;
for(;;){
if(*in == '\0' || i>sizeof(out)-3){
out[i] = '\0';
break;
}
if(*in=='\n'){
out[i] = 13;
out[i+1] = 10;
in++;
i += 2;
continue;
}
out[i] = *in;
in++;
i++;
}
if(IsWindow(hwnd)){
Edit_SetSel(hwnd,-1,-1);
Edit_ReplaceSel(hwnd,out);
}
}
#else
void PutsEditCtlWnd(HWND hwnd, char *str)
{
if(!IsWindow(hwnd))
return;
PrintfEditCtlWnd(hwnd,"%s",str);
}
#endif
void ClearEditCtlWnd(HWND hwnd)
{
char pszVoid[]="";
if(!IsWindow(hwnd))
return;
if(IsWindow(hwnd)){
// Edit_SetSel(hwnd,0,-1);
Edit_SetSel(hwnd,-1,-1);
}
Edit_SetText(hwnd,pszVoid);
}
static void VersionWnd(HWND hParentWnd)
{
char VersionText[2024];
sprintf(VersionText,
"TiMidity++ %s%s" NLS NLS
"TiMidity-0.2i by Tuukka Toivonen <tt@cgs.fi>." NLS
"TiMidity Win32 version by Davide Moretti <dave@rimini.com>." NLS
"TiMidity Windows 95 port by Nicolas Witczak." NLS
"Twsynth by Keishi Suenaga <s_keishi@mutt.freemail.ne.jp>." NLS
"Twsynth GUI by Daisuke Aoki <dai@y7.net>." NLS
" Japanese menu, dialog, etc by Saito <timidity@flashmail.com>." NLS
"TiMidity++ by Masanao Izumo <mo@goice.co.jp>." NLS
,(strcmp(timidity_version, "current")) ? "version " : "", timidity_version);
MessageBox(hParentWnd, VersionText, "Version", MB_OK);
}
static void TiMidityWnd(HWND hParentWnd)
{
char TiMidityText[2024];
sprintf(TiMidityText,
" TiMidity++ %s%s -- MIDI to WAVE converter and player" NLS
" Copyright (C) 1999-2002 Masanao Izumo <mo@goice.co.jp>" NLS
" Copyright (C) 1995 Tuukka Toivonen <tt@cgs.fi>" NLS
NLS
" Win32 version by Davide Moretti <dmoretti@iper.net>" NLS
" GUI by Daisuke Aoki <dai@y7.net>." NLS
" Modified by Masanao Izumo <mo@goice.co.jp>." NLS
NLS
" This program is free software; you can redistribute it and/or modify" NLS
" it under the terms of the GNU General Public License as published by" NLS
" the Free Software Foundation; either version 2 of the License, or" NLS
" (at your option) any later version." NLS
NLS
" This program is distributed in the hope that it will be useful," NLS
" but WITHOUT ANY WARRANTY; without even the implied warranty of"NLS
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the" NLS
" GNU General Public License for more details." NLS
NLS
" You should have received a copy of the GNU General Public License" NLS
" along with this program; if not, write to the Free Software" NLS
" Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA" NLS
,
(strcmp(timidity_version, "current")) ? "version " : "", timidity_version
);
MessageBox(hParentWnd, TiMidityText, "TiMidity", MB_OK);
}
// ***************************************************************************
//
// Console Window
//
// ***************************************************************************
// ---------------------------------------------------------------------------
// variables
static int ConsoleWndMaxSize = 64 * 1024;
static HFONT hFontConsoleWnd = NULL;
// ---------------------------------------------------------------------------
// prototypes of functions
static BOOL CALLBACK ConsoleWndProc(HWND hwnd, UINT uMess, WPARAM wParam, LPARAM lParam);
static void ConsoleWndAllUpdate(void);
static void ConsoleWndVerbosityUpdate(void);
static void ConsoleWndVerbosityApply(void);
static void ConsoleWndValidUpdate(void);
static void ConsoleWndValidApply(void);
static void ConsoleWndVerbosityApplyIncDec(int num);
static int ConsoleWndInfoReset(HWND hwnd);
static int ConsoleWndInfoApply(void);
void ClearConsoleWnd(void);
// ---------------------------------------------------------------------------
// Global Functions
// Initialization
void InitConsoleWnd(HWND hParentWnd)
{
if (hConsoleWnd != NULL) {
DestroyWindow(hConsoleWnd);
hConsoleWnd = NULL;
}
switch(PlayerLanguage){
case LANGUAGE_ENGLISH:
hConsoleWnd = CreateDialog
(hInst,MAKEINTRESOURCE(IDD_DIALOG_CONSOLE_EN),hParentWnd,ConsoleWndProc);
break;
default:
case LANGUAGE_JAPANESE:
hConsoleWnd = CreateDialog
(hInst,MAKEINTRESOURCE(IDD_DIALOG_CONSOLE),hParentWnd,ConsoleWndProc);
break;
}
ShowWindow(hConsoleWnd,SW_HIDE);
UpdateWindow(hConsoleWnd);
ConsoleWndVerbosityApplyIncDec(0);
CheckDlgButton(hConsoleWnd, IDC_CHECKBOX_VALID, ConsoleWndFlag);
Edit_LimitText(GetDlgItem(hConsoleWnd,IDC_EDIT), ConsoleWndMaxSize);
}
// Window Procedure
static BOOL CALLBACK
ConsoleWndProc(HWND hwnd, UINT uMess, WPARAM wParam, LPARAM lParam)
{
switch (uMess){
case WM_INITDIALOG:
PutsConsoleWnd("Console Window\n");
ConsoleWndAllUpdate();
return FALSE;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDCLOSE:
ShowWindow(hwnd, SW_HIDE);
break;
case IDCLEAR:
ClearConsoleWnd();
break;
case IDC_CHECKBOX_VALID:
ConsoleWndValidApply();
break;
case IDC_BUTTON_VERBOSITY:
ConsoleWndVerbosityApply();
break;
case IDC_BUTTON_INC:
ConsoleWndVerbosityApplyIncDec(1);
break;
case IDC_BUTTON_DEC:
ConsoleWndVerbosityApplyIncDec(-1);
break;
default:
break;
}
switch (HIWORD(wParam)) {
case EN_ERRSPACE:
ClearConsoleWnd();
PutsConsoleWnd("### EN_ERRSPACE -> Clear! ###\n");
break;
default:
break;
}
break;
case WM_SIZE:
ConsoleWndAllUpdate();
return FALSE;
case WM_MOVE:
break;
// See PreDispatchMessage() in w32g2_main.c
case WM_SYSKEYDOWN:
case WM_KEYDOWN:
{
int nVirtKey = (int)wParam;
switch(nVirtKey){
case VK_ESCAPE:
SendMessage(hwnd,WM_CLOSE,0,0);
break;
}
}
break;
case WM_DESTROY:
break;
case WM_CLOSE:
ShowWindow(hConsoleWnd, SW_HIDE);
break;
case WM_SETFOCUS:
HideCaret(hwnd);
break;
case WM_KILLFOCUS:
ShowCaret(hwnd);
break;
default:
return FALSE;
}
return FALSE;
}
// puts()
void PutsConsoleWnd(char *str)
{
HWND hwnd;
if(!IsWindow(hConsoleWnd) || !ConsoleWndFlag)
return;
hwnd = GetDlgItem(hConsoleWnd,IDC_EDIT);
PutsEditCtlWnd(hwnd,str);
}
// printf()
void PrintfConsoleWnd(char *fmt, ...)
{
HWND hwnd;
va_list ap;
if(!IsWindow(hConsoleWnd) || !ConsoleWndFlag)
return;
hwnd = GetDlgItem(hConsoleWnd,IDC_EDIT);
va_start(ap, fmt);
VprintfEditCtlWnd(hwnd,fmt,ap);
va_end(ap);
}
// Clear
void ClearConsoleWnd(void)
{
HWND hwnd;
if(!IsWindow(hConsoleWnd))
return;
hwnd = GetDlgItem(hConsoleWnd,IDC_EDIT);
ClearEditCtlWnd(hwnd);
}
// ---------------------------------------------------------------------------
// Static Functions
static void ConsoleWndAllUpdate(void)
{
ConsoleWndVerbosityUpdate();
ConsoleWndValidUpdate();
Edit_LimitText(GetDlgItem(hConsoleWnd,IDC_EDIT_VERBOSITY),3);
Edit_LimitText(GetDlgItem(hConsoleWnd,IDC_EDIT),ConsoleWndMaxSize);
}
static void ConsoleWndValidUpdate(void)
{
if(ConsoleWndFlag)
CheckDlgButton(hConsoleWnd, IDC_CHECKBOX_VALID, 1);
else
CheckDlgButton(hConsoleWnd, IDC_CHECKBOX_VALID, 0);
}
static void ConsoleWndValidApply(void)
{
if(IsDlgButtonChecked(hConsoleWnd,IDC_CHECKBOX_VALID))
ConsoleWndFlag = 1;
else
ConsoleWndFlag = 0;
}
static void ConsoleWndVerbosityUpdate(void)
{
SetDlgItemInt(hConsoleWnd,IDC_EDIT_VERBOSITY,(UINT)ctl->verbosity, TRUE);
}
static void ConsoleWndVerbosityApply(void)
{
char buffer[64];
HWND hwnd;
hwnd = GetDlgItem(hConsoleWnd,IDC_EDIT_VERBOSITY);
if(!IsWindow(hConsoleWnd)) return;
if(Edit_GetText(hwnd,buffer,60)<=0) return;
ctl->verbosity = atoi(buffer);
ConsoleWndVerbosityUpdate();
}
static void ConsoleWndVerbosityApplyIncDec(int num)
{
if(!IsWindow(hConsoleWnd)) return;
ctl->verbosity += num;
RANGE(ctl->verbosity, -1, 4);
ConsoleWndVerbosityUpdate();
}
#endif // HAVE_SYN_CONSOLE
#endif // IA_W32G_SYN
|