static void RegParamLinearizeMth (MidiEvPtr e, Ev2StreamPtr f) { Byte status; short n = e->info.param.num & 0x3FFF; short v = e->info.param.val & 0x3FFF; status = ControlChg + Chan(e); if( f->runStat== status) f->count= 8; else { f->runStat= f->data[9]= status; f->count= 9; } f->data[8] = RPMSB; f->data[7] = n >> 7; f->data[6] = RPLSB; f->data[5] = n & 0x7F; f->data[4] = DENTRYMSB; f->data[3] = v >> 7; f->data[2] = DENTRYLSB; f->data[1] = v & 0x7F; MidiFreeCell (e); }
void MidiInputDeviceMidiShare::KeyOffTask(long date, short ref, long a1, long a2, long a3) { MidiInputDeviceMidiShare* driver = (MidiInputDeviceMidiShare*)MidiGetInfo(ref); MidiEvPtr ev =(MidiEvPtr)a1; driver->DispatchNoteOn(Pitch(ev),Vel(ev),Chan(ev)); MidiFreeEv(ev); }
/*____________________________________________________________________*/ static void TestCanal( int i) { MidiEvPtr e; int n, result= true; for( n=0; n<16; n++) { e= MidiNewEv( typeKeyOn); if( e) { Chan(e)= n; MidiSendIm( refNum, e); wait( 2); e= GetReceived(); if( e) { if( n== i) { print ("\n error: canal %d not filtered\n", n); result= false; } MidiFreeEv( e); } else if( n!= i) { print ("\n error: canal %d filtered\n", n); result= false; } } else { print ("\n cannot allocate a new event !\n"); break; } } if( result) print ("ok\n"); }
static inline void LinearizeCommon (int i, MidiEvPtr e, Ev2UDPStreamPtr f) { f->data[i--] = EvType(e); LinearizeDate (i, e, f); i -= kDateSize; f->data[i--] = Port(e); f->data[i] = Chan(e); }
static void Ctrl14bLinearizeMth (MidiEvPtr e, Ev2StreamPtr f) { Byte status; short n = e->info.param.num & 0x1F; short v = e->info.param.val & 0x3FFF; status = ControlChg + Chan(e); if( f->runStat== status) f->count= 4; else { f->runStat= f->data[5]= status; f->count= 5; } f->data[5] = ControlChg + Chan(e); f->data[4] = (Byte)n; f->data[3] = v >> 7; f->data[2] = n+32; f->data[1] = v & 0x7F; MidiFreeCell (e); }
static void ProgChangeLinearizeMth (MidiEvPtr e, Ev2StreamPtr f) { Byte status = ProgramChg + Chan(e); if( f->runStat== status) f->count= 1; else { f->runStat= f->data[2] = status; f->count = 2; } f->data[1] = Pitch(e); MidiFreeCell (e); }
static void NoteLinearizeMth (MidiEvPtr e, Ev2StreamPtr f) { Byte status = NoteOn + Chan(e); if( f->runStat== status) f->count= 2; else { f->runStat= f->data[3] = status; f->count = 3; } f->data[2] = Pitch(e); f->data[1] = Vel(e); }
static void __benchMark9(short refNum) { long i, d = MidiGetTime() - 16; for (i = 1; i <= 16; i++) { MidiEvPtr e = MidiNewEv(typeKeyOn); if (e) { Chan(e) = i - 1; MidiTask(keyOnProcess, d + i, refNum, 16, (long)e, 0); } } }
void sendText(int aTextType, char* c) { MidiEvPtr e = MidiNewEv(aTextType); if (e) { Chan(e) = 0; // channels have numbers from 0 to 15 Port(e) = 0; // port 0 is Modem port, port 1 is Printer port while (*c) MidiAddField(e, *c++); // Fill the event with the string MidiSendIm(ourRefNum, e); } }
//_____________________________________________________________________________ static MidiEvPtr rcvChan (UDPStreamPtr f, Byte c) { // UDPParseMethodPtr next = f->rcv[EvType(f->ptrCur)]; // MidiEvPtr e = 0; f->length--; Chan(f->ptrCur) = c; if (!f->length) return parseComplete (f); f->parse = f->rcv[EvType(f->ptrCur)]; f->next = 0; return 0; }
static void ChanPressLinearizeMth (MidiEvPtr e, Ev2StreamPtr f) { Byte status = AfterTouch + Chan(e); if( f->runStat== status) f->count= 1; else { f->runStat= f->data[2] = status; f->count = 2; } f->data[1] = Pitch(e); MidiFreeCell (e); }
static void PitchWheelLinearizeMth (MidiEvPtr e, Ev2StreamPtr f) { Byte status = PitchBend + Chan(e); if( f->runStat== status) f->count= 2; else { f->runStat= f->data[3] = status; f->count = 3; } f->data[2] = Pitch(e); f->data[1] = Vel(e); MidiFreeCell (e); }
/*__________________________________________________________________________________*/ static MidiEvPtr NewSmallEv( lifo* fl, short typeNum) { MidiEvPtr ev = MSNewCell( fl); if( ev) { Link(ev)= 0; Date(ev)= defaultTime; EvType(ev)= (uchar)typeNum; RefNum(ev)= 0xff; Chan(ev) = Port(ev) = 0; ev->info.longField = 0; } return ev; }
static void CtrlChangeLinearizeMth (MidiEvPtr e, Ev2StreamPtr f) { Byte status = ControlChg + Chan(e); if( f->runStat== status) f->count= 2; else { f->runStat= f->data[3] = status; f->count = 3; } f->data[2] = Pitch(e); f->data[1] = Vel(e); MidiFreeCell (e); }
void MidiInputDeviceMidiShare::ReceiveEvents(short ref) { MidiInputDeviceMidiShare* driver = (MidiInputDeviceMidiShare*)MidiGetInfo(ref); MidiEvPtr ev; while ((ev = MidiGetEv(ref))) switch(EvType(ev)) { case typeCtrlChange: driver->DispatchControlChange(MidiGetField(ev,0),MidiGetField(ev,0),Chan(ev)); MidiFreeEv(ev); break; case typePitchWheel: driver->DispatchPitchbend(((MidiGetField(ev,0)+(MidiGetField(ev,1) << 7)) - 8192),Chan(ev)); MidiFreeEv(ev); break; case typeNote: driver->DispatchNoteOn(Pitch(ev),Vel(ev),Chan(ev)); MidiTask(KeyOffTask,Date(ev)+Dur(ev),ref,(long)ev,0,0); break; case typeKeyOn: if (Vel(ev) > 0) driver->DispatchNoteOn(Pitch(ev),Vel(ev),Chan(ev)); else driver->DispatchNoteOff(Pitch(ev),Vel(ev),Chan(ev)); MidiFreeEv(ev); break; case typeKeyOff: driver->DispatchNoteOff(Pitch(ev),Vel(ev),Chan(ev)); MidiFreeEv(ev); break; } }
void sendNote(long pitch) { MidiEvPtr e = MidiNewEv(typeNote); if (e) { Chan(e) = 0; // channels have numbers from 0 to 15 Port(e) = 0; // port 0 is Modem port, port 1 is Printer port MidiSetField(e, 0, pitch); // the pitch MidiSetField(e, 1, 80); // the velocity MidiSetField(e, 2, 1000); // the duration in milliseconds MidiSendIm(ourRefNum, e); } }
static pascal void AccProcess(long d, short refNum, long a1, long a2, long a3) { short i; for (i = 0; i <= 15; i++) { MidiEvPtr e = MidiNewEv(typeNote); if (e) { Pitch(e) = 60; Vel(e) = 80; Dur(e) = 16; Chan(e) = i; } MidiSend (refNum, e); } MidiTask (AccProcess, d + 32, refNum, a1, a2, a3); }
/* -----------------------------------------------------------------------------*/ static pascal void GenProcess(long d, short ref, long start, long num, long freq) { short i, adv = 5; for (i = 0; i <= 15; i++) { MidiEvPtr e = MidiNewEv (typeKeyPress); if (e) { Pitch(e) = 60; Vel(e) = 80; Chan(e) = i; MidiSendAt (ref, e, start + adv + num * 1000 / freq); num++; } } genTask = MidiTask (GenProcess, start + num * 1000 / freq, ref, start, num, freq); }
/* * fluid_midishare_keyoff_task */ static void fluid_midishare_keyoff_task (long date, short ref, long a1, long a2, long a3) { fluid_midishare_midi_driver_t* dev = (fluid_midishare_midi_driver_t*)MidiGetInfo(ref); fluid_midi_event_t new_event; MidiEvPtr e =(MidiEvPtr)a1; fluid_midi_event_set_type(&new_event, NOTE_OFF); fluid_midi_event_set_channel(&new_event, Chan(e)); fluid_midi_event_set_pitch(&new_event, Pitch(e)); fluid_midi_event_set_velocity(&new_event, Vel(e)); /* release vel */ /* and send it on its way to the router */ (*dev->driver.handler)(dev->driver.data, &new_event); MidiFreeEv(e); }
void sendSMPTEOffset (long format, long hours, long minutes, long seconds, long frames, long subframes) { MidiEvPtr e = MidiNewEv(typeSMPTEOffset); if (e) { Chan(e) = 0; // channels have numbers from 0 to 15 Port(e) = 0; // port 0 is Modem port, port 1 is Printer port MidiSetField(e, 0, format); MidiSetField(e, 1, hours); MidiSetField(e, 2, minutes); MidiSetField(e, 3, seconds); MidiSetField(e, 4, frames); MidiSetField(e, 5, subframes); MidiSendIm(ourRefNum, e); } }
void SendMultipleNotes (long n, long pitch, long delay) { long i; MidiEvPtr e = MidiNewEv(typeNote); long dt = MidiGetTime(); if (e) { Chan(e) = 0; Port(e) = 0; MidiSetField(e, 0, pitch); // the pitch MidiSetField(e, 1, 80); // the velocity MidiSetField(e, 2, delay-1); // the duration for (i=0; i<n; i++) MidiSendAt(ourRefNum, MidiCopyEv(e), dt + i*delay); MidiFreeEv(e); } }
/* ------------------------------------------------------------------------- */ static char * EvToText ( MidiEvPtr e, char *buff) { unsigned long mn, sec; unsigned int h, ms; char sDatas[50]; sec = Date(e)/1000; ms = Date(e)%1000; mn = sec / 60; sec %= 60; h = mn / 60; mn %= 60; *buff= 0; sprintf (buff, "%02d:%02d:%02d:%03d %s %-3d %-2d %s", h, (int)mn, (int)sec, ms, TblLibEv[EvType(e)], (int)Port(e), (int)Chan(e), DatasToText(e, sDatas)); return buff; }
/*__________________________________________________________________________________*/ static MidiEvPtr NewPrivateEv( lifo* fl, short typeNum) { MidiEvPtr ev = MSNewCell( fl); if( ev) { MidiSTPtr ext= (MidiSTPtr)MSNewCell(fl); if ( !ext) { MSFreeCell (ev, fl); return 0; } /* creates a clear extension block */ ext->val[0]= ext->val[1]= ext->val[2]= ext->val[3]= 0; Link(ev)= 0; /* initialize the header */ Date(ev)= defaultTime; EvType(ev)= (uchar)typeNum; RefNum(ev)= 0xff; Chan(ev) = Port(ev) = 0; LinkST(ev)= ext; /* link the extension block */ } return ev; }
/* -------------------------------------------------------- Application receive alarm -------------------------------------------------------- */ void MSALARMAPI ReceiveEvents ( short r) { MidiEvPtr e; unsigned long d; while (e = MidiGetEv(r)) { d = Date(e) + MSParam[kDelay]; if ( (MSParam[kChan]!=0) && (MSParam[kChan]!=Chan(e)+1) ) MidiFreeEv(e); else if ( EvType(e) == typeNote ) { if( !MidiTask(EchoTask,d,r,(long)e,0,0)) MidiFreeEv(e); } else if ( Vel(e) > 0 ) { EvType(e) = typeNote; Dur(e) = 100; if( !MidiTask(EchoTask,d,r,(long)e,0,0)) MidiFreeEv(e); } else MidiFreeEv(e); } }
short MIDISHAREAPI MidiGetChan (MidiEvPtr e) { return Chan(e); }
/*---------------------------------------------------*/ void STS_WriteScore (long s, ScorePtr sp) { MidiEvPtr e = 0; float p2, p3; long param; int ref, chan, type; FILE *f; char scoreline[1024]; char str[25]; char str2[25]; if((f = fopen(sp->scorefile, "wt")) != NULL){ if(sp->addinfile != "NULL") STS_AppendToScoreFile(sp->addinfile, f); e = FirstEv(s); if(e){ while(e){ type = EvType(e); if(!sp->events[type]){e = Link(e); continue;} if(sp->ab == abTrack){ ref = RefNum(e); if(sp->shiftref) ref += 1; if(!sp->trkchn[ref]){e = Link(e); continue;} else sprintf(scoreline, "i%u \t", ref); } if(sp->ab == abChan){ chan = Chan(e); if(!sp->trkchn[chan]){e = Link(e); continue;} else sprintf(scoreline, "i%u \t", chan + 1); } p2 = (float)Date(e) / 1000.; sprintf(str, "%.3f \t", p2); strcat(scoreline, str); switch(type){ case typeNote: p3 = (float)MidiGetField(e, 2) / 1000.; sprintf(str, "%.3f \t", p3); strcat(scoreline, str); STS_ConvertPitch(sp, str, MidiGetField(e, 0)); STS_ConvertAmpli(sp, str2, MidiGetField(e, 1)); STS_OrderParams(sp, scoreline, str, str2); break; case typeKeyPress: sprintf(str, "%.3f \t", sp->defdur / 1000.); strcat(scoreline, str); STS_ConvertPitch(sp, str, MidiGetField(e, 0)); STS_ConvertAmpli(sp, str2, MidiGetField(e, 1)); STS_OrderParams(sp, scoreline, str, str2); break; case typeCtrlChange: case typeCtrl14b: case typeNonRegParam: case typeRegParam: sprintf(str, "%.3f \t", sp->defdur / 1000.); strcat(scoreline, str); sprintf(str, "%03u \t", MidiGetField(e, 0)); strcat(scoreline, str); sprintf(str, "%03u \t", MidiGetField(e, 1)); strcat(scoreline, str); break; case typeProgChange: case typeChanPress: sprintf(str, "%.3f \t", sp->defdur / 1000.); strcat(scoreline, str); sprintf(str, "%03u \t", MidiGetField(e, 0)); strcat(scoreline, str); break; case typePitchWheel: sprintf(str, "%.3f \t", sp->defdur / 1000.); strcat(scoreline, str); param = STS_Build14BitValue((long)e) - 8192; sprintf(str, "%03li \t", param); strcat(scoreline, str); break; default: if(type >= typePrivate && type <= typeLastPrivate){ sprintf(str, "%.3f \t", sp->defdur / 1000.); strcat(scoreline, str); sp->CFunc(sp, str, (long)e); strcat(scoreline, str); } break; } strcat(scoreline, "\n"); fputs(scoreline, f); e = Link(e); } } if(sp->writesection){ if(sp->padout > 0.){ sprintf(str, "f0 %.3f\n", sp->padout / 1000.); fputs(str, f); } fputs("s", f); } else fputs("e", f); fclose(f); } }
string MpodCrate::GetModuleType(int slot) { int Number = slot*100; char str[128]; sprintf(str,"%d",Number); string Chan(str); string cmd = "snmpget -Oqv -v 2c -m +WIENER-CRATE-MIB -c public "+IP+" outputConfigMaxSenseVoltage.u"+Chan; FILE *io; char buff[512]; io = popen(cmd.c_str(),"r"); fgets(buff, sizeof(buff), io); string res(buff); res.erase(res.size()-5,res.size()-1); float MaxVoltage = atof(res.c_str()); pclose(io); cmd = "snmpget -Oqv -v 2c -m +WIENER-CRATE-MIB -c public "+IP+" outputConfigMaxCurrent.u"+Chan; io = popen(cmd.c_str(),"r"); fgets(buff, sizeof(buff), io); res = buff; res.erase(res.size()-5,res.size()-1); float MaxCurrent = atof(res.c_str()); pclose(io); // this is usefull to determine if it is a HV or a LV board cmd = "snmpget -Oqv -v 2c -m +WIENER-CRATE-MIB -c public "+IP+" outputSupervisionMaxSenseVoltage.u"+Chan; io = popen(cmd.c_str(),"r"); fgets(buff, sizeof(buff), io); res = buff; int loc1 = res.find("nan"); int HV=0; if ( loc1 != string::npos ) { // if (loc1>0){ HV=1; } pclose(io); if (DEBUG) { cout<<"Module slot "<<slot<<" :: "; cout<<"Maximum current: "<<MaxCurrent<<" Maximum voltage: "<<MaxVoltage<<endl; } string Mnam; if (HV) { Mnam += "EHS_"; } else { Mnam += "MPV_"; } if (HV) { if (MaxVoltage == 100.0) { Mnam += "201p-F-K"; } else if (MaxVoltage == 500.0) { Mnam += "205p-F"; } } else { if ((MaxVoltage == 8.0) && (MaxCurrent == 5.0)) { Mnam += "8008L"; } else if ((MaxVoltage == 8.0) && (MaxCurrent == 10.0)) { Mnam += "8008"; } else if ((MaxVoltage == 15.0) && (MaxCurrent == 5.0)) { Mnam += "8016"; } else if ((MaxVoltage == 30.0) && (MaxCurrent == 2.5)) { Mnam += "8030"; } else if ((MaxVoltage == 60.0) && (MaxCurrent == 1.0)) { Mnam += "8060"; } else if ((MaxVoltage == 120.0) && (MaxCurrent == 0.1)) { Mnam += "8120"; } } if (DEBUG) { cout<<"Slot "<<slot<<" module type: "<<Mnam<<endl; } return Mnam; }
void MIDISHAREAPI MidiSetChan (MidiEvPtr e, short c) { Chan(e) = (Byte)c; }
/* * fluid_midishare_midi_driver_receive */ static void fluid_midishare_midi_driver_receive(short ref) { fluid_midishare_midi_driver_t* dev = (fluid_midishare_midi_driver_t*)MidiGetInfo(ref); fluid_midi_event_t new_event; MidiEvPtr e; int count, i; while ((e = MidiGetEv (ref))) { switch (EvType (e)) { case typeNote: /* Copy the data to fluid_midi_event_t */ fluid_midi_event_set_type(&new_event, NOTE_ON); fluid_midi_event_set_channel(&new_event, Chan(e)); fluid_midi_event_set_pitch(&new_event, Pitch(e)); fluid_midi_event_set_velocity(&new_event, Vel(e)); /* and send it on its way to the router */ (*dev->driver.handler)(dev->driver.data, &new_event); #if defined(MACINTOSH) && defined(MACOS9) MidiTask(dev->upp_task_ptr, MidiGetTime()+Dur(e), ref, (long)e, 0, 0); #else MidiTask(fluid_midishare_keyoff_task, MidiGetTime()+Dur(e), ref, (long)e, 0, 0); #endif /* e gets freed in fluid_midishare_keyoff_task */ continue; case typeKeyOn: /* Copy the data to fluid_midi_event_t */ fluid_midi_event_set_type(&new_event, NOTE_ON); fluid_midi_event_set_channel(&new_event, Chan(e)); fluid_midi_event_set_pitch(&new_event, Pitch(e)); fluid_midi_event_set_velocity(&new_event, Vel(e)); break; case typeKeyOff: /* Copy the data to fluid_midi_event_t */ fluid_midi_event_set_type(&new_event, NOTE_OFF); fluid_midi_event_set_channel(&new_event, Chan(e)); fluid_midi_event_set_pitch(&new_event, Pitch(e)); fluid_midi_event_set_velocity(&new_event, Vel(e)); /* release vel */ break; case typeCtrlChange: /* Copy the data to fluid_midi_event_t */ fluid_midi_event_set_type(&new_event, CONTROL_CHANGE); fluid_midi_event_set_channel(&new_event, Chan(e)); fluid_midi_event_set_control(&new_event, MidiGetField(e,0)); fluid_midi_event_set_value(&new_event, MidiGetField(e,1)); break; case typeProgChange: /* Copy the data to fluid_midi_event_t */ fluid_midi_event_set_type(&new_event, PROGRAM_CHANGE); fluid_midi_event_set_channel(&new_event, Chan(e)); fluid_midi_event_set_program(&new_event, MidiGetField(e,0)); break; case typePitchWheel: /* Copy the data to fluid_midi_event_t */ fluid_midi_event_set_type(&new_event, PITCH_BEND); fluid_midi_event_set_channel(&new_event, Chan(e)); fluid_midi_event_set_value(&new_event, ((MidiGetField(e,0) + (MidiGetField(e,1) << 7)) - 8192)); break; case typeSysEx: count = MidiCountFields (e); /* Discard empty or too large SYSEX messages */ if (count == 0 || count > FLUID_MIDI_PARSER_MAX_DATA_SIZE) { MidiFreeEv (e); continue; } /* Copy SYSEX data, one byte at a time */ for (i = 0; i < count; i++) dev->sysexbuf[i] = MidiGetField (e, i); fluid_midi_event_set_sysex (&new_event, dev->sysexbuf, count, FALSE); break; default: MidiFreeEv (e); continue; } MidiFreeEv (e); /* Send the MIDI event */ (*dev->driver.handler)(dev->driver.data, &new_event); } }