Exemplo n.º 1
0
/*
 * fluid_midishare_open_driver
 */
static int fluid_midishare_open_driver (fluid_midishare_midi_driver_t* dev)
{
    /* gcc wanted me to use {0,0} to initialize the reserved[2] fields */
    TDriverInfos infos = { MSHDriverName, 100, 0, { 0, 0 } };
    TDriverOperation op = { fluid_midishare_wakeup, fluid_midishare_sleep, { 0, 0, 0 } };

    /* register to MidiShare */
#if defined(MACINTOSH) && defined(MACOS9)
    dev->upp_wakeup_ptr = NewDriverPtr(fluid_midishare_wakeup);
    dev->upp_sleep_ptr = NewDriverPtr(fluid_midishare_sleep);

    op.wakeup = (WakeupPtr)dev->upp_wakeup_ptr;
    op.sleep = (SleepPtr)dev->upp_sleep_ptr;

    dev->refnum = MidiRegisterDriver(&infos, &op);
    if (dev->refnum < 0) {
        FLUID_LOG(FLUID_ERR, "Can not open MidiShare Application client");
        return 0;
    }
    dev->slotRef = MidiAddSlot (dev->refnum, MSHSlotName, MidiOutputSlot);
    dev->upp_alarm_ptr = NewRcvAlarmPtr(fluid_midishare_midi_driver_receive);
    dev->upp_task_ptr = NewTaskPtr(fluid_midishare_keyoff_task);
    MidiSetRcvAlarm(dev->refnum, dev->upp_alarm_ptr);
#else
    dev->refnum = MidiRegisterDriver(&infos, &op);
    if (dev->refnum < 0) {
        FLUID_LOG(FLUID_ERR, "Can not open MidiShare Application client");
        return 0;
    }
    dev->slotRef = MidiAddSlot (dev->refnum, MSHSlotName, MidiOutputSlot);
    MidiSetRcvAlarm(dev->refnum, fluid_midishare_midi_driver_receive);
#endif
    return 1;
}
Exemplo n.º 2
0
//_______________________________________________________________________
void CnxInit (short ref)
{	
	gSrc = ref;
	MidiSetRcvAlarm (ref, rcvalarm);
	MidiSetApplAlarm (ref, applalarm);
	start ();
}
Exemplo n.º 3
0
void RecSeq(TSequencer * s)
{
        StopSeq(s);
        printf("Record\n");
        s->state = recording;
        MidiSetRcvAlarm(s->ref, RecRcv);
}
Exemplo n.º 4
0
void test20 ()
{
        printf("\n\n<TEST 20> transpose and delay in real-time\n");
        DebugStr ("--> use g or G to start transposing incoming events\n");

        MidiFlushEvs(ourRefNum);
        MidiSetRcvAlarm(ourRefNum, transposeAndDelay);
        MidiConnect(0, ourRefNum, true);
        MidiConnect(ourRefNum, 0, true);

        printf("Now play on the Midi keyboard, notes are transposed and delayed\n");
        DebugStr ("--> use g or G to stop transposing events and go to the next test\n");

        MidiConnect(0, ourRefNum, false);
        MidiSetRcvAlarm(ourRefNum, 0);
}
Exemplo n.º 5
0
void test19 ()
{
        printf("\n\n<TEST 19> thru incoming events\n");
        DebugStr ("--> use g or G to start thruing incoming events\n");

        MidiFlushEvs(ourRefNum);
        MidiSetRcvAlarm(ourRefNum, thru);
        MidiConnect(0, ourRefNum, true);
        MidiConnect(ourRefNum, 0, true);

        printf("Now play on the Midi keyboard\n");
        DebugStr ("--> use g or G to stop thruing incoming events and go to the next test\n");

        MidiConnect(0, ourRefNum, false);
        MidiSetRcvAlarm(ourRefNum, 0);
}
Exemplo n.º 6
0
/* ------------------------------------------------------------------------- */
void MSALARMAPI ReceiveEvents(short r)
{
	if (MidiTask(ReceivePolling,MidiGetTime(),r,(long)MidiGetInfo(r),0,0))
		MidiSetRcvAlarm (r, 0);
	else 
		MidiFlushEvs(r);
}
	void MidiInputDeviceMidiShare::OpenAppl() 
	{
	   hRefnum = MidiOpen(MSHDriverName);
		if (hRefnum < 0) {
			throw MidiInputException("MidiShare client can not be opened");	
		}
		MidiSetRcvAlarm(hRefnum,ReceiveEvents);
		MidiSetApplAlarm(hRefnum,ApplAlarm);
    }
