summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2009-07-23 03:01:31 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2009-07-23 03:01:31 +0000
commit38510cb19e217c62a8e1e1664bed13f44c42ef08 (patch)
tree6e4b5f25d7b2703d4c762b8f8e8c9f0370ed711a /libs
parent3804e3bc497f68d4b68f51794815db3ffe5e7a91 (diff)
install ardour.menus and bindings file (elthariel) ; initial, basic MIDI gain (fader) working
git-svn-id: svn://localhost/ardour2/branches/3.0@5416 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs')
-rw-r--r--libs/ardour/amp.cc52
-rw-r--r--libs/evoral/evoral/MIDIEvent.hpp7
2 files changed, 53 insertions, 6 deletions
diff --git a/libs/ardour/amp.cc b/libs/ardour/amp.cc
index 0efaaa3535..b8e0ad700f 100644
--- a/libs/ardour/amp.cc
+++ b/libs/ardour/amp.cc
@@ -154,6 +154,18 @@ Amp::run (BufferSet& bufs, sframes_t /*start_frame*/, sframes_t /*end_frame*/, n
/* gain has not changed, but its non-unity
*/
+ for (BufferSet::midi_iterator i = bufs.midi_begin(); i != bufs.midi_end(); ++i) {
+
+ MidiBuffer& mb (*i);
+
+ for (MidiBuffer::iterator m = mb.begin(); m != mb.end(); ++m) {
+ Evoral::MIDIEvent<MidiBuffer::TimeType> ev = *m;
+ if (ev.is_note_on()) {
+ ev.scale_velocity (_current_gain);
+ }
+ }
+ }
+
for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
apply_gain_to_buffer (i->data(), nframes, _current_gain);
}
@@ -197,16 +209,19 @@ Amp::apply_gain (BufferSet& bufs, nframes_t nframes, gain_t initial, gain_t targ
/* MIDI Gain */
for (BufferSet::midi_iterator i = bufs.midi_begin(); i != bufs.midi_end(); ++i) {
-#if 0
- MidiBuffer& mb (*i);
+
+ MidiBuffer& mb (*i);
+
for (MidiBuffer::iterator m = mb.begin(); m != mb.end(); ++m) {
- Evoral::MIDIEvent<MidiBuffer::TimeType> ev (*m);
- if (ev.buffer()[0] == MIDI_CMD_NOTE_ON) {
- ev.buffer()[2] = (uint8_t) rint (ev.buffer()[2] * 1.0);
+ Evoral::MIDIEvent<MidiBuffer::TimeType> ev = *m;
+
+ if (ev.is_note_on()) {
+ gain_t scale = delta * (ev.time()/nframes);
+ std::cerr << "scale by " << scale << " for " << ev.time() << " of " << nframes << std::endl;
+ ev.scale_velocity (scale);
}
}
-#endif
}
/* Audio Gain */
@@ -238,10 +253,35 @@ void
Amp::apply_simple_gain (BufferSet& bufs, nframes_t nframes, gain_t target)
{
if (target == 0.0) {
+
+ for (BufferSet::midi_iterator i = bufs.midi_begin(); i != bufs.midi_end(); ++i) {
+ MidiBuffer& mb (*i);
+
+ for (MidiBuffer::iterator m = mb.begin(); m != mb.end(); ++m) {
+ Evoral::MIDIEvent<MidiBuffer::TimeType> ev = *m;
+ if (ev.is_note_on()) {
+ ev.set_velocity (0);
+ }
+ }
+ }
+
for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
memset (i->data(), 0, sizeof (Sample) * nframes);
}
+
} else if (target != 1.0) {
+
+ for (BufferSet::midi_iterator i = bufs.midi_begin(); i != bufs.midi_end(); ++i) {
+ MidiBuffer& mb (*i);
+
+ for (MidiBuffer::iterator m = mb.begin(); m != mb.end(); ++m) {
+ Evoral::MIDIEvent<MidiBuffer::TimeType> ev = *m;
+ if (ev.is_note_on()) {
+ ev.scale_velocity (target);
+ }
+ }
+ }
+
for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
apply_gain_to_buffer (i->data(), nframes, target);
}
diff --git a/libs/evoral/evoral/MIDIEvent.hpp b/libs/evoral/evoral/MIDIEvent.hpp
index 12c57a96a0..f7df4980fe 100644
--- a/libs/evoral/evoral/MIDIEvent.hpp
+++ b/libs/evoral/evoral/MIDIEvent.hpp
@@ -19,6 +19,7 @@
#ifndef EVORAL_MIDI_EVENT_HPP
#define EVORAL_MIDI_EVENT_HPP
+#include <cmath>
#include <boost/shared_ptr.hpp>
#include "evoral/Event.hpp"
#include "evoral/midi_events.h"
@@ -68,6 +69,12 @@ struct MIDIEvent : public Event<Time> {
inline bool is_channel_pressure() const { return (type() == MIDI_CMD_CHANNEL_PRESSURE); }
inline uint8_t note() const { return (this->_buf[1]); }
inline uint8_t velocity() const { return (this->_buf[2]); }
+ inline void set_velocity(uint8_t value) { this->_buf[2] = value; }
+ inline void scale_velocity(float factor) {
+ if (factor < 0) factor = 0;
+ this->_buf[2] = (uint8_t) lrintf (this->_buf[2]*factor);
+ if (this->_buf[2] > 127) this->_buf[2] = 127;
+ }
inline uint8_t cc_number() const { return (this->_buf[1]); }
inline void set_cc_number(uint8_t number) { this->_buf[1] = number; }
inline uint8_t cc_value() const { return (this->_buf[2]); }