diff --git a/Activity/Observer.hpp b/Activity/Observer.hpp index 346219b70..4ebcd11ec 100644 --- a/Activity/Observer.hpp +++ b/Activity/Observer.hpp @@ -22,38 +22,38 @@ namespace Activity { and/or to show or unshow status indicators. */ class Observer { - public: - virtual ~Observer() = default; +public: + virtual ~Observer() = default; - /// Provides hints as to the sort of information presented on an LED. - enum LEDPresentation: uint8_t { - /// This LED informs the user of some sort of persistent state, e.g. scroll lock. - /// If this flag is absent then the LED describes an ephemeral state, such as media access. - Persistent = (1 << 0), - }; + /// Provides hints as to the sort of information presented on an LED. + enum LEDPresentation: uint8_t { + /// This LED informs the user of some sort of persistent state, e.g. scroll lock. + /// If this flag is absent then the LED describes an ephemeral state, such as media access. + Persistent = (1 << 0), + }; - /// Announces to the receiver that there is an LED of name @c name. - virtual void register_led([[maybe_unused]] const std::string &name, [[maybe_unused]] uint8_t presentation = 0) {} + /// Announces to the receiver that there is an LED of name @c name. + virtual void register_led([[maybe_unused]] const std::string &name, [[maybe_unused]] uint8_t presentation = 0) {} - /// Announces to the receiver that there is a drive of name @c name. - /// - /// If a drive has the same name as an LED, that LED goes with this drive. - virtual void register_drive([[maybe_unused]] const std::string &name) {} + /// Announces to the receiver that there is a drive of name @c name. + /// + /// If a drive has the same name as an LED, that LED goes with this drive. + virtual void register_drive([[maybe_unused]] const std::string &name) {} - /// Informs the receiver of the new state of the LED with name @c name. - virtual void set_led_status([[maybe_unused]] const std::string &name, [[maybe_unused]] bool lit) {} + /// Informs the receiver of the new state of the LED with name @c name. + virtual void set_led_status([[maybe_unused]] const std::string &name, [[maybe_unused]] bool lit) {} - enum class DriveEvent { - StepNormal, - StepBelowZero, - StepBeyondMaximum - }; + enum class DriveEvent { + StepNormal, + StepBelowZero, + StepBeyondMaximum + }; - /// Informs the receiver that the named event just occurred for the drive with name @c name. - virtual void announce_drive_event([[maybe_unused]] const std::string &name, [[maybe_unused]] DriveEvent event) {} + /// Informs the receiver that the named event just occurred for the drive with name @c name. + virtual void announce_drive_event([[maybe_unused]] const std::string &name, [[maybe_unused]] DriveEvent event) {} - /// Informs the receiver of the motor-on status of the drive with name @c name. - virtual void set_drive_motor_status([[maybe_unused]] const std::string &name, [[maybe_unused]] bool is_on) {} + /// Informs the receiver of the motor-on status of the drive with name @c name. + virtual void set_drive_motor_status([[maybe_unused]] const std::string &name, [[maybe_unused]] bool is_on) {} }; } diff --git a/Activity/Source.hpp b/Activity/Source.hpp index 6f540cf33..86d9642e4 100644 --- a/Activity/Source.hpp +++ b/Activity/Source.hpp @@ -13,8 +13,8 @@ namespace Activity { class Source { - public: - virtual void set_activity_observer(Observer *observer) = 0; +public: + virtual void set_activity_observer(Observer *observer) = 0; }; } diff --git a/Analyser/Dynamic/ConfidenceCounter.hpp b/Analyser/Dynamic/ConfidenceCounter.hpp index 8b8e80ea2..ca1002748 100644 --- a/Analyser/Dynamic/ConfidenceCounter.hpp +++ b/Analyser/Dynamic/ConfidenceCounter.hpp @@ -18,25 +18,25 @@ namespace Analyser::Dynamic { The initial value of the confidence counter is 0.5. */ class ConfidenceCounter: public ConfidenceSource { - public: - /*! @returns The computed probability, based on the history of events. */ - float get_confidence() final; +public: + /*! @returns The computed probability, based on the history of events. */ + float get_confidence() final; - /*! Records an event that implies this is the appropriate class: pushes probability up towards 1.0. */ - void add_hit(); + /*! Records an event that implies this is the appropriate class: pushes probability up towards 1.0. */ + void add_hit(); - /*! Records an event that implies this is not the appropriate class: pushes probability down towards 0.0. */ - void add_miss(); + /*! Records an event that implies this is not the appropriate class: pushes probability down towards 0.0. */ + void add_miss(); - /*! - Records an event that could be correct but isn't necessarily so; which can push probability - down towards 0.5, but will never push it upwards. - */ - void add_equivocal(); + /*! + Records an event that could be correct but isn't necessarily so; which can push probability + down towards 0.5, but will never push it upwards. + */ + void add_equivocal(); - private: - int hits_ = 1; - int misses_ = 1; +private: + int hits_ = 1; + int misses_ = 1; }; } diff --git a/Analyser/Dynamic/ConfidenceSummary.cpp b/Analyser/Dynamic/ConfidenceSummary.cpp index 5ffd9264f..c3f0c2607 100644 --- a/Analyser/Dynamic/ConfidenceSummary.cpp +++ b/Analyser/Dynamic/ConfidenceSummary.cpp @@ -13,7 +13,10 @@ using namespace Analyser::Dynamic; -ConfidenceSummary::ConfidenceSummary(const std::vector &sources, const std::vector &weights) : +ConfidenceSummary::ConfidenceSummary( + const std::vector &sources, + const std::vector &weights +) : sources_(sources), weights_(weights) { assert(weights.size() == sources.size()); weight_sum_ = std::accumulate(weights.begin(), weights.end(), 0.0f); diff --git a/Analyser/Dynamic/ConfidenceSummary.hpp b/Analyser/Dynamic/ConfidenceSummary.hpp index 880a9e8ea..90f3e78c9 100644 --- a/Analyser/Dynamic/ConfidenceSummary.hpp +++ b/Analyser/Dynamic/ConfidenceSummary.hpp @@ -18,24 +18,24 @@ namespace Analyser::Dynamic { Summaries a collection of confidence sources by calculating their weighted sum. */ class ConfidenceSummary: public ConfidenceSource { - public: - /*! - Instantiates a summary that will produce the weighted sum of - @c sources, each using the corresponding entry of @c weights. +public: + /*! + Instantiates a summary that will produce the weighted sum of + @c sources, each using the corresponding entry of @c weights. - Requires that @c sources and @c weights are of the same length. - */ - ConfidenceSummary( - const std::vector &sources, - const std::vector &weights); + Requires that @c sources and @c weights are of the same length. + */ + ConfidenceSummary( + const std::vector &sources, + const std::vector &weights); - /*! @returns The weighted sum of all sources. */ - float get_confidence() final; + /*! @returns The weighted sum of all sources. */ + float get_confidence() final; - private: - const std::vector sources_; - const std::vector weights_; - float weight_sum_; +private: + const std::vector sources_; + const std::vector weights_; + float weight_sum_; }; } diff --git a/Analyser/Dynamic/MultiMachine/Implementation/MultiConfigurable.cpp b/Analyser/Dynamic/MultiMachine/Implementation/MultiConfigurable.cpp index 28dbd9175..3556719b1 100644 --- a/Analyser/Dynamic/MultiMachine/Implementation/MultiConfigurable.cpp +++ b/Analyser/Dynamic/MultiMachine/Implementation/MultiConfigurable.cpp @@ -15,90 +15,90 @@ using namespace Analyser::Dynamic; namespace { class MultiStruct: public Reflection::Struct { - public: - MultiStruct(const std::vector &devices) : devices_(devices) { - for(auto device: devices) { - options_.emplace_back(device->get_options()); +public: + MultiStruct(const std::vector &devices) : devices_(devices) { + for(auto device: devices) { + options_.emplace_back(device->get_options()); + } + } + + void apply() { + auto options = options_.begin(); + for(auto device: devices_) { + device->set_options(*options); + ++options; + } + } + + std::vector all_keys() const final { + std::set keys; + for(auto &options: options_) { + const auto new_keys = options->all_keys(); + keys.insert(new_keys.begin(), new_keys.end()); + } + return std::vector(keys.begin(), keys.end()); + } + + std::vector values_for(const std::string &name) const final { + std::set values; + for(auto &options: options_) { + const auto new_values = options->values_for(name); + values.insert(new_values.begin(), new_values.end()); + } + return std::vector(values.begin(), values.end()); + } + + const std::type_info *type_of(const std::string &name) const final { + for(auto &options: options_) { + auto info = options->type_of(name); + if(info) return info; + } + return nullptr; + } + + size_t count_of(const std::string &name) const final { + for(auto &options: options_) { + auto info = options->type_of(name); + if(info) return options->count_of(name); + } + return 0; + } + + const void *get(const std::string &name) const final { + for(auto &options: options_) { + auto value = options->get(name); + if(value) return value; + } + return nullptr; + } + + void *get(const std::string &name) final { + for(auto &options: options_) { + auto value = options->get(name); + if(value) return value; + } + return nullptr; + } + + void set(const std::string &name, const void *value, const size_t offset) final { + const auto safe_type = type_of(name); + if(!safe_type) return; + + // Set this property only where the child's type is the same as that + // which was returned from here for type_of. + for(auto &options: options_) { + const auto type = options->type_of(name); + if(!type) continue; + + if(*type == *safe_type) { + options->set(name, value, offset); } } + } - void apply() { - auto options = options_.begin(); - for(auto device: devices_) { - device->set_options(*options); - ++options; - } - } - - std::vector all_keys() const final { - std::set keys; - for(auto &options: options_) { - const auto new_keys = options->all_keys(); - keys.insert(new_keys.begin(), new_keys.end()); - } - return std::vector(keys.begin(), keys.end()); - } - - std::vector values_for(const std::string &name) const final { - std::set values; - for(auto &options: options_) { - const auto new_values = options->values_for(name); - values.insert(new_values.begin(), new_values.end()); - } - return std::vector(values.begin(), values.end()); - } - - const std::type_info *type_of(const std::string &name) const final { - for(auto &options: options_) { - auto info = options->type_of(name); - if(info) return info; - } - return nullptr; - } - - size_t count_of(const std::string &name) const final { - for(auto &options: options_) { - auto info = options->type_of(name); - if(info) return options->count_of(name); - } - return 0; - } - - const void *get(const std::string &name) const final { - for(auto &options: options_) { - auto value = options->get(name); - if(value) return value; - } - return nullptr; - } - - void *get(const std::string &name) final { - for(auto &options: options_) { - auto value = options->get(name); - if(value) return value; - } - return nullptr; - } - - void set(const std::string &name, const void *value, size_t offset) final { - const auto safe_type = type_of(name); - if(!safe_type) return; - - // Set this property only where the child's type is the same as that - // which was returned from here for type_of. - for(auto &options: options_) { - const auto type = options->type_of(name); - if(!type) continue; - - if(*type == *safe_type) { - options->set(name, value, offset); - } - } - } - - private: - const std::vector &devices_; - std::vector> options_; +private: + const std::vector &devices_; + std::vector> options_; }; } diff --git a/Analyser/Dynamic/MultiMachine/Implementation/MultiConfigurable.hpp b/Analyser/Dynamic/MultiMachine/Implementation/MultiConfigurable.hpp index c18e039f0..07da52d3d 100644 --- a/Analyser/Dynamic/MultiMachine/Implementation/MultiConfigurable.hpp +++ b/Analyser/Dynamic/MultiMachine/Implementation/MultiConfigurable.hpp @@ -23,15 +23,15 @@ namespace Analyser::Dynamic { order of delivered messages. */ class MultiConfigurable: public Configurable::Device { - public: - MultiConfigurable(const std::vector> &machines); +public: + MultiConfigurable(const std::vector> &); - // Below is the standard Configurable::Device interface; see there for documentation. - void set_options(const std::unique_ptr &options) final; - std::unique_ptr get_options() final; + // Below is the standard Configurable::Device interface; see there for documentation. + void set_options(const std::unique_ptr &) final; + std::unique_ptr get_options() final; - private: - std::vector devices_; +private: + std::vector devices_; }; } diff --git a/Analyser/Dynamic/MultiMachine/Implementation/MultiJoystickMachine.cpp b/Analyser/Dynamic/MultiMachine/Implementation/MultiJoystickMachine.cpp index 7bf109e1b..4d3cf7404 100644 --- a/Analyser/Dynamic/MultiMachine/Implementation/MultiJoystickMachine.cpp +++ b/Analyser/Dynamic/MultiMachine/Implementation/MultiJoystickMachine.cpp @@ -15,52 +15,52 @@ using namespace Analyser::Dynamic; namespace { class MultiJoystick: public Inputs::Joystick { - public: - MultiJoystick(std::vector &machines, std::size_t index) { - for(const auto &machine: machines) { - const auto &joysticks = machine->get_joysticks(); - if(joysticks.size() >= index) { - joysticks_.push_back(joysticks[index].get()); - } +public: + MultiJoystick(std::vector &machines, const std::size_t index) { + for(const auto &machine: machines) { + const auto &joysticks = machine->get_joysticks(); + if(joysticks.size() >= index) { + joysticks_.push_back(joysticks[index].get()); } } + } - const std::vector &get_inputs() final { - if(inputs.empty()) { - for(const auto &joystick: joysticks_) { - std::vector joystick_inputs = joystick->get_inputs(); - for(const auto &input: joystick_inputs) { - if(std::find(inputs.begin(), inputs.end(), input) != inputs.end()) { - inputs.push_back(input); - } + const std::vector &get_inputs() final { + if(inputs.empty()) { + for(const auto &joystick: joysticks_) { + std::vector joystick_inputs = joystick->get_inputs(); + for(const auto &input: joystick_inputs) { + if(std::find(inputs.begin(), inputs.end(), input) != inputs.end()) { + inputs.push_back(input); } } } - - return inputs; } - void set_input(const Input &digital_input, bool is_active) final { - for(const auto &joystick: joysticks_) { - joystick->set_input(digital_input, is_active); - } - } + return inputs; + } - void set_input(const Input &digital_input, float value) final { - for(const auto &joystick: joysticks_) { - joystick->set_input(digital_input, value); - } + void set_input(const Input &digital_input, const bool is_active) final { + for(const auto &joystick: joysticks_) { + joystick->set_input(digital_input, is_active); } + } - void reset_all_inputs() final { - for(const auto &joystick: joysticks_) { - joystick->reset_all_inputs(); - } + void set_input(const Input &digital_input, const float value) final { + for(const auto &joystick: joysticks_) { + joystick->set_input(digital_input, value); } + } - private: - std::vector inputs; - std::vector joysticks_; + void reset_all_inputs() final { + for(const auto &joystick: joysticks_) { + joystick->reset_all_inputs(); + } + } + +private: + std::vector inputs; + std::vector joysticks_; }; } diff --git a/Analyser/Dynamic/MultiMachine/Implementation/MultiJoystickMachine.hpp b/Analyser/Dynamic/MultiMachine/Implementation/MultiJoystickMachine.hpp index 85fe40091..6a68fb2b5 100644 --- a/Analyser/Dynamic/MultiMachine/Implementation/MultiJoystickMachine.hpp +++ b/Analyser/Dynamic/MultiMachine/Implementation/MultiJoystickMachine.hpp @@ -22,14 +22,14 @@ namespace Analyser::Dynamic { order of delivered messages. */ class MultiJoystickMachine: public MachineTypes::JoystickMachine { - public: - MultiJoystickMachine(const std::vector> &machines); +public: + MultiJoystickMachine(const std::vector> &); - // Below is the standard JoystickMachine::Machine interface; see there for documentation. - const std::vector> &get_joysticks() final; + // Below is the standard JoystickMachine::Machine interface; see there for documentation. + const std::vector> &get_joysticks() final; - private: - std::vector> joysticks_; +private: + std::vector> joysticks_; }; } diff --git a/Analyser/Dynamic/MultiMachine/Implementation/MultiKeyboardMachine.cpp b/Analyser/Dynamic/MultiMachine/Implementation/MultiKeyboardMachine.cpp index d5a42ba5b..bb5cd0ce1 100644 --- a/Analyser/Dynamic/MultiMachine/Implementation/MultiKeyboardMachine.cpp +++ b/Analyser/Dynamic/MultiMachine/Implementation/MultiKeyboardMachine.cpp @@ -24,7 +24,7 @@ void MultiKeyboardMachine::clear_all_keys() { } } -void MultiKeyboardMachine::set_key_state(uint16_t key, bool is_pressed) { +void MultiKeyboardMachine::set_key_state(const uint16_t key, const bool is_pressed) { for(const auto &machine: machines_) { machine->set_key_state(key, is_pressed); } @@ -36,7 +36,7 @@ void MultiKeyboardMachine::type_string(const std::string &string) { } } -bool MultiKeyboardMachine::can_type(char c) const { +bool MultiKeyboardMachine::can_type(const char c) const { bool can_type = true; for(const auto &machine: machines_) { can_type &= machine->can_type(c); @@ -51,12 +51,20 @@ Inputs::Keyboard &MultiKeyboardMachine::get_keyboard() { MultiKeyboardMachine::MultiKeyboard::MultiKeyboard(const std::vector<::MachineTypes::KeyboardMachine *> &machines) : machines_(machines) { for(const auto &machine: machines_) { - observed_keys_.insert(machine->get_keyboard().observed_keys().begin(), machine->get_keyboard().observed_keys().end()); + observed_keys_.insert( + machine->get_keyboard().observed_keys().begin(), + machine->get_keyboard().observed_keys().end() + ); is_exclusive_ |= machine->get_keyboard().is_exclusive(); } } -bool MultiKeyboardMachine::MultiKeyboard::set_key_pressed(Key key, char value, bool is_pressed, bool is_repeat) { +bool MultiKeyboardMachine::MultiKeyboard::set_key_pressed( + const Key key, + const char value, + const bool is_pressed, + const bool is_repeat +) { bool was_consumed = false; for(const auto &machine: machines_) { was_consumed |= machine->get_keyboard().set_key_pressed(key, value, is_pressed, is_repeat); diff --git a/Analyser/Dynamic/MultiMachine/Implementation/MultiKeyboardMachine.hpp b/Analyser/Dynamic/MultiMachine/Implementation/MultiKeyboardMachine.hpp index 2bda83513..b04064020 100644 --- a/Analyser/Dynamic/MultiMachine/Implementation/MultiKeyboardMachine.hpp +++ b/Analyser/Dynamic/MultiMachine/Implementation/MultiKeyboardMachine.hpp @@ -23,34 +23,34 @@ namespace Analyser::Dynamic { order of delivered messages. */ class MultiKeyboardMachine: public MachineTypes::KeyboardMachine { - private: - std::vector machines_; +private: + std::vector machines_; - class MultiKeyboard: public Inputs::Keyboard { - public: - MultiKeyboard(const std::vector &machines); + class MultiKeyboard: public Inputs::Keyboard { + public: + MultiKeyboard(const std::vector &); - bool set_key_pressed(Key key, char value, bool is_pressed, bool is_repeat) final; - void reset_all_keys() final; - const std::set &observed_keys() const final; - bool is_exclusive() const final; + bool set_key_pressed(Key key, char value, bool is_pressed, bool is_repeat) final; + void reset_all_keys() final; + const std::set &observed_keys() const final; + bool is_exclusive() const final; - private: - const std::vector &machines_; - std::set observed_keys_; - bool is_exclusive_ = false; - }; - std::unique_ptr keyboard_; + private: + const std::vector &machines_; + std::set observed_keys_; + bool is_exclusive_ = false; + }; + std::unique_ptr keyboard_; - public: - MultiKeyboardMachine(const std::vector> &machines); +public: + MultiKeyboardMachine(const std::vector> &machines); - // Below is the standard KeyboardMachine::Machine interface; see there for documentation. - void clear_all_keys() final; - void set_key_state(uint16_t key, bool is_pressed) final; - void type_string(const std::string &) final; - bool can_type(char c) const final; - Inputs::Keyboard &get_keyboard() final; + // Below is the standard KeyboardMachine::Machine interface; see there for documentation. + void clear_all_keys() final; + void set_key_state(uint16_t key, bool is_pressed) final; + void type_string(const std::string &) final; + bool can_type(char c) const final; + Inputs::Keyboard &get_keyboard() final; }; } diff --git a/Analyser/Dynamic/MultiMachine/Implementation/MultiMediaTarget.hpp b/Analyser/Dynamic/MultiMachine/Implementation/MultiMediaTarget.hpp index 09a1f39d6..b1786441f 100644 --- a/Analyser/Dynamic/MultiMachine/Implementation/MultiMediaTarget.hpp +++ b/Analyser/Dynamic/MultiMachine/Implementation/MultiMediaTarget.hpp @@ -23,14 +23,14 @@ namespace Analyser::Dynamic { order of delivered messages. */ struct MultiMediaTarget: public MachineTypes::MediaTarget { - public: - MultiMediaTarget(const std::vector> &machines); +public: + MultiMediaTarget(const std::vector> &); - // Below is the standard MediaTarget::Machine interface; see there for documentation. - bool insert_media(const Analyser::Static::Media &media) final; + // Below is the standard MediaTarget::Machine interface; see there for documentation. + bool insert_media(const Analyser::Static::Media &) final; - private: - std::vector targets_; +private: + std::vector targets_; }; } diff --git a/Analyser/Dynamic/MultiMachine/Implementation/MultiProducer.cpp b/Analyser/Dynamic/MultiMachine/Implementation/MultiProducer.cpp index e9c614a83..c2c2c748a 100644 --- a/Analyser/Dynamic/MultiMachine/Implementation/MultiProducer.cpp +++ b/Analyser/Dynamic/MultiMachine/Implementation/MultiProducer.cpp @@ -53,7 +53,7 @@ void MultiInterface::perform_serial(const std::function> &machines, std::recursive_mutex &machines_mutex) : MultiInterface(machines, machines_mutex) { +MultiAudioProducer::MultiAudioProducer( + const std::vector> &machines, + std::recursive_mutex &machines_mutex +) : + MultiInterface(machines, machines_mutex) +{ speaker_ = MultiSpeaker::create(machines); } @@ -96,7 +101,7 @@ void MultiAudioProducer::did_change_machine_order() { // MARK: - MultiTimedMachine -void MultiTimedMachine::run_for(Time::Seconds duration) { +void MultiTimedMachine::run_for(const Time::Seconds duration) { perform_parallel([duration](::MachineTypes::TimedMachine *machine) { if(machine->get_confidence() >= 0.01f) machine->run_for(duration); }); diff --git a/Analyser/Dynamic/MultiMachine/Implementation/MultiProducer.hpp b/Analyser/Dynamic/MultiMachine/Implementation/MultiProducer.hpp index 35e153a84..a69291d00 100644 --- a/Analyser/Dynamic/MultiMachine/Implementation/MultiProducer.hpp +++ b/Analyser/Dynamic/MultiMachine/Implementation/MultiProducer.hpp @@ -21,88 +21,91 @@ namespace Analyser::Dynamic { template class MultiInterface { - public: - MultiInterface(const std::vector> &machines, std::recursive_mutex &machines_mutex) : - machines_(machines), machines_mutex_(machines_mutex), queues_(machines.size()) {} +public: + MultiInterface( + const std::vector> &machines, + std::recursive_mutex &machines_mutex + ) : + machines_(machines), machines_mutex_(machines_mutex), queues_(machines.size()) {} - protected: - /*! - Performs a parallel for operation across all machines, performing the supplied - function on each and returning only once all applications have completed. +protected: + /*! + Performs a parallel for operation across all machines, performing the supplied + function on each and returning only once all applications have completed. - No guarantees are extended as to which thread operations will occur on. - */ - void perform_parallel(const std::function &); + No guarantees are extended as to which thread operations will occur on. + */ + void perform_parallel(const std::function &); - /*! - Performs a serial for operation across all machines, performing the supplied - function on each on the calling thread. - */ - void perform_serial(const std::function &); + /*! + Performs a serial for operation across all machines, performing the supplied + function on each on the calling thread. + */ + void perform_serial(const std::function &); - protected: - const std::vector> &machines_; - std::recursive_mutex &machines_mutex_; +protected: + const std::vector> &machines_; + std::recursive_mutex &machines_mutex_; - private: - std::vector> queues_; +private: + std::vector> queues_; }; class MultiTimedMachine: public MultiInterface, public MachineTypes::TimedMachine { - public: - using MultiInterface::MultiInterface; +public: + using MultiInterface::MultiInterface; - /*! - Provides a mechanism by which a delegate can be informed each time a call to run_for has - been received. - */ - struct Delegate { - virtual void did_run_machines(MultiTimedMachine *) = 0; - }; - /// Sets @c delegate as the receiver of delegate messages. - void set_delegate(Delegate *delegate) { - delegate_ = delegate; - } + /*! + Provides a mechanism by which a delegate can be informed each time a call to run_for has + been received. + */ + struct Delegate { + virtual void did_run_machines(MultiTimedMachine *) = 0; + }; + /// Sets @c delegate as the receiver of delegate messages. + void set_delegate(Delegate *const delegate) { + delegate_ = delegate; + } - void run_for(Time::Seconds duration) final; + void run_for(Time::Seconds duration) final; - private: - void run_for(const Cycles) final {} - Delegate *delegate_ = nullptr; +private: + void run_for(Cycles) final {} + Delegate *delegate_ = nullptr; }; class MultiScanProducer: public MultiInterface, public MachineTypes::ScanProducer { - public: - using MultiInterface::MultiInterface; +public: + using MultiInterface::MultiInterface; - /*! - Informs the MultiScanProducer that the order of machines has changed; it - uses this as an opportunity to synthesis any CRTMachine::Machine::Delegate messages that - are necessary to bridge the gap between one machine and the next. - */ - void did_change_machine_order(); + /*! + Informs the MultiScanProducer that the order of machines has changed; it + uses this as an opportunity to synthesis any CRTMachine::Machine::Delegate messages that + are necessary to bridge the gap between one machine and the next. + */ + void did_change_machine_order(); - void set_scan_target(Outputs::Display::ScanTarget *scan_target) final; - Outputs::Display::ScanStatus get_scan_status() const final; + void set_scan_target(Outputs::Display::ScanTarget *) final; + Outputs::Display::ScanStatus get_scan_status() const final; - private: - Outputs::Display::ScanTarget *scan_target_ = nullptr; +private: + Outputs::Display::ScanTarget *scan_target_ = nullptr; }; class MultiAudioProducer: public MultiInterface, public MachineTypes::AudioProducer { - public: - MultiAudioProducer(const std::vector> &machines, std::recursive_mutex &machines_mutex); +public: + MultiAudioProducer(const std::vector> &, std::recursive_mutex &); - /*! - Informs the MultiAudio that the order of machines has changed; it - uses this as an opportunity to switch speaker delegates as appropriate. - */ - void did_change_machine_order(); + /*! + Informs the MultiAudio that the order of machines has changed; it + uses this as an opportunity to switch speaker delegates as appropriate. + */ + void did_change_machine_order(); - Outputs::Speaker::Speaker *get_speaker() final; + Outputs::Speaker::Speaker *get_speaker() final; - private: - MultiSpeaker *speaker_ = nullptr; +private: + MultiSpeaker *speaker_ = nullptr; }; /*! diff --git a/Analyser/Dynamic/MultiMachine/Implementation/MultiSpeaker.cpp b/Analyser/Dynamic/MultiMachine/Implementation/MultiSpeaker.cpp index 32882b9db..5bec5d698 100644 --- a/Analyser/Dynamic/MultiMachine/Implementation/MultiSpeaker.cpp +++ b/Analyser/Dynamic/MultiMachine/Implementation/MultiSpeaker.cpp @@ -28,7 +28,7 @@ MultiSpeaker::MultiSpeaker(const std::vector &speak } } -float MultiSpeaker::get_ideal_clock_rate_in_range(float minimum, float maximum) { +float MultiSpeaker::get_ideal_clock_rate_in_range(const float minimum, const float maximum) { float ideal = 0.0f; for(const auto &speaker: speakers_) { ideal += speaker->get_ideal_clock_rate_in_range(minimum, maximum); @@ -37,7 +37,7 @@ float MultiSpeaker::get_ideal_clock_rate_in_range(float minimum, float maximum) return ideal / float(speakers_.size()); } -void MultiSpeaker::set_computed_output_rate(float cycles_per_second, int buffer_size, bool stereo) { +void MultiSpeaker::set_computed_output_rate(const float cycles_per_second, const int buffer_size, const bool stereo) { stereo_output_ = stereo; for(const auto &speaker: speakers_) { speaker->set_computed_output_rate(cycles_per_second, buffer_size, stereo); @@ -54,13 +54,13 @@ bool MultiSpeaker::get_is_stereo() { return false; } -void MultiSpeaker::set_output_volume(float volume) { +void MultiSpeaker::set_output_volume(const float volume) { for(const auto &speaker: speakers_) { speaker->set_output_volume(volume); } } -void MultiSpeaker::speaker_did_complete_samples(Speaker *speaker, const std::vector &buffer) { +void MultiSpeaker::speaker_did_complete_samples(Speaker *const speaker, const std::vector &buffer) { auto delegate = delegate_.load(std::memory_order_relaxed); if(!delegate) return; { @@ -70,7 +70,7 @@ void MultiSpeaker::speaker_did_complete_samples(Speaker *speaker, const std::vec did_complete_samples(this, buffer, stereo_output_); } -void MultiSpeaker::speaker_did_change_input_clock(Speaker *speaker) { +void MultiSpeaker::speaker_did_change_input_clock(Speaker *const speaker) { auto delegate = delegate_.load(std::memory_order_relaxed); if(!delegate) return; { @@ -80,7 +80,7 @@ void MultiSpeaker::speaker_did_change_input_clock(Speaker *speaker) { delegate->speaker_did_change_input_clock(this); } -void MultiSpeaker::set_new_front_machine(::Machine::DynamicMachine *machine) { +void MultiSpeaker::set_new_front_machine(::Machine::DynamicMachine *const machine) { { std::lock_guard lock_guard(front_speaker_mutex_); front_speaker_ = machine->audio_producer()->get_speaker(); diff --git a/Analyser/Dynamic/MultiMachine/Implementation/MultiSpeaker.hpp b/Analyser/Dynamic/MultiMachine/Implementation/MultiSpeaker.hpp index 0a1990157..2e44e4de5 100644 --- a/Analyser/Dynamic/MultiMachine/Implementation/MultiSpeaker.hpp +++ b/Analyser/Dynamic/MultiMachine/Implementation/MultiSpeaker.hpp @@ -25,32 +25,32 @@ namespace Analyser::Dynamic { abreast of the current frontmost machine. */ class MultiSpeaker: public Outputs::Speaker::Speaker, Outputs::Speaker::Speaker::Delegate { - public: - /*! - Provides a construction mechanism that may return nullptr, in the case that all included - machines return nullptr as their speaker. - */ - static MultiSpeaker *create(const std::vector> &machines); +public: + /*! + Provides a construction mechanism that may return nullptr, in the case that all included + machines return nullptr as their speaker. + */ + static MultiSpeaker *create(const std::vector> &); - /// This class requires the caller to nominate changes in the frontmost machine. - void set_new_front_machine(::Machine::DynamicMachine *machine); + /// This class requires the caller to nominate changes in the frontmost machine. + void set_new_front_machine(::Machine::DynamicMachine *); - // Below is the standard Outputs::Speaker::Speaker interface; see there for documentation. - float get_ideal_clock_rate_in_range(float minimum, float maximum) override; - void set_computed_output_rate(float cycles_per_second, int buffer_size, bool stereo) override; - bool get_is_stereo() override; - void set_output_volume(float) override; + // Below is the standard Outputs::Speaker::Speaker interface; see there for documentation. + float get_ideal_clock_rate_in_range(float minimum, float maximum) override; + void set_computed_output_rate(float cycles_per_second, int buffer_size, bool stereo) override; + bool get_is_stereo() override; + void set_output_volume(float) override; - private: - void speaker_did_complete_samples(Speaker *speaker, const std::vector &buffer) final; - void speaker_did_change_input_clock(Speaker *speaker) final; - MultiSpeaker(const std::vector &speakers); +private: + void speaker_did_complete_samples(Speaker *speaker, const std::vector &buffer) final; + void speaker_did_change_input_clock(Speaker *speaker) final; + MultiSpeaker(const std::vector &speakers); - std::vector speakers_; - Outputs::Speaker::Speaker *front_speaker_ = nullptr; - std::mutex front_speaker_mutex_; + std::vector speakers_; + Outputs::Speaker::Speaker *front_speaker_ = nullptr; + std::mutex front_speaker_mutex_; - bool stereo_output_ = false; + bool stereo_output_ = false; }; } diff --git a/Analyser/Dynamic/MultiMachine/MultiMachine.cpp b/Analyser/Dynamic/MultiMachine/MultiMachine.cpp index 2f20b4a30..e45ee8d38 100644 --- a/Analyser/Dynamic/MultiMachine/MultiMachine.cpp +++ b/Analyser/Dynamic/MultiMachine/MultiMachine.cpp @@ -27,7 +27,8 @@ MultiMachine::MultiMachine(std::vector> &&machin audio_producer_(machines_, machines_mutex_), joystick_machine_(machines_), keyboard_machine_(machines_), - media_target_(machines_) { + media_target_(machines_) +{ timed_machine_.set_delegate(this); } @@ -35,13 +36,13 @@ Activity::Source *MultiMachine::activity_source() { return nullptr; // TODO } -#define Provider(type, name, member) \ - type *MultiMachine::name() { \ - if(has_picked_) { \ +#define Provider(type, name, member) \ + type *MultiMachine::name() { \ + if(has_picked_) { \ return machines_.front()->name(); \ - } else { \ - return &member; \ - } \ + } else { \ + return &member; \ + } \ } Provider(Configurable::Device, configurable_device, configurable_) diff --git a/Analyser/Dynamic/MultiMachine/MultiMachine.hpp b/Analyser/Dynamic/MultiMachine/MultiMachine.hpp index 2b42b4f97..0dcdd965a 100644 --- a/Analyser/Dynamic/MultiMachine/MultiMachine.hpp +++ b/Analyser/Dynamic/MultiMachine/MultiMachine.hpp @@ -38,44 +38,44 @@ namespace Analyser::Dynamic { the others in the set, that machine stops running. */ class MultiMachine: public ::Machine::DynamicMachine, public MultiTimedMachine::Delegate { - public: - /*! - Allows a potential MultiMachine creator to enquire as to whether there's any benefit in - requesting this class as a proxy. +public: + /*! + Allows a potential MultiMachine creator to enquire as to whether there's any benefit in + requesting this class as a proxy. - @returns @c true if the multimachine would discard all but the first machine in this list; - @c false otherwise. - */ - static bool would_collapse(const std::vector> &machines); - MultiMachine(std::vector> &&machines); + @returns @c true if the multimachine would discard all but the first machine in this list; + @c false otherwise. + */ + static bool would_collapse(const std::vector> &); + MultiMachine(std::vector> &&); - Activity::Source *activity_source() final; - Configurable::Device *configurable_device() final; - MachineTypes::TimedMachine *timed_machine() final; - MachineTypes::ScanProducer *scan_producer() final; - MachineTypes::AudioProducer *audio_producer() final; - MachineTypes::JoystickMachine *joystick_machine() final; - MachineTypes::KeyboardMachine *keyboard_machine() final; - MachineTypes::MouseMachine *mouse_machine() final; - MachineTypes::MediaTarget *media_target() final; - void *raw_pointer() final; + Activity::Source *activity_source() final; + Configurable::Device *configurable_device() final; + MachineTypes::TimedMachine *timed_machine() final; + MachineTypes::ScanProducer *scan_producer() final; + MachineTypes::AudioProducer *audio_producer() final; + MachineTypes::JoystickMachine *joystick_machine() final; + MachineTypes::KeyboardMachine *keyboard_machine() final; + MachineTypes::MouseMachine *mouse_machine() final; + MachineTypes::MediaTarget *media_target() final; + void *raw_pointer() final; - private: - void did_run_machines(MultiTimedMachine *) final; +private: + void did_run_machines(MultiTimedMachine *) final; - std::vector> machines_; - std::recursive_mutex machines_mutex_; + std::vector> machines_; + std::recursive_mutex machines_mutex_; - MultiConfigurable configurable_; - MultiTimedMachine timed_machine_; - MultiScanProducer scan_producer_; - MultiAudioProducer audio_producer_; - MultiJoystickMachine joystick_machine_; - MultiKeyboardMachine keyboard_machine_; - MultiMediaTarget media_target_; + MultiConfigurable configurable_; + MultiTimedMachine timed_machine_; + MultiScanProducer scan_producer_; + MultiAudioProducer audio_producer_; + MultiJoystickMachine joystick_machine_; + MultiKeyboardMachine keyboard_machine_; + MultiMediaTarget media_target_; - void pick_first(); - bool has_picked_ = false; + void pick_first(); + bool has_picked_ = false; }; }