Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread Display Modes
Old Apr 6, 2012, 09:38 AM   #1
macrumors newbie
Join Date: Apr 2012
CoreMidi Devices

Good evening,
I am trying to play a note using CoreMidi library, the problem is that
I don't have any external MIDI device that receive messages I send.
I only have my macbook pro with MacOSX 10.6.8

My horrible code (I don't have checked error and other things, but, guys I first have to make it work) is in the following.
It simply try to send a note_on message to all destination of all entities of all device of my system.
The conclusion I get is that because I don't hear any sound there are no devices that can play sound connected. (is it correct?)

I know that MIDI programs work fine within this system. So, to who these programs (like tuxguitar) send MIDI messages?
Which functions/library I have to use to do my dirty trivial job?
Please share some knowledge with me.
#include <iostream>
#include <iostream>
#include <cstdlib>
#include <CoreMIDI/CoreMIDI.h>
#include <errno.h>

using namespace std;

void playPacketListOnAllDevices(MIDIPortRef midiout,  const MIDIPacketList* pktlist) {
	// send MIDI message to all MIDI output devices connected to computer:
	int devices = MIDIGetNumberOfDevices();
	int i;
	for (i=0; i<=devices;i++) {
		MIDIDeviceRef d = MIDIGetDevice(i);
		int entities = MIDIDeviceGetNumberOfEntities(d);
		int j;
			MIDIEntityRef e = MIDIDeviceGetEntity(d,j);
			int destinations =MIDIEntityGetNumberOfDestinations(e);
			int w;
			for (w=0;w<=destinations;w++){
				cout<<"("<<i<<" "<<j<<" "<<w<< ")\n";
				OSStatus status;
				int dest = MIDIGetDestination(w);
				if (status = MIDISend(midiout, dest, pktlist)) {
					printf("Problem sendint MIDI data on port %d\n", (int)dest);

int main(){
	Byte buffer[1024];             // storage space for MIDI Packets (max 65536)
	MIDIPacketList *packetlist = (MIDIPacketList*)buffer;
	MIDIPacket *currentpacket = MIDIPacketListInit(packetlist);
	MIDIClientRef midiclient  = NULL;
	MIDIPortRef   midiout     = NULL;
	OSStatus status;
	if (status = MIDIClientCreate(CFSTR("TeStInG"), NULL, NULL, &midiclient)) {
		printf("Error trying to create MIDI Client structure: %d\n", status);
	if (status = MIDIOutputPortCreate(midiclient, CFSTR("OuTpUt"), &midiout)) {
		printf("Error trying to create MIDI output port: %d\n", status);
	MIDITimeStamp timestamp = 0;   // 0 will mean play now. 
	Byte noteon[MESSAGESIZE] = {0x90, 60, 90};
	currentpacket = MIDIPacketListAdd(packetlist, sizeof(buffer), currentpacket, timestamp, MESSAGESIZE, noteon);	
	cout<<"Number of Devices is "<<(int)MIDIGetNumberOfDevices()<<"\n";
	playPacketListOnAllDevices(midiout, packetlist);

	return 0;}
Bob2000 is offline   0 Reply With Quote

MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
CoreMIDI gone mad! jakesaunders27 Digital Audio 1 Jan 20, 2014 03:31 PM
Nearly 300 Million Devices Running iOS 6, 60% of All iOS Devices Ever MacRumors MacRumors.com News Discussion 139 Jan 31, 2013 01:10 PM
What do you name your devices? mentaluproar Community Discussion 69 Jan 5, 2013 03:06 PM
External devices not appearing on Mountain Lion desktop or devices list. stop.the.clocks Mac Basics and Help 1 Aug 17, 2012 01:14 PM
2 out of 3 devices down.. devices not registered? se99jmk iOS 6 12 Jun 11, 2012 06:06 PM

Forum Jump

All times are GMT -5. The time now is 11:25 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2015, MacRumors.com, LLC