void csoundInputMessageInternal(CSOUND *csound, const char *message) { int32 size = (int32) strlen(message); int n; if ((n=linevent_alloc(csound, 0)) != 0) return; if (!size) return; if (UNLIKELY((STA(Linep) + size) >= STA(Linebufend))) { int extralloc = STA(Linep) + size - STA(Linebufend); if ((n=linevent_alloc(csound, STA(linebufsiz) + extralloc ), 0) != 0) { csoundErrorMsg(csound, Str("LineBuffer Overflow - " "Input Data has been Lost")); return; } } memcpy(STA(Linep), message, size); if (STA(Linep)[size - 1] != (char) '\n') STA(Linep)[size++] = (char) '\n'; STA(Linep) += size; }
int sensMidi(CSOUND *csound) { MGLOBAL *p = csound->midiGlobals; MEVENT *mep = p->Midevtblk; OPARMS *O = csound->oparms; int n; int16 c, type; nxtchr: if (p->bufp >= p->endatp) { p->bufp = &(p->mbuf[0]); p->endatp = p->bufp; if (O->Midiin && !csound->advanceCnt) { /* read MIDI device */ n = p->MidiReadCallback(csound, p->midiInUserData, p->bufp, MBUFSIZ); if (n < 0) csoundErrorMsg(csound, Str(" *** error reading MIDI device: %d (%s)"), n, csoundExternalMidiErrorString(csound, n)); else p->endatp += (int) n; } if (O->FMidiin) { /* read MIDI file */ n = csoundMIDIFileRead(csound, p->endatp, MBUFSIZ - (int) (p->endatp - p->bufp)); if (n > 0) p->endatp += (int) n; } if (p->endatp <= p->bufp) return 0; /* no events were received */ } if ((c = *(p->bufp++)) & 0x80) { /* STATUS byte: */ type = c & 0xF0; if (type == SYSTEM_TYPE) { int16 lo3 = (c & 0x07); if (c & 0x08) /* sys_realtime: */ switch (lo3) { /* dispatch now */ case 0: /* m_clktim++; */ /* timing clock */ case 2: /* start */ case 3: /* continue */ case 4: /* stop */ case 6: /* active sensing */ case 7: /* system reset */ goto nxtchr; default: csound->Message(csound, Str("undefined sys-realtime msg %x\n"), c); goto nxtchr; } else { /* sys_non-realtime status: */ p->sexp = 0; /* implies sys_exclus end */ switch (lo3) { /* dispatch on lo3: */ case 7: goto nxtchr; /* EOX: already done */ case 0: p->sexp = 1; /* sys_ex begin: */ goto nxtchr; /* goto copy data */ /* sys_common: need some data, so build evt */ case 1: /* MTC quarter frame */ case 3: p->datreq = 1; /* song select */ break; case 2: p->datreq = 2; /* song position */ break; case 6: /* tune request */ goto nxtchr; default: csound->Message(csound, Str("undefined sys_common msg %x\n"), c); p->datreq = 32767; /* waste any data following */ p->datcnt = 0; goto nxtchr; } } mep->type = type; /* begin sys_com event */ mep->chan = lo3; /* holding code in chan */ p->datcnt = 0; goto nxtchr; } else { /* other status types: */ int16 chan; p->sexp = 0; /* also implies sys_exclus end */ chan = c & 0xF; mep->type = type; /* & begin new event */ mep->chan = chan; p->datreq = datbyts[(type>>4) & 0x7]; p->datcnt = 0; goto nxtchr; } }