Fix MidiBuffer::merge_in_place and add aggressive correctness checking.
[ardour.git] / libs / ardour / event_type_map.cc
index 39c2e3d6eb5b247483161bbed4947df7b7f1348d..dd5b1a9149118b2535a140e211745b7d446e7792 100644 (file)
 
 */
 
-#include <ardour/types.h>
-#include <ardour/event_type_map.h>
-#include <evoral/Parameter.hpp>
-#include <evoral/midi_events.h>
-#include <evoral/MIDIParameters.hpp>
-#include <pbd/error.h>
-#include <pbd/compose.h>
+#include <cstdio>
+#include "ardour/types.h"
+#include "ardour/event_type_map.h"
+#include "evoral/Parameter.hpp"
+#include "evoral/midi_events.h"
+#include "evoral/MIDIParameters.hpp"
+#include "pbd/error.h"
+#include "pbd/compose.h"
 
 using namespace std;
 
@@ -38,14 +39,21 @@ EventTypeMap::type_is_midi(uint32_t type) const
        return (type >= MidiCCAutomation) && (type <= MidiChannelPressureAutomation);
 }
 
+bool
+EventTypeMap::is_midi_parameter(const Evoral::Parameter& param)
+{
+               return type_is_midi(param.type());
+}
+
 uint8_t
 EventTypeMap::parameter_midi_type(const Evoral::Parameter& param) const
 {
        switch (param.type()) {
-       case MidiCCAutomation:              return MIDI_CMD_CONTROL; break; 
-       case MidiPgmChangeAutomation:       return MIDI_CMD_PGM_CHANGE; break; 
-       case MidiChannelPressureAutomation: return MIDI_CMD_CHANNEL_PRESSURE; break; 
-       case MidiPitchBenderAutomation:     return MIDI_CMD_BENDER; break; 
+       case MidiCCAutomation:              return MIDI_CMD_CONTROL; break;
+       case MidiPgmChangeAutomation:       return MIDI_CMD_PGM_CHANGE; break;
+       case MidiChannelPressureAutomation: return MIDI_CMD_CHANNEL_PRESSURE; break;
+       case MidiPitchBenderAutomation:     return MIDI_CMD_BENDER; break;
+       case MidiSystemExclusiveAutomation: return MIDI_CMD_COMMON_SYSEX; break;
        default: return 0;
        }
 }
@@ -58,6 +66,7 @@ EventTypeMap::midi_event_type(uint8_t status) const
        case MIDI_CMD_PGM_CHANGE:       return MidiPgmChangeAutomation; break;
        case MIDI_CMD_CHANNEL_PRESSURE: return MidiChannelPressureAutomation; break;
        case MIDI_CMD_BENDER:           return MidiPitchBenderAutomation; break;
+       case MIDI_CMD_COMMON_SYSEX:     return MidiSystemExclusiveAutomation; break;
        default: return 0;
        }
 }
@@ -69,6 +78,60 @@ EventTypeMap::is_integer(const Evoral::Parameter& param) const
                        && param.type() <= MidiChannelPressureAutomation);
 }
 
+Evoral::ControlList::InterpolationStyle
+EventTypeMap::interpolation_of(const Evoral::Parameter& param)
+{
+       switch (param.type()) {
+       case MidiCCAutomation:
+               switch (param.id()) {
+               case MIDI_CTL_LSB_BANK:
+               case MIDI_CTL_MSB_BANK:
+               case MIDI_CTL_LSB_EFFECT1:
+               case MIDI_CTL_LSB_EFFECT2:
+               case MIDI_CTL_MSB_EFFECT1:
+               case MIDI_CTL_MSB_EFFECT2:
+               case MIDI_CTL_MSB_GENERAL_PURPOSE1:
+               case MIDI_CTL_MSB_GENERAL_PURPOSE2:
+               case MIDI_CTL_MSB_GENERAL_PURPOSE3:
+               case MIDI_CTL_MSB_GENERAL_PURPOSE4:
+               case MIDI_CTL_SUSTAIN:
+               case MIDI_CTL_PORTAMENTO:
+               case MIDI_CTL_SOSTENUTO:
+               case MIDI_CTL_SOFT_PEDAL:
+               case MIDI_CTL_LEGATO_FOOTSWITCH:
+               case MIDI_CTL_HOLD2:
+               case MIDI_CTL_GENERAL_PURPOSE5:
+               case MIDI_CTL_GENERAL_PURPOSE6:
+               case MIDI_CTL_GENERAL_PURPOSE7:
+               case MIDI_CTL_GENERAL_PURPOSE8:
+               case MIDI_CTL_DATA_INCREMENT:
+               case MIDI_CTL_DATA_DECREMENT:
+               case MIDI_CTL_NONREG_PARM_NUM_LSB:
+               case MIDI_CTL_NONREG_PARM_NUM_MSB:
+               case MIDI_CTL_REGIST_PARM_NUM_LSB:
+               case MIDI_CTL_REGIST_PARM_NUM_MSB:
+               case MIDI_CTL_ALL_SOUNDS_OFF:
+               case MIDI_CTL_RESET_CONTROLLERS:
+               case MIDI_CTL_LOCAL_CONTROL_SWITCH:
+               case MIDI_CTL_ALL_NOTES_OFF:
+               case MIDI_CTL_OMNI_OFF:
+               case MIDI_CTL_OMNI_ON:
+               case MIDI_CTL_MONO:
+               case MIDI_CTL_POLY:
+                       return Evoral::ControlList::Discrete;
+                       break;
+               default: return Evoral::ControlList::Linear; break;
+               }
+               break;
+       case MidiPgmChangeAutomation:       return Evoral::ControlList::Discrete; break;
+       case MidiChannelPressureAutomation: return Evoral::ControlList::Linear; break;
+       case MidiPitchBenderAutomation:     return Evoral::ControlList::Linear; break;
+       default: assert(false);
+       }
+       return Evoral::ControlList::Linear; // Not reached, suppress warnings
+}
+
+
 Evoral::Parameter
 EventTypeMap::new_parameter(uint32_t type, uint8_t channel, uint32_t id) const
 {
@@ -101,8 +164,10 @@ EventTypeMap::new_parameter(uint32_t type, uint8_t channel, uint32_t id) const
                Evoral::MIDI::controller_range(min, max, normal); break;
        case MidiPitchBenderAutomation:
                Evoral::MIDI::bender_range(min, max, normal); break;
+       case MidiSystemExclusiveAutomation:
+               return p;
        }
-       
+
        p.set_range(type, min, max, normal);
        return p;
 }