Merge branch 'export-dialog' into cairocanvas
[ardour.git] / libs / midi++2 / channel.cc
index bf71b0579c617760f61174f1f7c129984803e727..67d6f5fb11b44ff4b66786ee2c3581c926804233 100644 (file)
@@ -25,7 +25,8 @@
 
 using namespace MIDI;
 
-Channel::Channel (byte channelnum, Port &p) : _port (p)
+Channel::Channel (MIDI::byte channelnum, Port &p) 
+       : _port (p)
 {
        _channel_number = channelnum;
 
@@ -33,36 +34,21 @@ Channel::Channel (byte channelnum, Port &p) : _port (p)
 }      
 
 void
-Channel::connect_input_signals ()
+Channel::connect_signals ()
 {
-       _port.input()->channel_pressure[_channel_number].connect (*this, boost::bind (&Channel::process_chanpress, this, _1, _2));
-       _port.input()->channel_note_on[_channel_number].connect (*this, boost::bind (&Channel::process_note_on, this, _1, _2));
-       _port.input()->channel_note_off[_channel_number].connect (*this, boost::bind (&Channel::process_note_off, this, _1, _2));
-       _port.input()->channel_poly_pressure[_channel_number].connect (*this, boost::bind (&Channel::process_polypress, this, _1, _2));
-       _port.input()->channel_program_change[_channel_number].connect (*this, boost::bind (&Channel::process_program_change, this, _1, _2));
-       _port.input()->channel_controller[_channel_number].connect (*this, boost::bind (&Channel::process_controller, this, _1, _2));
-       _port.input()->channel_pitchbend[_channel_number].connect (*this, boost::bind (&Channel::process_pitchbend, this, _1, _2));
-
-       _port.input()->reset.connect (*this, boost::bind (&Channel::process_reset, this, _1));
+       _port.parser()->channel_pressure[_channel_number].connect_same_thread (*this, boost::bind (&Channel::process_chanpress, this, _1, _2));
+       _port.parser()->channel_note_on[_channel_number].connect_same_thread (*this, boost::bind (&Channel::process_note_on, this, _1, _2));
+       _port.parser()->channel_note_off[_channel_number].connect_same_thread (*this, boost::bind (&Channel::process_note_off, this, _1, _2));
+       _port.parser()->channel_poly_pressure[_channel_number].connect_same_thread (*this, boost::bind (&Channel::process_polypress, this, _1, _2));
+       _port.parser()->channel_program_change[_channel_number].connect_same_thread (*this, boost::bind (&Channel::process_program_change, this, _1, _2));
+       _port.parser()->channel_controller[_channel_number].connect_same_thread (*this, boost::bind (&Channel::process_controller, this, _1, _2));
+       _port.parser()->channel_pitchbend[_channel_number].connect_same_thread (*this, boost::bind (&Channel::process_pitchbend, this, _1, _2));
+
+       _port.parser()->reset.connect_same_thread (*this, boost::bind (&Channel::process_reset, this, _1));
 }
 
 void
