1 
2 module jack.port;
3 public import jack.error;
4 public import jack.c.types;
5 import jack.c.jack;
6 import jack.c.midiport;
7 import jack.impl.util;
8 import std.conv : to;
9 import std.string : toStringz;
10 
11 struct JackPort {
12   jack_port_t *handle_ = null;
13 
14 public:
15 
16   @property jack_port_t *handle()
17   {
18     return handle_;
19   }
20 
21   string get_name()
22   {
23     return to!string(jack_port_name(handle_));
24   }
25 
26   string get_short_name()
27   {
28     return to!string(jack_port_short_name(handle_));
29   }
30 
31   int get_flags()
32   {
33     return jack_port_flags(handle_);
34   }
35 
36   jack_port_type_id_t get_type_id()
37   {
38     return jack_port_type_id(handle_);
39   }
40 
41   int connected()
42   {
43     return jack_port_connected(handle_);
44   }
45 
46   bool connected_to(string port_name)
47   {
48     return jack_port_connected_to(handle_, port_name.toStringz) != 0;
49   }
50 
51   string[] get_connections()
52   {
53     const(char) **c_connections = jack_port_get_connections(handle_);
54     if (! c_connections)
55       return [];
56     scope(exit) jack_free(c_connections);
57     return cStringListToD(c_connections);
58   }
59 
60   void set_name(string name)
61   {
62     int ret = jack_port_set_name(handle_, name.toStringz);
63     if (ret != 0) {
64       throw new JackError("jack_port_set_name");
65     }
66   }
67 
68  void set_alias(string alia)
69   {
70     int ret = jack_port_set_alias(handle_, alia.toStringz);
71     if (ret != 0) {
72       throw new JackError("jack_port_set_alias");
73     }
74   }
75 
76   void unset_alias(string alia)
77   {
78     int ret = jack_port_unset_alias(handle_, alia.toStringz);
79     if (ret != 0) {
80       throw new JackError("jack_port_unset_alias");
81     }
82   }
83 
84   string[] get_aliases()
85   {
86     const(char) *[2] c_aliases;
87     int n = jack_port_get_aliases(handle_, c_aliases.ptr);
88     if (n < 0) {
89       throw new JackError("jack_port_get_aliases");
90     }
91     auto aliases = new string[n];
92     foreach (i, ref string x; aliases)
93       x = to!string(c_aliases[i]);
94     return aliases;
95   }
96 
97   void request_monitor(bool onoff)
98   {
99     if (jack_port_request_monitor(handle_, onoff) != 0) {
100       throw new JackError("jack_port_request_monitor");
101     }
102   }
103 
104   void ensure_monitor(bool onoff)
105   {
106     if (jack_port_ensure_monitor(handle_, onoff) != 0) {
107       throw new JackError("jack_port_ensure_monitor");
108     }
109   }
110 
111   bool monitoring_input()
112   {
113     return jack_port_monitoring_input(handle_) != 0;
114   }
115 
116   void get_latency_range(jack_latency_callback_mode_t mode, jack_latency_range_t *range)
117   {
118     jack_port_get_latency_range(handle_, mode, range);
119   }
120 
121   void set_latency_range(jack_latency_callback_mode_t mode, jack_latency_range_t *range)
122   {
123     jack_port_set_latency_range(handle_, mode, range);
124   }
125 
126 };
127 
128 jack_default_audio_sample_t *get_audio_buffer(JackPort port, jack_nframes_t nframes)
129 {
130   return cast(jack_default_audio_sample_t *)jack_port_get_buffer(port.handle, nframes);
131 }