2018-02-18 20:23:15 +00:00
|
|
|
//
|
|
|
|
// MultiSpeaker.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 18/02/2018.
|
|
|
|
// Copyright © 2018 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef MultiSpeaker_hpp
|
|
|
|
#define MultiSpeaker_hpp
|
|
|
|
|
|
|
|
#include "../../../../Machines/DynamicMachine.hpp"
|
|
|
|
#include "../../../../Outputs/Speaker/Speaker.hpp"
|
|
|
|
|
|
|
|
#include <memory>
|
2018-02-18 21:37:07 +00:00
|
|
|
#include <mutex>
|
2018-02-18 20:23:15 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace Analyser {
|
|
|
|
namespace Dynamic {
|
|
|
|
|
2018-02-19 21:03:17 +00:00
|
|
|
/*!
|
|
|
|
Provides a class that multiplexes calls to and from Outputs::Speaker::Speaker in order
|
|
|
|
transparently to connect a single caller to multiple destinations.
|
|
|
|
|
|
|
|
Makes a static internal copy of the list of machines; expects the owner to keep it
|
|
|
|
abreast of the current frontmost machine.
|
|
|
|
*/
|
2018-02-18 20:23:15 +00:00
|
|
|
class MultiSpeaker: public Outputs::Speaker::Speaker, Outputs::Speaker::Speaker::Delegate {
|
|
|
|
public:
|
2018-02-19 21:03:17 +00:00
|
|
|
/*!
|
|
|
|
Provides a construction mechanism that may return nullptr, in the case that all included
|
|
|
|
machines return nullptr as their speaker.
|
|
|
|
*/
|
2018-02-18 20:23:15 +00:00
|
|
|
static MultiSpeaker *create(const std::vector<std::unique_ptr<::Machine::DynamicMachine>> &machines);
|
|
|
|
|
2018-02-19 21:03:17 +00:00
|
|
|
/// This class requires the caller to nominate changes in the frontmost machine.
|
2018-02-18 20:23:15 +00:00
|
|
|
void set_new_front_machine(::Machine::DynamicMachine *machine);
|
|
|
|
|
2018-02-19 21:03:17 +00:00
|
|
|
// Below is the standard Outputs::Speaker::Speaker interface; see there for documentation.
|
2018-02-18 20:23:15 +00:00
|
|
|
float get_ideal_clock_rate_in_range(float minimum, float maximum);
|
|
|
|
void set_output_rate(float cycles_per_second, int buffer_size);
|
|
|
|
void set_delegate(Outputs::Speaker::Speaker::Delegate *delegate);
|
|
|
|
|
|
|
|
private:
|
2018-02-19 21:03:17 +00:00
|
|
|
void speaker_did_complete_samples(Speaker *speaker, const std::vector<int16_t> &buffer);
|
|
|
|
MultiSpeaker(const std::vector<Outputs::Speaker::Speaker *> &speakers);
|
|
|
|
|
2018-02-18 20:23:15 +00:00
|
|
|
std::vector<Outputs::Speaker::Speaker *> speakers_;
|
|
|
|
Outputs::Speaker::Speaker *front_speaker_ = nullptr;
|
|
|
|
Outputs::Speaker::Speaker::Delegate *delegate_ = nullptr;
|
2018-02-18 21:37:07 +00:00
|
|
|
std::mutex front_speaker_mutex_;
|
2018-02-18 20:23:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* MultiSpeaker_hpp */
|