Loading...
Searching...
No Matches
AudioFileChooserWidget.hpp
1#pragma once
2
3#include <Process/Dataflow/ControlWidgets.hpp>
4
5#include <Media/MediaFileHandle.hpp>
6
7#include <score_plugin_media_export.h>
8namespace Media::Sound
9{
10struct WaveformComputer;
11}
12namespace score
13{
14
15class SCORE_PLUGIN_MEDIA_EXPORT QGraphicsWaveformButton final
16 : public QObject
17 , public QGraphicsItem
18{
20
21 bool m_pressed{};
22
23public:
24 QGraphicsWaveformButton(QGraphicsItem* parent);
26
27 void pressed() E_SIGNAL(SCORE_PLUGIN_MEDIA_EXPORT, pressed);
28 void dropped(QString filename) E_SIGNAL(SCORE_PLUGIN_MEDIA_EXPORT, dropped, filename);
29 void bang();
30
31 const QString& text() const noexcept { return m_string; }
32 void setFile(const QString& s);
33 QRectF boundingRect() const override;
34
35private:
36 void on_finishedDecoding();
37 void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
38 void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override;
39 void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override;
40
41 void dragEnterEvent(QGraphicsSceneDragDropEvent* event) override;
42 void dragMoveEvent(QGraphicsSceneDragDropEvent* event) override;
43 void dragLeaveEvent(QGraphicsSceneDragDropEvent* event) override;
44 void dropEvent(QGraphicsSceneDragDropEvent* event) override;
45
46 void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
47 final override;
48 QRectF m_rect;
49 QString m_string;
50 std::shared_ptr<Media::AudioFile> m_file;
51 QVector<QImage*> m_images;
53};
54
55}
56namespace Media
57{
58
59struct AudioFileChooser : WidgetFactory::FileChooser
60{
61 template <typename T, typename Control_T>
62 static score::QGraphicsWaveformButton* make_item(
63 const T& slider, Control_T& inlet, const score::DocumentContext& ctx,
64 QGraphicsItem* parent, QObject* context)
65 {
66 auto bt = new score::QGraphicsWaveformButton{parent};
67 auto on_open = [&inlet, &ctx] {
68 auto filename
69 = QFileDialog::getOpenFileName(nullptr, "Open File", {}, inlet.filters());
70 if(filename.isEmpty())
71 return;
72
73 CommandDispatcher<>{ctx.commandStack}
74 .submit<WidgetFactory::SetControlValue<Control_T>>(
75 inlet, filename.toStdString());
76 };
77 auto on_set = [&inlet, &ctx](const QString& filename) {
78 if(filename.isEmpty())
79 return;
80
81 CommandDispatcher<>{ctx.commandStack}
82 .submit<WidgetFactory::SetControlValue<Control_T>>(
83 inlet, filename.toStdString());
84 };
85 QObject::connect(bt, &score::QGraphicsWaveformButton::pressed, &inlet, on_open);
86 QObject::connect(bt, &score::QGraphicsWaveformButton::dropped, &inlet, on_set);
87 auto set = [=](const ossia::value& val) {
88 auto str = QString::fromStdString(ossia::convert<std::string>(val));
89 if(str != bt->text())
90 {
91 if(!str.isEmpty())
92 bt->setFile(str);
93 else
94 bt->setFile({});
95 }
96 };
97
98 set(slider.value());
99 QObject::connect(&inlet, &Control_T::valueChanged, bt, set);
100
101 return bt;
102 }
103};
104}
The CommandDispatcher class.
Definition CommandDispatcher.hpp:13
Definition AudioFileChooserWidget.hpp:18
Base toolkit upon which the software is built.
Definition Application.cpp:90
Definition WaveformComputer.hpp:55
Definition plugins/score-lib-process/Process/Dataflow/ControlWidgets.hpp:979
Definition DocumentContext.hpp:18