Ejemplo n.º 1
0
bool osd_interface::midi_init()
{
	#ifndef DISABLE_MIDI
	Pm_Initialize();
	#endif
	return true;
}
Ejemplo n.º 2
0
PortMidiEnumerator::PortMidiEnumerator() : MidiEnumerator() {
    PmError err = Pm_Initialize();
    // Based on reading the source, it's not possible for this to fail.
    if (err != pmNoError) {
        qWarning() << "PortMidi error:" << Pm_GetErrorText(err);
    }
}
Ejemplo n.º 3
0
static int start_portmidi(CSOUND *csound)
{
    const char  *errMsg = NULL;

#if !defined(WIN32)
    csound_global_mutex_lock();
#endif
    if (!portmidi_init_cnt) {
      if (UNLIKELY(Pm_Initialize() != pmNoError))
        errMsg = Str(" *** error initialising PortMIDI");
      else if (UNLIKELY(Pt_Start(1, NULL, NULL) != ptNoError))
        errMsg = Str(" *** error initialising PortTime");
      }

    if (errMsg == NULL)
      portmidi_init_cnt++;
#if !defined(WIN32)
    csound_global_mutex_unlock();
#endif
    if (UNLIKELY(errMsg != NULL)) {
      csound->ErrorMsg(csound, Str(errMsg));
      return -1;
    }
#if !defined(WIN32)
    csound_global_mutex_unlock();
#endif
    return csound->RegisterResetCallback(csound, NULL, stop_portmidi);
}
Ejemplo n.º 4
0
void init() {
  PmError err1;
  PtError err2;
  
  if (isInit) return;
  
  mexPrintf("Initialising PortMidi\n");
  
  MUTEX_LOCK;
  note      = malloc(INPUT_BUFFER_SIZE*sizeof(int32_t));
  channel   = malloc(INPUT_BUFFER_SIZE*sizeof(int32_t));
  velocity  = malloc(INPUT_BUFFER_SIZE*sizeof(int32_t));
  timestamp = malloc(INPUT_BUFFER_SIZE*sizeof(int32_t));
  if (!(channel && note && velocity && timestamp)) {
    FREE(channel);
    FREE(note);
    FREE(velocity);
    FREE(timestamp);
    MUTEX_UNLOCK;
    mexErrMsgTxt("Could not allocate memory");
  }
  else {
    MUTEX_UNLOCK;
  }
  
  err1 = Pm_Initialize();
  reportPmError(err1);
  
  err2 = Pt_Start(1, receive_poll, NULL);
  reportPtError(err2);
  
  /* getting here means that PortMidi and PortTime are both fine */
  mexAtExit(exitFunction);
  isInit = 1;
}
Ejemplo n.º 5
0
bool midiInit()
{
        Pm_Initialize();

        // Initialize buffer
        nbEventWaiting = 0;
        iEventWaiting = 0;

        int portIn = -1;
        int portOut = -1;
        /* List device information */
        for (int i = 0; i < Pm_CountDevices(); i++) {
                const PmDeviceInfo *info = Pm_GetDeviceInfo(i);
                if ((info->input) || (info->output)) {
                        printf("%d: %s, %s", i, info->interf, info->name);
                        if (info->input) {
                                portIn = i;
                                printf(" (input)");
                        }

                        if (info->output) {
                                portOut = i;
                                printf(" (output)");
                        }
                        printf("\n");
                }
        }

        if(portOut == -1 || portIn == -1) {
                printf("Midi port not found.\r\n");
                return -1;
        }

        return false;
}
Ejemplo n.º 6
0
PMEXPORT const PmDeviceInfo* Pm_GetDeviceInfo( PmDeviceID id ) {
    Pm_Initialize(); /* no error check needed */
    if (id >= 0 && id < pm_descriptor_index) {
        return &descriptors[id].pub;
    }
    return NULL;
}
Ejemplo n.º 7
0
int Pm_CountDevices( void )
{
    PmError err = Pm_Initialize();
    if (err)
        return pm_errmsg(err);
    return pm_descriptor_index;
}
Ejemplo n.º 8
0
void FLiveEditorManager::Initialize()
{
	PmError Error = Pm_Initialize();
	if ( Error != pmNoError )
		return;

	FindDevices();
	MIDIBuffer = new PmEvent[DEFAULT_BUFFER_SIZE];

	GConfig->GetArray(TEXT("LiveEditor"), TEXT("ActiveBlueprintTemplates"), ActiveBlueprintTemplates, GEditorUserSettingsIni);
	for ( int32 i = ActiveBlueprintTemplates.Num()-1; i >= 0; --i )
	{
		FString &Name = ActiveBlueprintTemplates[i];
		if ( !FPackageName::DoesPackageExist(*Name) )
		{
			ActiveBlueprintTemplates.RemoveAt(i);
			GConfig->SetArray(TEXT("LiveEditor"), TEXT("ActiveBlueprintTemplates"), ActiveBlueprintTemplates, GEditorUserSettingsIni);
			GConfig->Flush(false, GEditorUserSettingsIni);
		}
	}

	LiveEditorUserData = new FLiveEditorUserData();

	bInitialized = true;
}
Ejemplo n.º 9
0
mastermidibus::mastermidibus ()
 :
    m_num_out_buses     (0),        // or c_max_busses, or what?
    m_num_in_buses      (0),        // or c_max_busses, or 1, or what?
    m_buses_out         (),         // array of c_max_busses midibus pointers
    m_buses_in          (),         // array of c_max_busses midibus pointers
    m_bus_announce      (nullptr),  // one pointer
    m_buses_out_active  (),         // array of c_max_busses booleans
    m_buses_in_active   (),         // array of c_max_busses booleans
    m_buses_out_init    (),         // array of c_max_busses booleans
    m_buses_in_init     (),         // array of c_max_busses booleans
    m_init_clock        (),         // array of c_max_busses clock_e values
    m_init_input        (),         // array of c_max_busses booleans
    m_queue             (0),
    m_ppqn              (0),
    m_bpm               (0),
    m_num_poll_descriptors (0),
    m_poll_descriptors  (nullptr),
    m_dumping_input     (false),
    m_seq               (nullptr),
    m_mutex             ()
{
    for (int i = 0; i < c_max_busses; ++i)        // why the global?
    {
        m_buses_in_active[i] = false;
        m_buses_out_active[i] = false;
        m_buses_in_init[i] = false;
        m_buses_out_init[i] = false;
        m_init_clock[i] = e_clock_off;
        m_init_input[i] = false;
    }
    Pm_Initialize();
}
Ejemplo n.º 10
0
int keyboard_init(MidiObj* m,char* name) {
		
	m->midi_stream_out = NULL;
	m->midi_stream = NULL;
	
	// open midi device
	if(! initialized)
	{
		Pm_Initialize();
		initialized=1;
	}

	int devid= find_device_id_in(name);
	int devid_out= find_device_id_out(name);
	const PmDeviceInfo* dev_info = Pm_GetDeviceInfo(devid);
	const PmDeviceInfo* dev_info_out = Pm_GetDeviceInfo(devid_out);

	if(dev_info_out) {
		Pm_OpenOutput(&(m->midi_stream_out), devid_out, NULL, KEYBOARD_MAX_EVENTS, NULL, NULL,0);
	}
	if(dev_info) {
		Pm_OpenInput(&(m->midi_stream), devid, NULL, KEYBOARD_MAX_EVENTS, NULL, NULL);
		return 1;
	}
	return 0;
}
Ejemplo n.º 11
0
static PmDeviceID pm_get_default_device_id(int is_input, char *key) {
    HKEY hkey;
#define PATTERN_MAX 256
    char pattern[PATTERN_MAX];
    long pattern_max = PATTERN_MAX;
    DWORD dwType;
    /* Find first input or device -- this is the default. */
    PmDeviceID id = pmNoDevice;
    int i, j;
    Pm_Initialize(); /* make sure descriptors exist! */
    for (i = 0; i < pm_descriptor_index; i++) {
        if (descriptors[i].pub.input == is_input) {
            id = i;
            break;
        }
    }
    /* Look in registry for a default device name pattern. */
    if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software", 0, KEY_READ, &hkey) != 
        ERROR_SUCCESS) {
        return id;
    }
    if (RegOpenKeyEx(hkey, "JavaSoft", 0, KEY_READ, &hkey) !=
        ERROR_SUCCESS) {
        return id;
    }
    if (RegOpenKeyEx(hkey, "Prefs", 0, KEY_READ, &hkey) !=
        ERROR_SUCCESS) {
        return id;
    }
    if (RegOpenKeyEx(hkey, "/Port/Midi", 0, KEY_READ, &hkey) !=
        ERROR_SUCCESS) {
        return id;
    }
    if (RegQueryValueEx(hkey, key, NULL, &dwType, (BYTE *) pattern, 
                        (DWORD *) &pattern_max) != 
	ERROR_SUCCESS) {
        return id;
    }

    /* decode pattern: upper case encoded with "/" prefix */
    i = j = 0;
    while (pattern[i]) {
        if (pattern[i] == '/' && pattern[i + 1]) {
            pattern[j++] = toupper(pattern[++i]);
	} else {
            pattern[j++] = tolower(pattern[i]);
	}
        i++;
    }
    pattern[j] = 0; /* end of string */

    /* now pattern is the string from the registry; search for match */
    i = pm_find_default_device(pattern, is_input);
    if (i != pmNoDevice) {
        id = i;
    }
    return id;
}
Ejemplo n.º 12
0
const PmDeviceInfo* Pm_GetDeviceInfo( PmDeviceID id ) {
    PmError err = Pm_Initialize();
    if (err) 
        return NULL;
    if (id >= 0 && id < pm_descriptor_index) {
        return &descriptors[id].pub;
    }
    return NULL;
}
Ejemplo n.º 13
0
int keyboard_init() {
	Pm_Initialize();
	const PmDeviceInfo* dev_info = Pm_GetDeviceInfo(KEYBOARD_DEV_ID);
	if (dev_info) {
		Pm_OpenInput(&midi_stream, KEYBOARD_DEV_ID, NULL, KEYBOARD_MAX_EVENTS, NULL, NULL);
		return 1;
	}
	return 0;
}
Ejemplo n.º 14
0
MidiWindow::MidiWindow(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MidiWindow)
{
    ui->setupUi(this);

    Pm_Initialize();
    m_sequencer = NULL;
    emit refreshHardware();
    emit newMidiSequencer( Pm_GetDefaultInputDeviceID());
    //Read profil box ...
    {
        QDir dir("./data/config/midi");
        QStringList files = dir.entryList();
        for(int i=0; i<files.size(); i++)
        {
            QString item = files.at(i).toLocal8Bit().constData();

            if( item != "." && item != ".." && item != ".svn" )
            {
                item.remove(item.length()-5,5);
                ui->profilBox->addItem(item);
            }
        }
    }
    //readConf();

    connect(ui->btnBassTimeSpeed, SIGNAL(clicked()), this, SLOT(learnBassTimeSpeedCC()));
    connect(ui->btnGamma, SIGNAL(clicked()), this, SLOT(learnGammaCC()));
    connect(ui->btnBrightness, SIGNAL(clicked()), this, SLOT(learnBrightnessCC()));
    connect(ui->btnContrast, SIGNAL(clicked()), this, SLOT(learnContrastCC()));
    connect(ui->btnDesaturate, SIGNAL(clicked()), this, SLOT(learnDesaturateCC()));
    connect(ui->btnBlackFade, SIGNAL(clicked()), this, SLOT(learnBlackFade()));
    connect(ui->btnTimeSpeed, SIGNAL(clicked()), this, SLOT(learnTimeSpeedCC()));
    connect(ui->btn1Effect1, SIGNAL(clicked()), this, SLOT(learn1Effect1CC()));
    connect(ui->btn1Effect2, SIGNAL(clicked()), this, SLOT(learn1Effect2CC()));
    connect(ui->btn1Effect3, SIGNAL(clicked()), this, SLOT(learn1Effect3CC()));
    connect(ui->btn1Effect4, SIGNAL(clicked()), this, SLOT(learn1Effect4CC()));
    connect(ui->btn2Effect1, SIGNAL(clicked()), this, SLOT(learn2Effect1CC()));
    connect(ui->btn2Effect2, SIGNAL(clicked()), this, SLOT(learn2Effect2CC()));
    connect(ui->btn2Effect3, SIGNAL(clicked()), this, SLOT(learn2Effect3CC()));
    connect(ui->btn2Effect4, SIGNAL(clicked()), this, SLOT(learn2Effect4CC()));
    connect(ui->btnSwitchDisplay, SIGNAL(clicked()), this, SLOT(learnSwitchDisplay()));
    connect(ui->btnSceneNext, SIGNAL(clicked()), this, SLOT(learnSceneUp()));
    connect(ui->btnSceneBack, SIGNAL(clicked()), this, SLOT(learnSceneDown()));
    connect(ui->btnTransitionUp, SIGNAL(clicked()), this, SLOT(learnTransitionUp()));
    connect(ui->btnTransitionDown, SIGNAL(clicked()), this, SLOT(learnTransitionDown()));
    connect(ui->cloneFaderCheck, SIGNAL(clicked()), this, SLOT(setCloneFader()));
    connect(ui->profilBox, SIGNAL(currentIndexChanged(int)), this, SLOT(readConf()));
    connect(ui->newProfilButton, SIGNAL(clicked()), this, SLOT(addProfil()));
    connect(ui->refreshButton, SIGNAL(clicked()), this, SLOT(refreshHardware()));
    connect(ui->hardwareComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(newMidiSequencer(int)));
    isLearning = false;
    learningCC = NULL;
}
Ejemplo n.º 15
0
NxMidiManager::NxMidiManager()
{

	if( Pm_Initialize() != pmNoError ) {
		Log("Could not initialize PortMidi.");
	}

	ListMidiInputs();
	ListMidiOutputs();

}
Ejemplo n.º 16
0
int port_init_seq()
{
    //if(seq_handle!=NULL) return 1;

    pm_status=Pm_Initialize();
    if(pm_status!=pmNoError)
    {
        fprintf(stderr, "Error initialising PortMIDI\n");
        return 0;
    }

    int i;
    const PmDeviceInfo *pm_dev_info;
    int num_devices=Pm_CountDevices();
    printf("Available MIDI devices:\n");
    for(i=0; i<num_devices; i++)
    {
        pm_dev_info=Pm_GetDeviceInfo(i);
        if(pm_dev_info->input) printf("%d: %s\n", i, pm_dev_info->name);
    }
    printf("\n");

    pm_status=Pm_OpenInput(&pm_stream, midiport, DRIVER_INFO, INPUT_BUFFER_SIZE, NULL, NULL);
    if(pm_status!=pmNoError)
    {
        fprintf(stderr, "Error opening MIDI input device\n");
    }


    /*
    	if(snd_seq_open(&seq_handle, "default", SND_SEQ_OPEN_INPUT, 0)<0) {
    		fprintf(stderr, "Error opening ALSA sequencer.\n");
    		return 0;
    	}

    	snd_seq_set_client_name(seq_handle, clientname);

    	in_port=snd_seq_create_simple_port(seq_handle, portname,
    		SND_SEQ_PORT_CAP_WRITE|SND_SEQ_PORT_CAP_SUBS_WRITE,
    		SND_SEQ_PORT_TYPE_APPLICATION);

    	if(in_port<0) {
    		fprintf(stderr, "Error creating sequencer port.\n");
    		return 0;
    	}

    	npfd=snd_seq_poll_descriptors_count(seq_handle, POLLIN);
    	pfd=(struct pollfd *)malloc(npfd*sizeof(struct pollfd));
    	snd_seq_poll_descriptors(seq_handle, pfd, npfd, POLLIN);
    */

    return 1;
}
Ejemplo n.º 17
0
PmError
Pm_InitializeWrapper ()
{
  if (init_count++ == 0)
    {
      return Pm_Initialize ();
    }
  else
    {
      return pmNoError;
    }
}
/*!
 @function midi_start
 @abstract
 @discussion
 @param
 @result
 */
