File Coverage

blib/lib/Audio/Ardour/Control.pm
Criterion Covered Total %
statement 16 18 88.8
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 22 24 91.6


line stmt bran cond sub pod time code
1             package Audio::Ardour::Control;
2              
3 1     1   21484 use 5.008008;
  1         3  
  1         31  
4 1     1   5 use strict;
  1         1  
  1         26  
5 1     1   5 use warnings;
  1         5  
  1         30  
6 1     1   4 use Carp;
  1         2  
  1         98  
7 1     1   6 use File::Spec;
  1         1  
  1         25  
8 1     1   395 use Net::LibLO;
  0            
  0            
9             use File::HomeDir;
10              
11             our $VERSION = '0.20';
12              
13             =head1 NAME
14              
15             Audio::Ardour::Control - Automate the Ardour DAW software.
16              
17             =head1 SYNOPSIS
18              
19             use Audio::Ardour::Control;
20              
21             my $ardcontrol = Audio::Ardour::Control->new($url);
22              
23             $ardcontrol->rec_enable_toggle();
24             $ardcontrol->transport_play();
25             # do stuff
26             $ardcontrol->transport_stop();
27              
28             =head1 DESCRIPTION
29              
30             Ardour is an open source digital audio workstation software (DAW) for
31             Unix-like systems, it provides an interface to allow it to be controlled
32             using the Open Sound Control (OSC) protocol. This module uses OSC to
33             enable control of Ardour from a Perl program.
34              
35             The methods below represent all of the actions exposed by Ardour via OSC,
36             for more detail on what they actually do you probably want to refer to the
37             Ardour documentation.
38              
39             =head2 METHODS
40              
41             =over 2
42              
43             =item new
44              
45             Construct a new Audio::Ardour::Control object. The only argument is the
46             URL of the Ardour OSC instance in the form C:/>,
47             this is printed to STDERR by Ardour when the OSC is enabled. For versions
48             of Ardour from 2.2 onwards the URL will be written to a file in the user
49             specific config directory and an attempt will be made to determine the URL
50             from that source, if it is not present and no URL has been specified as an
51             argument then this will croak.
52              
53             =cut
54              
55             sub new
56             {
57             my ( $class, $url ) = @_;
58            
59              
60             my $self = bless {}, $class;
61              
62             if( ! $self->url($url) )
63             {
64             croak "Cannot discover URL and no URL specified";
65             }
66              
67             return $self;
68              
69             }
70              
71              
72             =item add_marker
73              
74             Adds a new location marker at the current location of the playhead.
75              
76             =cut
77              
78             sub add_marker
79             {
80             my ( $self ) = @_;
81              
82             $self->send('/ardour/add_marker', undef);
83             }
84              
85              
86             =item loop_toggle
87              
88             This toggles the effect of the loop range, if loop is on then transport_play
89             will loop over the defined loop range.
90              
91             =cut
92              
93             sub loop_toggle
94             {
95             my ( $self ) = @_;
96              
97             $self->send('/ardour/loop_toggle', undef);
98             }
99              
100              
101             =item goto_start
102              
103             Reposition the playhead at the start of the tracks.
104              
105             =cut
106              
107             sub goto_start
108             {
109             my ( $self ) = @_;
110              
111             $self->send('/ardour/goto_start', undef);
112             }
113              
114              
115             =item goto_end
116              
117             Reposition the playhead at the end of the session - (i.e. the "End" marker)
118              
119             =cut
120              
121             sub goto_end
122             {
123             my ( $self ) = @_;
124              
125             $self->send('/ardour/goto_end', undef);
126             }
127              
128              
129             =item rewind
130              
131             Roll the transport backward at twice the standard transport speed.
132              
133             =cut
134              
135             sub rewind
136             {
137             my ( $self ) = @_;
138              
139             $self->send('/ardour/rewind', undef);
140             }
141              
142              
143             =item ffwd
144              
145             Roll the transport forward at twice the standard transport speed.
146              
147             =cut
148              
149             sub ffwd
150             {
151             my ( $self ) = @_;
152              
153             $self->send('/ardour/ffwd', undef);
154             }
155              
156              
157             =item transport_stop
158              
159             Stop the current motion of the transport.
160              
161             =cut
162              
163             sub transport_stop
164             {
165             my ( $self ) = @_;
166              
167             $self->send('/ardour/transport_stop', undef);
168             }
169              
170              
171             =item transport_play
172              
173             Start playing.
174              
175             =cut
176              
177             sub transport_play
178             {
179             my ( $self ) = @_;
180              
181             $self->send('/ardour/transport_play', undef);
182             }
183              
184              
185             =item set_transport_speed
186              
187             Set the transport speed for use by other operations. The argument is a
188             floating point number, where 0 is stopped and 1 is normal speed.
189              
190             =cut
191              
192             sub set_transport_speed
193             {
194             my ( $self , $arg ) = @_;
195              
196             $self->send('/ardour/set_transport_speed','f', $arg);
197             }
198              
199              
200             =item save_state
201              
202             Cause the session to be saved.
203              
204             =cut
205              
206             sub save_state
207             {
208             my ( $self ) = @_;
209              
210             $self->send('/ardour/save_state', undef);
211             }
212              
213              
214             =item prev_marker
215              
216             Move the playhead to the previous location marker.
217              
218             =cut
219              
220             sub prev_marker
221             {
222             my ( $self ) = @_;
223              
224             $self->send('/ardour/prev_marker', undef);
225             }
226              
227              
228             =item next_marker
229              
230             Move the playhead to the next location marker.
231              
232             =cut
233              
234             sub next_marker
235             {
236             my ( $self ) = @_;
237              
238             $self->send('/ardour/next_marker', undef);
239             }
240              
241              
242             =item undo
243              
244             Undo the last action.
245              
246             =cut
247              
248             sub undo
249             {
250             my ( $self ) = @_;
251              
252             $self->send('/ardour/undo', undef);
253             }
254              
255              
256             =item redo
257              
258             Repeat the last action.
259              
260             =cut
261              
262             sub redo
263             {
264             my ( $self ) = @_;
265              
266             $self->send('/ardour/redo', undef);
267             }
268              
269              
270             =item toggle_punch_in
271              
272             Switch the punch in point on or off.
273              
274             =cut
275              
276             sub toggle_punch_in
277             {
278             my ( $self ) = @_;
279              
280             $self->send('/ardour/toggle_punch_in', undef);
281             }
282              
283              
284             =item toggle_punch_out
285              
286             Switch the punch out point on or off.
287              
288             =cut
289              
290             sub toggle_punch_out
291             {
292             my ( $self ) = @_;
293              
294             $self->send('/ardour/toggle_punch_out', undef);
295             }
296              
297              
298             =item rec_enable_toggle
299              
300             Toggle the global record arming.
301              
302             =cut
303              
304             sub rec_enable_toggle
305             {
306             my ( $self ) = @_;
307              
308             $self->send('/ardour/rec_enable_toggle', undef);
309             }
310              
311              
312             =item toggle_all_rec_enables
313              
314             Toggle the track record enables. The track enables will not turn *off*
315             unless global record arming is set (i.e. the big record button is highlighted.)
316              
317             =cut
318              
319             sub toggle_all_rec_enables
320             {
321             my ( $self ) = @_;
322              
323             $self->send('/ardour/toggle_all_rec_enables', undef);
324             }
325              
326             =back
327              
328             =head2 INTERNAL METHODS
329              
330             The below methods are used internally and might not be useful for
331             general use unless you are sub-classing or extending this module.
332              
333             =over
334              
335             =item url
336              
337             Get and/or set the URL to connect to the instance of Ardour we want to
338             control.
339              
340             If the url is not specifiied and has not been previously set then
341             discover_url() will be called. It will return undef if no URL can be
342             found.
343              
344             =cut
345              
346             sub url
347             {
348             my ( $self, $url ) = @_;
349              
350             if ( defined $url )
351             {
352             $self->{_url} = $url;
353             }
354              
355             if ( not exists $self->{_url} )
356             {
357             if ( $url = $self->discover_url() )
358             {
359             $self->{_url} = $url;
360             }
361             }
362              
363             return $self->{_url};
364             }
365              
366             =item discover_url
367              
368             Attempt to read the URL from the $HOME/.ardour2/osc_url file, returns undef
369             if the file doesn't exist.
370              
371             This will not work for Ardour versions earlier than 2.2
372              
373             =cut
374              
375             sub discover_url
376             {
377             my ( $self ) = @_;
378              
379             my $home = File::HomeDir->my_home();
380             my $osc_url = File::Spec->catfile($home,'.ardour2','osc_url');
381              
382             my $url;
383             if ( open URL, $osc_url )
384             {
385             chomp($url = );
386             }
387             return $url;
388             }
389              
390             =item send
391              
392             Send a request to the OSC host. The arguments are the OSC path and the
393             arguments for the call.
394              
395             =cut
396              
397             sub send
398             {
399             my ( $self, $path, $argspec, $args ) = @_;
400             $self->lo()->send($self->address, $path, $argspec, $args);
401             }
402              
403             =item lo
404              
405             Get and/or set the underlying L object that we are using.
406              
407             =cut
408              
409             sub lo
410             {
411             my ( $self, $lo ) = @_;
412              
413             if ( defined $lo )
414             {
415             $self->{_lo} = $lo;
416             }
417              
418             if ( not exists $self->{_lo} )
419             {
420             $self->{_lo} = Net::LibLO->new();
421             }
422              
423             return $self->{_lo};
424             }
425              
426              
427             =item address
428              
429             Get and/or set the L object based on the URL of the
430             Ardour OSC instance that we are going to use. If the address has not previously
431             been set then a new object will be created.
432              
433             =cut
434              
435             sub address
436             {
437             my ( $self, $address ) = @_;
438              
439             if ( defined $address )
440             {
441             $self->{_addr} = $address;
442             }
443              
444             if ( not exists $self->{_addr} )
445             {
446             $self->{_addr} = Net::LibLO::Address->new($self->url());
447             }
448              
449             return $self->{_addr};
450              
451             }
452              
453             =back
454              
455             =head2 EXPORT
456              
457             None.
458              
459             =head1 BUGS AND SUPPORT
460              
461             Some of the control methods might not work in the version of Ardour that
462             you are using.
463              
464             The OSC support in Ardour and this module should be considered experimental,
465             you almost certainly don't want to use this on any important Sessions without
466             thorough testing.
467              
468             Please provider full details of the version of Ardour you are using if you
469             want to report a bug. Also please feel free to tell me which bits *do*
470             work along with the version of Ardour :-)
471              
472             =head1 SEE ALSO
473              
474             L, Ardour documentation L,
475             OSC
476              
477             =head1 AUTHOR
478              
479             Jonathan Stowe, Ejns@gellyfish.comE
480              
481             =head1 COPYRIGHT AND LICENSE
482              
483             Copyright (C) 2008 by Jonathan Stowe
484              
485             This library is free software; you can redistribute it and/or modify
486             it under the same terms as Perl itself, either Perl version 5.8.8 or,
487             at your option, any later version of Perl 5 you may have available.
488              
489              
490             =cut
491              
492              
493             1;
494             __END__