diff options
Diffstat (limited to 'apps/plugins/pdbox/PDa/src/s_main.c')
-rw-r--r-- | apps/plugins/pdbox/PDa/src/s_main.c | 837 |
1 files changed, 0 insertions, 837 deletions
diff --git a/apps/plugins/pdbox/PDa/src/s_main.c b/apps/plugins/pdbox/PDa/src/s_main.c index 84f4cfbbc2..b77f804e9f 100644 --- a/apps/plugins/pdbox/PDa/src/s_main.c +++ b/apps/plugins/pdbox/PDa/src/s_main.c | |||
@@ -836,841 +836,4 @@ static void sys_addreferencepath(void) | |||
836 | { | 836 | { |
837 | char sbuf[MAXPDSTRING]; | 837 | char sbuf[MAXPDSTRING]; |
838 | } | 838 | } |
839 | /* Copyright (c) 1997-1999 Miller Puckette and others. | ||
840 | * For information on usage and redistribution, and for a DISCLAIMER OF ALL | ||
841 | * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ | ||
842 | |||
843 | /* IOhannes : | ||
844 | * hacked the code to add advanced multidevice-support | ||
845 | * 1311:forum::für::umläute:2001 | ||
846 | */ | ||
847 | |||
848 | char pd_version[] = "Pd version 0.37.4\n"; | ||
849 | char pd_compiletime[] = __TIME__; | ||
850 | char pd_compiledate[] = __DATE__; | ||
851 | |||
852 | #include "m_pd.h" | ||
853 | #include "m_imp.h" | ||
854 | #include "s_stuff.h" | ||
855 | #include <sys/types.h> | ||
856 | #include <sys/stat.h> | ||
857 | #include <limits.h> | ||
858 | #include <string.h> | ||
859 | #include <stdio.h> | ||
860 | #include <fcntl.h> | ||
861 | #include <stdlib.h> | ||
862 | |||
863 | #ifdef UNIX | ||
864 | #include <unistd.h> | ||
865 | #endif | ||
866 | #ifdef MSW | ||
867 | #include <io.h> | ||
868 | #include <windows.h> | ||
869 | #include <winbase.h> | ||
870 | #endif | ||
871 | |||
872 | void pd_init(void); | ||
873 | int sys_argparse(int argc, char **argv); | ||
874 | void sys_findprogdir(char *progname); | ||
875 | int sys_startgui(const char *guipath); | ||
876 | int sys_rcfile(void); | ||
877 | int m_scheduler(void); | ||
878 | void sys_addhelppath(char *p); | ||
879 | void alsa_adddev(char *name); | ||
880 | |||
881 | int sys_debuglevel; | ||
882 | int sys_verbose; | ||
883 | int sys_noloadbang; | ||
884 | int sys_nogui; | ||
885 | int sys_stdin = 0; | ||
886 | char *sys_guicmd; | ||
887 | t_symbol *sys_libdir; | ||
888 | static t_symbol *sys_guidir; | ||
889 | static t_namelist *sys_externlist; | ||
890 | static t_namelist *sys_openlist; | ||
891 | static t_namelist *sys_messagelist; | ||
892 | static int sys_version; | ||
893 | int sys_oldtclversion; /* hack to warn g_rtext.c about old text sel */ | ||
894 | |||
895 | int sys_nmidiout = 1; | ||
896 | #ifdef MSW | ||
897 | int sys_nmidiin = 0; | ||
898 | #else | ||
899 | int sys_nmidiin = 1; | ||
900 | #endif | ||
901 | int sys_midiindevlist[MAXMIDIINDEV] = {1}; | ||
902 | int sys_midioutdevlist[MAXMIDIOUTDEV] = {1}; | ||
903 | |||
904 | static int sys_main_srate = DEFAULTSRATE; | ||
905 | static int sys_main_advance = DEFAULTADVANCE; | ||
906 | |||
907 | /* IOhannes { */ | ||
908 | |||
909 | /* here the "-1" counts signify that the corresponding vector hasn't been | ||
910 | specified in command line arguments; sys_open_audio will detect this | ||
911 | and fill things in. */ | ||
912 | int sys_nsoundin = -1; | ||
913 | int sys_nsoundout = -1; | ||
914 | int sys_soundindevlist[MAXAUDIOINDEV]; | ||
915 | int sys_soundoutdevlist[MAXAUDIOOUTDEV]; | ||
916 | |||
917 | int sys_nchin = -1; | ||
918 | int sys_nchout = -1; | ||
919 | int sys_chinlist[MAXAUDIOINDEV]; | ||
920 | int sys_choutlist[MAXAUDIOOUTDEV]; | ||
921 | /* } IOhannes */ | ||
922 | |||
923 | |||
924 | typedef struct _fontinfo | ||
925 | { | ||
926 | int fi_fontsize; | ||
927 | int fi_maxwidth; | ||
928 | int fi_maxheight; | ||
929 | int fi_hostfontsize; | ||
930 | int fi_width; | ||
931 | int fi_height; | ||
932 | } t_fontinfo; | ||
933 | |||
934 | /* these give the nominal point size and maximum height of the characters | ||
935 | in the six fonts. */ | ||
936 | |||
937 | static t_fontinfo sys_fontlist[] = { | ||
938 | {8, 5, 9, 0, 0, 0}, {10, 7, 13, 0, 0, 0}, {12, 9, 16, 0, 0, 0}, | ||
939 | {16, 10, 20, 0, 0, 0}, {24, 15, 25, 0, 0, 0}, {36, 25, 45, 0, 0, 0}}; | ||
940 | #define NFONT (sizeof(sys_fontlist)/sizeof(*sys_fontlist)) | ||
941 | |||
942 | /* here are the actual font size structs on msp's systems: | ||
943 | MSW: | ||
944 | font 8 5 9 8 5 11 | ||
945 | font 10 7 13 10 6 13 | ||
946 | font 12 9 16 14 8 16 | ||
947 | font 16 10 20 16 10 18 | ||
948 | font 24 15 25 16 10 18 | ||
949 | font 36 25 42 36 22 41 | ||
950 | 839 | ||
951 | linux: | ||
952 | font 8 5 9 8 5 9 | ||
953 | font 10 7 13 12 7 13 | ||
954 | font 12 9 16 14 9 15 | ||
955 | font 16 10 20 16 10 19 | ||
956 | font 24 15 25 24 15 24 | ||
957 | font 36 25 42 36 22 41 | ||
958 | */ | ||
959 | |||
960 | static t_fontinfo *sys_findfont(int fontsize) | ||
961 | { | ||
962 | unsigned int i; | ||
963 | t_fontinfo *fi; | ||
964 | for (i = 0, fi = sys_fontlist; i < (NFONT-1); i++, fi++) | ||
965 | if (fontsize < fi[1].fi_fontsize) return (fi); | ||
966 | return (sys_fontlist + (NFONT-1)); | ||
967 | } | ||
968 | |||
969 | int sys_nearestfontsize(int fontsize) | ||
970 | { | ||
971 | return (sys_findfont(fontsize)->fi_fontsize); | ||
972 | } | ||
973 | |||
974 | int sys_hostfontsize(int fontsize) | ||
975 | { | ||
976 | return (sys_findfont(fontsize)->fi_hostfontsize); | ||
977 | } | ||
978 | |||
979 | int sys_fontwidth(int fontsize) | ||
980 | { | ||
981 | return (sys_findfont(fontsize)->fi_width); | ||
982 | } | ||
983 | |||
984 | int sys_fontheight(int fontsize) | ||
985 | { | ||
986 | return (sys_findfont(fontsize)->fi_height); | ||
987 | } | ||
988 | |||
989 | int sys_defaultfont; | ||
990 | #ifdef MSW | ||
991 | #define DEFAULTFONT 12 | ||
992 | #else | ||
993 | #define DEFAULTFONT 10 | ||
994 | #endif | ||
995 | |||
996 | static void openit(const char *dirname, const char *filename) | ||
997 | { | ||
998 | char dirbuf[MAXPDSTRING], *nameptr; | ||
999 | int fd = open_via_path(dirname, filename, "", dirbuf, &nameptr, | ||
1000 | MAXPDSTRING, 0); | ||
1001 | if (fd) | ||
1002 | { | ||
1003 | close (fd); | ||
1004 | glob_evalfile(0, gensym(nameptr), gensym(dirbuf)); | ||
1005 | } | ||
1006 | else | ||
1007 | error("%s: can't open", filename); | ||
1008 | } | ||
1009 | |||
1010 | #define NHOSTFONT 7 | ||
1011 | |||
1012 | /* this is called from the gui process. The first argument is the cwd, and | ||
1013 | succeeding args give the widths and heights of known fonts. We wait until | ||
1014 | these are known to open files and send messages specified on the command line. | ||
1015 | We ask the GUI to specify the "cwd" in case we don't have a local OS to get it | ||
1016 | from; for instance we could be some kind of RT embedded system. However, to | ||
1017 | really make this make sense we would have to implement | ||
1018 | open(), read(), etc, calls to be served somehow from the GUI too. */ | ||
1019 | |||
1020 | void glob_initfromgui(void *dummy, t_symbol *s, int argc, t_atom *argv) | ||
1021 | { | ||
1022 | char *cwd = atom_getsymbolarg(0, argc, argv)->s_name; | ||
1023 | t_namelist *nl; | ||
1024 | unsigned int i, j; | ||
1025 | if (argc != 2 + 3 * NHOSTFONT) bug("glob_initfromgui"); | ||
1026 | for (i = 0; i < NFONT; i++) | ||
1027 | { | ||
1028 | int wantheight = sys_fontlist[i].fi_maxheight; | ||
1029 | for (j = 0; j < NHOSTFONT-1; j++) | ||
1030 | { | ||
1031 | if (atom_getintarg(3 * (j + 1) + 3, argc, argv) > wantheight) | ||
1032 | break; | ||
1033 | } | ||
1034 | /* j is now the "real" font index for the desired font index i. */ | ||
1035 | sys_fontlist[i].fi_hostfontsize = atom_getintarg(3 * j + 1, argc, argv); | ||
1036 | sys_fontlist[i].fi_width = atom_getintarg(3 * j + 2, argc, argv); | ||
1037 | sys_fontlist[i].fi_height = atom_getintarg(3 * j + 3, argc, argv); | ||
1038 | } | ||
1039 | #if 0 | ||
1040 | for (i = 0; i < 6; i++) | ||
1041 | fprintf(stderr, "font %d %d %d %d %d\n", | ||
1042 | sys_fontlist[i].fi_fontsize, | ||
1043 | sys_fontlist[i].fi_maxheight, | ||
1044 | sys_fontlist[i].fi_hostfontsize, | ||
1045 | sys_fontlist[i].fi_width, | ||
1046 | sys_fontlist[i].fi_height); | ||
1047 | #endif | ||
1048 | /* load dynamic libraries specified with "-lib" args */ | ||
1049 | for (nl = sys_externlist; nl; nl = nl->nl_next) | ||
1050 | if (!sys_load_lib(cwd, nl->nl_string)) | ||
1051 | post("%s: can't load library", nl->nl_string); | ||
1052 | namelist_free(sys_externlist); | ||
1053 | sys_externlist = 0; | ||
1054 | /* open patches specifies with "-open" args */ | ||
1055 | for (nl = sys_openlist; nl; nl = nl->nl_next) | ||
1056 | openit(cwd, nl->nl_string); | ||
1057 | namelist_free(sys_openlist); | ||
1058 | sys_openlist = 0; | ||
1059 | /* send messages specified with "-send" args */ | ||
1060 | for (nl = sys_messagelist; nl; nl = nl->nl_next) | ||
1061 | { | ||
1062 | t_binbuf *b = binbuf_new(); | ||
1063 | binbuf_text(b, nl->nl_string, strlen(nl->nl_string)); | ||
1064 | binbuf_eval(b, 0, 0, 0); | ||
1065 | binbuf_free(b); | ||
1066 | } | ||
1067 | namelist_free(sys_messagelist); | ||
1068 | sys_messagelist = 0; | ||
1069 | sys_oldtclversion = atom_getfloatarg(1 + 3 * NHOSTFONT, argc, argv); | ||
1070 | } | ||
1071 | |||
1072 | static void sys_afterargparse(void); | ||
1073 | |||
1074 | /* this is called from main() in s_entry.c */ | ||
1075 | int sys_main(int argc, char **argv) | ||
1076 | { | ||
1077 | #ifdef PD_DEBUG | ||
1078 | fprintf(stderr, "Pd: COMPILED FOR DEBUGGING\n"); | ||
1079 | #endif | ||
1080 | pd_init(); | ||
1081 | sys_findprogdir(argv[0]); /* set sys_progname, guipath */ | ||
1082 | #ifdef UNIX | ||
1083 | sys_rcfile(); /* parse the startup file */ | ||
1084 | #endif | ||
1085 | if (sys_argparse(argc, argv)) /* parse cmd line */ | ||
1086 | return (1); | ||
1087 | sys_afterargparse(); /* post-argparse settings */ | ||
1088 | if (sys_verbose || sys_version) fprintf(stderr, "%scompiled %s %s\n", | ||
1089 | pd_version, pd_compiletime, pd_compiledate); | ||
1090 | if (sys_version) /* if we were just asked our version, exit here. */ | ||
1091 | return (0); | ||
1092 | if (sys_startgui(sys_guidir->s_name)) /* start the gui */ | ||
1093 | return(1); | ||
1094 | /* open audio and MIDI */ | ||
1095 | sys_open_midi(sys_nmidiin, sys_midiindevlist, | ||
1096 | sys_nmidiout, sys_midioutdevlist); | ||
1097 | sys_open_audio(sys_nsoundin, sys_soundindevlist, sys_nchin, sys_chinlist, | ||
1098 | sys_nsoundout, sys_soundoutdevlist, sys_nchout, sys_choutlist, | ||
1099 | sys_main_srate, sys_main_advance, 1); | ||
1100 | /* run scheduler until it quits */ | ||
1101 | |||
1102 | return (m_scheduler_pda()); | ||
1103 | return (m_scheduler()); | ||
1104 | } | ||
1105 | |||
1106 | static char *(usagemessage[]) = { | ||
1107 | "usage: pd [-flags] [file]...\n", | ||
1108 | "\naudio configuration flags:\n", | ||
1109 | "-r <n> -- specify sample rate\n", | ||
1110 | "-audioindev ... -- audio in devices; e.g., \"1,3\" for first and third\n", | ||
1111 | "-audiooutdev ... -- audio out devices (same)\n", | ||
1112 | "-audiodev ... -- specify input and output together\n", | ||
1113 | "-inchannels ... -- audio input channels (by device, like \"2\" or \"16,8\")\n", | ||
1114 | "-outchannels ... -- number of audio out channels (same)\n", | ||
1115 | "-channels ... -- specify both input and output channels\n", | ||
1116 | "-audiobuf <n> -- specify size of audio buffer in msec\n", | ||
1117 | "-blocksize <n> -- specify audio I/O block size in sample frames\n", | ||
1118 | "-sleepgrain <n> -- specify number of milliseconds to sleep when idle\n", | ||
1119 | "-nodac -- suppress audio output\n", | ||
1120 | "-noadc -- suppress audio input\n", | ||
1121 | "-noaudio -- suppress audio input and output (-nosound is synonym) \n", | ||
1122 | "-listdev -- list audio and MIDI devices\n", | ||
1123 | |||
1124 | #ifdef USEAPI_OSS | ||
1125 | "-oss -- use OSS audio API\n", | ||
1126 | "-32bit ----- allow 32 bit OSS audio (for RME Hammerfall)\n", | ||
1127 | #endif | ||
1128 | |||
1129 | #ifdef USEAPI_ALSA | ||
1130 | "-alsa -- use ALSA audio API\n", | ||
1131 | "-alsaadd <name> -- add an ALSA device name to list\n", | ||
1132 | "-alsadev <n> ----- obsolete: use -audiodev\n", | ||
1133 | #endif | ||
1134 | |||
1135 | #ifdef USEAPI_JACK | ||
1136 | "-jack -- use JACK audio API\n", | ||
1137 | #endif | ||
1138 | |||
1139 | #ifdef USEAPI_PORTAUDIO | ||
1140 | #ifdef MSW | ||
1141 | "-asio -- use ASIO audio driver (via Portaudio)\n", | ||
1142 | "-pa -- synonym for -asio\n", | ||
1143 | #else | ||
1144 | "-pa -- use Portaudio API\n", | ||
1145 | #endif | ||
1146 | #endif | ||
1147 | |||
1148 | #ifdef USEAPI_MMIO | ||
1149 | "-mmio -- use MMIO audio API (default for Windows)\n", | ||
1150 | #endif | ||
1151 | " (default audio API for this platform: ", API_DEFSTRING, ")\n\n", | ||
1152 | |||
1153 | "\nMIDI configuration flags:\n", | ||
1154 | "-midiindev ... -- midi in device list; e.g., \"1,3\" for first and third\n", | ||
1155 | "-midioutdev ... -- midi out device list, same format\n", | ||
1156 | "-mididev ... -- specify -midioutdev and -midiindev together\n", | ||
1157 | "-nomidiin -- suppress MIDI input\n", | ||
1158 | "-nomidiout -- suppress MIDI output\n", | ||
1159 | "-nomidi -- suppress MIDI input and output\n", | ||
1160 | |||
1161 | "\nother flags:\n", | ||
1162 | "-path <path> -- add to file search path\n", | ||
1163 | "-helppath <path> -- add to help file search path\n", | ||
1164 | "-open <file> -- open file(s) on startup\n", | ||
1165 | "-lib <file> -- load object library(s)\n", | ||
1166 | "-font <n> -- specify default font size in points\n", | ||
1167 | "-verbose -- extra printout on startup and when searching for files\n", | ||
1168 | "-version -- don't run Pd; just print out which version it is \n", | ||
1169 | "-d <n> -- specify debug level\n", | ||
1170 | "-noloadbang -- suppress all loadbangs\n", | ||
1171 | "-nogui -- suppress starting the GUI\n", | ||
1172 | "-stdin -- scan stdin for keypresses\n", | ||
1173 | "-guicmd \"cmd...\" -- substitute another GUI program (e.g., rsh)\n", | ||
1174 | "-send \"msg...\" -- send a message at startup (after patches are loaded)\n", | ||
1175 | #ifdef UNIX | ||
1176 | "-rt or -realtime -- use real-time priority\n", | ||
1177 | "-nrt -- don't use real-time priority\n", | ||
1178 | #endif | ||
1179 | }; | ||
1180 | |||
1181 | static void sys_parsedevlist(int *np, int *vecp, int max, char *str) | ||
1182 | { | ||
1183 | int n = 0; | ||
1184 | while (n < max) | ||
1185 | { | ||
1186 | if (!*str) break; | ||
1187 | else | ||
1188 | { | ||
1189 | char *endp; | ||
1190 | vecp[n] = strtol(str, &endp, 10); | ||
1191 | if (endp == str) | ||
1192 | break; | ||
1193 | n++; | ||
1194 | if (!endp) | ||
1195 | break; | ||
1196 | str = endp + 1; | ||
1197 | } | ||
1198 | } | ||
1199 | *np = n; | ||
1200 | } | ||
1201 | |||
1202 | static int sys_getmultidevchannels(int n, int *devlist) | ||
1203 | { | ||
1204 | int sum = 0; | ||
1205 | if (n<0)return(-1); | ||
1206 | if (n==0)return 0; | ||
1207 | while(n--)sum+=*devlist++; | ||
1208 | return sum; | ||
1209 | } | ||
1210 | |||
1211 | |||
1212 | /* this routine tries to figure out where to find the auxilliary files | ||
1213 | Pd will need to run. This is either done by looking at the command line | ||
1214 | invokation for Pd, or if that fails, by consulting the variable | ||
1215 | INSTALL_PREFIX. In MSW, we don't try to use INSTALL_PREFIX. */ | ||
1216 | void sys_findprogdir(char *progname) | ||
1217 | { | ||
1218 | char sbuf[MAXPDSTRING], sbuf2[MAXPDSTRING], *sp; | ||
1219 | char *lastslash; | ||
1220 | #ifdef UNIX | ||
1221 | struct stat statbuf; | ||
1222 | #endif | ||
1223 | |||
1224 | /* find out by what string Pd was invoked; put answer in "sbuf". */ | ||
1225 | #ifdef MSW | ||
1226 | GetModuleFileName(NULL, sbuf2, sizeof(sbuf2)); | ||
1227 | sbuf2[MAXPDSTRING-1] = 0; | ||
1228 | sys_unbashfilename(sbuf2, sbuf); | ||
1229 | #endif /* MSW */ | ||
1230 | #ifdef UNIX | ||
1231 | strncpy(sbuf, progname, MAXPDSTRING); | ||
1232 | sbuf[MAXPDSTRING-1] = 0; | ||
1233 | #endif | ||
1234 | lastslash = strrchr(sbuf, '/'); | ||
1235 | if (lastslash) | ||
1236 | { | ||
1237 | /* bash last slash to zero so that sbuf is directory pd was in, | ||
1238 | e.g., ~/pd/bin */ | ||
1239 | *lastslash = 0; | ||
1240 | /* go back to the parent from there, e.g., ~/pd */ | ||
1241 | lastslash = strrchr(sbuf, '/'); | ||
1242 | if (lastslash) | ||
1243 | { | ||
1244 | strncpy(sbuf2, sbuf, lastslash-sbuf); | ||
1245 | sbuf2[lastslash-sbuf] = 0; | ||
1246 | } | ||
1247 | else strcpy(sbuf2, ".."); | ||
1248 | } | ||
1249 | else | ||
1250 | { | ||
1251 | /* no slashes found. Try INSTALL_PREFIX. */ | ||
1252 | #ifdef INSTALL_PREFIX | ||
1253 | strcpy(sbuf2, INSTALL_PREFIX); | ||
1254 | #else | ||
1255 | strcpy(sbuf2, "."); | ||
1256 | #endif | ||
1257 | } | ||
1258 | /* now we believe sbuf2 holds the parent directory of the directory | ||
1259 | pd was found in. We now want to infer the "lib" directory and the | ||
1260 | "gui" directory. In "simple" UNIX installations, the layout is | ||
1261 | .../bin/pd | ||
1262 | .../bin/pd-gui | ||
1263 | .../doc | ||
1264 | and in "complicated" UNIX installations, it's: | ||
1265 | .../bin/pd | ||
1266 | .../lib/pd/bin/pd-gui | ||
1267 | .../lib/pd/doc | ||
1268 | To decide which, we stat .../lib/pd; if that exists, we assume it's | ||
1269 | the complicated layout. In MSW, it's the "simple" layout, but | ||
1270 | the gui program is straight wish80: | ||
1271 | .../bin/pd | ||
1272 | .../bin/wish80.exe | ||
1273 | .../doc | ||
1274 | */ | ||
1275 | #ifdef UNIX | ||
1276 | strncpy(sbuf, sbuf2, MAXPDSTRING-30); | ||
1277 | sbuf[MAXPDSTRING-30] = 0; | ||
1278 | strcat(sbuf, "/lib/pd"); | ||
1279 | if (stat(sbuf, &statbuf) >= 0) | ||
1280 | { | ||
1281 | /* complicated layout: lib dir is the one we just stat-ed above */ | ||
1282 | sys_libdir = gensym(sbuf); | ||
1283 | /* gui lives in .../lib/pd/bin */ | ||
1284 | strncpy(sbuf, sbuf2, MAXPDSTRING-30); | ||
1285 | sbuf[MAXPDSTRING-30] = 0; | ||
1286 | strcat(sbuf, "/lib/pd/bin"); | ||
1287 | sys_guidir = gensym(sbuf); | ||
1288 | } | ||
1289 | else | ||
1290 | { | ||
1291 | /* simple layout: lib dir is the parent */ | ||
1292 | sys_libdir = gensym(sbuf2); | ||
1293 | /* gui lives in .../bin */ | ||
1294 | strncpy(sbuf, sbuf2, MAXPDSTRING-30); | ||
1295 | sbuf[MAXPDSTRING-30] = 0; | ||
1296 | strcat(sbuf, "/bin"); | ||
1297 | sys_guidir = gensym(sbuf); | ||
1298 | } | ||
1299 | #endif | ||
1300 | #ifdef MSW | ||
1301 | sys_libdir = gensym(sbuf2); | ||
1302 | sys_guidir = &s_; /* in MSW the guipath just depends on the libdir */ | ||
1303 | #endif | ||
1304 | } | ||
1305 | |||
1306 | #ifdef MSW | ||
1307 | static int sys_mmio = 1; | ||
1308 | #else | ||
1309 | static int sys_mmio = 0; | ||
1310 | #endif | ||
1311 | |||
1312 | int sys_argparse(int argc, char **argv) | ||
1313 | { | ||
1314 | char sbuf[MAXPDSTRING]; | ||
1315 | int i; | ||
1316 | argc--; argv++; | ||
1317 | while ((argc > 0) && **argv == '-') | ||
1318 | { | ||
1319 | if (!strcmp(*argv, "-r") && argc > 1 && | ||
1320 | sscanf(argv[1], "%d", &sys_main_srate) >= 1) | ||
1321 | { | ||
1322 | argc -= 2; | ||
1323 | argv += 2; | ||
1324 | } | ||
1325 | else if (!strcmp(*argv, "-inchannels")) | ||
1326 | { /* IOhannes */ | ||
1327 | sys_parsedevlist(&sys_nchin, | ||
1328 | sys_chinlist, MAXAUDIOINDEV, argv[1]); | ||
1329 | |||
1330 | if (!sys_nchin) | ||
1331 | goto usage; | ||
1332 | |||
1333 | argc -= 2; argv += 2; | ||
1334 | } | ||
1335 | else if (!strcmp(*argv, "-outchannels")) | ||
1336 | { /* IOhannes */ | ||
1337 | sys_parsedevlist(&sys_nchout, sys_choutlist, | ||
1338 | MAXAUDIOOUTDEV, argv[1]); | ||
1339 | |||
1340 | if (!sys_nchout) | ||
1341 | goto usage; | ||
1342 | |||
1343 | argc -= 2; argv += 2; | ||
1344 | } | ||
1345 | else if (!strcmp(*argv, "-channels")) | ||
1346 | { | ||
1347 | sys_parsedevlist(&sys_nchin, sys_chinlist,MAXAUDIOINDEV, | ||
1348 | argv[1]); | ||
1349 | sys_parsedevlist(&sys_nchout, sys_choutlist,MAXAUDIOOUTDEV, | ||
1350 | argv[1]); | ||
1351 | |||
1352 | if (!sys_nchout) | ||
1353 | goto usage; | ||
1354 | |||
1355 | argc -= 2; argv += 2; | ||
1356 | } | ||
1357 | else if (!strcmp(*argv, "-soundbuf") || !strcmp(*argv, "-audiobuf")) | ||
1358 | { | ||
1359 | sys_main_advance = atoi(argv[1]); | ||
1360 | argc -= 2; argv += 2; | ||
1361 | } | ||
1362 | else if (!strcmp(*argv, "-blocksize")) | ||
1363 | { | ||
1364 | sys_setblocksize(atoi(argv[1])); | ||
1365 | argc -= 2; argv += 2; | ||
1366 | } | ||
1367 | else if (!strcmp(*argv, "-sleepgrain")) | ||
1368 | { | ||
1369 | sys_sleepgrain = 1000 * atoi(argv[1]); | ||
1370 | argc -= 2; argv += 2; | ||
1371 | } | ||
1372 | else if (!strcmp(*argv, "-nodac")) | ||
1373 | { /* IOhannes */ | ||
1374 | sys_nsoundout=0; | ||
1375 | sys_nchout = 0; | ||
1376 | argc--; argv++; | ||
1377 | } | ||
1378 | else if (!strcmp(*argv, "-noadc")) | ||
1379 | { /* IOhannes */ | ||
1380 | sys_nsoundin=0; | ||
1381 | sys_nchin = 0; | ||
1382 | argc--; argv++; | ||
1383 | } | ||
1384 | else if (!strcmp(*argv, "-nosound") || !strcmp(*argv, "-noaudio")) | ||
1385 | { /* IOhannes */ | ||
1386 | sys_nsoundin=sys_nsoundout = 0; | ||
1387 | sys_nchin = sys_nchout = 0; | ||
1388 | argc--; argv++; | ||
1389 | } | ||
1390 | #ifdef USEAPI_OSS | ||
1391 | else if (!strcmp(*argv, "-oss")) | ||
1392 | { | ||
1393 | sys_set_audio_api(API_OSS); | ||
1394 | argc--; argv++; | ||
1395 | } | ||
1396 | else if (!strcmp(*argv, "-32bit")) | ||
1397 | { | ||
1398 | sys_set_audio_api(API_OSS); | ||
1399 | oss_set32bit(); | ||
1400 | argc--; argv++; | ||
1401 | } | ||
1402 | #endif | ||
1403 | #ifdef USEAPI_ALSA | ||
1404 | else if (!strcmp(*argv, "-alsa")) | ||
1405 | { | ||
1406 | sys_set_audio_api(API_ALSA); | ||
1407 | argc--; argv++; | ||
1408 | } | ||
1409 | else if (!strcmp(*argv, "-alsaadd")) | ||
1410 | { | ||
1411 | if (argc > 1) | ||
1412 | alsa_adddev(argv[1]); | ||
1413 | else goto usage; | ||
1414 | argc -= 2; argv +=2; | ||
1415 | } | ||
1416 | /* obsolete flag for setting ALSA device number or name */ | ||
1417 | else if (!strcmp(*argv, "-alsadev")) | ||
1418 | { | ||
1419 | int devno = 0; | ||
1420 | if (argv[1][0] >= '1' && argv[1][0] <= '9') | ||
1421 | devno = 1 + 2 * (atoi(argv[1]) - 1); | ||
1422 | else if (!strncmp(argv[1], "hw:", 3)) | ||
1423 | devno = 1 + 2 * atoi(argv[1]+3); | ||
1424 | else if (!strncmp(argv[1], "plughw:", 7)) | ||
1425 | devno = 2 + 2 * atoi(argv[1]+7); | ||
1426 | else goto usage; | ||
1427 | sys_nsoundin = sys_nsoundout = 1; | ||
1428 | sys_soundindevlist[0] = sys_soundoutdevlist[0] = devno; | ||
1429 | sys_set_audio_api(API_ALSA); | ||
1430 | argc -= 2; argv +=2; | ||
1431 | } | ||
1432 | #endif | ||
1433 | #ifdef USEAPI_JACK | ||
1434 | else if (!strcmp(*argv, "-jack")) | ||
1435 | { | ||
1436 | sys_set_audio_api(API_JACK); | ||
1437 | argc--; argv++; | ||
1438 | } | ||
1439 | #endif | ||
1440 | #ifdef USEAPI_PORTAUDIO | ||
1441 | else if (!strcmp(*argv, "-pa") || !strcmp(*argv, "-portaudio") | ||
1442 | #ifdef MSW | ||
1443 | || !strcmp(*argv, "-asio") | ||
1444 | #endif | ||
1445 | ) | ||
1446 | { | ||
1447 | sys_set_audio_api(API_PORTAUDIO); | ||
1448 | sys_mmio = 0; | ||
1449 | argc--; argv++; | ||
1450 | } | ||
1451 | #endif | ||
1452 | #ifdef USEAPI_MMIO | ||
1453 | else if (!strcmp(*argv, "-mmio")) | ||
1454 | { | ||
1455 | sys_set_audio_api(API_MMIO); | ||
1456 | sys_mmio = 1; | ||
1457 | argc--; argv++; | ||
1458 | } | ||
1459 | #endif | ||
1460 | else if (!strcmp(*argv, "-nomidiin")) | ||
1461 | { | ||
1462 | sys_nmidiin = 0; | ||
1463 | argc--; argv++; | ||
1464 | } | ||
1465 | else if (!strcmp(*argv, "-nomidiout")) | ||
1466 | { | ||
1467 | sys_nmidiout = 0; | ||
1468 | argc--; argv++; | ||
1469 | } | ||
1470 | else if (!strcmp(*argv, "-nomidi")) | ||
1471 | { | ||
1472 | sys_nmidiin = sys_nmidiout = 0; | ||
1473 | argc--; argv++; | ||
1474 | } | ||
1475 | else if (!strcmp(*argv, "-midiindev")) | ||
1476 | { | ||
1477 | sys_parsedevlist(&sys_nmidiin, sys_midiindevlist, MAXMIDIINDEV, | ||
1478 | argv[1]); | ||
1479 | if (!sys_nmidiin) | ||
1480 | goto usage; | ||
1481 | argc -= 2; argv += 2; | ||
1482 | } | ||
1483 | else if (!strcmp(*argv, "-midioutdev")) | ||
1484 | { | ||
1485 | sys_parsedevlist(&sys_nmidiout, sys_midioutdevlist, MAXMIDIOUTDEV, | ||
1486 | argv[1]); | ||
1487 | if (!sys_nmidiout) | ||
1488 | goto usage; | ||
1489 | argc -= 2; argv += 2; | ||
1490 | } | ||
1491 | else if (!strcmp(*argv, "-mididev")) | ||
1492 | { | ||
1493 | sys_parsedevlist(&sys_nmidiin, sys_midiindevlist, MAXMIDIINDEV, | ||
1494 | argv[1]); | ||
1495 | sys_parsedevlist(&sys_nmidiout, sys_midioutdevlist, MAXMIDIOUTDEV, | ||
1496 | argv[1]); | ||
1497 | if (!sys_nmidiout) | ||
1498 | goto usage; | ||
1499 | argc -= 2; argv += 2; | ||
1500 | } | ||
1501 | else if (!strcmp(*argv, "-path")) | ||
1502 | { | ||
1503 | sys_addpath(argv[1]); | ||
1504 | argc -= 2; argv += 2; | ||
1505 | } | ||
1506 | else if (!strcmp(*argv, "-helppath")) | ||
1507 | { | ||
1508 | sys_addhelppath(argv[1]); | ||
1509 | argc -= 2; argv += 2; | ||
1510 | } | ||
1511 | else if (!strcmp(*argv, "-open") && argc > 1) | ||
1512 | { | ||
1513 | sys_openlist = namelist_append(sys_openlist, argv[1]); | ||
1514 | argc -= 2; argv += 2; | ||
1515 | } | ||
1516 | else if (!strcmp(*argv, "-lib") && argc > 1) | ||
1517 | { | ||
1518 | sys_externlist = namelist_append(sys_externlist, argv[1]); | ||
1519 | argc -= 2; argv += 2; | ||
1520 | } | ||
1521 | else if (!strcmp(*argv, "-font") && argc > 1) | ||
1522 | { | ||
1523 | sys_defaultfont = sys_nearestfontsize(atoi(argv[1])); | ||
1524 | argc -= 2; | ||
1525 | argv += 2; | ||
1526 | } | ||
1527 | else if (!strcmp(*argv, "-verbose")) | ||
1528 | { | ||
1529 | sys_verbose = 1; | ||
1530 | argc--; argv++; | ||
1531 | } | ||
1532 | else if (!strcmp(*argv, "-version")) | ||
1533 | { | ||
1534 | sys_version = 1; | ||
1535 | argc--; argv++; | ||
1536 | } | ||
1537 | else if (!strcmp(*argv, "-d") && argc > 1 && | ||
1538 | sscanf(argv[1], "%d", &sys_debuglevel) >= 1) | ||
1539 | { | ||
1540 | argc -= 2; | ||
1541 | argv += 2; | ||
1542 | } | ||
1543 | else if (!strcmp(*argv, "-noloadbang")) | ||
1544 | { | ||
1545 | sys_noloadbang = 1; | ||
1546 | argc--; argv++; | ||
1547 | } | ||
1548 | else if (!strcmp(*argv, "-nogui")) | ||
1549 | { | ||
1550 | sys_nogui = 1; | ||
1551 | argc--; argv++; | ||
1552 | } | ||
1553 | else if (!strcmp(*argv, "-stdin")) | ||
1554 | { | ||
1555 | sys_stdin = 1; | ||
1556 | argc--; argv++; | ||
1557 | } | ||
1558 | else if (!strcmp(*argv, "-guicmd") && argc > 1) | ||
1559 | { | ||
1560 | sys_guicmd = argv[1]; | ||
1561 | argc -= 2; argv += 2; | ||
1562 | } | ||
1563 | else if (!strcmp(*argv, "-send") && argc > 1) | ||
1564 | { | ||
1565 | sys_messagelist = namelist_append(sys_messagelist, argv[1]); | ||
1566 | argc -= 2; argv += 2; | ||
1567 | } | ||
1568 | else if (!strcmp(*argv, "-listdev")) | ||
1569 | { | ||
1570 | sys_listdevs(); | ||
1571 | argc--; argv++; | ||
1572 | } | ||
1573 | #ifdef UNIX | ||
1574 | else if (!strcmp(*argv, "-rt") || !strcmp(*argv, "-realtime")) | ||
1575 | { | ||
1576 | sys_hipriority = 1; | ||
1577 | argc--; argv++; | ||
1578 | } | ||
1579 | else if (!strcmp(*argv, "-nrt")) | ||
1580 | { | ||
1581 | sys_hipriority = 0; | ||
1582 | argc--; argv++; | ||
1583 | } | ||
1584 | #endif | ||
1585 | else if (!strcmp(*argv, "-soundindev") || | ||
1586 | !strcmp(*argv, "-audioindev")) | ||
1587 | { /* IOhannes */ | ||
1588 | sys_parsedevlist(&sys_nsoundin, sys_soundindevlist, | ||
1589 | MAXAUDIOINDEV, argv[1]); | ||
1590 | if (!sys_nsoundin) | ||
1591 | goto usage; | ||
1592 | argc -= 2; argv += 2; | ||
1593 | } | ||
1594 | else if (!strcmp(*argv, "-soundoutdev") || | ||
1595 | !strcmp(*argv, "-audiooutdev")) | ||
1596 | { /* IOhannes */ | ||
1597 | sys_parsedevlist(&sys_nsoundout, sys_soundoutdevlist, | ||
1598 | MAXAUDIOOUTDEV, argv[1]); | ||
1599 | if (!sys_nsoundout) | ||
1600 | goto usage; | ||
1601 | argc -= 2; argv += 2; | ||
1602 | } | ||
1603 | else if (!strcmp(*argv, "-sounddev") || !strcmp(*argv, "-audiodev")) | ||
1604 | { | ||
1605 | sys_parsedevlist(&sys_nsoundin, sys_soundindevlist, | ||
1606 | MAXAUDIOINDEV, argv[1]); | ||
1607 | sys_parsedevlist(&sys_nsoundout, sys_soundoutdevlist, | ||
1608 | MAXAUDIOOUTDEV, argv[1]); | ||
1609 | if (!sys_nsoundout) | ||
1610 | goto usage; | ||
1611 | argc -= 2; argv += 2; | ||
1612 | } | ||
1613 | else | ||
1614 | { | ||
1615 | unsigned int i; | ||
1616 | usage: | ||
1617 | for (i = 0; i < sizeof(usagemessage)/sizeof(*usagemessage); i++) | ||
1618 | fprintf(stderr, "%s", usagemessage[i]); | ||
1619 | return (1); | ||
1620 | } | ||
1621 | } | ||
1622 | if (!sys_defaultfont) | ||
1623 | sys_defaultfont = DEFAULTFONT; | ||
1624 | for (; argc > 0; argc--, argv++) | ||
1625 | sys_openlist = namelist_append(sys_openlist, *argv); | ||
1626 | |||
1627 | |||
1628 | return (0); | ||
1629 | } | ||
1630 | |||
1631 | int sys_getblksize(void) | ||
1632 | { | ||
1633 | return (DEFDACBLKSIZE); | ||
1634 | } | ||
1635 | |||
1636 | /* stuff to do, once, after calling sys_argparse() -- which may itself | ||
1637 | be called twice because of the .pdrc hack. */ | ||
1638 | static void sys_afterargparse(void) | ||
1639 | { | ||
1640 | char sbuf[MAXPDSTRING]; | ||
1641 | int i; | ||
1642 | /* add "extra" library to path */ | ||
1643 | strncpy(sbuf, sys_libdir->s_name, MAXPDSTRING-30); | ||
1644 | sbuf[MAXPDSTRING-30] = 0; | ||
1645 | strcat(sbuf, "/extra"); | ||
1646 | sys_addpath(sbuf); | ||
1647 | strncpy(sbuf, sys_libdir->s_name, MAXPDSTRING-30); | ||
1648 | sbuf[MAXPDSTRING-30] = 0; | ||
1649 | strcat(sbuf, "/intern"); | ||
1650 | sys_addpath(sbuf); | ||
1651 | /* add "doc/5.reference" library to helppath */ | ||
1652 | strncpy(sbuf, sys_libdir->s_name, MAXPDSTRING-30); | ||
1653 | sbuf[MAXPDSTRING-30] = 0; | ||
1654 | strcat(sbuf, "/doc/5.reference"); | ||
1655 | sys_addhelppath(sbuf); | ||
1656 | /* correct to make audio and MIDI device lists zero based. On | ||
1657 | MMIO, however, "1" really means the second device (the first one | ||
1658 | is "mapper" which is was not included when the command args were | ||
1659 | set up, so we leave it that way for compatibility. */ | ||
1660 | if (!sys_mmio) | ||
1661 | { | ||
1662 | for (i = 0; i < sys_nsoundin; i++) | ||
1663 | sys_soundindevlist[i]--; | ||
1664 | for (i = 0; i < sys_nsoundout; i++) | ||
1665 | sys_soundoutdevlist[i]--; | ||
1666 | } | ||
1667 | for (i = 0; i < sys_nmidiin; i++) | ||
1668 | sys_midiindevlist[i]--; | ||
1669 | for (i = 0; i < sys_nmidiout; i++) | ||
1670 | sys_midioutdevlist[i]--; | ||
1671 | } | ||
1672 | |||
1673 | static void sys_addreferencepath(void) | ||
1674 | { | ||
1675 | char sbuf[MAXPDSTRING]; | ||
1676 | } | ||