From ed932acb5860bf8b9296169676499562a55d139e Mon Sep 17 00:00:00 2001 From: Miller Puckette Date: Mon, 6 Sep 2004 20:20:36 +0000 Subject: checking in version 0.38test5. Oops, I realize I forgot some more nice files, will add them and re-commit. svn path=/trunk/; revision=2010 --- pd/src/x_midi.c | 424 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 212 insertions(+), 212 deletions(-) (limited to 'pd/src/x_midi.c') diff --git a/pd/src/x_midi.c b/pd/src/x_midi.c index 1ff0e4b3..6b2fd60c 100644 --- a/pd/src/x_midi.c +++ b/pd/src/x_midi.c @@ -69,15 +69,15 @@ static void sysexin_free(t_midiin *x) static void midiin_setup(void) { midiin_class = class_new(gensym("midiin"), (t_newmethod)midiin_new, - (t_method)midiin_free, sizeof(t_midiin), - CLASS_NOINLET, A_DEFFLOAT, 0); + (t_method)midiin_free, sizeof(t_midiin), + CLASS_NOINLET, A_DEFFLOAT, 0); class_addlist(midiin_class, midiin_list); class_sethelpsymbol(midiin_class, gensym("midi")); midiin_sym = gensym("#midiin"); sysexin_class = class_new(gensym("sysexin"), (t_newmethod)sysexin_new, - (t_method)sysexin_free, sizeof(t_midiin), - CLASS_NOINLET, A_DEFFLOAT, 0); + (t_method)sysexin_free, sizeof(t_midiin), + CLASS_NOINLET, A_DEFFLOAT, 0); class_addlist(sysexin_class, midiin_list); class_sethelpsymbol(sysexin_class, gensym("midi")); sysexin_sym = gensym("#sysexin"); @@ -88,9 +88,9 @@ void inmidi_byte(int portno, int byte) t_atom at[2]; if (midiin_sym->s_thing) { - SETFLOAT(at, byte); - SETFLOAT(at+1, portno + 1); - pd_list(midiin_sym->s_thing, 0, 2, at); + SETFLOAT(at, byte); + SETFLOAT(at+1, portno + 1); + pd_list(midiin_sym->s_thing, 0, 2, at); } } @@ -99,9 +99,9 @@ void inmidi_sysex(int portno, int byte) t_atom at[2]; if (sysexin_sym->s_thing) { - SETFLOAT(at, byte); - SETFLOAT(at+1, portno + 1); - pd_list(sysexin_sym->s_thing, 0, 2, at); + SETFLOAT(at, byte); + SETFLOAT(at+1, portno + 1); + pd_list(sysexin_sym->s_thing, 0, 2, at); } } @@ -138,15 +138,15 @@ static void notein_list(t_notein *x, t_symbol *s, int argc, t_atom *argv) float channel = atom_getfloatarg(2, argc, argv); if (x->x_channel != 0) { - if (channel != x->x_channel) return; - outlet_float(x->x_outlet2, velo); - outlet_float(x->x_outlet1, pitch); + if (channel != x->x_channel) return; + outlet_float(x->x_outlet2, velo); + outlet_float(x->x_outlet1, pitch); } else { - outlet_float(x->x_outlet3, channel); - outlet_float(x->x_outlet2, velo); - outlet_float(x->x_outlet1, pitch); + outlet_float(x->x_outlet3, channel); + outlet_float(x->x_outlet2, velo); + outlet_float(x->x_outlet1, pitch); } } @@ -158,7 +158,7 @@ static void notein_free(t_notein *x) static void notein_setup(void) { notein_class = class_new(gensym("notein"), (t_newmethod)notein_new, - (t_method)notein_free, sizeof(t_notein), CLASS_NOINLET, A_DEFFLOAT, 0); + (t_method)notein_free, sizeof(t_notein), CLASS_NOINLET, A_DEFFLOAT, 0); class_addlist(notein_class, notein_list); class_sethelpsymbol(notein_class, gensym("midi")); notein_sym = gensym("#notein"); @@ -168,11 +168,11 @@ void inmidi_noteon(int portno, int channel, int pitch, int velo) { if (notein_sym->s_thing) { - t_atom at[3]; - SETFLOAT(at, pitch); - SETFLOAT(at+1, velo); - SETFLOAT(at+2, (channel + (portno << 4) + 1)); - pd_list(notein_sym->s_thing, &s_list, 3, at); + t_atom at[3]; + SETFLOAT(at, pitch); + SETFLOAT(at+1, velo); + SETFLOAT(at+2, (channel + (portno << 4) + 1)); + pd_list(notein_sym->s_thing, &s_list, 3, at); } } @@ -204,8 +204,8 @@ static void *ctlin_new(t_symbol *s, int argc, t_atom *argv) x->x_outlet1 = outlet_new(&x->x_obj, &s_float); if (!channel) { - if (x->x_ctlno < 0) x->x_outlet2 = outlet_new(&x->x_obj, &s_float); - x->x_outlet3 = outlet_new(&x->x_obj, &s_float); + if (x->x_ctlno < 0) x->x_outlet2 = outlet_new(&x->x_obj, &s_float); + x->x_outlet3 = outlet_new(&x->x_obj, &s_float); } pd_bind(&x->x_obj.ob_pd, ctlin_sym); return (x); @@ -231,8 +231,8 @@ static void ctlin_free(t_ctlin *x) static void ctlin_setup(void) { ctlin_class = class_new(gensym("ctlin"), (t_newmethod)ctlin_new, - (t_method)ctlin_free, sizeof(t_ctlin), - CLASS_NOINLET, A_GIMME, 0); + (t_method)ctlin_free, sizeof(t_ctlin), + CLASS_NOINLET, A_GIMME, 0); class_addlist(ctlin_class, ctlin_list); class_sethelpsymbol(ctlin_class, gensym("midi")); ctlin_sym = gensym("#ctlin"); @@ -242,11 +242,11 @@ void inmidi_controlchange(int portno, int channel, int ctlnumber, int value) { if (ctlin_sym->s_thing) { - t_atom at[3]; - SETFLOAT(at, ctlnumber); - SETFLOAT(at+1, value); - SETFLOAT(at+2, (channel + (portno << 4) + 1)); - pd_list(ctlin_sym->s_thing, &s_list, 3, at); + t_atom at[3]; + SETFLOAT(at, ctlnumber); + SETFLOAT(at+1, value); + SETFLOAT(at+2, (channel + (portno << 4) + 1)); + pd_list(ctlin_sym->s_thing, &s_list, 3, at); } } @@ -280,13 +280,13 @@ static void pgmin_list(t_pgmin *x, t_symbol *s, int argc, t_atom *argv) float channel = atom_getfloatarg(1, argc, argv); if (x->x_channel != 0) { - if (channel != x->x_channel) return; - outlet_float(x->x_outlet1, value); + if (channel != x->x_channel) return; + outlet_float(x->x_outlet1, value); } else { - outlet_float(x->x_outlet2, channel); - outlet_float(x->x_outlet1, value); + outlet_float(x->x_outlet2, channel); + outlet_float(x->x_outlet1, value); } } @@ -298,8 +298,8 @@ static void pgmin_free(t_pgmin *x) static void pgmin_setup(void) { pgmin_class = class_new(gensym("pgmin"), (t_newmethod)pgmin_new, - (t_method)pgmin_free, sizeof(t_pgmin), - CLASS_NOINLET, A_DEFFLOAT, 0); + (t_method)pgmin_free, sizeof(t_pgmin), + CLASS_NOINLET, A_DEFFLOAT, 0); class_addlist(pgmin_class, pgmin_list); class_sethelpsymbol(pgmin_class, gensym("midi")); pgmin_sym = gensym("#pgmin"); @@ -309,10 +309,10 @@ void inmidi_programchange(int portno, int channel, int value) { if (pgmin_sym->s_thing) { - t_atom at[2]; - SETFLOAT(at, value + 1); - SETFLOAT(at+1, (channel + (portno << 4) + 1)); - pd_list(pgmin_sym->s_thing, &s_list, 2, at); + t_atom at[2]; + SETFLOAT(at, value + 1); + SETFLOAT(at+1, (channel + (portno << 4) + 1)); + pd_list(pgmin_sym->s_thing, &s_list, 2, at); } } @@ -346,13 +346,13 @@ static void bendin_list(t_bendin *x, t_symbol *s, int argc, t_atom *argv) t_float channel = atom_getfloatarg(1, argc, argv); if (x->x_channel != 0) { - if (channel != x->x_channel) return; - outlet_float(x->x_outlet1, value); + if (channel != x->x_channel) return; + outlet_float(x->x_outlet1, value); } else { - outlet_float(x->x_outlet2, channel); - outlet_float(x->x_outlet1, value); + outlet_float(x->x_outlet2, channel); + outlet_float(x->x_outlet1, value); } } @@ -364,7 +364,7 @@ static void bendin_free(t_bendin *x) static void bendin_setup(void) { bendin_class = class_new(gensym("bendin"), (t_newmethod)bendin_new, - (t_method)bendin_free, sizeof(t_bendin), CLASS_NOINLET, A_DEFFLOAT, 0); + (t_method)bendin_free, sizeof(t_bendin), CLASS_NOINLET, A_DEFFLOAT, 0); class_addlist(bendin_class, bendin_list); class_sethelpsymbol(bendin_class, gensym("midi")); bendin_sym = gensym("#bendin"); @@ -374,10 +374,10 @@ void inmidi_pitchbend(int portno, int channel, int value) { if (bendin_sym->s_thing) { - t_atom at[2]; - SETFLOAT(at, value); - SETFLOAT(at+1, (channel + (portno << 4) + 1)); - pd_list(bendin_sym->s_thing, &s_list, 2, at); + t_atom at[2]; + SETFLOAT(at, value); + SETFLOAT(at+1, (channel + (portno << 4) + 1)); + pd_list(bendin_sym->s_thing, &s_list, 2, at); } } @@ -411,13 +411,13 @@ static void touchin_list(t_touchin *x, t_symbol *s, int argc, t_atom *argv) t_float channel = atom_getfloatarg(1, argc, argv); if (x->x_channel) { - if (channel != x->x_channel) return; - outlet_float(x->x_outlet1, value); + if (channel != x->x_channel) return; + outlet_float(x->x_outlet1, value); } else { - outlet_float(x->x_outlet2, channel); - outlet_float(x->x_outlet1, value); + outlet_float(x->x_outlet2, channel); + outlet_float(x->x_outlet1, value); } } @@ -429,8 +429,8 @@ static void touchin_free(t_touchin *x) static void touchin_setup(void) { touchin_class = class_new(gensym("touchin"), (t_newmethod)touchin_new, - (t_method)touchin_free, sizeof(t_touchin), - CLASS_NOINLET, A_DEFFLOAT, 0); + (t_method)touchin_free, sizeof(t_touchin), + CLASS_NOINLET, A_DEFFLOAT, 0); class_addlist(touchin_class, touchin_list); class_sethelpsymbol(touchin_class, gensym("midi")); touchin_sym = gensym("#touchin"); @@ -440,10 +440,10 @@ void inmidi_aftertouch(int portno, int channel, int value) { if (touchin_sym->s_thing) { - t_atom at[2]; - SETFLOAT(at, value); - SETFLOAT(at+1, (channel + (portno << 4) + 1)); - pd_list(touchin_sym->s_thing, &s_list, 2, at); + t_atom at[2]; + SETFLOAT(at, value); + SETFLOAT(at+1, (channel + (portno << 4) + 1)); + pd_list(touchin_sym->s_thing, &s_list, 2, at); } } @@ -481,15 +481,15 @@ static void polytouchin_list(t_polytouchin *x, t_symbol *s, int argc, t_float channel = atom_getfloatarg(2, argc, argv); if (x->x_channel != 0) { - if (channel != x->x_channel) return; - outlet_float(x->x_outlet2, pitch); - outlet_float(x->x_outlet1, value); + if (channel != x->x_channel) return; + outlet_float(x->x_outlet2, pitch); + outlet_float(x->x_outlet1, value); } else { - outlet_float(x->x_outlet3, channel); - outlet_float(x->x_outlet2, pitch); - outlet_float(x->x_outlet1, value); + outlet_float(x->x_outlet3, channel); + outlet_float(x->x_outlet2, pitch); + outlet_float(x->x_outlet1, value); } } @@ -501,8 +501,8 @@ static void polytouchin_free(t_polytouchin *x) static void polytouchin_setup(void) { polytouchin_class = class_new(gensym("polytouchin"), - (t_newmethod)polytouchin_new, (t_method)polytouchin_free, - sizeof(t_polytouchin), CLASS_NOINLET, A_DEFFLOAT, 0); + (t_newmethod)polytouchin_new, (t_method)polytouchin_free, + sizeof(t_polytouchin), CLASS_NOINLET, A_DEFFLOAT, 0); class_addlist(polytouchin_class, polytouchin_list); class_sethelpsymbol(polytouchin_class, gensym("midi")); polytouchin_sym = gensym("#polytouchin"); @@ -512,11 +512,11 @@ void inmidi_polyaftertouch(int portno, int channel, int pitch, int value) { if (polytouchin_sym->s_thing) { - t_atom at[3]; - SETFLOAT(at, pitch); - SETFLOAT(at+1, value); - SETFLOAT(at+2, (channel + (portno << 4) + 1)); - pd_list(polytouchin_sym->s_thing, &s_list, 3, at); + t_atom at[3]; + SETFLOAT(at, pitch); + SETFLOAT(at+1, value); + SETFLOAT(at+2, (channel + (portno << 4) + 1)); + pd_list(polytouchin_sym->s_thing, &s_list, 3, at); } } @@ -558,10 +558,10 @@ static void midiclkin_free(t_midiclkin *x) static void midiclkin_setup(void) { midiclkin_class = class_new(gensym("midiclkin"), - (t_newmethod)midiclkin_new, (t_method)midiclkin_free, - sizeof(t_midiclkin), CLASS_NOINLET, A_DEFFLOAT, 0); + (t_newmethod)midiclkin_new, (t_method)midiclkin_free, + sizeof(t_midiclkin), CLASS_NOINLET, A_DEFFLOAT, 0); class_addlist(midiclkin_class, midiclkin_list); - class_sethelpsymbol(midiclkin_class, gensym("midi")); + class_sethelpsymbol(midiclkin_class, gensym("midi")); midiclkin_sym = gensym("#midiclkin"); } @@ -574,20 +574,20 @@ void inmidi_clk(double timing) if (midiclkin_sym->s_thing) { - t_atom at[2]; - diff =timing - prev; - count++; + t_atom at[2]; + diff =timing - prev; + count++; - if (count == 3) - { /* 24 count per quoter note */ - SETFLOAT(at, 1 ); - count = 0; - } - else SETFLOAT(at, 0); - - SETFLOAT(at+1, diff); - pd_list(midiclkin_sym->s_thing, &s_list, 2, at); - prev = timing; + if (count == 3) + { /* 24 count per quoter note */ + SETFLOAT(at, 1 ); + count = 0; + } + else SETFLOAT(at, 0); + + SETFLOAT(at+1, diff); + pd_list(midiclkin_sym->s_thing, &s_list, 2, at); + prev = timing; } } @@ -634,10 +634,10 @@ static void midirealtimein_free(t_midirealtimein *x) static void midirealtimein_setup(void) { midirealtimein_class = class_new(gensym("midirealtimein"), - (t_newmethod)midirealtimein_new, (t_method)midirealtimein_free, - sizeof(t_midirealtimein), CLASS_NOINLET, A_DEFFLOAT, 0); + (t_newmethod)midirealtimein_new, (t_method)midirealtimein_free, + sizeof(t_midirealtimein), CLASS_NOINLET, A_DEFFLOAT, 0); class_addlist(midirealtimein_class, midirealtimein_list); - class_sethelpsymbol(midirealtimein_class, gensym("midi")); + class_sethelpsymbol(midirealtimein_class, gensym("midi")); midirealtimein_sym = gensym("#midirealtimein"); } @@ -645,10 +645,10 @@ void inmidi_realtimein(int portno, int SysMsg) { if (midirealtimein_sym->s_thing) { - t_atom at[2]; - SETFLOAT(at, portno); - SETFLOAT(at+1, SysMsg); - pd_list(midirealtimein_sym->s_thing, &s_list, 1, at); + t_atom at[2]; + SETFLOAT(at, portno); + SETFLOAT(at+1, SysMsg); + pd_list(midirealtimein_sym->s_thing, &s_list, 1, at); } } @@ -684,7 +684,7 @@ static void midiout_float(t_midiout *x, t_floatarg f) static void midiout_setup(void) { midiout_class = class_new(gensym("midiout"), (t_newmethod)midiout_new, 0, - sizeof(t_midiout), 0, A_DEFFLOAT, A_DEFFLOAT, 0); + sizeof(t_midiout), 0, A_DEFFLOAT, A_DEFFLOAT, 0); class_addfloat(midiout_class, midiout_float); class_sethelpsymbol(midiout_class, gensym("midi")); } @@ -715,15 +715,15 @@ static void noteout_float(t_noteout *x, t_float f) { int binchan = x->x_channel - 1; if (binchan < 0) - binchan = 0; + binchan = 0; outmidi_noteon((binchan >> 4), - (binchan & 15), (int)f, (int)x->x_velo); + (binchan & 15), (int)f, (int)x->x_velo); } static void noteout_setup(void) { noteout_class = class_new(gensym("noteout"), (t_newmethod)noteout_new, 0, - sizeof(t_noteout), 0, A_DEFFLOAT, 0); + sizeof(t_noteout), 0, A_DEFFLOAT, 0); class_addfloat(noteout_class, noteout_float); class_sethelpsymbol(noteout_class, gensym("midi")); } @@ -755,15 +755,15 @@ static void ctlout_float(t_ctlout *x, t_float f) { int binchan = x->x_channel - 1; if (binchan < 0) - binchan = 0; + binchan = 0; outmidi_controlchange((binchan >> 4), - (binchan & 15), (int)(x->x_ctl), (int)f); + (binchan & 15), (int)(x->x_ctl), (int)f); } static void ctlout_setup(void) { ctlout_class = class_new(gensym("ctlout"), (t_newmethod)ctlout_new, 0, - sizeof(t_ctlout), 0, A_DEFFLOAT, A_DEFFLOAT, 0); + sizeof(t_ctlout), 0, A_DEFFLOAT, A_DEFFLOAT, 0); class_addfloat(ctlout_class, ctlout_float); class_sethelpsymbol(ctlout_class, gensym("midi")); } @@ -793,17 +793,17 @@ static void pgmout_float(t_pgmout *x, t_floatarg f) int binchan = x->x_channel - 1; int n = f - 1; if (binchan < 0) - binchan = 0; + binchan = 0; if (n < 0) n = 0; else if (n > 127) n = 127; outmidi_programchange((binchan >> 4), - (binchan & 15), n); + (binchan & 15), n); } static void pgmout_setup(void) { pgmout_class = class_new(gensym("pgmout"), (t_newmethod)pgmout_new, 0, - sizeof(t_pgmout), 0, A_DEFFLOAT, 0); + sizeof(t_pgmout), 0, A_DEFFLOAT, 0); class_addfloat(pgmout_class, pgmout_float); class_sethelpsymbol(pgmout_class, gensym("midi")); } @@ -833,14 +833,14 @@ static void bendout_float(t_bendout *x, t_float f) int binchan = x->x_channel - 1; int n = (int)f + 8192; if (binchan < 0) - binchan = 0; + binchan = 0; outmidi_pitchbend((binchan >> 4), (binchan & 15), n); } static void bendout_setup(void) { bendout_class = class_new(gensym("bendout"), (t_newmethod)bendout_new, 0, - sizeof(t_bendout), 0, A_DEFFLOAT, 0); + sizeof(t_bendout), 0, A_DEFFLOAT, 0); class_addfloat(bendout_class, bendout_float); class_sethelpsymbol(bendout_class, gensym("midi")); } @@ -868,14 +868,14 @@ static void touchout_float(t_touchout *x, t_float f) { int binchan = x->x_channel - 1; if (binchan < 0) - binchan = 0; + binchan = 0; outmidi_aftertouch((binchan >> 4), (binchan & 15), (int)f); } static void touchout_setup(void) { touchout_class = class_new(gensym("touchout"), (t_newmethod)touchout_new, 0, - sizeof(t_touchout), 0, A_DEFFLOAT, 0); + sizeof(t_touchout), 0, A_DEFFLOAT, 0); class_addfloat(touchout_class, touchout_float); class_sethelpsymbol(touchout_class, gensym("midi")); } @@ -906,15 +906,15 @@ static void polytouchout_float(t_polytouchout *x, t_float n) { int binchan = x->x_channel - 1; if (binchan < 0) - binchan = 0; + binchan = 0; outmidi_polyaftertouch((binchan >> 4), (binchan & 15), x->x_pitch, n); } static void polytouchout_setup(void) { polytouchout_class = class_new(gensym("polytouchout"), - (t_newmethod)polytouchout_new, 0, - sizeof(t_polytouchout), 0, A_DEFFLOAT, 0); + (t_newmethod)polytouchout_new, 0, + sizeof(t_polytouchout), 0, A_DEFFLOAT, 0); class_addfloat(polytouchout_class, polytouchout_float); class_sethelpsymbol(polytouchout_class, gensym("midi")); } @@ -963,11 +963,11 @@ static void makenote_tick(t_hang *hang) if (x->x_hang == hang) x->x_hang = hang->h_next; else for (h2 = x->x_hang; h3 = h2->h_next; h2 = h3) { - if (h3 == hang) - { - h2->h_next = h3->h_next; - break; - } + if (h3 == hang) + { + h2->h_next = h3->h_next; + break; + } } clock_free(hang->h_clock); freebytes(hang, sizeof(*hang)); @@ -993,11 +993,11 @@ static void makenote_stop(t_makenote *x) t_hang *hang; while (hang = x->x_hang) { - outlet_float(x->x_velout, 0); - outlet_float(x->x_pitchout, hang->h_pitch); - x->x_hang = hang->h_next; - clock_free(hang->h_clock); - freebytes(hang, sizeof(*hang)); + outlet_float(x->x_velout, 0); + outlet_float(x->x_pitchout, hang->h_pitch); + x->x_hang = hang->h_next; + clock_free(hang->h_clock); + freebytes(hang, sizeof(*hang)); } } @@ -1006,22 +1006,22 @@ static void makenote_clear(t_makenote *x) t_hang *hang; while (hang = x->x_hang) { - x->x_hang = hang->h_next; - clock_free(hang->h_clock); - freebytes(hang, sizeof(*hang)); + x->x_hang = hang->h_next; + clock_free(hang->h_clock); + freebytes(hang, sizeof(*hang)); } } static void makenote_setup(void) { makenote_class = class_new(gensym("makenote"), - (t_newmethod)makenote_new, (t_method)makenote_clear, - sizeof(t_makenote), 0, A_DEFFLOAT, A_DEFFLOAT, 0); + (t_newmethod)makenote_new, (t_method)makenote_clear, + sizeof(t_makenote), 0, A_DEFFLOAT, A_DEFFLOAT, 0); class_addfloat(makenote_class, makenote_float); class_addmethod(makenote_class, (t_method)makenote_stop, gensym("stop"), - 0); + 0); class_addmethod(makenote_class, (t_method)makenote_clear, gensym("clear"), - 0); + 0); } /* -------------------------- stripnote -------------------------- */ @@ -1056,7 +1056,7 @@ static void stripnote_float(t_stripnote *x, t_float f) static void stripnote_setup(void) { stripnote_class = class_new(gensym("stripnote"), - (t_newmethod)stripnote_new, 0, sizeof(t_stripnote), 0, 0); + (t_newmethod)stripnote_new, 0, sizeof(t_stripnote), 0, 0); class_addfloat(stripnote_class, stripnote_float); } @@ -1092,7 +1092,7 @@ static void *poly_new(float fnvoice, float fsteal) x->x_n = n; x->x_vec = (t_voice *)getbytes(n * sizeof(*x->x_vec)); for (v = x->x_vec, i = n; i--; v++) - v->v_pitch = v->v_used = v->v_serial = 0; + v->v_pitch = v->v_used = v->v_serial = 0; x->x_vel = 0; x->x_steal = (fsteal != 0); floatinlet_new(&x->x_obj, &x->x_vel); @@ -1111,49 +1111,49 @@ static void poly_float(t_poly *x, t_float f) unsigned int serialon, serialoff, onindex = 0, offindex = 0; if (x->x_vel > 0) { - /* note on. Look for a vacant voice */ - for (v = x->x_vec, i = 0, firston = firstoff = 0, - serialon = serialoff = 0xffffffff; i < x->x_n; v++, i++) - { - if (v->v_used && v->v_serial < serialon) - firston = v, serialon = v->v_serial, onindex = i; - else if (!v->v_used && v->v_serial < serialoff) - firstoff = v, serialoff = v->v_serial, offindex = i; - } - if (firstoff) - { - outlet_float(x->x_velout, x->x_vel); - outlet_float(x->x_pitchout, firstoff->v_pitch = f); - outlet_float(x->x_obj.ob_outlet, offindex+1); - firstoff->v_used = 1; - firstoff->v_serial = x->x_serial++; - } - /* if none, steal one */ - else if (firston && x->x_steal) - { - outlet_float(x->x_velout, 0); - outlet_float(x->x_pitchout, firston->v_pitch); - outlet_float(x->x_obj.ob_outlet, onindex+1); - outlet_float(x->x_velout, x->x_vel); - outlet_float(x->x_pitchout, firston->v_pitch = f); - outlet_float(x->x_obj.ob_outlet, onindex+1); - firston->v_serial = x->x_serial++; - } + /* note on. Look for a vacant voice */ + for (v = x->x_vec, i = 0, firston = firstoff = 0, + serialon = serialoff = 0xffffffff; i < x->x_n; v++, i++) + { + if (v->v_used && v->v_serial < serialon) + firston = v, serialon = v->v_serial, onindex = i; + else if (!v->v_used && v->v_serial < serialoff) + firstoff = v, serialoff = v->v_serial, offindex = i; + } + if (firstoff) + { + outlet_float(x->x_velout, x->x_vel); + outlet_float(x->x_pitchout, firstoff->v_pitch = f); + outlet_float(x->x_obj.ob_outlet, offindex+1); + firstoff->v_used = 1; + firstoff->v_serial = x->x_serial++; + } + /* if none, steal one */ + else if (firston && x->x_steal) + { + outlet_float(x->x_velout, 0); + outlet_float(x->x_pitchout, firston->v_pitch); + outlet_float(x->x_obj.ob_outlet, onindex+1); + outlet_float(x->x_velout, x->x_vel); + outlet_float(x->x_pitchout, firston->v_pitch = f); + outlet_float(x->x_obj.ob_outlet, onindex+1); + firston->v_serial = x->x_serial++; + } } else /* note off. Turn off oldest match */ { - for (v = x->x_vec, i = 0, firston = 0, serialon = 0xffffffff; - i < x->x_n; v++, i++) - if (v->v_used && v->v_pitch == f && v->v_serial < serialon) - firston = v, serialon = v->v_serial, onindex = i; - if (firston) - { - firston->v_used = 0; - firston->v_serial = x->x_serial++; - outlet_float(x->x_velout, 0); - outlet_float(x->x_pitchout, firston->v_pitch); - outlet_float(x->x_obj.ob_outlet, onindex+1); - } + for (v = x->x_vec, i = 0, firston = 0, serialon = 0xffffffff; + i < x->x_n; v++, i++) + if (v->v_used && v->v_pitch == f && v->v_serial < serialon) + firston = v, serialon = v->v_serial, onindex = i; + if (firston) + { + firston->v_used = 0; + firston->v_serial = x->x_serial++; + outlet_float(x->x_velout, 0); + outlet_float(x->x_pitchout, firston->v_pitch); + outlet_float(x->x_obj.ob_outlet, onindex+1); + } } } @@ -1162,13 +1162,13 @@ static void poly_stop(t_poly *x) int i; t_voice *v; for (i = 0, v = x->x_vec; i < x->x_n; i++, v++) - if (v->v_used) + if (v->v_used) { - outlet_float(x->x_velout, 0L); - outlet_float(x->x_pitchout, v->v_pitch); - outlet_float(x->x_obj.ob_outlet, i+1); - v->v_used = 0; - v->v_serial = x->x_serial++; + outlet_float(x->x_velout, 0L); + outlet_float(x->x_pitchout, v->v_pitch); + outlet_float(x->x_obj.ob_outlet, i+1); + v->v_used = 0; + v->v_serial = x->x_serial++; } } @@ -1187,8 +1187,8 @@ static void poly_free(t_poly *x) static void poly_setup(void) { poly_class = class_new(gensym("poly"), - (t_newmethod)poly_new, (t_method)poly_clear, - sizeof(t_poly), 0, A_DEFFLOAT, A_DEFFLOAT, 0); + (t_newmethod)poly_new, (t_method)poly_clear, + sizeof(t_poly), 0, A_DEFFLOAT, A_DEFFLOAT, 0); class_addfloat(poly_class, poly_float); class_addmethod(poly_class, (t_method)poly_stop, gensym("stop"), 0); class_addmethod(poly_class, (t_method)poly_clear, gensym("clear"), 0); @@ -1226,34 +1226,34 @@ static void bag_float(t_bag *x, t_float f) t_bagelem *bagelem, *e2, *e3; if (x->x_velo != 0) { - bagelem = (t_bagelem *)getbytes(sizeof *bagelem); - bagelem->e_next = 0; - bagelem->e_value = f; - if (!x->x_first) x->x_first = bagelem; - else /* LATER replace with a faster algorithm */ - { - for (e2 = x->x_first; e3 = e2->e_next; e2 = e3) - ; - e2->e_next = bagelem; - } + bagelem = (t_bagelem *)getbytes(sizeof *bagelem); + bagelem->e_next = 0; + bagelem->e_value = f; + if (!x->x_first) x->x_first = bagelem; + else /* LATER replace with a faster algorithm */ + { + for (e2 = x->x_first; e3 = e2->e_next; e2 = e3) + ; + e2->e_next = bagelem; + } } else { - if (!x->x_first) return; - if (x->x_first->e_value == f) - { - bagelem = x->x_first; - x->x_first = x->x_first->e_next; - freebytes(bagelem, sizeof(*bagelem)); - return; - } - for (e2 = x->x_first; e3 = e2->e_next; e2 = e3) - if (e3->e_value == f) - { - e2->e_next = e3->e_next; - freebytes(e3, sizeof(*e3)); - return; - } + if (!x->x_first) return; + if (x->x_first->e_value == f) + { + bagelem = x->x_first; + x->x_first = x->x_first->e_next; + freebytes(bagelem, sizeof(*bagelem)); + return; + } + for (e2 = x->x_first; e3 = e2->e_next; e2 = e3) + if (e3->e_value == f) + { + e2->e_next = e3->e_next; + freebytes(e3, sizeof(*e3)); + return; + } } } @@ -1262,9 +1262,9 @@ static void bag_flush(t_bag *x) t_bagelem *bagelem; while (bagelem = x->x_first) { - outlet_float(x->x_obj.ob_outlet, bagelem->e_value); - x->x_first = bagelem->e_next; - freebytes(bagelem, sizeof(*bagelem)); + outlet_float(x->x_obj.ob_outlet, bagelem->e_value); + x->x_first = bagelem->e_next; + freebytes(bagelem, sizeof(*bagelem)); } } @@ -1273,16 +1273,16 @@ static void bag_clear(t_bag *x) t_bagelem *bagelem; while (bagelem = x->x_first) { - x->x_first = bagelem->e_next; - freebytes(bagelem, sizeof(*bagelem)); + x->x_first = bagelem->e_next; + freebytes(bagelem, sizeof(*bagelem)); } } static void bag_setup(void) { bag_class = class_new(gensym("bag"), - (t_newmethod)bag_new, (t_method)bag_clear, - sizeof(t_bag), 0, 0); + (t_newmethod)bag_new, (t_method)bag_clear, + sizeof(t_bag), 0, 0); class_addfloat(bag_class, bag_float); class_addmethod(bag_class, (t_method)bag_flush, gensym("flush"), 0); class_addmethod(bag_class, (t_method)bag_clear, gensym("clear"), 0); -- cgit v1.2.1