1 |
/*************************************************************************** |
2 |
* * |
3 |
* Copyright (C) 2008 - 2012 Andreas Persson * |
4 |
* * |
5 |
* This program is free software; you can redistribute it and/or modify * |
6 |
* it under the terms of the GNU General Public License as published by * |
7 |
* the Free Software Foundation; either version 2 of the License, or * |
8 |
* (at your option) any later version. * |
9 |
* * |
10 |
* This program is distributed in the hope that it will be useful, * |
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
13 |
* GNU General Public License for more details. * |
14 |
* * |
15 |
* You should have received a copy of the GNU General Public License * |
16 |
* along with this program; if not, write to the Free Software * |
17 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, * |
18 |
* MA 02110-1301 USA * |
19 |
***************************************************************************/ |
20 |
|
21 |
#ifndef LS_PLUGINLV2_H |
22 |
#define LS_PLUGINLV2_H |
23 |
|
24 |
#include "../../drivers/Plugin.h" |
25 |
|
26 |
#include <lv2/lv2plug.in/ns/lv2core/lv2.h> |
27 |
#include <lv2/lv2plug.in/ns/ext/atom/atom.h> |
28 |
#include <lv2/lv2plug.in/ns/ext/state/state.h> |
29 |
#include <lv2/lv2plug.in/ns/ext/urid/urid.h> |
30 |
|
31 |
namespace { |
32 |
|
33 |
class PluginLv2 : public LinuxSampler::Plugin { |
34 |
public: |
35 |
PluginLv2(const LV2_Descriptor* Descriptor, |
36 |
double SampleRate, const char* BundlePath, |
37 |
const LV2_Feature* const* Features); |
38 |
~PluginLv2(); |
39 |
void ConnectPort(uint32_t Port, void* DataLocation); |
40 |
void Activate(); |
41 |
void Run(uint32_t SampleCount); |
42 |
void Deactivate(); |
43 |
LV2_State_Status Save(LV2_State_Store_Function store, void* data, |
44 |
uint32_t flags, const LV2_Feature* const* features); |
45 |
LV2_State_Status Restore(LV2_State_Retrieve_Function retrieve, void* data, |
46 |
uint32_t flags, const LV2_Feature* const* features); |
47 |
|
48 |
protected: |
49 |
virtual String PathToState(const String& string); |
50 |
virtual String PathFromState(const String& string); |
51 |
|
52 |
private: |
53 |
LV2_URID uri_to_id(const char* uri) { |
54 |
return UriMap->map(UriMap->handle, uri); |
55 |
} |
56 |
|
57 |
void SetStateFeatures(const LV2_Feature* const* Features); |
58 |
|
59 |
float** Out; |
60 |
LV2_Atom_Sequence* MidiBuf; |
61 |
LV2_URID_Map* UriMap; |
62 |
LV2_URID MidiEventType; |
63 |
LV2_State_Map_Path* MapPath; |
64 |
LV2_State_Make_Path* MakePath; |
65 |
|
66 |
String DefaultState; |
67 |
}; |
68 |
|
69 |
class PluginInfo { |
70 |
public: |
71 |
static const LV2_Descriptor* Lv2Descriptor() { |
72 |
return &Instance.Lv2; |
73 |
} |
74 |
static const LV2_State_Interface* Lv2StateInterface() { |
75 |
return &Instance.StateInterface; |
76 |
} |
77 |
private: |
78 |
LV2_Descriptor Lv2; |
79 |
LV2_State_Interface StateInterface; |
80 |
|
81 |
PluginInfo(); |
82 |
static PluginInfo Instance; |
83 |
}; |
84 |
|
85 |
extern "C" { |
86 |
static LV2_Handle instantiate(const LV2_Descriptor* descriptor, |
87 |
double sample_rate, const char* bundle_path, |
88 |
const LV2_Feature* const* features); |
89 |
static void connect_port(LV2_Handle instance, uint32_t port, |
90 |
void* data_location); |
91 |
static void activate(LV2_Handle instance); |
92 |
static void run(LV2_Handle instance, uint32_t sample_count); |
93 |
static void deactivate(LV2_Handle instance); |
94 |
static void cleanup(LV2_Handle instance); |
95 |
static const void* extension_data(const char* uri); |
96 |
|
97 |
static LV2_State_Status save(LV2_Handle handle, |
98 |
LV2_State_Store_Function store, |
99 |
LV2_State_Handle state, uint32_t flags, |
100 |
const LV2_Feature* const* features); |
101 |
|
102 |
static LV2_State_Status restore(LV2_Handle handle, |
103 |
LV2_State_Retrieve_Function retrieve, |
104 |
LV2_State_Handle state, uint32_t flags, |
105 |
const LV2_Feature* const* features); |
106 |
} |
107 |
} |
108 |
|
109 |
#endif |