Browse Source

New JackWinMMEPort class to factorize some code.

tags/1.9.8
Stephane Letz 14 years ago
parent
commit
eb24bdac93
6 changed files with 185 additions and 124 deletions
  1. +24
    -35
      windows/winmme/JackWinMMEInputPort.cpp
  2. +9
    -16
      windows/winmme/JackWinMMEInputPort.h
  3. +18
    -49
      windows/winmme/JackWinMMEOutputPort.cpp
  4. +7
    -24
      windows/winmme/JackWinMMEOutputPort.h
  5. +69
    -0
      windows/winmme/JackWinMMEPort.cpp
  6. +58
    -0
      windows/winmme/JackWinMMEPort.h

+ 24
- 35
windows/winmme/JackWinMMEInputPort.cpp View File

@@ -59,7 +59,7 @@ JackWinMMEInputPort::JackWinMMEInputPort(const char *alias_name,
(DWORD)this,
CALLBACK_FUNCTION | MIDI_IO_STATUS);
if (result != MMSYSERR_NOERROR) {
GetErrorString(result, error_message);
GetInErrorString(result, error_message);
goto delete_sysex_buffer;
}
sysex_header.dwBufferLength = max_bytes;
@@ -70,19 +70,19 @@ JackWinMMEInputPort::JackWinMMEInputPort(const char *alias_name,
sysex_header.lpNext = 0;
result = midiInPrepareHeader(handle, &sysex_header, sizeof(MIDIHDR));
if (result != MMSYSERR_NOERROR) {
GetErrorString(result, error_message);
GetInErrorString(result, error_message);
goto close_handle;
}
result = midiInAddBuffer(handle, &sysex_header, sizeof(MIDIHDR));
if (result != MMSYSERR_NOERROR) {
GetErrorString(result, error_message);
GetInErrorString(result, error_message);
goto unprepare_header;
}
MIDIINCAPS capabilities;
char *name_tmp;
result = midiInGetDevCaps(index, &capabilities, sizeof(capabilities));
if (result != MMSYSERR_NOERROR) {
WriteError("JackWinMMEInputPort [constructor]", "midiInGetDevCaps",
WriteInError("JackWinMMEInputPort [constructor]", "midiInGetDevCaps",
result);
name_tmp = driver_name;
} else {
@@ -100,13 +100,13 @@ JackWinMMEInputPort::JackWinMMEInputPort(const char *alias_name,
unprepare_header:
result = midiInUnprepareHeader(handle, &sysex_header, sizeof(MIDIHDR));
if (result != MMSYSERR_NOERROR) {
WriteError("JackWinMMEInputPort [constructor]",
WriteInError("JackWinMMEInputPort [constructor]",
"midiInUnprepareHeader", result);
}
close_handle:
result = midiInClose(handle);
if (result != MMSYSERR_NOERROR) {
WriteError("JackWinMMEInputPort [constructor]", "midiInClose", result);
WriteInError("JackWinMMEInputPort [constructor]", "midiInClose", result);
}
delete_sysex_buffer:
delete[] sysex_buffer;
@@ -118,16 +118,16 @@ JackWinMMEInputPort::~JackWinMMEInputPort()
Stop();
MMRESULT result = midiInReset(handle);
if (result != MMSYSERR_NOERROR) {
WriteError("JackWinMMEInputPort [destructor]", "midiInReset", result);
WriteInError("JackWinMMEInputPort [destructor]", "midiInReset", result);
}
result = midiInUnprepareHeader(handle, &sysex_header, sizeof(MIDIHDR));
if (result != MMSYSERR_NOERROR) {
WriteError("JackWinMMEInputPort [destructor]", "midiInUnprepareHeader",
WriteInError("JackWinMMEInputPort [destructor]", "midiInUnprepareHeader",
result);
}
result = midiInClose(handle);
if (result != MMSYSERR_NOERROR) {
WriteError("JackWinMMEInputPort [destructor]", "midiInClose", result);
WriteInError("JackWinMMEInputPort [destructor]", "midiInClose", result);
}
delete[] sysex_buffer;
delete thread_queue;
@@ -154,27 +154,6 @@ JackWinMMEInputPort::EnqueueMessage(jack_nframes_t time, size_t length,
}
}

const char *
JackWinMMEInputPort::GetAlias()
{
return alias;
}

const char *
JackWinMMEInputPort::GetName()
{
return name;
}

void
JackWinMMEInputPort::GetErrorString(MMRESULT error, LPTSTR text)
{
MMRESULT result = midiInGetErrorText(error, text, MAXERRORLENGTH);
if (result != MMSYSERR_NOERROR) {
snprintf(text, MAXERRORLENGTH, "Unknown error code '%d'", error);
}
}

void
JackWinMMEInputPort::ProcessJack(JackMidiBuffer *port_buffer,
jack_nframes_t frames)
@@ -254,7 +233,7 @@ JackWinMMEInputPort::ProcessWinMME(UINT message, DWORD param1, DWORD param2)
MMRESULT result = midiInAddBuffer(handle, &sysex_header,
sizeof(MIDIHDR));
if (result != MMSYSERR_NOERROR) {
WriteError("JackWinMMEInputPort::ProcessWinMME", "midiInAddBuffer",
WriteInError("JackWinMMEInputPort::ProcessWinMME", "midiInAddBuffer",
result);
}
break;
@@ -274,7 +253,7 @@ JackWinMMEInputPort::Start()
MMRESULT result = midiInStart(handle);
started = result == MMSYSERR_NOERROR;
if (! started) {
WriteError("JackWinMMEInputPort::Start", "midiInStart", result);
WriteInError("JackWinMMEInputPort::Start", "midiInStart", result);
}
}
return started;
@@ -287,17 +266,27 @@ JackWinMMEInputPort::Stop()
MMRESULT result = midiInStop(handle);
started = result != MMSYSERR_NOERROR;
if (started) {
WriteError("JackWinMMEInputPort::Stop", "midiInStop", result);
WriteInError("JackWinMMEInputPort::Stop", "midiInStop", result);
}
}
return ! started;
}

void
JackWinMMEInputPort::WriteError(const char *jack_func, const char *mm_func,
JackWinMMEInputPort::GetInErrorString(MMRESULT error, LPTSTR text)
{
MMRESULT result = midiInGetErrorText(error, text, MAXERRORLENGTH);
if (result != MMSYSERR_NOERROR) {
snprintf(text, MAXERRORLENGTH, "Unknown error code '%d'", error);
}
}

void
JackWinMMEInputPort::WriteInError(const char *jack_func, const char *mm_func,
MMRESULT result)
{
char error_message[MAXERRORLENGTH];
GetErrorString(result, error_message);
GetInErrorString(result, error_message);
jack_error("%s - %s: %s", jack_func, mm_func, error_message);
}


+ 9
- 16
windows/winmme/JackWinMMEInputPort.h View File

@@ -24,10 +24,11 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

#include "JackMidiAsyncQueue.h"
#include "JackMidiBufferWriteQueue.h"
#include "JackWinMMEPort.h"

namespace Jack {

class JackWinMMEInputPort {
class JackWinMMEInputPort : public JackRunnableInterface {

private:

@@ -39,19 +40,10 @@ namespace Jack {
EnqueueMessage(jack_nframes_t time, size_t length,
jack_midi_data_t *data);

void
GetErrorString(MMRESULT error, LPTSTR text);

void
ProcessWinMME(UINT message, DWORD param1, DWORD param2);

void
WriteError(const char *jack_func, const char *mm_func,
MMRESULT result);

char alias[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE];
char name[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE];

HMIDIIN handle;
jack_midi_event_t *jack_event;
jack_midi_data_t *sysex_buffer;
@@ -61,6 +53,13 @@ namespace Jack {

bool started;

void
WriteOSError(const char *jack_func, const char *os_func);

void
WriteInError(const char *jack_func, const char *mm_func,
MMRESULT result);

public:

JackWinMMEInputPort(const char *alias_name, const char *client_name,
@@ -69,12 +68,6 @@ namespace Jack {

~JackWinMMEInputPort();

const char *
GetAlias();

const char *
GetName();

void
ProcessJack(JackMidiBuffer *port_buffer, jack_nframes_t frames);



+ 18
- 49
windows/winmme/JackWinMMEOutputPort.cpp View File

@@ -58,7 +58,7 @@ JackWinMMEOutputPort::JackWinMMEOutputPort(const char *alias_name,
MMRESULT result = midiOutOpen(&handle, index, (DWORD)HandleMessageEvent,
(DWORD)this, CALLBACK_FUNCTION);
if (result != MMSYSERR_NOERROR) {
GetMMErrorString(result, error_message);
GetOutErrorString(result, error_message);
goto raise_exception;
}
thread_queue_semaphore = CreateSemaphore(NULL, 0, max_messages, NULL);
@@ -75,7 +75,7 @@ JackWinMMEOutputPort::JackWinMMEOutputPort(const char *alias_name,
char *name_tmp;
result = midiOutGetDevCaps(index, &capabilities, sizeof(capabilities));
if (result != MMSYSERR_NOERROR) {
WriteMMError("JackWinMMEOutputPort [constructor]", "midiOutGetDevCaps",
WriteOutError("JackWinMMEOutputPort [constructor]", "midiOutGetDevCaps",
result);
name_tmp = driver_name;
} else {
@@ -95,7 +95,7 @@ JackWinMMEOutputPort::JackWinMMEOutputPort(const char *alias_name,
close_handle:
result = midiOutClose(handle);
if (result != MMSYSERR_NOERROR) {
WriteMMError("JackWinMMEOutputPort [constructor]", "midiOutClose",
WriteOutError("JackWinMMEOutputPort [constructor]", "midiOutClose",
result);
}
raise_exception:
@@ -107,12 +107,12 @@ JackWinMMEOutputPort::~JackWinMMEOutputPort()
Stop();
MMRESULT result = midiOutReset(handle);
if (result != MMSYSERR_NOERROR) {
WriteMMError("JackWinMMEOutputPort [destructor]", "midiOutReset",
WriteOutError("JackWinMMEOutputPort [destructor]", "midiOutReset",
result);
}
result = midiOutClose(handle);
if (result != MMSYSERR_NOERROR) {
WriteMMError("JackWinMMEOutputPort [destructor]", "midiOutClose",
WriteOutError("JackWinMMEOutputPort [destructor]", "midiOutClose",
result);
}
if (! CloseHandle(sysex_semaphore)) {
@@ -179,7 +179,7 @@ JackWinMMEOutputPort::Execute()
message |= (DWORD) data[0];
result = midiOutShortMsg(handle, message);
if (result != MMSYSERR_NOERROR) {
WriteMMError("JackWinMMEOutputPort::Execute",
WriteOutError("JackWinMMEOutputPort::Execute",
"midiOutShortMsg", result);
}
continue;
@@ -193,13 +193,13 @@ JackWinMMEOutputPort::Execute()
header.lpData = (LPSTR)data;
result = midiOutPrepareHeader(handle, &header, sizeof(MIDIHDR));
if (result != MMSYSERR_NOERROR) {
WriteMMError("JackWinMMEOutputPort::Execute",
WriteOutError("JackWinMMEOutputPort::Execute",
"midiOutPrepareHeader", result);
continue;
}
result = midiOutLongMsg(handle, &header, sizeof(MIDIHDR));
if (result != MMSYSERR_NOERROR) {
WriteMMError("JackWinMMEOutputPort::Execute", "midiOutLongMsg",
WriteOutError("JackWinMMEOutputPort::Execute", "midiOutLongMsg",
result);
continue;
}
@@ -213,7 +213,7 @@ JackWinMMEOutputPort::Execute()

result = midiOutUnprepareHeader(handle, &header, sizeof(MIDIHDR));
if (result != MMSYSERR_NOERROR) {
WriteMMError("JackWinMMEOutputPort::Execute",
WriteOutError("JackWinMMEOutputPort::Execute",
"midiOutUnprepareHeader", result);
break;
}
@@ -223,38 +223,6 @@ JackWinMMEOutputPort::Execute()
return false;
}

const char *
JackWinMMEOutputPort::GetAlias()
{
return alias;
}

void
JackWinMMEOutputPort::GetMMErrorString(MMRESULT error, LPTSTR text)
{
MMRESULT result = midiOutGetErrorText(error, text, MAXERRORLENGTH);
if (result != MMSYSERR_NOERROR) {
snprintf(text, MAXERRORLENGTH, "Unknown MM error code '%d'", error);
}
}

const char *
JackWinMMEOutputPort::GetName()
{
return name;
}

void
JackWinMMEOutputPort::GetOSErrorString(LPTSTR text)
{
DWORD error = GetLastError();
if (! FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), text,
MAXERRORLENGTH, NULL)) {
snprintf(text, MAXERRORLENGTH, "Unknown OS error code '%d'", error);
}
}

void
JackWinMMEOutputPort::HandleMessage(UINT message, DWORD_PTR param1,
DWORD_PTR param2)
@@ -388,18 +356,19 @@ JackWinMMEOutputPort::Wait(HANDLE semaphore)
}

void
JackWinMMEOutputPort::WriteMMError(const char *jack_func, const char *mm_func,
MMRESULT result)
JackWinMMEOutputPort::GetOutErrorString(MMRESULT error, LPTSTR text)
{
char error_message[MAXERRORLENGTH];
GetMMErrorString(result, error_message);
jack_error("%s - %s: %s", jack_func, mm_func, error_message);
MMRESULT result = midiOutGetErrorText(error, text, MAXERRORLENGTH);
if (result != MMSYSERR_NOERROR) {
snprintf(text, MAXERRORLENGTH, "Unknown MM error code '%d'", error);
}
}

void
JackWinMMEOutputPort::WriteOSError(const char *jack_func, const char *os_func)
JackWinMMEOutputPort::WriteOutError(const char *jack_func, const char *mm_func,
MMRESULT result)
{
char error_message[MAXERRORLENGTH];
GetOSErrorString(error_message);
jack_error("%s - %s: %s", jack_func, os_func, error_message);
GetMMErrorString(result, error_message);
jack_error("%s - %s: %s", jack_func, mm_func, error_message);
}

+ 7
- 24
windows/winmme/JackWinMMEOutputPort.h View File

@@ -29,7 +29,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

namespace Jack {

class JackWinMMEOutputPort: public JackRunnableInterface {
class JackWinMMEOutputPort :
public JackWinMMEPort, public JackRunnableInterface {

private:

@@ -37,12 +38,6 @@ namespace Jack {
HandleMessageEvent(HMIDIOUT handle, UINT message, DWORD_PTR port,
DWORD_PTR param1, DWORD_PTR param2);

void
GetMMErrorString(MMRESULT error, LPTSTR text);

void
GetOSErrorString(LPTSTR text);

void
HandleMessage(UINT message, DWORD_PTR param1, DWORD_PTR param2);

@@ -52,16 +47,6 @@ namespace Jack {
bool
Wait(HANDLE semaphore);

void
WriteMMError(const char *jack_func, const char *mm_func,
MMRESULT result);

void
WriteOSError(const char *jack_func, const char *os_func);

char alias[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE];
char name[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE];

HMIDIOUT handle;
JackMidiBufferReadQueue *read_queue;
HANDLE sysex_semaphore;
@@ -70,7 +55,11 @@ namespace Jack {
HANDLE thread_queue_semaphore;

void
GetErrorString(MMRESULT error, LPTSTR text);
GetOutErrorString(MMRESULT error, LPTSTR text);

void
WriteOutError(const char *jack_func, const char *mm_func,
MMRESULT result);

public:

@@ -95,12 +84,6 @@ namespace Jack {
bool
Stop();

const char *
GetAlias();

const char *
GetName();

};

}


+ 69
- 0
windows/winmme/JackWinMMEPort.cpp View File

@@ -0,0 +1,69 @@
/*
Copyright (C) 2011 Devin Anderson

This program is free software; you can redistribute it and/or modify
it 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.

This program 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 this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/

#include <memory>
#include <stdexcept>

#include "JackWinMMEPort.h"

using Jack::JackWinMMEPort;

///////////////////////////////////////////////////////////////////////////////
// Class
///////////////////////////////////////////////////////////////////////////////

JackWinMMEPort::JackWinMMEPort(const char *alias_name,
const char *client_name,
const char *driver_name)
{}

JackWinMMEPort::~JackWinMMEPort()
{}

const JackWinMMEPort *
JackWinMMEOutputPort::GetAlias()
{
return alias;
}

const char *
JackWinMMEPort::GetName()
{
return name;
}

void
JackWinMMEPort::GetOSErrorString(LPTSTR text)
{
DWORD error = GetLastError();
if (! FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), text,
MAXERRORLENGTH, NULL)) {
snprintf(text, MAXERRORLENGTH, "Unknown OS error code '%d'", error);
}
}

void
JackWinMMEPort::WriteOSError(const char *jack_func, const char *os_func)
{
char error_message[MAXERRORLENGTH];
GetOSErrorString(error_message);
jack_error("%s - %s: %s", jack_func, os_func, error_message);
}


+ 58
- 0
windows/winmme/JackWinMMEPort.h View File

@@ -0,0 +1,58 @@
/*
Copyright (C) 2011 Devin Anderson

This program is free software; you can redistribute it and/or modify
it 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.

This program 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 this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/

#ifndef __JackWinMMEPort__
#define __JackWinMMEPort__

#include <mmsystem.h>
#include <windows.h>

namespace Jack {

class JackWinMMEPort {

protected:

char alias[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE];
char name[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE];

public:

JackWinMMEPort(const char *alias_name, const char *client_name,
const char *driver_name);

~JackWinMMEPort();

const char *
GetAlias();

const char *
GetName();

void
GetOSErrorString(LPTSTR text);

void
GetInErrorString(MMRESULT error, LPTSTR text);

};

}

#endif

Loading…
Cancel
Save