Exemplo n.º 8
0
/* -----------------------------------------------------------------------------*/
Boolean SetupMidi(void)
{
	myRefNum = MidiOpen (ApplName);
	if (myRefNum == MIDIerrSpace) return false;

	chgDriver = chgCon = false;
	MidiSetApplAlarm (myRefNum, ApplAlarm);
	MidiSetRcvAlarm (myRefNum, RcvAlarm);
	return true;
}
Exemplo n.º 9
0
/* ------------------------------------------------------------------------- */
void MSALARMAPI ReceivePolling ( long date, short r, long a, long b, long c)
{
	long n;

	n= MidiCountEvs (r);
	if (n) {
		DisplayTask(r);
		MidiTask (ReceivePolling, date+100, r, a, 0, 0);
	}
	else MidiSetRcvAlarm (r, ReceiveEvents);
}
	void MidiInputDeviceMidiShare::OpenDriver()
	{
		/* gcc wanted me to use {0,0} to initialize the reserved[2] fields */
		TDriverInfos infos = { MSHDriverName, 100, 0, { 0, 0 } };
		TDriverOperation op = { WakeUp, Sleep, { 0, 0, 0 } }; 
		hRefnum = MidiRegisterDriver(&infos, &op);
		if (hRefnum < 0) {
			throw MidiInputException("MidiShare driver can not be opened");	
		}
		hSlotRef = MidiAddSlot(hRefnum,MSHSlotName,MidiOutputSlot);
		MidiSetRcvAlarm(hRefnum,ReceiveEvents);
	}
Exemplo n.º 11
0
//________________________________________________________________________________________
bool MS2MM(short refNum, SlotPtr slot, MidiEvPtr e)
{
	int type = EvType(e);
	
	if ((type == typeSysEx) || (type == typeStream)) {
		MidiSetRcvAlarm(refNum,0);  
		SendSysEx(slot,e); 
		return false;
	}else{
		SendSmallEv(slot,e,&slot->state);
		return true;
	}
}
Exemplo n.º 12
0
/*
 * fluid_midishare_open_appl
 */
