aboutsummaryrefslogtreecommitdiff
path: root/externals/grill/py/source/pybuffer.h
blob: 1d59dd95449c41a742a28873dbf8ae63dd11035d (plain)
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
/* 

py/pyext - python script object for PD and Max/MSP

Copyright (c)2002-2005 Thomas Grill (gr@grrrr.org)
For information on usage and redistribution, and for a DISCLAIMER OF ALL
WARRANTIES, see the file, "license.txt," in this distribution.  

*/

#ifndef __PYBUFFER_H
#define __PYBUFFER_H

#include <flext.h>

#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 500)
#error You need at least flext version 0.5.0
#endif

#if FLEXT_OS == FLEXT_OS_MAC
#include <Python/Python.h>
#else
#include <Python.h>
#endif


#ifdef _MSC_VER
    #ifdef PY_EXPORTS
        #define PY_EXPORT __declspec(dllexport)
    #else
        #define PY_EXPORT __declspec(dllimport)
    #endif
#else
    #define PY_EXPORT
#endif

typedef struct {
    PyObject_HEAD
    /* Type-specific fields go here. */
    const t_symbol *sym;
    flext::buffer *buf;
    flext::buffer::lock_t lock;
    bool dirty;
} pySamplebuffer;

PY_EXPORT extern PyTypeObject pySamplebuffer_Type;

#define pySamplebuffer_Check(op) PyObject_TypeCheck(op, &pySamplebuffer_Type)
#define pySamplebuffer_CheckExact(op) ((op)->ob_type == &PySamplebuffer_Type)


PY_EXPORT PyObject *pySamplebuffer_FromSymbol(const t_symbol *sym);

inline PyObject *pySamplebuffer_FromString(const char *str)
{
    return pySamplebuffer_FromSymbol(flext::MakeSymbol(str));
}

inline PyObject *pySamplebuffer_FromString(PyObject *str)
{
    return pySamplebuffer_FromString(PyString_AsString(str));
}

inline const t_symbol *pySamplebuffer_AS_SYMBOL(PyObject *op) 
{
    return ((pySamplebuffer *)op)->sym;
}

inline const t_symbol *pySamplebuffer_AsSymbol(PyObject *op) 
{
    return pySamplebuffer_Check(op)?pySamplebuffer_AS_SYMBOL(op):NULL;
}

inline const char *pySamplebuffer_AS_STRING(PyObject *op) 
{
    return flext::GetString(pySamplebuffer_AS_SYMBOL(op));
}

#endif