Coding style cleanup. Hope I got it right...
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33265 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -8,28 +8,30 @@
|
|||||||
* Philippe Houdoin
|
* Philippe Houdoin
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "debug.h"
|
||||||
#include "DeviceWatcher.h"
|
#include "DeviceWatcher.h"
|
||||||
#include "PortDrivers.h"
|
#include "PortDrivers.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <new>
|
||||||
|
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
#include <Bitmap.h>
|
#include <Bitmap.h>
|
||||||
#include <Directory.h>
|
#include <Directory.h>
|
||||||
#include <Entry.h>
|
#include <Entry.h>
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
|
#include <PathMonitor.h>
|
||||||
#include <Resources.h>
|
#include <Resources.h>
|
||||||
#include <Roster.h>
|
#include <Roster.h>
|
||||||
#include <PathMonitor.h>
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <new>
|
|
||||||
using std::nothrow;
|
using std::nothrow;
|
||||||
|
|
||||||
using namespace BPrivate;
|
using namespace BPrivate;
|
||||||
using BPrivate::HashMap;
|
using BPrivate::HashMap;
|
||||||
using BPrivate::HashString;
|
using BPrivate::HashString;
|
||||||
|
|
||||||
|
|
||||||
const char *kDevicesRoot = "/dev/midi";
|
const char *kDevicesRoot = "/dev/midi";
|
||||||
// const char *kDevicesRoot = "/Data/tmp";
|
// const char *kDevicesRoot = "/Data/tmp";
|
||||||
|
|
||||||
@@ -42,8 +44,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
int fFD;
|
int fFD;
|
||||||
MidiPortConsumer* fConsumer;
|
MidiPortConsumer* fConsumer;
|
||||||
MidiPortProducer* fProducer;
|
MidiPortProducer* fProducer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -150,7 +152,7 @@ DeviceWatcher::MessageReceived(BMessage* message)
|
|||||||
int32
|
int32
|
||||||
DeviceWatcher::_InitialDevicesScanThread(void* data)
|
DeviceWatcher::_InitialDevicesScanThread(void* data)
|
||||||
{
|
{
|
||||||
((DeviceWatcher*) data)->_ScanDevices(kDevicesRoot);
|
((DeviceWatcher*)data)->_ScanDevices(kDevicesRoot);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,7 +160,7 @@ DeviceWatcher::_InitialDevicesScanThread(void* data)
|
|||||||
void
|
void
|
||||||
DeviceWatcher::_ScanDevices(const char* path)
|
DeviceWatcher::_ScanDevices(const char* path)
|
||||||
{
|
{
|
||||||
// printf("DeviceWatcher::_ScanDevices(\"%s\");\n", path);
|
TRACE(("DeviceWatcher::_ScanDevices(\"%s\");\n", path));
|
||||||
|
|
||||||
BDirectory dir(path);
|
BDirectory dir(path);
|
||||||
if (dir.InitCheck() != B_OK)
|
if (dir.InitCheck() != B_OK)
|
||||||
@@ -179,11 +181,12 @@ DeviceWatcher::_ScanDevices(const char* path)
|
|||||||
void
|
void
|
||||||
DeviceWatcher::_AddDevice(const char* path)
|
DeviceWatcher::_AddDevice(const char* path)
|
||||||
{
|
{
|
||||||
// printf("DeviceWatcher::_AddDevice(\"%s\");\n", path);
|
TRACE(("DeviceWatcher::_AddDevice(\"%s\");\n", path));
|
||||||
|
|
||||||
if ( fDeviceEndpointsMap.ContainsKey(path) )
|
if (fDeviceEndpointsMap.ContainsKey(path)) {
|
||||||
// Already known
|
// Already known
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
BEntry entry(path);
|
BEntry entry(path);
|
||||||
if (entry.IsDirectory())
|
if (entry.IsDirectory())
|
||||||
@@ -192,9 +195,10 @@ DeviceWatcher::_AddDevice(const char* path)
|
|||||||
|
|
||||||
if (entry.IsSymLink()) {
|
if (entry.IsSymLink()) {
|
||||||
BEntry symlink(path, true);
|
BEntry symlink(path, true);
|
||||||
if (symlink.IsDirectory())
|
if (symlink.IsDirectory()) {
|
||||||
// Invalid path!
|
// Invalid path!
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int fd = open(path, O_RDWR | O_EXCL);
|
int fd = open(path, O_RDWR | O_EXCL);
|
||||||
@@ -203,15 +207,15 @@ DeviceWatcher::_AddDevice(const char* path)
|
|||||||
|
|
||||||
MidiPortConsumer* consumer = new MidiPortConsumer(fd, path);
|
MidiPortConsumer* consumer = new MidiPortConsumer(fd, path);
|
||||||
_SetIcons(consumer);
|
_SetIcons(consumer);
|
||||||
// printf("Register %s MidiPortConsumer\n", consumer->Name());
|
TRACE(("Register %s MidiPortConsumer\n", consumer->Name()));
|
||||||
consumer->Register();
|
consumer->Register();
|
||||||
|
|
||||||
MidiPortProducer* producer = new MidiPortProducer(fd, path);
|
MidiPortProducer* producer = new MidiPortProducer(fd, path);
|
||||||
_SetIcons(producer);
|
_SetIcons(producer);
|
||||||
// printf("Register %s MidiPortProducer\n", producer->Name());
|
TRACE(("Register %s MidiPortProducer\n", producer->Name()));
|
||||||
producer->Register();
|
producer->Register();
|
||||||
|
|
||||||
DeviceEndpoints * deviceEndpoints = new DeviceEndpoints(fd, consumer, producer);
|
DeviceEndpoints* deviceEndpoints = new DeviceEndpoints(fd, consumer, producer);
|
||||||
fDeviceEndpointsMap.Put(path, deviceEndpoints);
|
fDeviceEndpointsMap.Put(path, deviceEndpoints);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,9 +223,9 @@ DeviceWatcher::_AddDevice(const char* path)
|
|||||||
void
|
void
|
||||||
DeviceWatcher::_RemoveDevice(const char* path)
|
DeviceWatcher::_RemoveDevice(const char* path)
|
||||||
{
|
{
|
||||||
// printf("DeviceWatcher::_RemoveDevice(\"%s\");\n", path);
|
TRACE(("DeviceWatcher::_RemoveDevice(\"%s\");\n", path));
|
||||||
|
|
||||||
DeviceEndpoints * deviceEndpoints = fDeviceEndpointsMap.Get(path);
|
DeviceEndpoints* deviceEndpoints = fDeviceEndpointsMap.Get(path);
|
||||||
if (!deviceEndpoints)
|
if (!deviceEndpoints)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -9,19 +9,19 @@
|
|||||||
* Philippe Houdoin
|
* Philippe Houdoin
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "PortDrivers.h"
|
|
||||||
|
|
||||||
#include <String.h>
|
#include "PortDrivers.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <String.h>
|
||||||
|
|
||||||
MidiPortConsumer::MidiPortConsumer(int fd, const char* name)
|
MidiPortConsumer::MidiPortConsumer(int fd, const char* name)
|
||||||
: BMidiLocalConsumer(name)
|
: BMidiLocalConsumer(name),
|
||||||
|
fFileDescriptor(fd)
|
||||||
{
|
{
|
||||||
fFileDescriptor = fd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -41,11 +41,10 @@ MidiPortConsumer::Data(uchar* data, size_t length,
|
|||||||
|
|
||||||
|
|
||||||
MidiPortProducer::MidiPortProducer(int fd, const char *name)
|
MidiPortProducer::MidiPortProducer(int fd, const char *name)
|
||||||
: BMidiLocalProducer(name)
|
: BMidiLocalProducer(name),
|
||||||
{
|
fFileDescriptor(fd), fKeepRunning(true)
|
||||||
fFileDescriptor = fd;
|
|
||||||
fKeepRunning = true;
|
|
||||||
|
|
||||||
|
{
|
||||||
BString tmp = name;
|
BString tmp = name;
|
||||||
tmp << " reader";
|
tmp << " reader";
|
||||||
|
|
||||||
@@ -89,20 +88,16 @@ MidiPortProducer::GetData()
|
|||||||
|
|
||||||
uint8 next = 0;
|
uint8 next = 0;
|
||||||
|
|
||||||
while (fKeepRunning)
|
while (fKeepRunning) {
|
||||||
{
|
if (read(fFileDescriptor, &next, 1) != 1) {
|
||||||
if (read(fFileDescriptor, &next, 1) != 1)
|
|
||||||
{
|
|
||||||
perror("Error reading data from driver");
|
perror("Error reading data from driver");
|
||||||
if (haveSysEx)
|
break;
|
||||||
{
|
|
||||||
free(sysexBuf);
|
|
||||||
}
|
|
||||||
return B_ERROR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (haveSysEx) { // System Exclusive mode
|
if (haveSysEx) {
|
||||||
if (next < 0x80) { // System Exclusive data byte
|
// System Exclusive mode
|
||||||
|
if (next < 0x80) {
|
||||||
|
// System Exclusive data byte
|
||||||
sysexBuf[sysexSize++] = next;
|
sysexBuf[sysexSize++] = next;
|
||||||
if (sysexSize == sysexAlloc) {
|
if (sysexSize == sysexAlloc) {
|
||||||
sysexAlloc *= 2;
|
sysexAlloc *= 2;
|
||||||
@@ -110,31 +105,31 @@ MidiPortProducer::GetData()
|
|||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
} else if ((next & 0xF8) == 0xF8) {
|
} else if ((next & 0xF8) == 0xF8) {
|
||||||
// System Realtime interleaved in System Exclusive byte(s)
|
// System Realtime interleaved in System Exclusive sequence
|
||||||
SpraySystemRealTime(next);
|
SpraySystemRealTime(next);
|
||||||
continue;
|
continue;
|
||||||
} else { // whatever byte, this one ends the running SysEx sequence
|
} else {
|
||||||
|
// Whatever byte, this one ends the running SysEx sequence
|
||||||
SpraySystemExclusive(sysexBuf, sysexSize);
|
SpraySystemExclusive(sysexBuf, sysexSize);
|
||||||
haveSysEx = false;
|
haveSysEx = false;
|
||||||
if (next == B_SYS_EX_END)
|
if (next == B_SYS_EX_END) {
|
||||||
// swallow SysEx end byte
|
// swallow SysEx end byte
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
// any other byte, while ending the SysEx sequence,
|
// any other byte, while ending the SysEx sequence,
|
||||||
// should be handled, not dropped
|
// should be handled, not dropped
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((next & 0xF8) == 0xF8) // System Realtime
|
if ((next & 0xF8) == 0xF8) {
|
||||||
{
|
// System Realtime
|
||||||
SpraySystemRealTime(next);
|
SpraySystemRealTime(next);
|
||||||
}
|
} else if ((next & 0xF0) == 0xF0) {
|
||||||
else if ((next & 0xF0) == 0xF0) // System Common
|
// System Common
|
||||||
{
|
|
||||||
runningStatus = 0;
|
runningStatus = 0;
|
||||||
msgBuf[0] = next;
|
msgBuf[0] = next;
|
||||||
msgPtr = msgBuf + 1;
|
msgPtr = msgBuf + 1;
|
||||||
switch (next)
|
switch (next) {
|
||||||
{
|
|
||||||
case B_SYS_EX_START:
|
case B_SYS_EX_START:
|
||||||
sysexAlloc = 4096;
|
sysexAlloc = 4096;
|
||||||
sysexBuf = (uint8*) malloc(sysexAlloc);
|
sysexBuf = (uint8*) malloc(sysexAlloc);
|
||||||
@@ -154,19 +149,18 @@ MidiPortProducer::GetData()
|
|||||||
msgSize = 2;
|
msgSize = 2;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case B_SYS_EX_END:
|
||||||
|
// Unpaired with B_SYS_EX_START, but pass it anyway...
|
||||||
case B_TUNE_REQUEST:
|
case B_TUNE_REQUEST:
|
||||||
case B_SYS_EX_END: // Unpaired with B_SYS_EX_START, but pass it anyway...
|
|
||||||
SpraySystemCommon(next, 0, 0);
|
SpraySystemCommon(next, 0, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
} else if ((next & 0x80) == 0x80) {
|
||||||
else if ((next & 0x80) == 0x80) // Voice message
|
// Voice message
|
||||||
{
|
|
||||||
runningStatus = next;
|
runningStatus = next;
|
||||||
msgBuf[0] = next;
|
msgBuf[0] = next;
|
||||||
msgPtr = msgBuf + 1;
|
msgPtr = msgBuf + 1;
|
||||||
switch (next & 0xF0)
|
switch (next & 0xF0) {
|
||||||
{
|
|
||||||
case B_NOTE_OFF:
|
case B_NOTE_OFF:
|
||||||
case B_NOTE_ON:
|
case B_NOTE_ON:
|
||||||
case B_KEY_PRESSURE:
|
case B_KEY_PRESSURE:
|
||||||
@@ -182,14 +176,11 @@ MidiPortProducer::GetData()
|
|||||||
msgSize = 2;
|
msgSize = 2;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
} else if (needed > 0) {
|
||||||
else if (needed > 0) // Data bytes to complete message
|
// Data bytes to complete message
|
||||||
{
|
|
||||||
*msgPtr++ = next;
|
*msgPtr++ = next;
|
||||||
if (--needed == 0)
|
if (--needed == 0) {
|
||||||
{
|
switch (msgBuf[0] & 0xF0) {
|
||||||
switch (msgBuf[0] & 0xF0)
|
|
||||||
{
|
|
||||||
case B_NOTE_OFF:
|
case B_NOTE_OFF:
|
||||||
SprayNoteOff(msgBuf[0] & 0x0F, msgBuf[1], msgBuf[2]);
|
SprayNoteOff(msgBuf[0] & 0x0F, msgBuf[1], msgBuf[2]);
|
||||||
break;
|
break;
|
||||||
@@ -219,8 +210,7 @@ MidiPortProducer::GetData()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (msgBuf[0])
|
switch (msgBuf[0]) {
|
||||||
{
|
|
||||||
case B_SONG_POSITION:
|
case B_SONG_POSITION:
|
||||||
SpraySystemCommon(msgBuf[0], msgBuf[1], msgBuf[2]);
|
SpraySystemCommon(msgBuf[0], msgBuf[1], msgBuf[2]);
|
||||||
break;
|
break;
|
||||||
@@ -232,22 +222,17 @@ MidiPortProducer::GetData()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if (runningStatus != 0) {
|
||||||
else if (runningStatus != 0) // Repeated voice command
|
// Repeated voice command
|
||||||
{
|
|
||||||
msgBuf[0] = runningStatus;
|
msgBuf[0] = runningStatus;
|
||||||
msgBuf[1] = next;
|
msgBuf[1] = next;
|
||||||
msgPtr = msgBuf + 2;
|
msgPtr = msgBuf + 2;
|
||||||
needed = msgSize - 2;
|
needed = msgSize - 2;
|
||||||
}
|
}
|
||||||
}
|
} // while fKeepRunning
|
||||||
|
|
||||||
if (haveSysEx)
|
if (haveSysEx)
|
||||||
{
|
|
||||||
free(sysexBuf);
|
free(sysexBuf);
|
||||||
}
|
|
||||||
|
|
||||||
return B_OK;
|
return fKeepRunning ? B_ERROR : B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|||||||
@@ -10,13 +10,13 @@
|
|||||||
#ifndef PORT_DRIVERS_H
|
#ifndef PORT_DRIVERS_H
|
||||||
#define PORT_DRIVERS_H
|
#define PORT_DRIVERS_H
|
||||||
|
|
||||||
|
|
||||||
#include <MidiProducer.h>
|
#include <MidiProducer.h>
|
||||||
#include <MidiConsumer.h>
|
#include <MidiConsumer.h>
|
||||||
|
|
||||||
class MidiPortConsumer : public BMidiLocalConsumer
|
class MidiPortConsumer : public BMidiLocalConsumer {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
MidiPortConsumer(int fd, const char* path);
|
MidiPortConsumer(int fd, const char* path);
|
||||||
|
|
||||||
void Data(uchar* data, size_t length, bool atomic, bigtime_t time);
|
void Data(uchar* data, size_t length, bool atomic, bigtime_t time);
|
||||||
|
|
||||||
@@ -25,11 +25,10 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class MidiPortProducer : public BMidiLocalProducer
|
class MidiPortProducer : public BMidiLocalProducer {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
MidiPortProducer(int fd, const char* path = NULL);
|
MidiPortProducer(int fd, const char* path = NULL);
|
||||||
~MidiPortProducer(void);
|
virtual ~MidiPortProducer(void);
|
||||||
|
|
||||||
int32 GetData(void);
|
int32 GetData(void);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user