static int fluid_midishare_open_appl (fluid_midishare_midi_driver_t* dev)
{
    /* register to MidiShare */
#if defined(MACINTOSH) && defined(MACOS9)
    dev->refnum = MidiOpen(MSHDriverName);
    if (dev->refnum < 0) {
        FLUID_LOG(FLUID_ERR, "Can not open MidiShare Driver client");
        return 0;
    }
    dev->upp_alarm_ptr = NewRcvAlarmPtr(fluid_midishare_midi_driver_receive);
    dev->upp_task_ptr = NewTaskPtr(fluid_midishare_keyoff_task);
    MidiSetRcvAlarm(dev->refnum, dev->upp_alarm_ptr);
#else
    dev->refnum = MidiOpen(MSHDriverName);
    if (dev->refnum < 0) {
        FLUID_LOG(FLUID_ERR, "Can not open MidiShare Driver client");
        return 0;
    }
    MidiSetRcvAlarm(dev->refnum, fluid_midishare_midi_driver_receive);
    MidiConnect(0,dev->refnum,true);
#endif
    return 1;
}
Exemplo n.º 13
0
void StopSeq(TSequencer * s)
{
        printf("Stop\n");
        switch (s->state) {
                case playing :
                        MidiForgetTask(&s->playtask);
			MidiForgetTask(&s->looptask);
                        s->state = idle;
                        break;
                case recording :
                        MidiSetRcvAlarm(s->ref, NullRcv);
                        s->state = idle;
                        break;
        }
}
Exemplo n.º 14
0
void test21 ()
{
        long    n;
        
        printf("\n\n<TEST 21> record and playback a sequence\n");
        DebugStr ("--> use g or G to start recording\n");

        ourSequence = MidiNewSeq();
    	ourFilter = MidiNewFilter();
        InstallFilter(ourRefNum,ourFilter);
        MidiFlushEvs(ourRefNum);
        MidiSetRcvAlarm(ourRefNum, record);
        MidiConnect(0, ourRefNum, true);
        MidiConnect(ourRefNum, 0, true);
        
        printf("Now play on the Midi keyboard, every thing is recorded\n");
        DebugStr ("--> use g or G to stop recording\n");

        MidiConnect(0, ourRefNum, false);
        MidiSetRcvAlarm(ourRefNum, 0);
        
        printf (" %ld events where recorded\n", size(ourSequence));

        DebugStr ("--> use g or G to play back the sequence\n");

        stopFlag = 0;
        if (FirstEv(ourSequence)) {
                MidiCall(play, MidiGetTime(), ourRefNum, (long) FirstEv(ourSequence), 0, 0);
        }
        
        printf("Now playing the sequence\n");
        DebugStr ("--> use g or G to stop play back and go to the next test\n");
        
        stopFlag = 1;
        MidiFreeSeq(ourSequence);
}
Exemplo n.º 15
0
/* ----------------------------------------------------------------------------
MidiShare setup
---------------------------------------------------------------------------- */
Boolean SetUpMidi(void)
{
  if ( !MidiShare() ) {
                printf("MidiShare is not installed\n");
                return false;
  }
  myRefNum = MidiOpen(AppliName);
  if ( myRefNum == MIDIerrSpace ) {
                printf("Too much MidiShare client applications\n");
                return false;
  }
  MidiSetRcvAlarm(myRefNum,ReceiveEvents);
  InstallFilter();
  MidiConnect (myRefNum, 0, true);
  MidiConnect (0, myRefNum, true);
  return true;
}
Exemplo n.º 16
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));
}
Exemplo n.º 17
0
/* ------------------------------------------------------------------------- */
int InitMidi()
{
if ( !MidiShare())
{
sprintf (string_Last_Order,"MidiShare not available\n");
}
InitTblLibEv();
myRefNum = MidiOpen(AppliName);
if (myRefNum < 0) {sprintf(string_Last_Order,"MidiOpen failed!");}

MidiSetRcvAlarm(myRefNum,ReceiveEvents);
MidiConnect(0, myRefNum, true);//in
MidiConnect(myRefNum,0,true);//out
myFilter = MidiNewFilter();
InstallFilter( myRefNum,myFilter ); //filtrage

return(0);
}
Exemplo n.º 18
0
void OpenSeq(TSequencer * s, char * n)
{
        midiFILE *      f;
        int             i;
        
 // initialisation
 
 	s->ref = MidiOpen("msMidiPlayer");
        s->state = idle;
        s->seq = MidiNewSeq();
        s->playtask = 0;
	s->looptask = 0;
		
        
 // read the midi file
        
        f = MidiFileOpen(n, MidiFileRead);
		
        if (!f) {
                printf ("Error opening MidiFile %s (%d)\n", n, MidiFile_errno);
                CloseSeq(s);
                exit(MidiFile_errno);
        }
        for (i = f->ntrks; i; i--){ MixSeq( MidiFileReadTrack(f), s->seq); }
	           
        if (smpte(f)) 
                TrsfSmpteSeq(s->seq, frame_par_sec(f), ticks_par_frame(f));
        else
                TrsfTempoSeq(s->seq, ticks_par_quarterNote(f));
	
	if (First(s->seq))
	 	printf("File : %s, Format : %d, Tracks : %d, Length : %d, Duration : %d\n",
                        n, f->format, f->ntrks, LenSeq(s->seq), Date(Last(s->seq)) );
	           
        (void) MidiFileClose(f);
       
 // installation
    	
        MidiSetInfo(s->ref, s);
        MidiSetRcvAlarm(s->ref, NullRcv);
        
        MidiConnect(s->ref, 0, 1);
        MidiConnect(0, s->ref, 1);
}
Exemplo n.º 19
0
int main(int argc, char *argv[] )
{
	GtkWidget *window, *vbox;
	char applName[256];

	// Initialisations
	gtk_init (&argc, &argv);
	StripPath (argv[0], applName);
	CheckMidiShare (applName);
	gRefNum = MidiOpen(applName);
	MidiSetRcvAlarm (gRefNum,rcv_alarm);
	MidiConnect(gRefNum,0,1);
	MidiConnect(0,gRefNum,1);

	// Window definition
	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title(GTK_WINDOW(window), applName);
	gtk_container_set_border_width(GTK_CONTAINER(window), 10);

	vbox = gtk_vbox_new (FALSE, 10);
	
	// Add controllers
	add_time (vbox);
	add(vbox, gtk_hseparator_new());
	add_buttons (vbox);
	
	gtk_container_add(GTK_CONTAINER(window), vbox);	
	gtk_widget_show_all (window);
	
	gtk_signal_connect(GTK_OBJECT(gRun), "clicked", GTK_SIGNAL_FUNC(start_stop_action), NULL);
	gtk_signal_connect(GTK_OBJECT(gReset), "clicked", GTK_SIGNAL_FUNC(reset_action), NULL);

	// Connexion of signals	
	gtk_signal_connect(
			GTK_OBJECT(window), "destroy", 
			GTK_SIGNAL_FUNC(my_delete_action), NULL
	);
	
	gtk_main ();

	return(0);
}
   /**
     * Create MidiShare input device for LinuxSampler. 
	 *
     * @param AutoConnectPortID - (optional) Alsa client and port ID of a
     *                            MIDI source we should auto connect to
     *                            (e.g. "64:0")
     * @throws MidiInputException  if initialization failed
     */
    MidiInputDeviceMidiShare::MidiInputDeviceMidiShare(char* AutoConnectPortID) : MidiInputDevice(MidiInputDevice::type_midishare) 
	{
		if (!MidiShare())
			throw MidiInputException("MidiShare not installed");
			
		#if defined(MIDISHARE_DRIVER)
			OpenDriver();
		#else
			OpenAppl();
		#endif
		
		hMidiFilter = MidiNewFilter();
		
		if (hMidiFilter == 0) {
			MidiClose(hRefnum);
			throw MidiInputException("MidiShare filter can not be allocated");	
		}
		  
		for (int i = 0 ; i < 256; i++) {
			MidiAcceptPort(hMidiFilter, i, 1); /* accept all ports */
			MidiAcceptType(hMidiFilter, i, 0); /* reject all types */ 
		} 
		  
		for (int i = 0 ; i < 16; i++) {
			MidiAcceptChan(hMidiFilter, i, 1); /* accept all chan */ 
		} 
		/* accept only the following types */
		MidiAcceptType(hMidiFilter, typeNote, 1);
		MidiAcceptType(hMidiFilter, typeKeyOn, 1);
		MidiAcceptType(hMidiFilter, typeKeyOff, 1);
		MidiAcceptType(hMidiFilter, typeCtrlChange, 1);
		//MidiAcceptType(hMidiFilter, typeProgChange, 1);
		MidiAcceptType(hMidiFilter, typePitchWheel, 1);
		  
		/* set the filter */
		MidiSetFilter(hRefnum, hMidiFilter);
	
		MidiSetRcvAlarm(hRefnum,ReceiveEvents);
		MidiSetApplAlarm(hRefnum,ApplAlarm);
		MidiSetInfo(hRefnum,this);
		MidiConnect(0,hRefnum,true);
	}
