summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2025-01-11 11:43:58 +0100
committerRoland Reichwein <mail@reichwein.it>2025-01-11 11:43:58 +0100
commit171aa5502cfcac1abc5315c8792521790195e4a9 (patch)
tree4c8e944938501ba2ef3d0a7e0d5980d07b588221
parent3c7b85d8355c64dec5b4ce011753196d53774103 (diff)
Add notes and temperature monitor
-rw-r--r--MIDI.cpp4
-rw-r--r--Makefile3
-rw-r--r--Temperature.cpp22
-rw-r--r--Temperature.h10
-rw-r--r--UI.cpp23
-rw-r--r--UI.h4
6 files changed, 58 insertions, 8 deletions
diff --git a/MIDI.cpp b/MIDI.cpp
index dedd94a..4713a55 100644
--- a/MIDI.cpp
+++ b/MIDI.cpp
@@ -137,7 +137,7 @@ void MIDI::process(snd_seq_event_t *ev)
else if (ev->type == SND_SEQ_EVENT_SENSING)
{
signal_active_sensing();
- debug_cout << fmt::format("[{}] Active Sensing\n", timestamp_from_event(ev)) << std::endl;
+ debug_cout << fmt::format("[{}] Active Sensing", timestamp_from_event(ev)) << std::endl;
}
else if (ev->type == SND_SEQ_EVENT_CLOCK)
{
@@ -146,7 +146,7 @@ void MIDI::process(snd_seq_event_t *ev)
}
else
{
- log_cout << fmt::format("[{}] Unknown MIDI event: {}\n", timestamp_from_event(ev), ev->type) << std::endl;
+ log_cout << fmt::format("[{}] Unknown MIDI event: {}", timestamp_from_event(ev), ev->type) << std::endl;
}
signal_count_events();
diff --git a/Makefile b/Makefile
index 991d020..3561227 100644
--- a/Makefile
+++ b/Makefile
@@ -18,7 +18,8 @@ SRCS= \
InternalClick.cpp \
BPMDetect.cpp \
Touchpad.cpp \
- PIDFile.cpp
+ PIDFile.cpp \
+ Temperature.cpp \
HEADERS=$(SRCS:.cpp=.h)
diff --git a/Temperature.cpp b/Temperature.cpp
new file mode 100644
index 0000000..dece26a
--- /dev/null
+++ b/Temperature.cpp
@@ -0,0 +1,22 @@
+#include "Temperature.h"
+
+#include <libreichwein/file.h>
+
+#include <filesystem>
+
+namespace fs = std::filesystem;
+
+namespace {
+ // e.g. 46000 for 46C
+ fs::path temp_path{"/sys/class/thermal/thermal_zone0/temp"};
+}
+
+Temperature::Temperature()
+{
+}
+
+int Temperature::read_degree() const
+{
+ std::string contents {Reichwein::File::getFile(temp_path)};
+ return std::stoul(contents) / 1000;
+}
diff --git a/Temperature.h b/Temperature.h
new file mode 100644
index 0000000..7210c09
--- /dev/null
+++ b/Temperature.h
@@ -0,0 +1,10 @@
+#pragma once
+
+class Temperature
+{
+public:
+ Temperature();
+
+ int read_degree() const;
+};
+
diff --git a/UI.cpp b/UI.cpp
index 0b281b9..5332bba 100644
--- a/UI.cpp
+++ b/UI.cpp
@@ -58,6 +58,7 @@ UI::UI(Config& config):
m_config(config),
m_main_loops{},
m_midi_events{},
+ m_midi_notes{},
m_active_sensing_timestamp{},
m_midi_timestamp{},
m_note_bpm{},
@@ -89,6 +90,9 @@ void UI::draw()
std::vector<int> cpuloads = get_cpu_loads();
int main_loops_per_second = m_main_loops.get_count_per_second();
int midi_events_per_second = m_midi_events.get_count_per_second();
+ int midi_notes_per_second = m_midi_notes.get_count_per_second();
+
+ int temperature = m_temperature.read_degree();
int mode = m_config.get_mode();
int channel = m_config.get_midi_channel();
@@ -159,12 +163,14 @@ void UI::draw()
std::cout << std::endl;
std::cout << fmt::format(" MIDI Timestamp: {}", m_midi_timestamp) << std::endl;
std::cout << " MIDI Active Sensing: " << fmt::format(value_color, "{}", active_sensing_names[active_sensing_detected]) << std::endl;
- std::cout << fmt::format(" MIDI Events/s: {}", midi_events_per_second) << std::endl;
- std::cout << fmt::format(" MIDI Click: {:3} BPM", m_note_bpm) << std::endl;
- std::cout << fmt::format(" MIDI Clock: {:3} BPM", m_clock_bpm) << std::endl;
- std::cout << fmt::format(" Internal: {:3} BPM", internal_bpm) << std::endl;
+ std::cout << fmt::format(" MIDI Events/s:{:3}", midi_events_per_second) << std::endl;
+ std::cout << fmt::format(" MIDI Notes/s: {:3}", midi_notes_per_second) << std::endl;
+ std::cout << fmt::format(" MIDI Click: {:3} BPM", m_note_bpm) << std::endl;
+ std::cout << fmt::format(" MIDI Clock: {:3} BPM", m_clock_bpm) << std::endl;
+ std::cout << fmt::format(" Internal: {:3} BPM", internal_bpm) << std::endl;
- std::cout << fmt::format(" Main loops/s: {}", main_loops_per_second) << std::endl;
+ std::cout << fmt::format(" Main loops/s: {:3}", main_loops_per_second) << std::endl;
+ std::cout << fmt::format(" Temperature: {:3} C", temperature) << std::endl;
std::cout << std::endl;
std::cout << "Log:" << std::endl;
@@ -227,6 +233,11 @@ void UI::count_midi_events()
m_midi_events.count();
}
+void UI::count_midi_notes()
+{
+ m_midi_notes.count();
+}
+
void UI::slot_active_sensing()
{
m_active_sensing_timestamp = clock_type::now();
@@ -241,6 +252,8 @@ void UI::slot_midi_note(int channel, int note, uint64_t timestamp)
while (m_midi_monitor.size() > midi_monitor_max_size) {
m_midi_monitor.pop_back();
}
+
+ count_midi_notes();
}
void UI::slot_note_bpm(int bpm)
diff --git a/UI.h b/UI.h
index b1dd7dd..02b0822 100644
--- a/UI.h
+++ b/UI.h
@@ -9,6 +9,7 @@
#include <boost/signals2.hpp>
#include "Touchpad.h"
+#include "Temperature.h"
using clock_type = std::chrono::high_resolution_clock;
@@ -46,6 +47,7 @@ public:
// slots
void count_main_loops();
void count_midi_events();
+ void count_midi_notes();
void slot_active_sensing();
void slot_midi_note(int channel, int note, uint64_t timestamp);
void slot_note_bpm(int bpm);
@@ -56,6 +58,7 @@ private:
IntervalCounter m_main_loops;
IntervalCounter m_midi_events;
+ IntervalCounter m_midi_notes;
std::chrono::time_point<clock_type> m_active_sensing_timestamp;
@@ -66,5 +69,6 @@ private:
int m_clock_bpm;
Touchpad m_touchpad;
+ Temperature m_temperature;
};