From 5b02561573abf73b86092dacde860affd59df698 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Tue, 14 May 2024 17:20:01 +0200 Subject: [PATCH 1/3] Fix MIDI Tracer (print polypress value) --- gtk2_ardour/midi_tracer.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gtk2_ardour/midi_tracer.cc b/gtk2_ardour/midi_tracer.cc index e0c35e301c..22ae957ed7 100644 --- a/gtk2_ardour/midi_tracer.cc +++ b/gtk2_ardour/midi_tracer.cc @@ -338,9 +338,9 @@ MidiTracer::tracer (Parser&, MIDI::byte* msg, size_t len, samplecnt_t now) case polypress: if (show_hex) { - s += snprintf (&buf[s], bufsize, "%16s chn %2d %02x\n", "PolyPressure", (msg[0]&0xf)+1, (int) msg[1]); + s += snprintf (&buf[s], bufsize, "%16s chn %2d %02x %02x\n", "PolyPressure", (msg[0]&0xf)+1, (int) msg[1], msg[2]); } else { - s += snprintf (&buf[s], bufsize, "%16s chn %2d %-3d\n", "PolyPressure", (msg[0]&0xf)+1, (int) msg[1]); + s += snprintf (&buf[s], bufsize, "%16s chn %2d %-3d %-3d\n", "PolyPressure", (msg[0]&0xf)+1, (int) msg[1], msg[2]); } break; @@ -362,9 +362,9 @@ MidiTracer::tracer (Parser&, MIDI::byte* msg, size_t len, samplecnt_t now) case chanpress: if (show_hex) { - s += snprintf (&buf[s], bufsize, "%16s chn %2d %02x/%-3d\n", "Channel Pressure", (msg[0]&0xf)+1, (int) msg[1], (int) msg[1]); + s += snprintf (&buf[s], bufsize, "%16s chn %2d %02x\n", "Channel Pressure", (msg[0]&0xf)+1, (int) msg[1]); } else { - s += snprintf (&buf[s], bufsize, "%16s chn %2d %02x/%-3d\n", "Channel Pressure", (msg[0]&0xf)+1, (int) msg[1], (int) msg[1]); + s += snprintf (&buf[s], bufsize, "%16s chn %2d %-3d\n", "Channel Pressure", (msg[0]&0xf)+1, (int) msg[1]); } break; From ac476880231e431da767c877c520e7cf144ad1f8 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Tue, 14 May 2024 17:20:52 +0200 Subject: [PATCH 2/3] Add Lua plugin to map DM10-mkII Studio HiHat MIDI messages --- share/scripts/dm10studio.lua | 67 ++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 share/scripts/dm10studio.lua diff --git a/share/scripts/dm10studio.lua b/share/scripts/dm10studio.lua new file mode 100644 index 0000000000..44c790031e --- /dev/null +++ b/share/scripts/dm10studio.lua @@ -0,0 +1,67 @@ +ardour { + ["type"] = "dsp", + name = "DM10-mkII-Studio HiHat", + category = "Utility", + license = "MIT", + author = "Ardour Community", + description = [[Map HiHat MIDI events depending on pedal CC. Specifically MIDI Note Number 8 is translated to 54,47,58 deending on CC-8.]] +} + +function dsp_ioconfig () + return { { midi_in = 1, midi_out = 1, audio_in = 0, audio_out = 0}, } +end + +local hihat_note = -1 +local hihat_state = 0 + +function dsp_run (_, _, n_samples) + assert (type(midiin) == "table") + assert (type(midiout) == "table") + local cnt = 1; + + function tx_midi (time, data) + midiout[cnt] = {} + midiout[cnt]["time"] = time; + midiout[cnt]["data"] = data; + cnt = cnt + 1; + end + + -- for each incoming midi event + for _,b in pairs (midiin) do + local t = b["time"] -- t = [ 1 .. n_samples ] + local d = b["data"] -- midi-event data + local event_type + if #d == 0 then event_type = -1 else event_type = d[1] >> 4 end + + -- intercept CC message + if #d == 3 and event_type == 11 and d[2] == 8 then + hihat_state = d[3] + end + + -- map Note event + if (#d == 3) and d[2] == 8 and event_type == 9 then + if hihat_state < 42 then hihat_note = 54 -- Hihat_Closed + elseif hihat_state < 92 then hihat_note = 46 -- Hihat_Semi_Open + else hihat_note = 58 -- Hihat_Open + end + d[2] = hihat_note + end + + -- translate aftertouch + if (#d == 3) and d[2] == 8 and event_type == 10 then + if (hihat_note > 0) then + d[2] = hihat_note + end + end + + -- intercept note off + if (#d == 3) and d[2] == 8 and event_type == 8 then + if (hihat_note > 0) then + d[2] = hihat_note + end + --hihat_note = -1 + end + + tx_midi (t, d) + end +end From 86c3b70c54fdeca4a3a0b681e33ce8dcb146d3a9 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 14 May 2024 12:25:58 -0600 Subject: [PATCH 3/3] add some utility functions to Buffers and BufferSets to allow some kinds of debugging easily --- libs/ardour/ardour/audio_buffer.h | 2 ++ libs/ardour/ardour/buffer.h | 3 +++ libs/ardour/ardour/buffer_set.h | 3 +++ libs/ardour/ardour/midi_buffer.h | 1 + libs/ardour/audio_buffer.cc | 11 +++++++++++ libs/ardour/buffer_set.cc | 13 +++++++++++++ 6 files changed, 33 insertions(+) diff --git a/libs/ardour/ardour/audio_buffer.h b/libs/ardour/ardour/audio_buffer.h index 5eba406669..bec4bdd7cc 100644 --- a/libs/ardour/ardour/audio_buffer.h +++ b/libs/ardour/ardour/audio_buffer.h @@ -42,6 +42,8 @@ public: */ void silence (samplecnt_t len, samplecnt_t offset = 0); + bool silent_data() const; + /** Copy samples from src array starting at src_offset into self starting at dst_offset * @param src array to read from * @param len number of samples to copy diff --git a/libs/ardour/ardour/buffer.h b/libs/ardour/ardour/buffer.h index 8f0cf7e815..e262ecf821 100644 --- a/libs/ardour/ardour/buffer.h +++ b/libs/ardour/ardour/buffer.h @@ -69,6 +69,9 @@ public: /** Clear (eg zero, or empty) buffer */ virtual void silence (samplecnt_t len, samplecnt_t offset = 0) = 0; + /* return true if all data is silent (or for MIDI-like, non-existent */ + virtual bool silent_data () const = 0; + /** Clear the entire buffer */ virtual void clear() { silence(_capacity, 0); } diff --git a/libs/ardour/ardour/buffer_set.h b/libs/ardour/ardour/buffer_set.h index f05804f15e..38891f4a47 100644 --- a/libs/ardour/ardour/buffer_set.h +++ b/libs/ardour/ardour/buffer_set.h @@ -82,6 +82,9 @@ public: void ensure_buffers(DataType type, size_t num_buffers, size_t buffer_capacity); void ensure_buffers(const ChanCount& chns, size_t buffer_capacity); + /* Returns true if Buffer::silent_data() is true for all buffers */ + bool silent_data() const; + const ChanCount& available() const { return _available; } ChanCount& available() { return _available; } diff --git a/libs/ardour/ardour/midi_buffer.h b/libs/ardour/ardour/midi_buffer.h index 4ea57e6b67..6538ec37f1 100644 --- a/libs/ardour/ardour/midi_buffer.h +++ b/libs/ardour/ardour/midi_buffer.h @@ -59,6 +59,7 @@ public: void resize(size_t); size_t size() const { return _size; } bool empty() const { return _size == 0; } + bool silent_data () const { return _size == 0; } bool insert_event(const Evoral::Event& event); bool merge_in_place(const MidiBuffer &other); diff --git a/libs/ardour/audio_buffer.cc b/libs/ardour/audio_buffer.cc index 982c8947c1..0d51bbf850 100644 --- a/libs/ardour/audio_buffer.cc +++ b/libs/ardour/audio_buffer.cc @@ -81,6 +81,17 @@ AudioBuffer::check_silence (pframes_t nframes, pframes_t& n) const return true; } +bool +AudioBuffer::silent_data () const +{ + for (pframes_t n = 0; n < _capacity; ++n) { + if (_data[n]) { + return false; + } + } + return true; +} + void AudioBuffer::silence (samplecnt_t len, samplecnt_t offset) { diff --git a/libs/ardour/buffer_set.cc b/libs/ardour/buffer_set.cc index d46c7c5264..bf847b6333 100644 --- a/libs/ardour/buffer_set.cc +++ b/libs/ardour/buffer_set.cc @@ -229,6 +229,19 @@ BufferSet::ensure_buffers(const ChanCount& chns, size_t buffer_capacity) } } +bool +BufferSet::silent_data () const +{ + for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) { + for (BufferSet::const_iterator i = begin (*t); i != end (*t); ++i) { + if (!i->silent_data ()) { + return false; + } + } + } + return true; +} + /** Get the capacity (size) of the available buffers of the given type. * * All buffers of a certain type always have the same capacity.