1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
// ------------------------------------------------------------------------
// midiio.cpp: Routines common for all MIDI IO-devices.
// Copyright (C) 2000 Kai Vehmanen
//
// 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// ------------------------------------------------------------------------
#include <string>
#include <kvu_message_item.h>
#include "midiio.h"
#include "samplebuffer.h"
#include "eca-error.h"
#include "eca-logger.h"
// ===================================================================
// Attributes
/**
* Returns info about supported I/O modes (bitwise-OR)
*
* By default, all I/O modes are supported.
*/
int MIDI_IO::supported_io_modes(void) const { return(io_read | io_readwrite | io_write); }
/**
* Whether device supports non-blocking I/O mode.
*
* By default, nonblocking mode is not supported.
*/
bool MIDI_IO::supports_nonblocking_mode(void) const { return(false); }
// ===================================================================
// Configuration (setting and getting configuration parameters)
/**
* Returns info about the current I/O mode.
*/
int MIDI_IO::io_mode(void) const { return(io_mode_rep); }
/**
* Set object input/output-mode. If the requested mode isn't
* supported, the nearest supported mode is used. Because
* of this, it's wise to afterwards check whether the requested
* mode was accepted.
*
* require:
* is_open() != true
*/
void MIDI_IO::io_mode(int mode) { io_mode_rep = mode; }
/**
* Sets object label. Label is used to identify the object instance.
* Unlike ECA_OBJECT::name(), label() is not necessarily unique
* among different class instances. Device and file names are typical
* label values.
*
* require:
* is_open() != true
*/
void MIDI_IO::label(const std::string& id_label) { id_label_rep = id_label; }
/**
* Enable/disbale nonblocking mode.
*
* require:
* is_open() != true
*/
void MIDI_IO::toggle_nonblocking_mode(bool value) { nonblocking_rep = value; }
/**
* Returns the current label. See documentation for
* label(const std::string&).
*/
const std::string& MIDI_IO::label(void) const { return(id_label_rep); }
void MIDI_IO::set_parameter(int param,
std::string value) {
if (param == 1) label(value);
}
std::string MIDI_IO::get_parameter(int param) const {
if (param == 1) return(label());
return("");
}
// ===================================================================
// Runtime information
/**
* Is nonblocking mode is enabled?
*/
bool MIDI_IO::nonblocking_mode(void) const { return(nonblocking_rep); }
/**
* Is the MIDI object ready for reading?
*/
bool MIDI_IO::readable(void) const { return(is_open() && io_mode() != io_write); }
/**
* Is the MIDI object ready for writing?
*/
bool MIDI_IO::writable(void) const { return(is_open() && io_mode() != io_read); }
/**
* Sets device's state to enabled or disabled.
*/
void MIDI_IO::toggle_open_state(bool value) { open_rep = value; }
// ===================================================================
// Constructors and destructors
MIDI_IO::~MIDI_IO(void) { }
MIDI_IO::MIDI_IO(const std::string& name,
int mode) {
label(name);
io_mode(mode);
nonblocking_rep = false;
readable_rep = writable_rep = open_rep = false;
}
|