예제 #1
0
static void Linearize1Long (MidiEvPtr e, Ev2UDPStreamPtr f)
{
	f->count = kCommonSize + 4;
	LinearizeFixedCommon (kCommonSize + 4, e, f);
	LinearizeLong (4, Tempo(e), f);
	MidiFreeEv (e);
}
예제 #2
0
/*____________________________________________________________________*/
static int TestEv( int i, short t1, short t2)
{
	MidiEvPtr e;
	short n, result= true;
	
	for( n=t1; n<=t2; n++) {
		e= MidiNewEv( n);
		if( e) {
			MidiSendIm( refNum, e);
			wait( 2);
			e= GetReceived();
			if( e) {
				if( n== i) {
					if( n== typePrivate)
						print (" not filtered ");
					else {
						print ("\n    error: type %s not filtered\n", typeListe[n]);
						result= false;
					}
				}
				MidiFreeEv( e);
			}
			else if( n!= i) {
				print ("\n    error: type %s filtered\n", typeListe[n]);
				result= false;
			}
		}
		else {
			print ("\n  cannot allocate a new event !\n");
			return false;
		}
	}
	return result;
}
예제 #3
0
static void Linearize1Byte (MidiEvPtr e, Ev2UDPStreamPtr f)
{
	f->count = kCommonSize + 1;
	LinearizeFixedCommon (kCommonSize + 1, e, f);
	f->data[1] = Data(e)[0];
	MidiFreeEv (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);
	}
예제 #5
0
static void Linearize1Short (MidiEvPtr e, Ev2UDPStreamPtr f)
{
	f->count = kCommonSize + 2;
	LinearizeFixedCommon (kCommonSize + 2, e, f);
	LinearizeShort (2, e->info.param.num, f);
	MidiFreeEv (e);
}
예제 #6
0
/*____________________________________________________________________*/
static void TestPort( int i)
{
	MidiEvPtr e;
	int n, result= true;
	
	for( n=0; n<LastPort; n++) {
		e= MidiNewEv( typeKeyOn);
		if( e) {
			Port(e)= n;
			MidiSendIm( refNum, e);
			wait( 2);
			e= GetReceived();
			if( e) {
				if( n== i) {
					print ("\n    error: port %d not filtered\n", n);
					result= false;
				}
				MidiFreeEv( e);
			}
			else if( n!= i) {
				print ("\n    error: port %d filtered\n", n);
				result= false;
			}
		}
		else {
			print ("\n  cannot allocate a new event !\n");
			break;
		}
	}
	if( result) print ("ok\n");
}
/* --------------------------------------------------------
Real time echo management task
-------------------------------------------------------- */
void MSALARMAPI EchoTask( long d,short ref,long el,long a2, long a3)
{
    MidiEvPtr e;
    short v,p;

    e= (MidiEvPtr)el;
    v = Vel(e)+MSParam[kVel];
    p = Pitch(e)+MSParam[kPitch];
    if ( ((v>0)&&(v<128)) && ((p>=0)&&(p<128)) ) {
        Vel(e) = v;
        Pitch(e) = p;
        MidiSendAt(ref, MidiCopyEv(e), d);
        if( !MidiTask(EchoTask, d+MSParam[kDelay], ref, el, 0, 0))
            MidiFreeEv(e);
    }
    else MidiFreeEv(e);
}
예제 #8
0
static void Linearize2Bytes1Short (MidiEvPtr e, Ev2UDPStreamPtr f)
{
	f->count = kCommonSize + 4;
	LinearizeFixedCommon (kCommonSize + 4, e, f);
	f->data[4] = Data(e)[0];
	f->data[3] = Data(e)[1];
	LinearizeShort (2, e->info.param.val, f);
	MidiFreeEv (e);
}
예제 #9
0
static void Linearize4Bytes (MidiEvPtr e, Ev2UDPStreamPtr f)
{
	f->count = kCommonSize + 4;
	LinearizeFixedCommon (kCommonSize + 4, e, f);
	f->data[4] = Data(e)[0];
	f->data[3] = Data(e)[1];
	f->data[2] = Data(e)[2];
	f->data[1] = Data(e)[3];
	MidiFreeEv (e);
}
예제 #10
0
//_____________________________________________________________________________
void UDPParseReset (UDPStreamPtr f)
{
	if (f->ptrCur) MidiFreeEv (f->ptrCur);
	f->ptrCur = 0;
	f->length = 0;
	f->index  = 0;
	f->shortDst = &f->length;
	f->parse  = rcvShortHigh;
	f->next  = rcvType;
}
	void MidiInputDeviceMidiShare::ReceiveEvents(short ref)
	{
		MidiInputDeviceMidiShare* driver = (MidiInputDeviceMidiShare*)MidiGetInfo(ref);
		MidiEvPtr ev;
		
		while ((ev = MidiGetEv(ref)))
		
			switch(EvType(ev)) { 
			
				case typeCtrlChange:
					if (MidiGetField(ev,0) == 0)
						driver->DispatchBankSelectMsb(MidiGetField(ev,0),Chan(ev));
					else if (MidiGetField(ev,0) == 32)
						driver->DispatchBankSelectLsb(MidiGetField(ev,0),Chan(ev));
					else
						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;
			}
		}
