diff options
author | Goran Mekić <meka@tilda.center> | 2017-12-29 23:36:55 +0100 |
---|---|---|
committer | Goran Mekić <meka@tilda.center> | 2017-12-30 15:18:26 +0100 |
commit | a6343737453b34335a7a5494c8ac6b393d15604c (patch) | |
tree | 73fb775a93302909e269205d443516e51359309c /drumgizmo/input/ossmidi.cc | |
parent | 476a82d1c431c26f71286a2d904144bfa5468101 (diff) |
Open midi device in non-blocking mode
Diffstat (limited to 'drumgizmo/input/ossmidi.cc')
-rw-r--r-- | drumgizmo/input/ossmidi.cc | 45 |
1 files changed, 43 insertions, 2 deletions
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 <sys/soundcard.h> +#include <fcntl.h> +#include <stdlib.h> +#include <unistd.h> #include <iostream> 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<event_t>& 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; } - |