score-plugin-faust/Faust/Library.hpp
1 #pragma once
2 #include <Process/Drop/ProcessDropHandler.hpp>
3 
4 #include <Library/LibraryInterface.hpp>
5 #include <Library/LibrarySettings.hpp>
6 #include <Library/ProcessesItemModel.hpp>
7 
8 #include <QFileInfo>
9 #include <QTimer>
10 
11 #include <Faust/EffectModel.hpp>
12 
13 namespace Faust
14 {
15 class LibraryHandler final
16  : public QObject
18 {
19  SCORE_CONCRETE("e274ee7b-9142-43a0-9d77-9286a63af4d9")
20 
21  QSet<QString> acceptedFiles() const noexcept override { return {"dsp"}; }
22 
23  static inline const QRegularExpression nameExpr{
24  R"_(declare name "([a-zA-Z0-9_\-]+)";)_"};
25  static inline const QRegularExpression authorExpr{
26  R"_(declare author "([a-zA-Z0-9_\-]+)";)_"};
27  static inline const QRegularExpression descExpr{
28  R"_(declare description "([a-zA-Z0-9.<>\‍(\):/~, _\-]+)";)_"};
29 
30  Library::Subcategories categories;
31 
32  void setup(Library::ProcessesItemModel& model, const score::GUIApplicationContext& ctx)
33  override
34  {
35  // TODO relaunch whenever library path changes...
36  const auto& key = FaustEffectFactory{}.concreteKey();
37  QModelIndex node = model.find(key);
38  if(node == QModelIndex{})
39  return;
40 
41  categories.init(node, ctx);
42  }
43 
44  void addPath(std::string_view path) override
45  {
46  score::PathInfo file{path};
47  if(file.fileName != "layout.dsp")
48  registerDSP(file);
49  }
50 
51  void registerDSP(const score::PathInfo& file)
52  {
54  pdata.prettyName
55  = QString::fromUtf8(file.completeBaseName.data(), file.completeBaseName.size());
57  pdata.customData
58  = QString::fromUtf8(file.absoluteFilePath.data(), file.absoluteFilePath.size());
59  pdata.author = "Faust standard library";
60 
61  {
62  auto matches = nameExpr.match(pdata.customData);
63  if(matches.hasMatch())
64  {
65  pdata.prettyName = matches.captured(1);
66  }
67  }
68  {
69  auto matches = authorExpr.match(pdata.customData);
70  if(matches.hasMatch())
71  {
72  pdata.author = matches.captured(1);
73  }
74  }
75  {
76  auto matches = descExpr.match(pdata.customData);
77  if(matches.hasMatch())
78  {
79  pdata.description = matches.captured(1);
80  }
81  }
82 
83  categories.add(file, std::move(pdata));
84  }
85 };
86 
88 {
89  SCORE_CONCRETE("1e83a000-5aca-4427-8de5-1dc7a390e201")
90 
91  QSet<QString> fileExtensions() const noexcept override { return {"dsp"}; }
92 
93  void dropPath(
94  std::vector<ProcessDrop>& vec, const score::FilePath& filename,
95  const score::DocumentContext& ctx) const noexcept override
96  {
99 
100  // TODO use faust-provided name
101  p.creation.prettyName = filename.basename;
102  p.creation.customData = filename.relative;
103 
104  vec.push_back(std::move(p));
105  }
106 };
107 
108 }
Definition: score-plugin-faust/Faust/Library.hpp:88
Definition: score-plugin-faust/Faust/Library.hpp:18
Definition: LibraryInterface.hpp:22
Definition: ProcessesItemModel.hpp:45
Definition: EffectFactory.hpp:14
Definition: ProcessDropHandler.hpp:25
Definition: ProcessesItemModel.hpp:32
Definition: ProcessesItemModel.hpp:86
Static metadata implementation.
Definition: lib/score/tools/Metadata.hpp:36
Definition: ProcessDropHandler.hpp:29
Definition: ObjectMatches.hpp:6
Definition: DocumentContext.hpp:18
Definition: FilePath.hpp:25
Specializes ApplicationContext with the QMainWindow.
Definition: GUIApplicationContext.hpp:15
Definition: File.hpp:20