diff options
author | Miller Puckette <millerpuckette@users.sourceforge.net> | 2007-08-02 00:33:50 +0000 |
---|---|---|
committer | Miller Puckette <millerpuckette@users.sourceforge.net> | 2007-08-02 00:33:50 +0000 |
commit | d94dbe2eca3ace84a23bfff30c729662a4486a5a (patch) | |
tree | 5868261a1706a36112b5927f2d013613fe4f5971 /pd/src | |
parent | 4e5ef76c3a0a96b04eaf605af434094896984319 (diff) |
fix name clash in s_audio_jack.c (again) and applied some sourceforge patches
svn path=/trunk/; revision=8342
Diffstat (limited to 'pd/src')
-rw-r--r-- | pd/src/configure.in | 10 | ||||
-rw-r--r-- | pd/src/g_rtext.c | 2 | ||||
-rw-r--r-- | pd/src/makefile.in | 16 | ||||
-rw-r--r-- | pd/src/s_audio_jack.c | 4 | ||||
-rw-r--r-- | pd/src/s_file.c | 46 | ||||
-rw-r--r-- | pd/src/s_midi.c | 14 | ||||
-rw-r--r-- | pd/src/s_midi_alsa.c | 86 | ||||
-rw-r--r-- | pd/src/s_midi_pm.c | 41 | ||||
-rw-r--r-- | pd/src/u_main.tk | 6 | ||||
-rw-r--r-- | pd/src/x_midi.c | 12 | ||||
-rw-r--r-- | pd/src/x_misc.c | 7 |
11 files changed, 203 insertions, 41 deletions
diff --git a/pd/src/configure.in b/pd/src/configure.in index fb757526..6ea60a50 100644 --- a/pd/src/configure.in +++ b/pd/src/configure.in @@ -419,5 +419,15 @@ AC_TRY_LINK( [ fi ## }JMZ: end of large-file support section +if test -d ../obj +then echo -n +else mkdir ../obj +fi + +if test -d ../bin +then echo -n +else mkdir ../bin +fi + AC_OUTPUT(makefile) diff --git a/pd/src/g_rtext.c b/pd/src/g_rtext.c index 28becbdb..cbb0ba88 100644 --- a/pd/src/g_rtext.c +++ b/pd/src/g_rtext.c @@ -442,7 +442,7 @@ void rtext_key(t_rtext *x, int keynum, t_symbol *keysym) /* at Guenter's suggestion, use 'n>31' to test wither a character might be printable in whatever 8-bit character set we find ourselves. */ - if (n == '\n' || n > 31) + if (n == '\n' || (n > 31 && n != 127)) { newsize = x->x_bufsize+1; x->x_buf = resizebytes(x->x_buf, x->x_bufsize, newsize); diff --git a/pd/src/makefile.in b/pd/src/makefile.in index 33ac2b99..d77d4ac4 100644 --- a/pd/src/makefile.in +++ b/pd/src/makefile.in @@ -146,14 +146,14 @@ $(BIN_DIR)/pdtcl.dll: $(GOBJ) strip --strip-unneeded $(BIN_DIR)/pdtcl.dll externs: - cd ../extra/bonk~;make @EXTERNTARGET@ - cd ../extra/choice;make @EXTERNTARGET@ - cd ../extra/expr~;make @EXTERNTARGET@ - cd ../extra/fiddle~;make @EXTERNTARGET@ - cd ../extra/loop~;make @EXTERNTARGET@ - cd ../extra/lrshift~;make @EXTERNTARGET@ - cd ../extra/pique;make @EXTERNTARGET@ - cd ../extra/sigmund~;make @EXTERNTARGET@ + make -C ../extra/bonk~ @EXTERNTARGET@ + make -C ../extra/choice @EXTERNTARGET@ + make -C ../extra/expr~ @EXTERNTARGET@ + make -C ../extra/fiddle~ @EXTERNTARGET@ + make -C ../extra/loop~ @EXTERNTARGET@ + make -C ../extra/lrshift~ @EXTERNTARGET@ + make -C ../extra/pique @EXTERNTARGET@ + make -C ../extra/sigmund~ @EXTERNTARGET@ BINARYMODE=@binarymode@ diff --git a/pd/src/s_audio_jack.c b/pd/src/s_audio_jack.c index a6df3968..92f652e9 100644 --- a/pd/src/s_audio_jack.c +++ b/pd/src/s_audio_jack.c @@ -194,7 +194,7 @@ static int jack_connect_ports(char* client) } -void jack_error_callback(const char *desc) { +void pd_jack_error_callback(const char *desc) { return; } @@ -244,7 +244,7 @@ jack_open_audio(int inchans, int outchans, int rate) jack_set_process_callback (jack_client, process, 0); - jack_set_error_function (jack_error_callback); + jack_set_error_function (pd_jack_error_callback); #ifdef JACK_XRUN jack_set_xrun_callback (jack_client, jack_xrun, NULL); diff --git a/pd/src/s_file.c b/pd/src/s_file.c index e954eb5d..53d71bfa 100644 --- a/pd/src/s_file.c +++ b/pd/src/s_file.c @@ -42,10 +42,20 @@ static void sys_initloadpreferences( void) { char filenamebuf[MAXPDSTRING], *homedir = getenv("HOME"); int fd, length; - - if (!homedir) - return; - snprintf(filenamebuf, MAXPDSTRING, "%s/.pdsettings", homedir); + char user_prefs_file[MAXPDSTRING]; /* user prefs file */ + /* default prefs embedded in the package */ + char default_prefs_file[MAXPDSTRING]; + struct stat statbuf; + + snprintf(default_prefs_file, MAXPDSTRING, "%s/default.pdsettings", + sys_libdir->s_name); + if (homedir) + snprintf(user_prefs_file, MAXPDSTRING, "%s/.pdsettings", homedir); + if (stat(user_prefs_file, &statbuf) == 0) + strncpy(filenamebuf, user_prefs_file, MAXPDSTRING); + else if (stat(default_prefs_file, &statbuf) == 0) + strncpy(filenamebuf, default_prefs_file, MAXPDSTRING); + else return; filenamebuf[MAXPDSTRING-1] = 0; if ((fd = open(filenamebuf, 0)) < 0) { @@ -215,7 +225,21 @@ static int sys_getpreference(const char *key, char *value, int size) { char cmdbuf[256]; int nread = 0, nleft = size; - snprintf(cmdbuf, 256, "defaults read org.puredata.pd %s 2> /dev/null\n", key); + char embedded_prefs[MAXPDSTRING]; + char user_prefs[MAXPDSTRING]; + char *homedir = getenv("HOME"); + struct stat statbuf; + /* the 'defaults' command expects the filename without .plist at the + end */ + snprintf(embedded_prefs, MAXPDSTRING, "%s/../org.puredata.pd", + sys_libdir->s_name); + snprintf(user_prefs, MAXPDSTRING, + "%s/Library/Preferences/org.puredata.pd.plist", homedir); + if (stat(user_prefs, &statbuf) == 0) + snprintf(cmdbuf, 256, "defaults read org.puredata.pd %s 2> /dev/null\n", + key); + else snprintf(cmdbuf, 256, "defaults read %s %s 2> /dev/null\n", + embedded_prefs, key); FILE *fp = popen(cmdbuf, "r"); while (nread < size) { @@ -272,8 +296,9 @@ void sys_loadpreferences( void) if (sys_getpreference("audioapi", prefbuf, MAXPDSTRING) && sscanf(prefbuf, "%d", &api) > 0) sys_set_audio_api(api); + /* JMZ/MB: brackets for initializing */ if (sys_getpreference("noaudioin", prefbuf, MAXPDSTRING) && - (!strcmp(prefbuf, ".") || !strcmp(prefbuf, "True"))) /* JMZ/MB: brackets for initializing */ + (!strcmp(prefbuf, ".") || !strcmp(prefbuf, "True"))) naudioindev = 0; else { @@ -290,8 +315,9 @@ void sys_loadpreferences( void) if (naudioindev == 0) naudioindev = -1; } + /* JMZ/MB: brackets for initializing */ if (sys_getpreference("noaudioout", prefbuf, MAXPDSTRING) && - (!strcmp(prefbuf, ".") || !strcmp(prefbuf, "True"))) /* JMZ/MB: brackets for initializing */ + (!strcmp(prefbuf, ".") || !strcmp(prefbuf, "True"))) naudiooutdev = 0; else { @@ -315,8 +341,9 @@ void sys_loadpreferences( void) naudiooutdev, audiooutdev, naudiooutdev, choutdev, rate, advance, 0); /* load MIDI preferences */ + /* JMZ/MB: brackets for initializing */ if (sys_getpreference("nomidiin", prefbuf, MAXPDSTRING) && - (!strcmp(prefbuf, ".") || !strcmp(prefbuf, "True"))) /* JMZ/MB: brackets for initializing */ + (!strcmp(prefbuf, ".") || !strcmp(prefbuf, "True"))) nmidiindev = 0; else for (i = 0, nmidiindev = 0; i < MAXMIDIINDEV; i++) { @@ -327,8 +354,9 @@ void sys_loadpreferences( void) break; nmidiindev++; } + /* JMZ/MB: brackets for initializing */ if (sys_getpreference("nomidiout", prefbuf, MAXPDSTRING) && - (!strcmp(prefbuf, ".") || !strcmp(prefbuf, "True"))) /* JMZ/MB: brackets for initializing */ + (!strcmp(prefbuf, ".") || !strcmp(prefbuf, "True"))) nmidioutdev = 0; else for (i = 0, nmidioutdev = 0; i < MAXMIDIOUTDEV; i++) { diff --git a/pd/src/s_midi.c b/pd/src/s_midi.c index 508b3ff2..52dab7b0 100644 --- a/pd/src/s_midi.c +++ b/pd/src/s_midi.c @@ -236,6 +236,20 @@ void outmidi_mclk(int portno) sys_queuemidimess(portno, 1, 0xf8, 0,0); } +void outmidi_byte(int portno, int value) +{ +#ifdef USEAPI_ALSA + if (sys_midiapi == API_ALSA) + { + sys_alsa_putmidibyte(portno, value); + } + else +#endif + { + sys_putmidibyte(portno, value); + } +} + /* ------------------------- MIDI input queue handling ------------------ */ typedef struct midiparser { diff --git a/pd/src/s_midi_alsa.c b/pd/src/s_midi_alsa.c index 1d19c111..dcc50006 100644 --- a/pd/src/s_midi_alsa.c +++ b/pd/src/s_midi_alsa.c @@ -47,8 +47,16 @@ void sys_alsa_do_open_midi(int nmidiin, int *midiinvec, int client; int i; snd_seq_client_info_t *alsainfo; + /* do we want to connect pd automatically with other devices ?; see below! */ + /* LATER: think about a flag to enable/disable automatic connection + * (sometimes it could be a pain) + */ + int autoconnect = 1; alsa_nmidiin = 0; alsa_nmidiout = 0; + + if (nmidiout == 0 && nmidiin == 0) return; + if(nmidiin>MAXMIDIINDEV ) { post("midi input ports reduced to maximum %d", MAXMIDIINDEV); @@ -73,25 +81,28 @@ void sys_alsa_do_open_midi(int nmidiin, int *midiinvec, post("couldn't open alsa sequencer"); return; } - for (i=0;i<nmidiout;i++) + for (i=0;i<nmidiin;i++) { int port; sprintf(portname,"Pure Data Midi-In %d",i+1); - port = snd_seq_create_simple_port(midi_handle,portname,SND_SEQ_PORT_CAP_WRITE |SND_SEQ_PORT_CAP_SUBS_WRITE , SND_SEQ_PORT_TYPE_APPLICATION); + port = snd_seq_create_simple_port(midi_handle,portname, + SND_SEQ_PORT_CAP_WRITE |SND_SEQ_PORT_CAP_SUBS_WRITE, + SND_SEQ_PORT_TYPE_APPLICATION); alsa_midiinfd[i] = port; if (port < 0) goto error; } - for (i=0;i<nmidiin;i++) + for (i=0;i<nmidiout;i++) { int port; sprintf(portname,"Pure Data Midi-Out %d",i+1); - port = snd_seq_create_simple_port(midi_handle,portname, SND_SEQ_PORT_CAP_SUBS_READ | SND_SEQ_PORT_CAP_READ, SND_SEQ_PORT_TYPE_APPLICATION); + port = snd_seq_create_simple_port(midi_handle,portname, + SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ, + SND_SEQ_PORT_TYPE_APPLICATION); alsa_midioutfd[i] = port; if (port < 0) goto error; } - if (nmidiout == 0 && nmidiin == 0) return; snd_seq_client_info_malloc(&alsainfo); snd_seq_get_client_info(midi_handle,alsainfo); snd_seq_client_info_set_name(alsainfo,"Pure Data"); @@ -103,8 +114,67 @@ void sys_alsa_do_open_midi(int nmidiin, int *midiinvec, snd_midi_event_new(20,&midiev); alsa_nmidiout = nmidiout; alsa_nmidiin = nmidiin; + + /* JMZ: connect all available devices to pd */ + if (autoconnect) + { + + snd_seq_client_info_t *cinfo; + snd_seq_port_info_t *pinfo; + + snd_seq_port_subscribe_t *subs; + snd_seq_addr_t other, topd, frompd; + /* since i don't know how to connect multiple ports + * (connect everything to each port, modulo,...), + * i only fully connect where we have only one single port + */ + if(alsa_nmidiin) + { + topd.client =client; + topd.port =alsa_midiinfd[0]; + } + if(alsa_nmidiout) + { + frompd.client =client; + frompd.port =alsa_midioutfd[0]; + } + + snd_seq_port_subscribe_alloca(&subs); + + snd_seq_client_info_alloca(&cinfo); + snd_seq_port_info_alloca(&pinfo); + snd_seq_client_info_set_client(cinfo, -1); + while (snd_seq_query_next_client(midi_handle, cinfo) >= 0) + { + /* reset query info */ + int client_id=snd_seq_client_info_get_client(cinfo); + + if((SND_SEQ_CLIENT_SYSTEM != client_id)&&(client != client_id)) + { /* skipping port 0 and ourself */ + snd_seq_port_info_set_client(pinfo, client_id); + snd_seq_port_info_set_port(pinfo, -1); + while (snd_seq_query_next_port(midi_handle, pinfo) >= 0) + { + other.client=client_id; + other.port =snd_seq_port_info_get_port(pinfo); + if(1==alsa_nmidiin) /* only autoconnect 1st port */ + { + snd_seq_port_subscribe_set_sender(subs, &other); + snd_seq_port_subscribe_set_dest(subs, &topd); + snd_seq_subscribe_port(midi_handle, subs); + } + if(1==alsa_nmidiout) /* only autoconnect 1st port */ + { + snd_seq_port_subscribe_set_sender(subs, &frompd); + snd_seq_port_subscribe_set_dest(subs, &other); + snd_seq_subscribe_port(midi_handle, subs); + } + } + } + } + } return; - error: + error: sys_setalarm(1000000); post("couldn't open alsa MIDI output device"); return; @@ -169,10 +239,8 @@ void sys_alsa_putmidibyte(int portno, int byte) { // repack into 1 byte char and put somewhere to point at unsigned char data = (unsigned char)byte; - unsigned char *dataptr = malloc(1); - memcpy(dataptr,&byte,1); - snd_seq_ev_set_sysex(&ev,1,dataptr); //...set_variable *should* have worked but didn't + snd_seq_ev_set_sysex(&ev,1,&data); //...set_variable *should* have worked but didn't snd_seq_ev_set_direct(&ev); snd_seq_ev_set_subs(&ev); snd_seq_ev_set_source(&ev,alsa_midioutfd[portno]); diff --git a/pd/src/s_midi_pm.c b/pd/src/s_midi_pm.c index a79c839b..b0993268 100644 --- a/pd/src/s_midi_pm.c +++ b/pd/src/s_midi_pm.c @@ -140,7 +140,7 @@ void sys_putmidibyte(int portno, int byte) writemidi4(mac_midioutdevlist[portno], byte, 0, 0, 0); else if (byte == 0xf0) { - mess[0] = 0xf7; + mess[0] = 0xf0; nbytes = 1; sysex = 1; } @@ -209,6 +209,38 @@ void sys_putmidibyte(int portno, int byte) } } +/* this is non-zero if we are in the middle of transmitting sysex */ + +int nd_sysex_mode=0; + +/* send in 4 bytes of sysex data. if one of the bytes is 0xF7 (sysex end) stop and unset nd_sysex_mode */ +void nd_sysex_inword(int midiindev, int status, int data1, int data2, int data3) +{ + if (nd_sysex_mode) { + sys_midibytein(midiindev, status); + if (status == 0xF7) + nd_sysex_mode = 0; + } + + if (nd_sysex_mode) { + sys_midibytein(midiindev, data1); + if (data1 == 0xF7) + nd_sysex_mode = 0; + } + + if (nd_sysex_mode) { + sys_midibytein(midiindev, data2); + if (data2 == 0xF7) + nd_sysex_mode = 0; + } + + if (nd_sysex_mode) { + sys_midibytein(midiindev, data3); + if (data3 == 0xF7) + nd_sysex_mode = 0; + } +} + void sys_poll_midi(void) { int i, nmess; @@ -221,6 +253,7 @@ void sys_poll_midi(void) int status = Pm_MessageStatus(buffer.message); int data1 = Pm_MessageData1(buffer.message); int data2 = Pm_MessageData2(buffer.message); + int data3 = ((buffer.message >> 24) & 0xFF); int msgtype = (status >> 4) - 8; switch (msgtype) { @@ -239,8 +272,12 @@ void sys_poll_midi(void) sys_midibytein(i, data1); break; case 7: - sys_midibytein(i, status); + nd_sysex_mode=1; + nd_sysex_inword(i, status, data1, data2, data3); break; + default: + if (nd_sysex_mode) + nd_sysex_inword(i, status, data1, data2, data3); } } } diff --git a/pd/src/u_main.tk b/pd/src/u_main.tk index 8c43905b..b44aedab 100644 --- a/pd/src/u_main.tk +++ b/pd/src/u_main.tk @@ -434,16 +434,16 @@ proc menu_doc_browser {dir} { proc doc_make_listbox {base dir count} { # check for [file readable]? - if { [info tclversion] >= 8.5 } { + #if { [info tclversion] >= 8.5 } { # requires Tcl 8.5 but probably deals with special chars better # destroy {expand}[lrange [winfo children $base] [expr {2 * $count}] end] - } else { + #} else { if { [catch { eval destroy [lrange [winfo children $base] \ [expr { 2 * $count }] end] } \ errorMessage] } { puts stderr "doc_make_listbox: error listing $dir\n" } - } + #} # exportselection 0 looks good, but selection gets easily out-of-sync set current_listbox [listbox "[set b "$base.listbox$count"]-list" -yscrollcommand \ [list "$b-scroll" set] -height 20 -exportselection 0] diff --git a/pd/src/x_midi.c b/pd/src/x_midi.c index b985041d..3e25cf4e 100644 --- a/pd/src/x_midi.c +++ b/pd/src/x_midi.c @@ -12,6 +12,8 @@ void outmidi_pitchbend(int portno, int channel, int value); void outmidi_aftertouch(int portno, int channel, int value); void outmidi_polyaftertouch(int portno, int channel, int pitch, int value); void outmidi_mclk(int portno); +void outmidi_byte(int portno, int value); + /* ----------------------- midiin and sysexin ------------------------- */ @@ -32,8 +34,8 @@ static void *midiin_new( void) x->x_outlet1 = outlet_new(&x->x_obj, &s_float); x->x_outlet2 = outlet_new(&x->x_obj, &s_float); pd_bind(&x->x_obj.ob_pd, midiin_sym); -#ifndef __linux__ - pd_error(x, "midiin: works under Linux only"); +#ifdef WIN32 + pd_error(x, "midiin: windows: not supported"); #endif return (x); } @@ -55,8 +57,8 @@ static void *sysexin_new( void) x->x_outlet1 = outlet_new(&x->x_obj, &s_float); x->x_outlet2 = outlet_new(&x->x_obj, &s_float); pd_bind(&x->x_obj.ob_pd, sysexin_sym); -#ifndef __linux__ - pd_error(x, "sysexin: works under Linux only"); +#ifdef WIN32 + pd_error(x, "sysexin: windows: not supported"); #endif return (x); } @@ -678,7 +680,7 @@ static void *midiout_new(t_floatarg portno) static void midiout_float(t_midiout *x, t_floatarg f) { - sys_putmidibyte(x->x_portno - 1, f); + outmidi_byte(x->x_portno - 1, f); } static void midiout_setup(void) diff --git a/pd/src/x_misc.c b/pd/src/x_misc.c index 411304fa..0c894c72 100644 --- a/pd/src/x_misc.c +++ b/pd/src/x_misc.c @@ -22,7 +22,10 @@ #endif #if defined (__APPLE__) || defined (__FreeBSD__) -#define HZ CLK_TCK +#define CLOCKHZ CLK_TCK +#endif +#if defined (__linux__) +#define CLOCKHZ sysconf(_SC_CLK_TCK) #endif /* -------------------------- random ------------------------------ */ @@ -230,7 +233,7 @@ static void cputime_bang2(t_cputime *x) times(&newcputime); elapsedcpu = 1000 * ( newcputime.tms_utime + newcputime.tms_stime - - x->x_setcputime.tms_utime - x->x_setcputime.tms_stime) / HZ; + x->x_setcputime.tms_utime - x->x_setcputime.tms_stime) / CLOCKHZ; outlet_float(x->x_obj.ob_outlet, elapsedcpu); #endif #ifdef MSW |