PatternLibrary.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 <Patternist/Commands/PatternProperties.hpp>
12 #include <Patternist/PatternFactory.hpp>
13 #include <Patternist/PatternModel.hpp>
14 #include <Patternist/PatternParsing.hpp>
15 
16 namespace Patternist
17 {
18 class LibraryHandler final
19  : public QObject
21 {
22  SCORE_CONCRETE("81375b6a-2172-49e5-bbf9-0d2eecc30677")
23 
24  QSet<QString> acceptedFiles() const noexcept override { return {"pat"}; }
25 
26  Library::Subcategories categories;
27 
28  void setup(Library::ProcessesItemModel& model, const score::GUIApplicationContext& ctx)
29  override
30  {
31  // TODO relaunch whenever library path changes...
33  QModelIndex node = model.find(key);
34  if(node == QModelIndex{})
35  return;
36 
37  categories.init(node, ctx);
38  }
39 
40  void addPath(std::string_view path) override
41  {
42  QFileInfo file{QString::fromUtf8(path.data(), path.length())};
44  pdata.prettyName = file.completeBaseName();
46  pdata.author = "Drum Patterns";
47  pdata.customData = file.absoluteFilePath();
48  categories.add(file, std::move(pdata));
49  }
50 };
51 
53 {
54  SCORE_CONCRETE("6ba4246f-45cd-49f5-a103-8718ec52576b")
55 
56  QSet<QString> fileExtensions() const noexcept override { return {"pat"}; }
57 
58  void dropData(
59  std::vector<ProcessDrop>& vec, const DroppedFile& data,
60  const score::DocumentContext& ctx) const noexcept override
61  {
62  const auto& [filename, content] = data;
63 
64  auto pat = parsePattern(content);
65  if(pat.lanes.size() > 0)
66  {
69  p.creation.prettyName = filename.basename;
70  p.setup = [pat = std::move(pat)](
71  Process::ProcessModel& m, score::Dispatcher& disp) mutable {
72  auto& proc = static_cast<Patternist::ProcessModel&>(m);
73  disp.submit(new Patternist::UpdatePattern{proc, 0, std::move(pat)});
74  };
75  vec.push_back(std::move(p));
76  }
77  }
78 };
79 
80 }
Definition: LibraryInterface.hpp:22
Definition: ProcessesItemModel.hpp:45
Definition: PatternLibrary.hpp:53
Definition: PatternLibrary.hpp:21
Definition: PatternModel.hpp:36
Definition: PatternProperties.hpp:16
Definition: ProcessDropHandler.hpp:25
The Process class.
Definition: score-lib-process/Process/Process.hpp:61
Definition: ProcessesItemModel.hpp:32
Definition: ProcessesItemModel.hpp:86
Static metadata implementation.
Definition: lib/score/tools/Metadata.hpp:36
Definition: ProcessDropHandler.hpp:36
Definition: ProcessDropHandler.hpp:29
Definition: RuntimeDispatcher.hpp:7
Definition: DocumentContext.hpp:18
Specializes ApplicationContext with the QMainWindow.
Definition: GUIApplicationContext.hpp:15