예제 #12
0
/* ------------------------------------------------------------------------- */
void Display ( MidiEvPtr e)
{
	char s[120];

	if (e) {
		EvToText (e, s);
		printf(s);
		printf("\n");
		MidiFreeEv(e);
	}
}
예제 #13
0
/* ------------------------------------------------------------------------- */
void DisplayTask (short ref)
{
	long n;

	n= MidiCountEvs(ref);
	while (n > 16) {
		MidiFreeEv (MidiGetEv (ref));
		n--;
	}
	while (n--) {
		Display (MidiGetEv (ref));
	}
}
예제 #14
0
/* --------------------------------------------------------
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);
  }
}
예제 #15
0
//_____________________________________________________________________________
static MidiEvPtr rcvIgnore (UDPStreamPtr f, Byte c)
{
	if (! --f->length) 	{
//		parseComplete (f);
		MidiEvPtr e = f->ptrCur;
		f->ptrCur = 0;
		f->shortDst = &f->length;
		f->parse  = rcvShortHigh;
		f->next  = rcvType;
		f->index = 0;
		if (e) MidiFreeEv (e);
	}
	return 0;
}
예제 #16
0
//_________________________________________________________
void SendEvents1 (short refNum)
{
	SlotPtr slot = 0;
	MidiEvPtr e;
	
	while ((e = MidiGetEv (refNum))) {
		if (!slot || (Slot(slot->refNum) != Port(e)))
			slot = FindSlot(gOutSlots, Port(e));
		if (slot) {
			if (!MS2MM (refNum, slot, e)) return; 
		}else{
			MidiFreeEv(e);
		}
	}
}
예제 #17
0
/*
 * 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);
}
예제 #18
0
static void rcv_alarm (short refnum)
{
	MidiEvPtr e = MidiGetEv (refnum);
	while (e) {
		switch (EvType(e)) {
			case typeStart:	start(TRUE);
				break;
			case typeStop:	stop(TRUE);
				break;
			case typeReset:	reset();
				break;
		}
		MidiFreeEv (e);
		e = MidiGetEv (refnum);
	}
}
예제 #19
0
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);
        }
}
예제 #20
0
//_________________________________________________________
void SendEvents2 (short refNum)
{
	SlotPtr slot = 0;
	MidiEvPtr e;
	
	while ((e = MidiGetEv (refNum))) {
		if (!slot || (Slot(slot->refNum) != Port(e)))
			slot = FindSlot(gOutSlots, Port(e));
		if (slot) {
			if (!MS2MM (refNum, slot, e)) return;  // A SysEx is sent 
		}else{
			MidiFreeEv(e);
		}
	}
	
	MidiSetRcvAlarm(refNum,RcvAlarm);
	MidiSendIm(refNum, MidiNewEv(typeRestart));
}
예제 #21
0
 void transposeAndDelay (short aRefNum)
{
        MidiEvPtr e;
        
        while (e = MidiGetEv(aRefNum)) {
                switch (EvType(e)) {
                        case typeNote:
                        case typeKeyOn:
                        case typeKeyOff:
                                MidiSetField(e, 0, 7 + MidiGetField(e,0));      // transpose pitch + 7
                                Date(e) += 1000;                                // delay 1000 ms
                                MidiSend(aRefNum, e);
                                break;
                        default:
                                MidiFreeEv(e);
                }
        }
}
예제 #22
0
MSALARMAPI void NullRcv (short ref)
{
        MidiEvPtr e;
        while (e = MidiGetEv(ref)) MidiFreeEv(e);
}
예제 #23
0
static void Linearize0Byte (MidiEvPtr e, Ev2UDPStreamPtr f)
{
	f->count = kCommonSize;
	LinearizeFixedCommon (kCommonSize, e, f);
	MidiFreeEv (e);
}
예제 #24
0
static void NullLinearizeMth (MidiEvPtr e, Ev2UDPStreamPtr f)
{
	MidiFreeEv (e);
}
예제 #25
0
/*
 * 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);
    }
}