void midi_start()
{
    Pm_Initialize();
    Pt_Start(1, NULL, NULL);

    retval = Pm_OpenOutput(&mstream, 0,NULL,512,NULL,NULL,0);
    if(retval != pmNoError)
    {
        printf("error: %s \n", Pm_GetErrorText(retval));
    }
    else /* set channel 1 to grand piano */
        program_change(1, 1);
}
Ejemplo n.º 19
0
void FLiveEditorManager::RefreshDeviceConnections()
{
	CloseDeviceConnections();
	Pm_Terminate();

	PmError Error = Pm_Initialize();
	if ( Error != pmNoError )
	{
		bInitialized = false;
		return;
	}

	FindDevices();
}
Ejemplo n.º 20
0
/// Gets the lists of names and lists of labels which are
/// used in the choice controls.
/// The names are what the user sees in the wxChoice.
/// The corresponding labels are what gets stored.
void MidiIOPrefs::GetNamesAndLabels() {
   // Gather list of hosts.  Only added hosts that have devices attached.
   Pm_Terminate(); // close and open to refresh device lists
   Pm_Initialize();
   int nDevices = Pm_CountDevices();
   for (int i = 0; i < nDevices; i++) {
      const PmDeviceInfo *info = Pm_GetDeviceInfo(i);
      if (info->output || info->input) { //should always happen
         wxString name(info->interf, wxConvLocal);
         if (mHostNames.Index(name) == wxNOT_FOUND) {
            mHostNames.Add(name);
            mHostLabels.Add(name);
         }
      }
   }
}
Ejemplo n.º 21
0
void init() {
  PmError err;
  
  if (isInit) return;
  
  printf("Initialising PortMidi\n");
  err = Pm_Initialize();
  reportPmError(err);
  
  if (Pt_Start(1,NULL,NULL) == 0) {
    mexAtExit(exitFunction);
    isInit = 1;
  } else {
    Pm_Terminate();
    mexErrMsgTxt("Could start PortMidi, but not PortTime.");
  }
}
Ejemplo n.º 22
0
void Server::start() {
	// midi
	Pm_Initialize();
	int dev_count = Pm_CountDevices();
	int i;
	for (i = 0; i < dev_count; i++) {
		auto info = Pm_GetDeviceInfo(i);
		if (info->output &&
			std::string(info->name).find("MIDI") != std::string::npos) break;
	}
	if (i < dev_count) Pm_OpenInput(&m_midi, 3, nullptr, 0, nullptr, nullptr);

	// start sound server
	static SDL_AudioSpec spec = { MIXRATE, AUDIO_S16SYS,
		2, 0, 1024, 0, 0, &Server::audio_callback, this
	};
	SDL_OpenAudio(&spec, &spec);
	SDL_PauseAudio(0);
}
Ejemplo n.º 23
0
int initMIDI()
{
	try {
		midiCleanUp();

		TPmErr(Pm_Initialize());
		int nbDev = Pm_CountDevices();
		int inIndex = 0;
		int outIndex = 0;
		int pmdid;

		for( int i = 0; i < nbDev ; ++i ) {
			const PmDeviceInfo* devInfo = Pm_GetDeviceInfo(i);
			if( devInfo->input )
			{
				gNumMIDIInPorts++;
				gMidiInputIndexToPmDevIndex[inIndex++] = i;
				gMidiPmDevIndexToInputIndex[i] = inIndex;
			}
			if( devInfo->output )
			{
				gNumMIDIOutPorts++;
				gMidiOutputIndexToPmDevIndex[outIndex++] = i;
				gMidiPmDevIndexToOutputIndex[i] = outIndex;
			}
		}

		for( int i = 0; i < gNumMIDIOutPorts; i++) {
			pmdid = gMidiOutputIndexToPmDevIndex[i];
			Pm_OpenOutput(&gMIDIOutStreams[i], pmdid, NULL, 512, NULL, NULL, 0);
		}

		/* will call our function, PMProcessMidi() every millisecond */
		Pt_Start(1, &PMProcessMidi, 0); /* start a timer with millisecond accuracy */
	}
	catch(PmError) {
		return errFailed;
	}

	gMIDIInitialized = true;
	return errNone;
}
Ejemplo n.º 24
0
int main(int argc, const char * argv[])
{
    int i, numDevices, selectedDeviceIndex = 3;
    long channel;
    const PmDeviceInfo *info;
    PortMidiStream *stream;
    PmEvent event;

    Pm_Initialize();

    numDevices = Pm_CountDevices();
    if (numDevices == 0) {
        return 0;
    }
    for (i = 0; i < numDevices; i++) {
        info = Pm_GetDeviceInfo(i);
        if (info->input) {
        }
    }

    info = Pm_GetDeviceInfo(selectedDeviceIndex);

    channel = 1;
    channel--;

    Pm_OpenInput(&stream,
                 selectedDeviceIndex,
                 NULL,
                 8192,
                 NULL,
                 NULL);

    printf("Setup complete! Waiting for MIDI data...\n");
    system("setterm -blank force");//kills all display.  to bring back call: setterm -blank poke
    while (1) {

        long status, data1, data2;
        int length, person, audioFile;

        length = Pm_Read(stream, &event, sizeof(long));
        if (length > 0) {

            status = Pm_MessageStatus(event.message);
            data1 = Pm_MessageData1(event.message);
            data2 = Pm_MessageData2(event.message);

            if (status == (0x80 + channel)) {
                printf("Note off: %ld, %ld\n", data1, data2);
            } else if (status == (0x90 + channel)) {
                printf("Note on: %ld, %ld\n", data1, data2);
            } else if (status == (0xB0 + channel)) {
                printf("CC: %ld, %ld\n", data1, data2);


            }

        }



        if (data1 == 25) {
            if (data2 == 127) {
                system("clear");
                system("playMovie");
            }
        }
        if(data1 == 26) {
            if(data2 == 127) {
                system("setterm -blank force");
            }
            if(data2 == 0) {
                system("setterm -blank poke");
            }
        }
    }
    Pm_Close(stream);

    Pm_Terminate();

    return 0;
}
/*!
 @function initialiseMIDISystem
 @abstract
 @discussion
 @param
 @result
 */
