# Linux MIDI support?

**URL:** <https://forum.juce.com/t/linux-midi-support/863>\
**Category:** Linux\
**Created:** [May 31, 2006, 12:11pm UTC](https://forum.juce.com/t/linux-midi-support/863 "2006-05-31T12:11:17Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![NiallM](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/niallm/32/293_2.png) [@NiallM](https://forum.juce.com/u/NiallM)\
**Post date:** [May 31, 2006, 12:11pm UTC](https://forum.juce.com/t/linux-midi-support/863/1 "2006-05-31T12:11:17Z")

</div>

Jules, do you have an idea when you might add MIDI support for the linux port? It’s just that I’m adding MIDI to my Mouse to OSC program, and I’m going to need it working on my linux machine at uni.

It’s relatively urgent (I had actually thought MIDI was already implemented, having noticed the juce\_linux\_Midi.cpp file - it was only recently that I realised that file is essentially empty :oops:), so if it’s low down on your list of priorities, I’ll have a go at implementing it myself, but I don’t want to end up replicating lines of code if you’re already working on it.

- Niall.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [May 31, 2006, 1:35pm UTC](https://forum.juce.com/t/linux-midi-support/863/2 "2006-05-31T13:35:07Z")

</div>

Hi there

No immediate plans, and I’m a bit booked up, but if you wanted to have a shot I’d be happy to advise and help out. I had a quick look at it when I was doing ALSA and it seemed fairly straightforward.

---

<div class="post-metadata">

**Author:** ![NiallM](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/niallm/32/293_2.png) [@NiallM](https://forum.juce.com/u/NiallM)\
**Post date:** [July 5, 2006, 10:14am UTC](https://forum.juce.com/t/linux-midi-support/863/3 "2006-07-05T10:14:15Z")

</div>

Okay, here’s my juce\_linux\_midi.cpp, using ALSA’s sequencer API, so you can do inter-app connections :D. It’s not by any means complete - it only handles MIDI input, and I left out anything I don’t actually need (timestamps, sysex etc.), but it works well:

# [code]/\*

This file is part of the JUCE library - "Jules’ Utility Class Extensions"  
Copyright 2004-6 by Raw Material Software ltd.

* * *

JUCE can be redistributed and/or modified under the terms of the  
GNU General Public License, as published by the Free Software Foundation;  
either version 2 of the License, or (at your option) any later version.

JUCE is distributed in the hope that it will be useful,  
but WITHOUT ANY WARRANTY; without even the implied warranty of  
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  
GNU General Public License for more details.

You should have received a copy of the GNU General Public License  
along with JUCE; if not, visit [www.gnu.org/licenses](http://www.gnu.org/licenses) or write to the  
Free Software Foundation, Inc., 59 Temple Place, Suite 330,  
Boston, MA 02111-1307 USA

* * *

If you’d like to release a closed-source product which uses JUCE, commercial  
licenses are also available: visit [www.rawmaterialsoftware.com/juce](http://www.rawmaterialsoftware.com/juce) for  
more information.

==============================================================================  
\*/

#include “juce\_Config.h”  
#if JUCE\_BUILD\_GUI\_CLASSES

#include “…/…/…/src/juce\_core/basics/juce\_StandardHeader.h”

#include “alsa/asoundlib.h”  
#include

using namespace std;

BEGIN\_JUCE\_NAMESPACE

#include “…/…/…/src/juce\_appframework/audio/devices/juce\_MidiOutput.h”  
#include “…/…/…/src/juce\_appframework/audio/devices/juce\_MidiInput.h”  
#include “…/…/…/src/juce\_core/threads/juce\_Thread.h”

//==============================================================================  
const StringArray MidiOutput::getDevices()  
{  
StringArray s;  
return s;  
}

int MidiOutput::getDefaultDeviceIndex()  
{  
return 0;  
}

MidiOutput\* MidiOutput::openDevice (int deviceIndex)  
{  
return 0;  
}

MidiOutput::MidiOutput()  
{  
}

MidiOutput::~MidiOutput()  
{  
}

void MidiOutput::reset()  
{  
}

bool MidiOutput::getVolume (float& leftVol, float& rightVol)  
{  
return false;  
}

void MidiOutput::setVolume (float leftVol, float rightVol)  
{  
}

void MidiOutput::sendMessageNow (const MidiMessage& message)  
{  
}

//==============================================================================

//------------------------------------------------------------------------------  
/// Thread used to handle all MIDI input.  
class MidiInputThread : public Thread  
{  
public:  
/// Constructor.  
/\*!  
\param input Pointer to the MidiInput object in charge of the MIDI  
stuff.  
\param handle Handle to the sequencer object used to receive MIDI events  
from.  
\param inputCallback Pointer to the callback object to be called when  
a MIDI event is received.  
\*/  
MidiInputThread(MidiInput \*input,  
snd\_seq\_t \*handle,  
MidiInputCallback \* const inputCallback):  
Thread(T(“JUCE MIDI Input Thread”)),  
midiInput(input),  
seqHandle(handle),  
callback(inputCallback)  
{

```
};
///	Destructor.
~MidiInputThread()
{
	if(seqHandle)
	{
		//Do I need to do anything else?
		snd_seq_close(seqHandle);
	}
};

///	Where the main thread activity takes place.
void run()
{
	int npfd = -1;
	struct pollfd *pfd = 0;
	snd_seq_event_t *event = 0;
	unsigned char tempBytes[32];
	snd_midi_event_t *midiParser;
	int byteCount;

	if(snd_midi_event_new(32, &midiParser) != 0)
	{
		cout << "Could not create MIDI parser." << endl;
		midiParser = 0;
	}

	//Polling code taken from:
	//http://www.suse.de/~mana/seqdemo.c
	if(seqHandle)
	{
		npfd = snd_seq_poll_descriptors_count(seqHandle, POLLIN);
		pfd = (struct pollfd *)alloca(npfd * sizeof(struct pollfd));
		snd_seq_poll_descriptors(seqHandle, pfd, npfd, POLLIN);

		while(!threadShouldExit())
		{
			if(poll(pfd, npfd, 200) > 0)
			{
				while(snd_seq_event_input(seqHandle, &event) >= 0)
				{
					if(!midiParser)
						continue;

					byteCount = snd_midi_event_decode(midiParser,
													  tempBytes,
													  32,
													  event);
					snd_midi_event_reset_decode(midiParser);

					//Ignore timestamp for now (not sure what to do with
					//it?).
					const MidiMessage message((const uint8 * const)tempBytes,
											  byteCount);

					callback->handleIncomingMidiMessage(midiInput, message);
				}
				//Should this be inside the above loop?
				snd_seq_free_event(event);
			}
		}
	}

	if(midiParser)
		snd_midi_event_free(midiParser);
};

juce_UseDebuggingNewOperator

```

private:  
/// The MidiInput object associated with this thread.  
MidiInput \*midiInput;  
/// The sequencer handle for this client.  
snd\_seq\_t \*seqHandle;  
/// The callback to call when we receive a MIDI event.  
MidiInputCallback \*callback;  
};

const StringArray MidiInput::getDevices()  
{  
StringArray s;

```
snd_seq_t *seqHandle;
snd_seq_system_info_t *info;
snd_seq_client_info_t *info2;
snd_seq_port_info_t *portInfo;

if(snd_seq_open(&seqHandle, "default", SND_SEQ_OPEN_INPUT, 0) < 0)
{
	cout << "Could not open ALSA seq client." << endl;
	return s;
}

if(!snd_seq_system_info_malloc(&info))
{
	if(!snd_seq_system_info(seqHandle, info))
	{
		if(!snd_seq_client_info_malloc(&info2))
		{
			int tempint = snd_seq_system_info_get_cur_clients(info);
			for(int i=0;i<tempint;++i)
			{
				if(!snd_seq_query_next_client(seqHandle, info2))
				{

					if(!snd_seq_port_info_malloc(&portInfo))
					{
						int tempint2;
						int tempint3 = snd_seq_client_info_get_num_ports(info2);
						tempint2 = snd_seq_client_info_get_client(info2);
						snd_seq_port_info_set_client(portInfo, tempint2);
						snd_seq_port_info_set_port(portInfo, -1);
						for(int j=0;j<tempint3;++j)
						{
							if(!snd_seq_query_next_port(seqHandle, portInfo))
							{
								unsigned int caps;

								caps = snd_seq_port_info_get_capability(portInfo);
								if(caps&SND_SEQ_PORT_CAP_READ)
								{
									s.add(snd_seq_client_info_get_name(info2));
								}
							}
						}
						snd_seq_port_info_free(portInfo);
					}
				}
				else
					cout << "Could not get client info " << i << endl;
			}
			if(!snd_seq_get_client_info(seqHandle, info2))
			{
				cout << "Got current client info." << endl;
				cout << "Client ID: ";
				cout << snd_seq_client_info_get_client(info2) << endl;
				cout << "Client name: ";
				cout << snd_seq_client_info_get_name(info2) << endl;
			}
			snd_seq_client_info_free(info2);
		}
	}
	else
		cout << "Could not get ALSA seq system info." << endl;

	snd_seq_system_info_free(info);
}
else
	cout << "Could not allocate system info struct." << endl;

snd_seq_close(seqHandle);

return s;

```

}

int MidiInput::getDefaultDeviceIndex()  
{  
return 0;  
}

MidiInput\* MidiInput::openDevice (int deviceIndex, MidiInputCallback\* callback)  
{  
snd\_seq\_t \*seqHandle;  
snd\_seq\_system\_info\_t \*info;  
snd\_seq\_client\_info\_t \*info2;  
snd\_seq\_port\_info\_t \*portInfo;  
int portId;  
int sourcePort = -1;  
int currentIndex = -1;  
MidiInput \*retval = 0;  
MidiInputThread \*thread;

```
if(snd_seq_open(&seqHandle, "default", SND_SEQ_OPEN_INPUT, 0) < 0)
	return 0;

if(!snd_seq_system_info_malloc(&info))
{
	if(!snd_seq_system_info(seqHandle, info))
	{
		if(!snd_seq_client_info_malloc(&info2))
		{
			int tempint = snd_seq_system_info_get_cur_clients(info);
			for(int i=0;i<tempint;++i)
			{
				if(!snd_seq_query_next_client(seqHandle, info2))
				{
					if(!snd_seq_port_info_malloc(&portInfo))
					{
						int tempint2;
						int tempint3 = snd_seq_client_info_get_num_ports(info2);
						tempint2 = snd_seq_client_info_get_client(info2);
						snd_seq_port_info_set_client(portInfo, tempint2);
						snd_seq_port_info_set_port(portInfo, -1);
						for(int j=0;j<tempint3;++j)
						{
							if(!snd_seq_query_next_port(seqHandle, portInfo))
							{
								unsigned int caps;

								sourcePort = snd_seq_port_info_get_port(portInfo);

								caps = snd_seq_port_info_get_capability(portInfo);
								if(caps&SND_SEQ_PORT_CAP_READ)
								{
									++currentIndex;
									break;
								}
							}
						}
						if((currentIndex == deviceIndex) &&
						   (sourcePort != -1))
						{
							String tempstr;
							int sourceClient;

							//Get client name, put into tempstr.
							tempstr << snd_seq_client_info_get_name(info2);

							//Set name for our client.
							snd_seq_set_client_name(seqHandle,
													"JUCE Midi Input");

							//Open port for seqHandle (do I need to save the ID?).
							portId = snd_seq_create_simple_port(seqHandle,
													   			"JUCE Midi In Port",
													   			SND_SEQ_PORT_CAP_WRITE,
													   			SND_SEQ_PORT_TYPE_MIDI_GENERIC);

							//Subscribe to relevant client port.
							sourceClient = snd_seq_client_info_get_client(info2);
							snd_seq_connect_from(seqHandle,
												 portId,
												 sourceClient,
												 sourcePort);

							retval = new MidiInput(tempstr);
							thread = new MidiInputThread(retval,
														 seqHandle,
														 callback);
							retval->internal = thread;

							snd_seq_port_info_free(portInfo);
							break;
						}

						snd_seq_port_info_free(portInfo);
					}
				}
			}
			snd_seq_client_info_free(info2);
		}
	}

	snd_seq_system_info_free(info);
}

if(!retval)
	snd_seq_close(seqHandle);

return retval;

```

}

MidiInput::~MidiInput()  
{  
MidiInputThread \*thread;

```
if(internal)
{
	thread = (MidiInputThread *)internal;
	delete thread;
}

```

}

MidiInput::MidiInput(const String &name\_):  
internal(0),  
name(name\_)  
{

}

void MidiInput::start()  
{  
((MidiInputThread \*)internal)-\>startThread();  
}

void MidiInput::stop()  
{  
((MidiInputThread \*)internal)-\>stopThread(250);  
}

END\_JUCE\_NAMESPACE

#endif  
[/code]

- Niall.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [July 5, 2006, 8:27pm UTC](https://forum.juce.com/t/linux-midi-support/863/4 "2006-07-05T20:27:35Z")

</div>

Nice job! Do you mind if I take that, hack it around, and put it into the official build?

---

<div class="post-metadata">

**Author:** ![NiallM](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/niallm/32/293_2.png) [@NiallM](https://forum.juce.com/u/NiallM)\
**Post date:** [July 6, 2006, 9:16am UTC](https://forum.juce.com/t/linux-midi-support/863/5 "2006-07-06T09:16:27Z")

</div>

😃 Of course! I’m happy to be able to contribute to such a great library.

- Niall.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [July 6, 2006, 9:55am UTC](https://forum.juce.com/t/linux-midi-support/863/6 "2006-07-06T09:55:04Z")

</div>

ok, well I zoomed through and did a bit of tidying-up.. Here’s my version (bears very little resemblence to the original!). If you could try it out I’d appreciate it, because I don’t have any midi on my linux set-up (using VMWare).

One thing I noticed is that it won’t handle large sysexes. I’ve increased the buffer size to 16K but they could be megabytes in size. Will leave that for the future, I think..

# [code]/\*

This file is part of the JUCE library - “Jules’ Utility Class Extensions”  
Copyright 2004-6 by Raw Material Software ltd.

* * *

JUCE can be redistributed and/or modified under the terms of the  
GNU General Public License, as published by the Free Software Foundation;  
either version 2 of the License, or (at your option) any later version.

JUCE is distributed in the hope that it will be useful,  
but WITHOUT ANY WARRANTY; without even the implied warranty of  
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  
GNU General Public License for more details.

You should have received a copy of the GNU General Public License  
along with JUCE; if not, visit [Licenses - GNU Project - Free Software Foundation](http://www.gnu.org/licenses) or write to the  
Free Software Foundation, Inc., 59 Temple Place, Suite 330,  
Boston, MA 02111-1307 USA

* * *

If you’d like to release a closed-source product which uses JUCE, commercial  
licenses are also available: visit [www.rawmaterialsoftware.com/juce](http://www.rawmaterialsoftware.com/juce) for  
more information.

==============================================================================  
\*/

#include “juce\_Config.h”

#if JUCE\_BUILD\_GUI\_CLASSES

#include “../../../src/juce\_core/basics/juce\_StandardHeader.h”

#include \<alsa/asoundlib.h\>

BEGIN\_JUCE\_NAMESPACE

#include “../../../src/juce\_appframework/audio/devices/juce\_MidiOutput.h”  
#include “../../../src/juce\_appframework/audio/devices/juce\_MidiInput.h”  
#include “../../../src/juce\_core/threads/juce\_Thread.h”  
#include “../../../src/juce\_core/basics/juce\_Time.h”

//==============================================================================  
const StringArray MidiOutput::getDevices()  
{  
StringArray s;  
return s;  
}

int MidiOutput::getDefaultDeviceIndex()  
{  
return 0;  
}

MidiOutput\* MidiOutput::openDevice (int deviceIndex)  
{  
return 0;  
}

MidiOutput::MidiOutput()  
{  
}

MidiOutput::~MidiOutput()  
{  
}

void MidiOutput::reset()  
{  
}

bool MidiOutput::getVolume (float& leftVol, float& rightVol)  
{  
return false;  
}

void MidiOutput::setVolume (float leftVol, float rightVol)  
{  
}

void MidiOutput::sendMessageNow (const MidiMessage& message)  
{  
}

//==============================================================================  
class MidiInputThread : public Thread  
{  
public:  
MidiInputThread (MidiInput\* const midiInput\_,  
snd\_seq\_t\* const seqHandle\_,  
MidiInputCallback\* const callback\_)  
: Thread (T(“Juce MIDI Input”)),  
midiInput (midiInput\_),  
seqHandle (seqHandle\_),  
callback (callback\_)  
{  
jassert (seqHandle != 0 && callback != 0 && midiInput != 0);  
}

```
~MidiInputThread()
{
    snd_seq_close (seqHandle);
}

void run()
{
    const int maxEventSize = 16 * 1024;
    snd_midi_event_t* midiParser;

    if (snd_midi_event_new (maxEventSize, &midiParser) >= 0)
    {
        uint8* const buffer = (uint8*) juce_malloc (maxEventSize);

        const int numPfds = snd_seq_poll_descriptors_count (seqHandle, POLLIN);
        struct pollfd* const pfd = (struct pollfd*) alloca (numPfds * sizeof (struct pollfd));

        snd_seq_poll_descriptors (seqHandle, pfd, numPfds, POLLIN);

        while (! threadShouldExit())
        {
            if (poll (pfd, numPfds, 200) > 0)
            {
                snd_seq_event_t* inputEvent = 0;

                while (snd_seq_event_input (seqHandle, &inputEvent) >= 0)
                {
                    // xxx what about SYSEXes that are too big for the buffer?
                    const int numBytes = snd_midi_event_decode (midiParser, buffer, maxEventSize, inputEvent);

                    snd_midi_event_reset_decode (midiParser);

                    const MidiMessage message ((const uint8*) buffer, 
                                               numBytes,
                                               Time::getMillisecondCounter() * 0.001);

                    callback->handleIncomingMidiMessage (midiInput, message);
                }

                snd_seq_free_event (inputEvent);
            }
        }

        snd_midi_event_free (midiParser);
        juce_free (buffer);
    }
};

juce_UseDebuggingNewOperator

```

private:  
MidiInput\* const midiInput;  
snd\_seq\_t\* const seqHandle;  
MidiInputCallback\* const callback;  
};

//==============================================================================  
MidiInput::MidiInput (const String& name\_)  
: internal (0),  
name (name\_)  
{  
}

MidiInput::~MidiInput()  
{  
stop();  
MidiInputThread\* const thread = (MidiInputThread\*) internal;  
delete thread;  
}

void MidiInput::start()  
{  
((MidiInputThread\*) internal)-\>startThread();  
}

void MidiInput::stop()  
{  
((MidiInputThread\*) internal)-\>stopThread (2000);  
}

int MidiInput::getDefaultDeviceIndex()  
{  
return 0;  
}

static snd\_seq\_t\* iterateDevices (StringArray& deviceNamesFound, const int deviceIndexToOpen)  
{  
snd\_seq\_t\* returnedHandle = 0;

```
snd_seq_t* seqHandle;
if (snd_seq_open (&seqHandle, "default", SND_SEQ_OPEN_INPUT, 0) == 0)
{
    snd_seq_system_info_t* systemInfo;
    snd_seq_client_info_t* clientInfo;

    if (snd_seq_system_info_malloc (&systemInfo) == 0)
    {
        if (snd_seq_system_info (seqHandle, systemInfo) == 0
             && snd_seq_client_info_malloc (&clientInfo) == 0)
        {
            int numClients = snd_seq_system_info_get_cur_clients (systemInfo);

            while (--numClients >= 0 && returnedHandle == 0)
            {
                if (snd_seq_query_next_client (seqHandle, clientInfo) == 0)
                {
                    snd_seq_port_info_t* portInfo;
                    if (snd_seq_port_info_malloc (&portInfo) == 0)
                    {
                        int numPorts = snd_seq_client_info_get_num_ports (clientInfo);
                        const int client = snd_seq_client_info_get_client (clientInfo);

                        snd_seq_port_info_set_client (portInfo, client);
                        snd_seq_port_info_set_port (portInfo, -1);

                        while (--numPorts >= 0)
                        {
                            if (snd_seq_query_next_port (seqHandle, portInfo) == 0
                                 && (snd_seq_port_info_get_capability (portInfo) & SND_SEQ_PORT_CAP_READ) != 0)
                            {
                                deviceNamesFound.add (snd_seq_client_info_get_name (clientInfo));

                                if (deviceNamesFound.size() == deviceIndexToOpen + 1)
                                {
                                    const int sourcePort = snd_seq_port_info_get_port (portInfo);
                                    const int sourceClient = snd_seq_client_info_get_client (clientInfo);

                                    if (sourcePort != -1)
                                    {
                                        snd_seq_set_client_name (seqHandle, "Juce Midi Input");

                                        const int portId
                                            = snd_seq_create_simple_port (seqHandle, "Juce Midi In Port",
                                                                          SND_SEQ_PORT_CAP_WRITE,
                                                                          SND_SEQ_PORT_TYPE_MIDI_GENERIC);

                                        snd_seq_connect_from (seqHandle, portId, sourceClient, sourcePort);

                                        returnedHandle = seqHandle;
                                        break;
                                    }
                                }
                            }
                        }

                        snd_seq_port_info_free (portInfo);
                    }
                }
            }

            snd_seq_client_info_free (clientInfo);
        }

        snd_seq_system_info_free (systemInfo);
    }

    if (returnedHandle == 0)
        snd_seq_close (seqHandle);
}

return returnedHandle;

```

}

const StringArray MidiInput::getDevices()  
{  
StringArray devices;  
iterateDevices (devices, -1);  
return devices;  
}

MidiInput\* MidiInput::openDevice (int deviceIndex, MidiInputCallback\* callback)  
{  
MidiInput\* newDevice = 0;

```
StringArray devices;
snd_seq_t* const handle = iterateDevices (devices, deviceIndex);

if (handle != 0)
{
    newDevice = new MidiInput (devices [deviceIndex]);
    newDevice->internal = new MidiInputThread (newDevice, handle, callback);
}

return newDevice;

```

}

END\_JUCE\_NAMESPACE

#endif  
[/code]

---

<div class="post-metadata">

**Author:** ![NiallM](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/niallm/32/293_2.png) [@NiallM](https://forum.juce.com/u/NiallM)\
**Post date:** [July 6, 2006, 10:57am UTC](https://forum.juce.com/t/linux-midi-support/863/7 "2006-07-06T10:57:17Z")

</div>

Yep, that seems to work fine. I should point out that I’ve only got a hardware control surface here (no keyboard), so I’ve only been testing it with CCs so far, but I just had a go with the ALSA vkeybd virtual keyboard app and it caught all my mouse clicks/fake key presses (since ALSA’s sequencer api handles inter-app communication, you should be able to test it yourself too, even without a hardware input).

- Niall.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [July 6, 2006, 11:58am UTC](https://forum.juce.com/t/linux-midi-support/863/8 "2006-07-06T11:58:46Z")

</div>

Cool. I’ll add it to the build then - thanks!

---

<div class="post-metadata">

**Author:** ![mercurysquad](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@mercurysquad](https://forum.juce.com/u/mercurysquad)\
**Post date:** [August 4, 2006, 8:36am UTC](https://forum.juce.com/t/linux-midi-support/863/9 "2006-08-04T08:36:18Z")

</div>

Arghh… I was looking for ALSA midi I/O in juce as well and assumed it was already functional.

Anyway so the hard part (midi in) has already been implemented thanks to NiallM. I’ll be giving MIDI out a try, via ALSA. I’ve written midi i/o libraries on Windows before but I am only just starting with Linux so I’m not making any promises, but let’s see how far I get…

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [August 4, 2006, 10:13am UTC](https://forum.juce.com/t/linux-midi-support/863/10 "2006-08-04T10:13:21Z")

</div>

Cool. Feel free to throw code in my direction for sanity checking and tidying-up!

---

<div class="post-metadata">

**Author:** ![NiallM](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/niallm/32/293_2.png) [@NiallM](https://forum.juce.com/u/NiallM)\
**Post date:** [August 4, 2006, 10:41am UTC](https://forum.juce.com/t/linux-midi-support/863/11 "2006-08-04T10:41:36Z")

</div>

It shouldn’t be too hard, but make sure you use ALSA’s sequencer api, rather than the rawmidi one. The sequencer api allows for fancy inter-app connections, but IIRC rawmidi is a much more basic api that only handles connections to the hardware MIDI IO ports. I was going to post a link to the sequencer documentation, but it seems the ALSA site is down at the moment, so the best I can manage is this: [http://www.alsa-project.org/documentation.php](http://www.alsa-project.org/documentation.php). Also, there’s a tutorial which uses the sequencer api [here](http://www.suse.de/~mana/alsa090_howto.html).

Good luck!

- Niall.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [May 12, 2017, 10:01am UTC](https://forum.juce.com/t/linux-midi-support/863/12 "2017-05-12T10:01:10Z")

</div>

Closed on May 12, 2017, 10:01am UTC