Exemplo n.º 21
0
//_______________________________________________________________________
static void SetupMidi (char *name, DrvMemPtr mem)
{
	MidiFilterPtr filter;
	short ref = MidiOpen (name);
	if (ref < 0) FatalError ("MidiOpen failed !");
	mem->refNum = ref;

	filter = MidiNewFilter ();
	if (!filter) FatalError ("MidiNewFilter failed !");
	mem->filter = filter;
	SetupFilter (filter);
	MidiSetFilter (ref, filter);

	MidiParseInitMthTbl (mem->inMthd);
	MidiParseInitTypeTbl(mem->inTypes);
	MidiParseInit (&mem->inFifo, mem->inMthd, mem->inTypes);

	MidiStreamInitMthTbl (mem->outMthd);
	MidiStreamInit (&mem->outFifo, mem->outMthd);

	MidiSetRcvAlarm (ref, RcvAlarm);
}
Exemplo n.º 22
0
/* ------------------------------------------------------------------------- */
Boolean SetUpMidi(void)
{
	char buff[32], *name;

	InitTblLibEv();
	
	if ( !MidiShare()) {
		printf ("MidiShare not available\n");
		return false;
	}

	myRefNum = MidiOpen(AppliName);
	if ( myRefNum == MIDIerrSpace ){
		printf ( "Too much MidiShare client applications\n");
		return false;
	}
	
	MidiSetRcvAlarm(myRefNum,ReceiveEvents);
	MidiConnect( 0, myRefNum, true);
	myFilter = MidiNewFilter();
	InstallFilter( myRefNum, myFilter);
	return true;
}