DummyInterface.hpp
1 #pragma once
2 #include <Audio/AudioInterface.hpp>
3 #include <Audio/Settings/Model.hpp>
4 #include <Audio/Settings/View.hpp>
5 
6 #include <score/tools/Bind.hpp>
7 
8 #include <ossia/audio/dummy_protocol.hpp>
9 
10 #include <QFormLayout>
11 #include <QLabel>
12 #include <QSlider>
13 namespace Audio
14 {
15 
16 class DummyFactory final : public AudioFactory
17 {
18  SCORE_CONCRETE("13dabcc3-9cda-422f-a8c7-5fef5c220677")
19 public:
20  ~DummyFactory() override { }
21  bool available() const noexcept override { return true; }
22  void
23  initialize(Audio::Settings::Model& set, const score::ApplicationContext& ctx) override
24  {
25  }
26 
27  QString prettyName() const override { return QObject::tr("Dummy (No audio)"); };
28  std::shared_ptr<ossia::audio_engine> make_engine(
29  const Audio::Settings::Model& set, const score::ApplicationContext& ctx) override
30  {
31  return std::make_shared<ossia::dummy_engine>(set.getRate(), set.getBufferSize());
32  }
33 
34  static void updateLabel(QLabel& l, int bs, int rate)
35  {
36  l.setText(QString{"%1 ms"}.arg(1e3 * double(bs) / rate, 0, 'f', 3));
37  }
38 
39  QWidget* make_settings(
41  score::SettingsCommandDispatcher& m_disp, QWidget* parent) override
42  {
43  auto w = new QWidget{parent};
44  auto lay = new QFormLayout{w};
45 
46  auto timeLabel = new QLabel;
47  con(m, &Audio::Settings::Model::BufferSizeChanged, timeLabel,
48  [=, &m](int b) { updateLabel(*timeLabel, b, m.getRate()); });
49  con(m, &Audio::Settings::Model::RateChanged, timeLabel,
50  [=, &m](int r) { updateLabel(*timeLabel, m.getBufferSize(), r); });
51 
52  updateLabel(*timeLabel, m.getBufferSize(), m.getRate());
53 
54  lay->addRow(QObject::tr("Tick duration"), timeLabel);
55  {
56  auto cb = new QSlider{Qt::Horizontal};
57  cb->setObjectName("BufferSize");
58  lay->addRow(QObject::tr("Buffer size"), cb);
59  cb->setRange(16, 10000);
60  cb->setValue(m.getBufferSize());
61  QObject::connect(cb, &QSlider::valueChanged, w, [cb, &v, &m, timeLabel](int i) {
62  v.BufferSizeChanged(cb->value());
63  updateLabel(*timeLabel, i, m.getRate());
64  });
65  }
66 
67  addSampleRateWidget(*w, m, v);
68 
69  return w;
70  }
71 };
72 }
Definition: AudioInterface.hpp:28
Definition: DummyInterface.hpp:17
Definition: score-plugin-audio/Audio/Settings/Model.hpp:22
Definition: score-plugin-audio/Audio/Settings/View.hpp:19
Definition: SettingsCommandDispatcher.hpp:10
Used to access all the application-wide state and structures.
Definition: ApplicationContext.hpp:24