Add function PBD::sys::copy_file intended to replace PBD::copy_file
[ardour.git] / libs / midi++2 / midiport.cc
1 /*
2     Copyright (C) 1998 Paul Barton-Davis
3     
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18     $Id$
19 */
20
21 #include <cstdio>
22 #include <fcntl.h>
23
24 #include <midi++/types.h>
25 #include <midi++/port.h>
26 #include <midi++/channel.h>
27 #include <midi++/port_request.h>
28
29 using namespace Select;
30 using namespace MIDI;
31
32 size_t Port::nports = 0;
33
34 Port::Port (PortRequest &req)
35         : _currently_in_cycle(false)
36         , _nframes_this_cycle(0)
37 {
38         _ok = false;  /* derived class must set to true if constructor
39                          succeeds.
40                       */
41
42         bytes_written = 0;
43         bytes_read = 0;
44         input_parser = 0;
45         output_parser = 0;
46         slowdown = 0;
47
48         _devname = req.devname;
49         _tagname = req.tagname;
50         _mode = req.mode;
51         _number = nports++;
52
53         if (_mode == O_RDONLY || _mode == O_RDWR) {
54                 input_parser = new Parser (*this);
55         } else {
56                 input_parser = 0;
57         }
58
59         if (_mode == O_WRONLY || _mode == O_RDWR) {
60                 output_parser = new Parser (*this);
61         } else {
62                 output_parser = 0;
63         }
64
65         for (int i = 0; i < 16; i++) {
66                 _channel[i] =  new Channel (i, *this);
67
68                 if (input_parser) {
69                         _channel[i]->connect_input_signals ();
70                 }
71
72                 if (output_parser) {
73                         _channel[i]->connect_output_signals ();
74                 }
75         }
76 }
77
78
79 Port::~Port ()
80         
81 {
82         for (int i = 0; i < 16; i++) {
83                 delete _channel[i];
84         }
85 }
86
87 /** Send a clock tick message.
88  * \return true on success.
89  */
90 bool
91 Port::clock (timestamp_t timestamp)
92 {
93         static byte clockmsg = 0xf8;
94         
95         if (_mode != O_RDONLY) {
96                 return midimsg (&clockmsg, 1, timestamp);
97         }
98         
99         return false;
100 }
101
102 void
103 Port::cycle_start (nframes_t nframes)
104 {
105         _currently_in_cycle = true;
106         _nframes_this_cycle = nframes;
107 }
108
109 void
110 Port::cycle_end ()
111 {
112         _currently_in_cycle = false;
113         _nframes_this_cycle = 0;
114 }
115