aboutsummaryrefslogtreecommitdiff
path: root/dmx512/src/dmxin.c
blob: cfccd4be0bab01ed15ed1dca2c2330c6f7c34c41 (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
80
81
82
83
84
85
86
87
88
89
90
91
/******************************************************
 *
 * dmxin - implementation file
 *
 * copyleft (c) IOhannes m zmölnig
 *
 *   0603:forum::für::umläute:2008
 *
 *   institute of electronic music and acoustics (iem)
 *
 ******************************************************
 *
 * license: GNU General Public License v.2
 *
 ******************************************************/


#include "dmx4pd.h"


static t_class *dmxin_class;

typedef struct _dmxin
{
  t_object x_obj;
  int      x_device;

  t_outlet*x_outlet1, *x_outlet2;
} t_dmxin;




static void dmxin_close(t_dmxin*x)
{
  if(x->x_device>=0) {
    close(x->x_device);
  }
  x->x_device=-1;
}


static void dmxin_open(t_dmxin*x, t_symbol*s_devname)
{
  int argc=2;
  const char *args[2] = {"--dmx", s_devname->s_name};
  const char**argv=args;
  char*devname="";
  int fd;

  if(s_devname && s_devname->s_name)
    devname=s_devname->s_name;

  //  strncpy(args[0], "--dmx", MAXPDSTRING);
  //  strncpy(args[1], devname, MAXPDSTRING);

  fd = open (DMXINdev(&argc, argv), O_RDONLY);

  if(fd!=-1) {
    dmxin_close(x);
    x->x_device=fd;
  }
}


static void *dmxin_new(void)
{
  if(0) {
    t_dmxin *x = (t_dmxin *)pd_new(dmxin_class);
    return (x);
  } else {
    error("[dmxin] not yet implemented");
    return 0;
  }
}
static void *dmxin_free(t_dmxin*x)
{
  dmxin_close(x);
}

void dmxin_setup(void)
{
  dmxin_class = class_new(gensym("dmxin"), (t_newmethod)dmxin_new, (t_method)dmxin_free,
                          sizeof(t_dmxin),  
                          CLASS_NOINLET,
                          A_NULL);

#ifdef DMX4PD_POSTBANNER
  DMX4PD_POSTBANNER
#endif
}