-Channel::connect_output_signals ()
-
-{
-       _port.output()->channel_pressure[_channel_number].connect (*this, boost::bind (&Channel::process_chanpress, this, _1, _2));
-       _port.output()->channel_note_on[_channel_number].connect (*this, boost::bind (&Channel::process_note_on, this, _1, _2));
-       _port.output()->channel_note_off[_channel_number].connect (*this, boost::bind (&Channel::process_note_off, this, _1, _2));
-       _port.output()->channel_poly_pressure[_channel_number].connect (*this, boost::bind (&Channel::process_polypress, this, _1, _2));
-       _port.output()->channel_program_change[_channel_number].connect (*this, boost::bind (&Channel::process_program_change, this, _1, _2));
-       _port.output()->channel_controller[_channel_number].connect (*this, boost::bind (&Channel::process_controller, this, _1, _2));
-       _port.output()->channel_pitchbend[_channel_number].connect (*this, boost::bind (&Channel::process_pitchbend, this, _1, _2));
-
-       _port.output()->reset.connect (*this, boost::bind (&Channel::process_reset, this, _1));
-}
-
-void
-Channel::reset (timestamp_t timestamp, nframes_t /*nframes*/, bool notes_off)
+Channel::reset (timestamp_t timestamp, framecnt_t /*nframes*/, bool notes_off)
 {
        _program_number = _channel_number;
        _bank_number = 0;
@@ -129,7 +115,7 @@ Channel::process_controller (Parser & /*parser*/, EventTwoBytes *tb)
           all changes *are* atomic.
        */
 
-       if (tb->controller_number <= 31) { /* unsigned: no test for >= 0 */
+       if (tb->controller_number < 32) { /* unsigned: no test for >= 0 */
 
                /* if this controller is already known to use 14 bits,
                   then treat this value as the MSB, and combine it 
@@ -142,7 +128,7 @@ Channel::process_controller (Parser & /*parser*/, EventTwoBytes *tb)
                cv = (unsigned short) _controller_val[tb->controller_number];
 
                if (_controller_14bit[tb->controller_number]) {
-                       cv = ((tb->value << 7) | (cv & 0x7f));
+                       cv = ((tb->value & 0x7f) << 7) | (cv & 0x7f);
                } else {
                        cv = tb->value;
                }
@@ -152,7 +138,9 @@ Channel::process_controller (Parser & /*parser*/, EventTwoBytes *tb)
        } else if ((tb->controller_number >= 32 && 
                    tb->controller_number <= 63)) {
                   
-               cv = (unsigned short) _controller_val[tb->controller_number];
+               int cn = tb->controller_number - 32;
+
+               cv = (unsigned short) _controller_val[cn];
 
                /* LSB for CC 0-31 arrived. 
 
@@ -165,7 +153,6 @@ Channel::process_controller (Parser & /*parser*/, EventTwoBytes *tb)
                   high 7.
                */
 
-               int cn = tb->controller_number - 32;
                   
                if (_controller_14bit[cn] == false) {
                        _controller_14bit[cn] = true;
@@ -174,8 +161,14 @@ Channel::process_controller (Parser & /*parser*/, EventTwoBytes *tb)
                        cv = (cv & 0x3f80) | (tb->value & 0x7f);
                }
 
-               _controller_val[tb->controller_number] = 
-                       (controller_value_t) cv;
+               /* update the 14 bit value */
+               _controller_val[cn] = (controller_value_t) cv;
+
+               /* also store the "raw" 7 bit value in the incoming controller
+                  value store
+               */
+               _controller_val[tb->controller_number] = (controller_value_t) tb->value;
+
        } else {
 
                /* controller can only take 7 bit values */
@@ -187,25 +180,21 @@ Channel::process_controller (Parser & /*parser*/, EventTwoBytes *tb)
        /* bank numbers are special, in that they have their own signal
         */
 
-       if (tb->controller_number == 0) {
-               _bank_number = (unsigned short) _controller_val[0];
-               if (_port.input()) {
-                       _port.input()->bank_change (*_port.input(), _bank_number);
-                       _port.input()->channel_bank_change[_channel_number] 
-                               (*_port.input(), _bank_number);
-               }
+       if (tb->controller_number == 0 || tb->controller_number == 0x20) {
+               _bank_number = _controller_val[0];
+               _port.parser()->bank_change (*_port.parser(), _bank_number);
+               _port.parser()->channel_bank_change[_channel_number] (*_port.parser(), _bank_number);
        }
-
 }
 
 void
-Channel::process_program_change (Parser & /*parser*/, byte val) 
+Channel::process_program_change (Parser & /*parser*/, MIDI::byte val) 
 {
        _program_number = val;
 }
 
 void
-Channel::process_chanpress (Parser & /*parser*/, byte val) 
+Channel::process_chanpress (Parser & /*parser*/, MIDI::byte val) 
 {
        _chanpress = val;
 }
@@ -232,7 +221,7 @@ Channel::process_reset (Parser & /*parser*/)
  * \return true if success
  */
 bool
-Channel::channel_msg (byte id, byte val1, byte val2, timestamp_t timestamp)
+Channel::channel_msg (MIDI::byte id, MIDI::byte val1, MIDI::byte val2, timestamp_t timestamp)
 {
        unsigned char msg[3];
        int len = 0;