From a6343737453b34335a7a5494c8ac6b393d15604c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Goran=20Meki=C4=87?= Date: Fri, 29 Dec 2017 23:36:55 +0100 Subject: Open midi device in non-blocking mode --- drumgizmo/drumgizmoc.cc | 2 +- drumgizmo/enginefactory.cc | 6 +++--- drumgizmo/enginefactory.h | 5 +++++ drumgizmo/input/ossmidi.cc | 45 +++++++++++++++++++++++++++++++++++++++++++-- drumgizmo/input/ossmidi.h | 8 +++++--- 5 files changed, 57 insertions(+), 9 deletions(-) (limited to 'drumgizmo') diff --git a/drumgizmo/drumgizmoc.cc b/drumgizmo/drumgizmoc.cc index 8bfe2f4..6a2458b 100644 --- a/drumgizmo/drumgizmoc.cc +++ b/drumgizmo/drumgizmoc.cc @@ -103,7 +103,7 @@ static std::string usage(std::string name) output << " midifile: file=, speed= (default 1.0),\n"; output << " track= (default -1, all tracks)\n"; output << " midimap=, loop=\n"; - output << " ossmidi: midimap=, dev= (default '/dev/dsp')\n"; + output << " ossmidi: midimap=, dev= (default '/dev/midi')\n"; output << " test: p= (default 0.1)\n"; output << " instr= (default -1, random instrument)\n"; output << " len= (default -1, forever)\n"; diff --git a/drumgizmo/enginefactory.cc b/drumgizmo/enginefactory.cc index d54c3e2..c93607e 100644 --- a/drumgizmo/enginefactory.cc +++ b/drumgizmo/enginefactory.cc @@ -118,10 +118,10 @@ std::unique_ptr EngineFactory::createInput(const std::string& return std::make_unique(*jack); } #endif -#ifdef HAVE_INPUT_OSS - if(name == "oss") +#ifdef HAVE_INPUT_OSSMIDI + if(name == "ossmidi") { - return std::make_unique(); + return std::make_unique(); } #endif diff --git a/drumgizmo/enginefactory.h b/drumgizmo/enginefactory.h index 327c326..0b37c6e 100644 --- a/drumgizmo/enginefactory.h +++ b/drumgizmo/enginefactory.h @@ -78,6 +78,11 @@ #endif +#ifdef HAVE_INPUT_OSSMIDI +#include "input/ossmidi.h" +#endif + + //! Factory for various input- and output engines class EngineFactory { diff --git a/drumgizmo/input/ossmidi.cc b/drumgizmo/input/ossmidi.cc index 024415e..56d77f0 100644 --- a/drumgizmo/input/ossmidi.cc +++ b/drumgizmo/input/ossmidi.cc @@ -25,31 +25,55 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ #include "ossmidi.h" +#include +#include +#include +#include #include OSSInputEngine::OSSInputEngine() + : AudioInputEngineMidi{} + , dev{"/dev/midi"} { } + OSSInputEngine::~OSSInputEngine() { } + bool OSSInputEngine::init(const Instruments& instruments) { + if(!loadMidiMap(midimap_file, instruments)) + { + std::cerr << "[OSSInputEngine] Failed to parse midimap '" + << midimap_file << std::endl; + return false; + } + if ((fd = open(dev.data(), O_RDONLY | O_NONBLOCK, 0)) == -1) + { + std::cerr << dev.data() << ' ' << std::strerror(errno) << std::endl; + return false; + } return true; } + void OSSInputEngine::setParm(const std::string& parm, const std::string& value) { if(parm == "dev") { dev = value; - std::cout << "dev = " << dev << std::endl; + } + else if(parm == "midimap") + { + midimap_file = value; } } + bool OSSInputEngine::start() { return true; @@ -59,20 +83,37 @@ void OSSInputEngine::stop() { } + void OSSInputEngine::pre() { } + void OSSInputEngine::run(size_t pos, size_t len, std::vector& events) { + int l; + unsigned char buf[128]; + if ((l = read (fd, buf, sizeof (buf))) != -1) + { + for (int i = 0; i < l; i++) + { + if (buf[i] & 0x80) /* Status byte */ + { + std::cout << std::endl; + } + std::cout << buf[i]; + } + std::cout << std::flush; + } } + void OSSInputEngine::post() { } + bool OSSInputEngine::isFreewheeling() const { return false; } - diff --git a/drumgizmo/input/ossmidi.h b/drumgizmo/input/ossmidi.h index 41cfb2b..c6abacd 100644 --- a/drumgizmo/input/ossmidi.h +++ b/drumgizmo/input/ossmidi.h @@ -25,10 +25,11 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ #pragma once -#include +#include "audioinputenginemidi.h" + class OSSInputEngine - : public AudioInputEngine + : public AudioInputEngineMidi { public: OSSInputEngine(); @@ -45,8 +46,9 @@ public: bool isFreewheeling() const override; private: - std::string dev; int fd; + std::string dev; std::size_t pos; std::vector events; + std::string midimap_file; }; -- cgit v1.2.3