void initialiseMIDISystem(void)
{
    Pm_Initialize();
}
Ejemplo n.º 26
0
int main()
{
    int id;
    long n;
    const PmDeviceInfo *info;
    char line[STRING_MAX];
    int spin;
    int done = FALSE;

    /* determine what type of test to run */
    printf("begin PortMidi multithread test...\n");
	
    /* note that it is safe to call PortMidi from the main thread for
       initialization and opening devices. You should not make any
       calls to PortMidi from this thread once the midi thread begins.
       to make PortMidi calls.
     */

    /* make the message queues */
    /* messages can be of any size and any type, but all messages in
     * a given queue must have the same size. We'll just use long's
     * for our messages in this simple example
     */
    midi_to_main = Pm_QueueCreate(32, sizeof(long));
    assert(midi_to_main != NULL);
    main_to_midi = Pm_QueueCreate(32, sizeof(long));
    assert(main_to_midi != NULL);

    /* a little test of enqueue and dequeue operations. Ordinarily, 
     * you would call Pm_Enqueue from one thread and Pm_Dequeue from
     * the other. Since the midi thread is not running, this is safe.
     */
    n = 1234567890;
    Pm_Enqueue(midi_to_main, &n);
    n = 987654321;
    Pm_Enqueue(midi_to_main, &n);
	Pm_Dequeue(midi_to_main, &n);
	if (n != 1234567890) {
        exit_with_message("Pm_Dequeue produced unexpected result.");
    }
    Pm_Dequeue(midi_to_main, &n);
	if(n != 987654321) {
        exit_with_message("Pm_Dequeue produced unexpected result.");
    }

    /* always start the timer before you start midi */
    Pt_Start(1, &process_midi, 0); /* start a timer with millisecond accuracy */
    /* the timer will call our function, process_midi() every millisecond */
    
	Pm_Initialize();

    id = Pm_GetDefaultOutputDeviceID();
    info = Pm_GetDeviceInfo(id);
    if (info == NULL) {
        printf("Could not open default output device (%d).", id);
        exit_with_message("");
    }
    printf("Opening output device %s %s\n", info->interf, info->name);

    /* use zero latency because we want output to be immediate */
    Pm_OpenOutput(&midi_out, 
                  id, 
                  DRIVER_INFO,
                  OUTPUT_BUFFER_SIZE,
                  TIME_PROC,
                  TIME_INFO,
                  LATENCY);

    id = Pm_GetDefaultInputDeviceID();
    info = Pm_GetDeviceInfo(id);
    if (info == NULL) {
        printf("Could not open default input device (%d).", id);
        exit_with_message("");
    }
    printf("Opening input device %s %s\n", info->interf, info->name);
    Pm_OpenInput(&midi_in, 
                 id, 
                 DRIVER_INFO,
                 INPUT_BUFFER_SIZE,
                 TIME_PROC,
                 TIME_INFO);

    active = TRUE; /* enable processing in the midi thread -- yes, this
                      is a shared variable without synchronization, but
                      this simple assignment is safe */

    printf("Enter midi input; it will be transformed as specified by...\n");
    printf("%s\n%s\n%s\n",
           "Type 'q' to quit, 'm' to monitor next pitch, t to toggle thru or",
           "type a number to specify transposition.",
		   "Must terminate with [ENTER]");

    while (!done) {
        long msg;
        int len;
        fgets(line, STRING_MAX, stdin);
        /* remove the newline: */
        len = strlen(line);
        if (len > 0) line[len - 1] = 0; /* overwrite the newline char */
        if (strcmp(line, "q") == 0) {
            msg = QUIT_MSG;
            Pm_Enqueue(main_to_midi, &msg);
            /* wait for acknowlegement */
            do {
                spin = Pm_Dequeue(midi_to_main, &msg);
            } while (spin == 0); /* spin */ ;
            done = TRUE; /* leave the command loop and wrap up */
        } else if (strcmp(line, "m") == 0) {
            msg = MONITOR_MSG;
            Pm_Enqueue(main_to_midi, &msg);
            printf("Waiting for note...\n");
            do {
                spin = Pm_Dequeue(midi_to_main, &msg);
            } while (spin == 0); /* spin */ ;
            printf("... pitch is %ld\n", msg);
        } else if (strcmp(line, "t") == 0) {
            /* reading midi_thru asynchronously could give incorrect results,
               e.g. if you type "t" twice before the midi thread responds to
               the first one, but we'll do it this way anyway. Perhaps a more
               correct way would be to wait for an acknowledgement message
               containing the new state. */
            printf("Setting THRU %s\n", (midi_thru ? "off" : "on"));
            msg = THRU_MSG;
            Pm_Enqueue(main_to_midi, &msg);
        } else if (sscanf(line, "%ld", &msg) == 1) {
            if (msg >= -127 && msg <= 127) {
                /* send transposition value */
                printf("Transposing by %ld\n", msg);
                Pm_Enqueue(main_to_midi, &msg);
            } else {
                printf("Transposition must be within -127...127\n");
            }
        } else {
            printf("%s\n%s\n%s\n",
                   "Type 'q' to quit, 'm' to monitor next pitch, or",
                   "type a number to specify transposition.",
				   "Must terminate with [ENTER]");
        }
    }

    /* at this point, midi thread is inactive and we need to shut down
     * the midi input and output
     */
    Pt_Stop(); /* stop the timer */
    Pm_QueueDestroy(midi_to_main);
    Pm_QueueDestroy(main_to_midi);

    /* Belinda! if close fails here, some memory is deleted, right??? */
    Pm_Close(midi_in);
    Pm_Close(midi_out);
    
    printf("finished portMidi multithread test...enter any character to quit [RETURN]...");
    fgets(line, STRING_MAX, stdin);
    return 0;
}
Ejemplo n.º 27
0
static PyObject * MidiListener_play(MidiListener *self) {
    int i, num_devices;
    PmError pmerr;

    /* always start the timer before you start midi */
    Pt_Start(1, &process_midi, (void *)self);
    
    pmerr = Pm_Initialize();
    if (pmerr) {
        PySys_WriteStdout("Portmidi warning: could not initialize Portmidi: %s\n", Pm_GetErrorText(pmerr));
    }

    num_devices = Pm_CountDevices();
    if (num_devices > 0) {
        if (self->mididev < num_devices) {
            if (self->mididev == -1)
                self->mididev = Pm_GetDefaultInputDeviceID();
            const PmDeviceInfo *info = Pm_GetDeviceInfo(self->mididev);
            if (info != NULL) {
                if (info->input) {
                    pmerr = Pm_OpenInput(&self->midiin[0], self->mididev, NULL, 100, NULL, NULL);
                    if (pmerr) {
                        PySys_WriteStdout("Portmidi warning: could not open midi input %d (%s): %s\n",
                             self->mididev, info->name, Pm_GetErrorText(pmerr));
                    }
                    else {
                        self->midicount = 1;
                    }
                }
            }
        }
        else if (self->mididev >= num_devices) {
            self->midicount = 0;
            for (i=0; i<num_devices; i++) {
                const PmDeviceInfo *info = Pm_GetDeviceInfo(i);
                if (info != NULL) {
                    if (info->input) {
                        pmerr = Pm_OpenInput(&self->midiin[self->midicount], i, NULL, 100, NULL, NULL);
                        if (pmerr) {
                            PySys_WriteStdout("Portmidi warning: could not open midi input %d (%s): %s\n",
                                    i, info->name, Pm_GetErrorText(pmerr));
                        }
                        else {
                            self->midicount++;
                        }
                    }
                }
            }
        }
    }

    for (i=0; i<self->midicount; i++) {
        Pm_SetFilter(self->midiin[i], PM_FILT_ACTIVE | PM_FILT_CLOCK);
    }

    if (self->midicount > 0)
        self->active = 1;

	Py_INCREF(Py_None);
	return Py_None;
};
Ejemplo n.º 28
0
int pm_module::init(const osd_options &options)
{
	Pm_Initialize();
	return 0;
}
Ejemplo n.º 29
0
bool osd_midi_init()
{
    Pm_Initialize();
    return true;
}
Ejemplo n.º 30
0
PmDeviceID Pm_GetDefaultOutputDeviceID() {
    Pm_Initialize();
    return pm_default_output_device_id;
}