From ba4b45f76027d4d43689b9284dfafb58321e60df Mon Sep 17 00:00:00 2001 From: Philippe Houdoin Date: Thu, 24 Sep 2009 17:53:49 +0000 Subject: [PATCH] Coding style cleanup. Hope I got it right... git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33265 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/servers/midi/DeviceWatcher.cpp | 36 +++++++----- src/servers/midi/PortDrivers.cpp | 93 +++++++++++++----------------- src/servers/midi/PortDrivers.h | 13 ++--- 3 files changed, 65 insertions(+), 77 deletions(-) diff --git a/src/servers/midi/DeviceWatcher.cpp b/src/servers/midi/DeviceWatcher.cpp index 926ad4eb18..310d498e20 100644 --- a/src/servers/midi/DeviceWatcher.cpp +++ b/src/servers/midi/DeviceWatcher.cpp @@ -8,28 +8,30 @@ * Philippe Houdoin */ + +#include "debug.h" #include "DeviceWatcher.h" #include "PortDrivers.h" +#include +#include + #include #include #include #include #include #include +#include #include #include -#include -#include -#include using std::nothrow; using namespace BPrivate; using BPrivate::HashMap; using BPrivate::HashString; - const char *kDevicesRoot = "/dev/midi"; // const char *kDevicesRoot = "/Data/tmp"; @@ -42,8 +44,8 @@ public: } int fFD; - MidiPortConsumer* fConsumer; - MidiPortProducer* fProducer; + MidiPortConsumer* fConsumer; + MidiPortProducer* fProducer; }; @@ -150,7 +152,7 @@ DeviceWatcher::MessageReceived(BMessage* message) int32 DeviceWatcher::_InitialDevicesScanThread(void* data) { - ((DeviceWatcher*) data)->_ScanDevices(kDevicesRoot); + ((DeviceWatcher*)data)->_ScanDevices(kDevicesRoot); return 0; } @@ -158,7 +160,7 @@ DeviceWatcher::_InitialDevicesScanThread(void* data) void DeviceWatcher::_ScanDevices(const char* path) { - // printf("DeviceWatcher::_ScanDevices(\"%s\");\n", path); + TRACE(("DeviceWatcher::_ScanDevices(\"%s\");\n", path)); BDirectory dir(path); if (dir.InitCheck() != B_OK) @@ -179,11 +181,12 @@ DeviceWatcher::_ScanDevices(const char* path) void 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 return; + } BEntry entry(path); if (entry.IsDirectory()) @@ -192,9 +195,10 @@ DeviceWatcher::_AddDevice(const char* path) if (entry.IsSymLink()) { BEntry symlink(path, true); - if (symlink.IsDirectory()) + if (symlink.IsDirectory()) { // Invalid path! return; + } } int fd = open(path, O_RDWR | O_EXCL); @@ -203,15 +207,15 @@ DeviceWatcher::_AddDevice(const char* path) MidiPortConsumer* consumer = new MidiPortConsumer(fd, path); _SetIcons(consumer); - // printf("Register %s MidiPortConsumer\n", consumer->Name()); + TRACE(("Register %s MidiPortConsumer\n", consumer->Name())); consumer->Register(); MidiPortProducer* producer = new MidiPortProducer(fd, path); _SetIcons(producer); - // printf("Register %s MidiPortProducer\n", producer->Name()); + TRACE(("Register %s MidiPortProducer\n", producer->Name())); producer->Register(); - DeviceEndpoints * deviceEndpoints = new DeviceEndpoints(fd, consumer, producer); + DeviceEndpoints* deviceEndpoints = new DeviceEndpoints(fd, consumer, producer); fDeviceEndpointsMap.Put(path, deviceEndpoints); } @@ -219,9 +223,9 @@ DeviceWatcher::_AddDevice(const char* path) void 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) return; diff --git a/src/servers/midi/PortDrivers.cpp b/src/servers/midi/PortDrivers.cpp index c6a88d1e54..0ff18d3c0a 100644 --- a/src/servers/midi/PortDrivers.cpp +++ b/src/servers/midi/PortDrivers.cpp @@ -9,19 +9,19 @@ * Philippe Houdoin */ -#include "PortDrivers.h" -#include +#include "PortDrivers.h" #include #include #include +#include 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) - : BMidiLocalProducer(name) + : BMidiLocalProducer(name), + fFileDescriptor(fd), fKeepRunning(true) + { - fFileDescriptor = fd; - fKeepRunning = true; - BString tmp = name; tmp << " reader"; @@ -89,20 +88,16 @@ MidiPortProducer::GetData() uint8 next = 0; - while (fKeepRunning) - { - if (read(fFileDescriptor, &next, 1) != 1) - { + while (fKeepRunning) { + if (read(fFileDescriptor, &next, 1) != 1) { perror("Error reading data from driver"); - if (haveSysEx) - { - free(sysexBuf); - } - return B_ERROR; + break; } - if (haveSysEx) { // System Exclusive mode - if (next < 0x80) { // System Exclusive data byte + if (haveSysEx) { + // System Exclusive mode + if (next < 0x80) { + // System Exclusive data byte sysexBuf[sysexSize++] = next; if (sysexSize == sysexAlloc) { sysexAlloc *= 2; @@ -110,31 +105,31 @@ MidiPortProducer::GetData() } continue; } else if ((next & 0xF8) == 0xF8) { - // System Realtime interleaved in System Exclusive byte(s) + // System Realtime interleaved in System Exclusive sequence SpraySystemRealTime(next); continue; - } else { // whatever byte, this one ends the running SysEx sequence + } else { + // Whatever byte, this one ends the running SysEx sequence SpraySystemExclusive(sysexBuf, sysexSize); haveSysEx = false; - if (next == B_SYS_EX_END) + if (next == B_SYS_EX_END) { // swallow SysEx end byte - continue; + continue; + } // any other byte, while ending the SysEx sequence, // should be handled, not dropped } } - if ((next & 0xF8) == 0xF8) // System Realtime - { + if ((next & 0xF8) == 0xF8) { + // System Realtime SpraySystemRealTime(next); - } - else if ((next & 0xF0) == 0xF0) // System Common - { + } else if ((next & 0xF0) == 0xF0) { + // System Common runningStatus = 0; msgBuf[0] = next; msgPtr = msgBuf + 1; - switch (next) - { + switch (next) { case B_SYS_EX_START: sysexAlloc = 4096; sysexBuf = (uint8*) malloc(sysexAlloc); @@ -154,19 +149,18 @@ MidiPortProducer::GetData() msgSize = 2; break; + case B_SYS_EX_END: + // Unpaired with B_SYS_EX_START, but pass it anyway... case B_TUNE_REQUEST: - case B_SYS_EX_END: // Unpaired with B_SYS_EX_START, but pass it anyway... SpraySystemCommon(next, 0, 0); break; } - } - else if ((next & 0x80) == 0x80) // Voice message - { + } else if ((next & 0x80) == 0x80) { + // Voice message runningStatus = next; msgBuf[0] = next; msgPtr = msgBuf + 1; - switch (next & 0xF0) - { + switch (next & 0xF0) { case B_NOTE_OFF: case B_NOTE_ON: case B_KEY_PRESSURE: @@ -182,14 +176,11 @@ MidiPortProducer::GetData() msgSize = 2; break; } - } - else if (needed > 0) // Data bytes to complete message - { + } else if (needed > 0) { + // Data bytes to complete message *msgPtr++ = next; - if (--needed == 0) - { - switch (msgBuf[0] & 0xF0) - { + if (--needed == 0) { + switch (msgBuf[0] & 0xF0) { case B_NOTE_OFF: SprayNoteOff(msgBuf[0] & 0x0F, msgBuf[1], msgBuf[2]); break; @@ -219,8 +210,7 @@ MidiPortProducer::GetData() break; } - switch (msgBuf[0]) - { + switch (msgBuf[0]) { case B_SONG_POSITION: SpraySystemCommon(msgBuf[0], msgBuf[1], msgBuf[2]); break; @@ -232,22 +222,17 @@ MidiPortProducer::GetData() break; } } - } - else if (runningStatus != 0) // Repeated voice command - { + } else if (runningStatus != 0) { + // Repeated voice command msgBuf[0] = runningStatus; msgBuf[1] = next; msgPtr = msgBuf + 2; needed = msgSize - 2; } - } + } // while fKeepRunning if (haveSysEx) - { free(sysexBuf); - } - return B_OK; + return fKeepRunning ? B_ERROR : B_OK; } - -//------------------------------------------------------------------------------ diff --git a/src/servers/midi/PortDrivers.h b/src/servers/midi/PortDrivers.h index 949b231d46..1426f0031a 100644 --- a/src/servers/midi/PortDrivers.h +++ b/src/servers/midi/PortDrivers.h @@ -10,13 +10,13 @@ #ifndef PORT_DRIVERS_H #define PORT_DRIVERS_H + #include #include -class MidiPortConsumer : public BMidiLocalConsumer -{ +class MidiPortConsumer : public BMidiLocalConsumer { 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); @@ -25,11 +25,10 @@ private: }; -class MidiPortProducer : public BMidiLocalProducer -{ +class MidiPortProducer : public BMidiLocalProducer { public: - MidiPortProducer(int fd, const char* path = NULL); - ~MidiPortProducer(void); + MidiPortProducer(int fd, const char* path = NULL); + virtual ~MidiPortProducer(void); int32 GetData(void);