summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2024-03-28 12:15:15 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2024-03-28 12:15:15 +0100
commit255e757419aed5bce8254b3fbf28f0f8da3eeba6 (patch)
treeec17fee4d570b92746571b9c0d759bb1141e4285 /src
parentbf7cb30a61bbb59790dd7a3dfa81945f9f1b0e61 (diff)
Linter fixes for audioinputenginemidi.cc
Diffstat (limited to 'src')
-rw-r--r--src/audioinputenginemidi.cc42
-rw-r--r--src/audioinputenginemidi.h13
-rw-r--r--src/configfile.h2
-rw-r--r--src/drumgizmo.h2
-rw-r--r--src/drumkitloader.cc2
5 files changed, 29 insertions, 32 deletions
diff --git a/src/audioinputenginemidi.cc b/src/audioinputenginemidi.cc
index 69aeeb6..2e794f4 100644
--- a/src/audioinputenginemidi.cc
+++ b/src/audioinputenginemidi.cc
@@ -28,26 +28,20 @@
#include "midimapparser.h"
-#include "drumgizmo.h"
+#include <cassert>
#include <hugin.hpp>
-AudioInputEngineMidi::AudioInputEngineMidi()
- : refs(REFSFILE)
-{
- is_valid = false;
-}
-
-bool AudioInputEngineMidi::loadMidiMap(const std::string& file,
+bool AudioInputEngineMidi::loadMidiMap(const std::string& midimap_file,
const Instruments& instruments)
{
- std::string f = file;
+ std::string file = midimap_file;
if(refs.load())
{
if(file.size() > 1 && file[0] == '@')
{
- f = refs.getValue(file.substr(1));
+ file = refs.getValue(file.substr(1));
}
}
else
@@ -58,16 +52,16 @@ bool AudioInputEngineMidi::loadMidiMap(const std::string& file,
midimap = "";
is_valid = false;
- DEBUG(mmap, "loadMidiMap(%s, i.size() == %d)\n", f.c_str(),
+ DEBUG(mmap, "loadMidiMap(%s, i.size() == %d)\n", file.c_str(),
(int)instruments.size());
- if(f == "")
+ if(file.empty())
{
return false;
}
MidiMapParser midimap_parser;
- if(!midimap_parser.parseFile(f))
+ if(!midimap_parser.parseFile(file))
{
return false;
}
@@ -75,7 +69,7 @@ bool AudioInputEngineMidi::loadMidiMap(const std::string& file,
instrmap_t instrmap;
for(size_t i = 0; i < instruments.size(); i++)
{
- instrmap[instruments[i]->getName()] = i;
+ instrmap[instruments[i]->getName()] = static_cast<int>(i);
}
mmap.swap(instrmap, midimap_parser.midimap);
@@ -97,12 +91,12 @@ bool AudioInputEngineMidi::isValid() const
}
// Note types:
-static const std::uint8_t NoteOff = 0x80;
-static const std::uint8_t NoteOn = 0x90;
-static const std::uint8_t NoteAftertouch = 0xA0;
+constexpr std::uint8_t NoteOff{0x80};
+constexpr std::uint8_t NoteOn{0x90};
+constexpr std::uint8_t NoteAftertouch{0xA0};
// Note type mask:
-static int const NoteMask = 0xF0;
+constexpr std::uint8_t NoteMask{0xF0};
void AudioInputEngineMidi::processNote(const std::uint8_t* midi_buffer,
std::size_t midi_buffer_length,
@@ -114,13 +108,13 @@ void AudioInputEngineMidi::processNote(const std::uint8_t* midi_buffer,
return;
}
- auto key = midi_buffer[1];
- auto velocity = midi_buffer[2];
+ auto key = midi_buffer[1]; // NOLINT - span
+ auto velocity = midi_buffer[2]; // NOLINT - span
auto instrument_idx = mmap.lookup(key);
auto instruments = mmap.lookup(key);
for(const auto& instrument_idx : instruments)
{
- switch(midi_buffer[0] & NoteMask)
+ switch(midi_buffer[0] & NoteMask) // NOLINT - span
{
case NoteOff:
// Ignore for now
@@ -129,8 +123,12 @@ void AudioInputEngineMidi::processNote(const std::uint8_t* midi_buffer,
case NoteOn:
if(velocity != 0)
{
+ constexpr float lower_offset{0.5f};
+ constexpr float midi_velocity_max{127.0f};
// maps velocities to [.5/127, 126.5/127]
- auto centered_velocity = (velocity-.5f)/127.0f;
+ assert(velocity <= 127); // MIDI only support up to 127
+ auto centered_velocity =
+ (static_cast<float>(velocity) - lower_offset) / midi_velocity_max;
events.push_back({EventType::OnSet, (std::size_t)instrument_idx,
offset, centered_velocity});
}
diff --git a/src/audioinputenginemidi.h b/src/audioinputenginemidi.h
index 8da7bd2..386a055 100644
--- a/src/audioinputenginemidi.h
+++ b/src/audioinputenginemidi.h
@@ -37,7 +37,7 @@ class AudioInputEngineMidi
: public AudioInputEngine
{
public:
- AudioInputEngineMidi();
+ AudioInputEngineMidi() = default;
virtual ~AudioInputEngineMidi() = default;
virtual bool init(const Instruments &instruments) = 0;
@@ -51,14 +51,15 @@ public:
virtual void run(size_t pos, size_t len, std::vector<event_t>& events) = 0;
virtual void post() = 0;
- virtual bool loadMidiMap(const std::string& file, const Instruments& i);
+ virtual bool loadMidiMap(const std::string& midimap_file,
+ const Instruments& i);
std::string getMidimapFile() const;
bool isValid() const;
- void processNote(const std::uint8_t* note_data,
- std::size_t note_data_size,
+ void processNote(const std::uint8_t* midi_buffer,
+ std::size_t midi_buffer_length,
std::size_t offset,
std::vector<event_t>& events);
@@ -67,7 +68,7 @@ protected:
private:
std::string midimap;
- bool is_valid;
+ bool is_valid{false};
- ConfigFile refs;
+ ConfigFile refs{REFSFILE};
};
diff --git a/src/configfile.h b/src/configfile.h
index c17811b..49dbdee 100644
--- a/src/configfile.h
+++ b/src/configfile.h
@@ -30,6 +30,8 @@
#include <map>
#include <fstream>
+static const std::string REFSFILE{"refs.conf"};
+
class ConfigFile
{
public:
diff --git a/src/drumgizmo.h b/src/drumgizmo.h
index 89c2960..0ee51e6 100644
--- a/src/drumgizmo.h
+++ b/src/drumgizmo.h
@@ -46,8 +46,6 @@
#include "inputprocessor.h"
#include "zrwrapper.h"
-#define REFSFILE "refs.conf"
-
class DrumGizmo
{
public:
diff --git a/src/drumkitloader.cc b/src/drumkitloader.cc
index d73efff..b3a0e5b 100644
--- a/src/drumkitloader.cc
+++ b/src/drumkitloader.cc
@@ -38,8 +38,6 @@
#include "domloader.h"
#include "directory.h"
-#define REFSFILE "refs.conf"
-
DrumKitLoader::DrumKitLoader(Settings& settings, DrumKit& kit,
AudioInputEngine& ie,
Random& rand,