diff options
author | Roland Reichwein <mail@reichwein.it> | 2025-01-11 11:43:58 +0100 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2025-01-11 11:43:58 +0100 |
commit | 171aa5502cfcac1abc5315c8792521790195e4a9 (patch) | |
tree | 4c8e944938501ba2ef3d0a7e0d5980d07b588221 | |
parent | 3c7b85d8355c64dec5b4ce011753196d53774103 (diff) |
Add notes and temperature monitor
-rw-r--r-- | MIDI.cpp | 4 | ||||
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | Temperature.cpp | 22 | ||||
-rw-r--r-- | Temperature.h | 10 | ||||
-rw-r--r-- | UI.cpp | 23 | ||||
-rw-r--r-- | UI.h | 4 |
6 files changed, 58 insertions, 8 deletions
@@ -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(); @@ -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; +}; + @@ -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) @@ -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; }; |