unecessary changes. (Sorry, doing a "sprint" based thing, this is the end of the first one) Achieved MIDI track and bus creation, associated Jack port and diskstream creation, and minimal GUI stuff for creating them. Should be set to start work on actually recording and playing midi to/from disk now. Relevant (significant) changes: - Creation of a Buffer class. Base class is type agnostic so things can point to a buffer but not care what kind it is (otherwise it'd be a template). Derived into AudioBuffer and MidiBuffer, with a type tag because checking type is necessary in parts of the code where dynamic_cast wouldn't be wise. Originally I considered this a hack, but passing around a type proved to be a very good solution to all the other problems (below). There is a 1:1 mapping between jack port data types and ardour Buffer types (with a conversion function), but that's easily removed if it ever becomes necessary. Having the type scoped in the Buffer class is maybe not the best spot for it, but whatever (this is proof of concept kinda stuff right now...) - IO now has a "default" port type (passed to the constructor and stored as a member), used by ensure_io (and similar) to create n ports. IO::register_***_port has a type argument that defaults to the default type if not passed. Rationale: previous IO API is identical, no changes needed to existing code, but path is paved for multiple port types in one IO, which we will need for eg synth plugin inserts, among other things. This is not quite ideal (best would be to only have the two port register functions and have them take a type), but the alternative is a lot of work (namely destroying the 'ensure' functions and everything that uses them) for very little gain. (I am convinced after quite a few tries at the whiteboard that subclassing IO in any way is not a feasible option, look at it's inheritance diagram in Doxygen and you can see why) - AudioEngine::register_audio_input_port is now register_input_port and takes a type argument. Ditto for output. - (Most significant change) AudioDiskstream abstracted into Distream, and sibling MidiDiskstream created. Very much still a work in progress, but Diskstream is there to switch references over to (most already are), which is the important part. It is still unclear what the MIDI diskstream's relation to channels is, but I'm pretty sure they will be single channel only (so SMF Type 0) since noone can come up with a reason otherwise. - MidiTrack creation. Same thing as AudioTrack but with a different default type basically. No big deal here. - Random cleanups and variable renamings etc. because I have OCD and can't help myself. :) Known broken: Loading of sessions containing MIDI tracks. git-svn-id: svn://localhost/ardour2/branches/midi@641 d708f5d6-7413-0410-9779-e7cbd77b26cf
183 lines
3.8 KiB
C++
183 lines
3.8 KiB
C++
/*
|
|
Copyright (C) 1999 Paul Barton-Davis
|
|
|
|
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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
$Id$
|
|
*/
|
|
|
|
#include <fcntl.h>
|
|
#include <cerrno>
|
|
|
|
#include <pbd/error.h>
|
|
#include <pbd/pathscanner.h>
|
|
|
|
#include <midi++/types.h>
|
|
#include <midi++/fd_midiport.h>
|
|
|
|
using namespace std;
|
|
using namespace MIDI;
|
|
using namespace PBD;
|
|
|
|
string *FD_MidiPort::midi_dirpath = 0;
|
|
string *FD_MidiPort::midi_filename_pattern = 0;
|
|
|
|
FD_MidiPort::FD_MidiPort (PortRequest &req,
|
|
const string &dirpath,
|
|
const string &pattern)
|
|
: Port (req)
|
|
{
|
|
open (req);
|
|
|
|
if (_fd < 0) {
|
|
switch (errno) {
|
|
case EBUSY:
|
|
error << "MIDI: port device in use" << endmsg;
|
|
req.status = PortRequest::Busy;
|
|
break;
|
|
case ENOENT:
|
|
error << "MIDI: no such port device" << endmsg;
|
|
req.status = PortRequest::NoSuchFile;
|
|
break;
|
|
case EACCES:
|
|
error << "MIDI: access to port denied" << endmsg;
|
|
req.status = PortRequest::NotAllowed;
|
|
break;
|
|
default:
|
|
req.status = PortRequest::Unknown;
|
|
}
|
|
} else {
|
|
_ok = true;
|
|
req.status = PortRequest::OK;
|
|
|
|
if (midi_dirpath == 0) {
|
|
midi_dirpath = new string (dirpath);
|
|
midi_filename_pattern = new string (pattern);
|
|
}
|
|
|
|
if (req.mode & O_NONBLOCK == 0) {
|
|
/* we unconditionally set O_NONBLOCK during
|
|
open, but the request didn't ask for it,
|
|
so remove it.
|
|
*/
|
|
|
|
int flags = fcntl (_fd, F_GETFL, 0);
|
|
fcntl (_fd, F_SETFL, flags & ~(O_NONBLOCK));
|
|
}
|
|
}
|
|
}
|
|
|
|
void
|
|
FD_MidiPort::open (PortRequest &req)
|
|
|
|
{
|
|
int mode = req.mode | O_NONBLOCK;
|
|
_fd = ::open (req.devname, mode);
|
|
}
|
|
|
|
vector<string *> *
|
|
FD_MidiPort::list_devices ()
|
|
|
|
{
|
|
PathScanner scanner;
|
|
|
|
return scanner (*midi_dirpath, *midi_filename_pattern, false, true);
|
|
}
|
|
|
|
int
|
|
FD_MidiPort::selectable () const
|
|
|
|
{
|
|
long flags;
|
|
|
|
/* turn on non-blocking mode, since we plan to use select/poll
|
|
to tell us when there is data to read.
|
|
*/
|
|
|
|
flags = fcntl (_fd, F_GETFL);
|
|
flags |= O_NONBLOCK;
|
|
|
|
if (fcntl (_fd, F_SETFL, flags)) {
|
|
error << "FD_MidiPort: could not turn on non-blocking mode"
|
|
<< " (" << strerror (errno)
|
|
<< ')'
|
|
<< endmsg;
|
|
|
|
return -1;
|
|
}
|
|
|
|
return _fd;
|
|
}
|
|
|
|
|
|
int
|
|
FD_MidiPort::do_slow_write (byte *msg, unsigned int msglen)
|
|
|
|
{
|
|
size_t n;
|
|
size_t i;
|
|
|
|
for (n = 0; n < msglen; n++) {
|
|
|
|
if (::write (_fd, &msg[n], 1) != 1) {
|
|
break;
|
|
}
|
|
|
|
bytes_written++;
|
|
for (i = 0; i < slowdown * 10000; i++);
|
|
}
|
|
|
|
|
|
if (n && output_parser) {
|
|
output_parser->raw_preparse (*output_parser, msg, n);
|
|
for (unsigned int i = 0; i < n; i++) {
|
|
output_parser->scanner (msg[i]);
|
|
}
|
|
output_parser->raw_postparse (*output_parser, msg, n);
|
|
}
|
|
|
|
return n;
|
|
}
|
|
|
|
int
|
|
FD_MidiPort::read (byte* buf, size_t max, timestamp_t timestamp)
|
|
{
|
|
int nread;
|
|
|
|
if ((_mode & O_ACCMODE) == O_WRONLY) {
|
|
return -EACCES;
|
|
}
|
|
|
|
// cerr << "MIDI: read up to " << max << " from " << _fd << " (" << name() << ')' << endl;
|
|
|
|
if ((nread = ::read (_fd, buf, max)) > 0) {
|
|
bytes_read += nread;
|
|
|
|
// cerr << " read " << nread << endl;
|
|
|
|
if (input_parser) {
|
|
input_parser->raw_preparse
|
|
(*input_parser, buf, nread);
|
|
for (int i = 0; i < nread; i++) {
|
|
input_parser->scanner (buf[i]);
|
|
}
|
|
input_parser->raw_postparse
|
|
(*input_parser, buf, nread);
|
|
}
|
|
}
|
|
|
|
return nread;
|
|
}
|