Csound/Composition.pm untested

filter: Statementstmt 0.0% 0 / 39 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 60 CC 5 SCAR 17.1
CC
5
Cov
0%
play
12.0
new
6.0
write
6.0
CRAP 5.5
1 #_{ Encoding and name
2 =encoding utf8
3 =head1 NAME
4  
5 Csound::Composition
6  
7 =cut
8 #_}
9 package Csound::Composition;
10  
11 use warnings;
12 use strict;
13  
14 use Carp;
15  
16 use Csound::Score;
17 use Csound::ScoreStatement::t;
18  
19 our $VERSION = $Csound::VERSION;
20 #_{ Synopsis
21  
22 =head1 SYNOPSIS
23  
24 use Csound::Composition;
25  
26 my $composition=Csound::Composition->new();
27  
28 =cut
29 #_}
30 #_{ Description
31 =head1 DESCRIPTION
32  
33 A Csound composition. Used to create
34 a L<Csound::Orchestra> and a L<Csound::Score>.
35  
36 =over
37  
38 =cut
39 #_}
40 #_{ Methods
41 =head1 METHODS
42 =cut
43 sub new { #_{
44 #_{ POD
45 =head2 new
46  
47  
48 my $composition = Csound::Composition->new();
49  
50 =cut
51 #_}
52  
53 my $class = shift;
54  
55 my $self = {};
56  
57 bless $self, $class;
58  
59 die unless $self->isa('Csound::Composition');
60  
61 $self->{score } = Csound::Score->new();
62 $self->{orchestra} = Csound::Orchestra->new();
63  
64 return $self;
65  
66 } #_}
67 sub t { #_{
68 #_{ POD
69 =head2 t
70  
71 my $t = $composition->t($start_tempo);
72  
73 Returns a L<< t statement|Csound::ScoreStatement::t >> which can be used to control the tempo at various beats in the composition:
74  
75 $t->tempo($t₁, 70); # Increase tempo from t₁
76 $t->tempo($t₂, 90); # until
77 $t->tempo($t₃, 95); # t₃.
78  
79 =cut
80  
81 my $self = shift;
82 my $start_tempo = shift;
83  
84 my $t = Csound::ScoreStatement::t->new($start_tempo);
85 $self->{score}->t($t);
86  
87 #_}
88 } #_}
89 sub play { #_{
90 #_{ POD
91 =head2 play
92  
93 my $composition = Csound::Composition->new();
94  
95 $composition->play($instr, $t_start, $t_duration, @params);
96  
97 =cut
98 #_}
99  
100 my $self = shift;
101  
102 die unless $self->isa('Csound::Composition');
103  
104 my $instr = shift;
105 croak "play requires an instrument" unless $instr->isa('Csound::Instrument');
106  
107 $self->{orchestra}->use_instrument($instr);
108 $self->{score}->play($instr, @_);
109  
110 } #_}
111 sub write { #_{
112 #_{ POD
113 =head2 play
114  
115  
116 $composition->write('filename');
117  
118 Writes C<filename.orc> and C<filename.sco>.
119
120  
121 =cut
122 #_}
123  
124 my $self = shift;
125  
126 die unless $self->isa('Csound::Composition');
127  
128 my $filename_without_suffix = shift;
129  
130 #
131 # Note Csound::Orchestra::write uses a Csound::Score reference ($self->{score})
132 # because it might write to the Csound::Score (notably the f statements.).
133 # Therefore, $self->{orchestra}->write() must be called before
134 # $self->{score}->write().
135 #
136 $self->{orchestra}->write($filename_without_suffix, $self->{score});
137 $self->{score }->write($filename_without_suffix);
138  
139 } #_}
140 #_}
141 #_{ POD: Copyright
142  
143 =head1 Copyright
144  
145 Copyright © 2017 René Nyffenegger, Switzerland. All rights reserved.
146 This program is free software; you can redistribute it and/or modify it
147 under the terms of the the Artistic License (2.0). You may obtain a
148 copy of the full license at: L<http://www.perlfoundation.org/artistic_license_2_0>
149  
150 =cut
151  
152 #_}
153  
154 'tq84';