forked from NeuroNetMem/PythonPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPythonPlugin.h
More file actions
196 lines (151 loc) · 5.4 KB
/
Copy pathPythonPlugin.h
File metadata and controls
196 lines (151 loc) · 5.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*
------------------------------------------------------------------
Python Plugin
Copyright (C) 2016 FP Battaglia
based on
Open Ephys GUI
Copyright (C) 2013, 2015 Open Ephys
------------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
==============================================================================
PythonPlugin.h
Created: 13 Jun 2014 5:56:17pm
Author: fpbatta
==============================================================================
*/
#ifndef __PYTHONPLUGIN_H
#define __PYTHONPLUGIN_H
#include <Python.h>
#if PY_MAJOR_VERSION>=3
#define DL_IMPORT PyAPI_FUNC
#endif
#ifndef __PYX_EXTERN_C
#ifdef __cplusplus
#define __PYX_EXTERN_C extern "C"
#else
#define __PYX_EXTERN_C extern
#endif
#endif
#include "PythonParamConfig.h"
#include "PythonEvent.h"
//extern "C" typedef void (*initfunc_t)(void);
#if PY_MAJOR_VERSION>=3
typedef PyObject * (*initfunc_t)(void);
#else
typedef PyMODINIT_FUNC (*initfunc_t)(void);
#endif
typedef DL_IMPORT(void) (*startupfunc_t)(float); // passes the sampling rate
typedef DL_IMPORT(void) (*pluginfunc_t)(float *, int, int, int, PythonEvent *);
typedef DL_IMPORT(int) (*isreadyfunc_t)(void);
typedef DL_IMPORT(int) (*getparamnumfunc_t)(void);
typedef DL_IMPORT(void) (*getparamconfigfunc_t)(struct ParamConfig*);
typedef DL_IMPORT(void) (*setintparamfunc_t)(char*, int);
typedef DL_IMPORT(void) (*setfloatparamfunc_t)(char*, float);
typedef DL_IMPORT(int) (*getintparamfunc_t)(char*);
typedef DL_IMPORT(float) (*getfloatparamfunc_t)(char*);
#ifdef _WIN32
#include <Windows.h>
#endif
#include <ProcessorHeaders.h>
//=============================================================================
/*
*/
class PythonPlugin : public GenericProcessor
{
public:
/** The class constructor, used to initialize any members. */
PythonPlugin(const String &processorName = "Python Plugin");
/** The class destructor, used to deallocate memory */
~PythonPlugin();
/** Determines whether the processor is treated as a source. */
virtual bool isSource()
{
return false;
}
/** Determines whether the processor is treated as a sink. */
virtual bool isSink()
{
return false;
}
/** Defines the functionality of the processor.
The process method is called every time a new data buffer is available.
Processors can either use this method to add new data, manipulate existing
data, or send data to an external target (such as a display or other hardware).
Continuous signals arrive in the "buffer" variable, event data (such as TTLs
and spikes) is contained in the "events" variable, and "nSamples" holds the
number of continous samples in the current buffer (which may differ from the
size of the buffer).
*/
virtual void process(AudioSampleBuffer& buffer /* , MidiBuffer& events */);
/** Any variables used by the "process" function _must_ be modified only through
this method while data acquisition is active. If they are modified in any
other way, the application will crash. */
void setParameter(int parameterIndex, float newValue);
AudioProcessorEditor* createEditor();
bool hasEditor() const
{
return true;
}
void updateSettings();
void createEventChannels();
void setFile(String fullpath);
String getFile();
bool isReady();
void setIntPythonParameter(String name, int value);
void setFloatPythonParameter(String name, float value);
int getNumPythonParams()
{
return numPythonParams;
}
ParamConfig *getPythonParams() const
{
return params;
}
Component **getParamsControl() const
{
return paramsControl;
}
int getIntPythonParameter(String name);
float getFloatPythonParameter(String name);
void resetConnections();
private:
String filePath;
void *plugin;
// private members and methods go here
//
// e.g.:
//
// float threshold;
// bool state;
int numPythonParams = 0;
ParamConfig *params;
Component **paramsControl;
// function pointers to the python plugin
pluginfunc_t pluginFunction;
isreadyfunc_t pluginIsReady;
startupfunc_t pluginStartupFunction;
getparamnumfunc_t getParamNumFunction;
getparamconfigfunc_t getParamConfigFunction;
setintparamfunc_t setIntParamFunction;
setfloatparamfunc_t setFloatParamFunction;
getintparamfunc_t getIntParamFunction;
getfloatparamfunc_t getFloatParamFunction;
PyThreadState *GUIThreadState = 0;
PyThreadState *processThreadState = 0;
const EventChannel* ttlChannel{ nullptr };
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PythonPlugin);
bool wasTriggered = 0;
uint16 lastChan = 0;
};
#endif // __PYTHONPLUGIN_H