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 <QComboBox>
11 #include <QFormLayout>
12 #include <QLabel>
13 #include <QSpinBox>
14 namespace Audio
15 {
16 
17 class DummyFactory final : public AudioFactory
18 {
19  SCORE_CONCRETE("13dabcc3-9cda-422f-a8c7-5fef5c220677")
20 public:
21  ~DummyFactory() override { }
22  bool available() const noexcept override { return true; }
23  void
24  initialize(Audio::Settings::Model& set, const score::ApplicationContext& ctx) override
25  {
26  }
27 
28  QString prettyName() const override { return QObject::tr("Dummy (No audio)"); };
29  std::shared_ptr<ossia::audio_engine> make_engine(
30  const Audio::Settings::Model& set, const score::ApplicationContext& ctx) override
31  {
32  return std::make_shared<ossia::dummy_engine>(set.getRate(), set.getBufferSize());
33  }
34 
35  static void updateLabel(QLabel& l, int bs, int rate)
36  {
37  l.setText(QString{"%1 ms (%2 hz)"}
38  .arg(1e3 * double(bs) / rate, 0, 'f', 3)
39  .arg(rate / double(bs), 0, 'f', 3));
40  }
41 
42  QWidget* make_settings(
44  score::SettingsCommandDispatcher& m_disp, QWidget* parent) override
45  {
46  auto w = new QWidget{parent};
47  auto lay = new QFormLayout{w};
48 
49  auto timeLabel = new QLabel;
50  updateLabel(*timeLabel, m.getBufferSize(), m.getRate());
51 
52  lay->addRow(QObject::tr("Tick duration"), timeLabel);
53  auto buffer_sb = new QSpinBox{};
54  {
55  buffer_sb->setObjectName("BufferSize");
56  lay->addRow(QObject::tr("Buffer size"), buffer_sb);
57  buffer_sb->setRange(1, 10000);
58  buffer_sb->setValue(m.getBufferSize());
59  }
60 
61  auto rate_cb = addSampleRateWidget(*w, m, v);
62  auto update_label = [timeLabel, rate_cb, buffer_sb] {
63  updateLabel(*timeLabel, buffer_sb->value(), rate_cb->currentText().toInt());
64  };
65  QObject::connect(
66  buffer_sb, &QSpinBox::valueChanged, w, [buffer_sb, &v, update_label] {
67  v.BufferSizeChanged(buffer_sb->value());
68  update_label();
69  });
70  QObject::connect(
71  rate_cb, &QComboBox::currentIndexChanged, &v, [&v, rate_cb, update_label] {
72  v.RateChanged(rate_cb->currentText().toInt());
73  update_label();
74  });
75 
76  con(m, &Audio::Settings::Model::BufferSizeChanged, timeLabel, update_label);
77  con(m, &Audio::Settings::Model::RateChanged, timeLabel, update_label);
78 
79  return w;
80  }
81 };
82 }
Definition: AudioInterface.hpp:28
Definition: DummyInterface.hpp:18
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