line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#_{ Encoding and name |
2
|
|
|
|
|
|
|
=encoding utf8 |
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Csound::Orchestra |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=cut |
8
|
|
|
|
|
|
|
#_} |
9
|
|
|
|
|
|
|
package Csound::Orchestra; |
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
384
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
37
|
|
12
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
34
|
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
7
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
626
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = $Csound::VERSION; |
17
|
|
|
|
|
|
|
#_{ Synopsis |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use Csound::Orchestra; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $orchestra=Csound::Orchestra->new(); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=cut |
26
|
|
|
|
|
|
|
#_} |
27
|
|
|
|
|
|
|
#_{ Description |
28
|
|
|
|
|
|
|
=head1 DESCRIPTION |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
An orchestra consists of L |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
An orchestra should be created by a L. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=over |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=item * a header section |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
The L specifies global options for instrument performance. It is written with L. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=item * an optional list of user defined opcodes |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
L are built with the I C<< L >> and |
43
|
|
|
|
|
|
|
C<< L >>. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=item * instrument definitions |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=back |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=cut |
50
|
|
|
|
|
|
|
#_} |
51
|
|
|
|
|
|
|
#_{ Methods |
52
|
|
|
|
|
|
|
=head1 METHODS |
53
|
|
|
|
|
|
|
=cut |
54
|
|
|
|
|
|
|
sub new { #_{ |
55
|
|
|
|
|
|
|
#_{ POD |
56
|
|
|
|
|
|
|
=head2 new |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
An orchestra should not be created by the end user. The user should rather use a L. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=cut |
61
|
|
|
|
|
|
|
#_} |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
my $self = {}; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
bless $self, $class; |
68
|
|
|
|
|
|
|
|
69
|
0
|
0
|
|
|
|
|
die unless $self->isa('Csound::Orchestra'); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# An orchestra requires some instruments. |
72
|
|
|
|
|
|
|
# The key of the hash is the instrument number. |
73
|
|
|
|
|
|
|
# The instruments are added with the L() method. |
74
|
0
|
|
|
|
|
|
$self->{instruments} = {}; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
return $self; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
} #_} |
79
|
|
|
|
|
|
|
sub use_instrument { |
80
|
|
|
|
|
|
|
#_{ POD |
81
|
|
|
|
|
|
|
=head2 use_instrument |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
$orc -> use_instrument($instr); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Add $instr to the instruments. An instrument can be added multiple times, for example by L. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=cut |
88
|
|
|
|
|
|
|
#_} |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
91
|
0
|
|
|
|
|
|
my $instr = shift; |
92
|
|
|
|
|
|
|
|
93
|
0
|
0
|
|
|
|
|
croak "Not an orchestra " unless $self ->isa('Csound::Orchestra'); |
94
|
0
|
0
|
|
|
|
|
croak "Not an instrument" unless $instr->isa('Csound::Instrument'); |
95
|
|
|
|
|
|
|
|
96
|
0
|
0
|
|
|
|
|
$self->{instruments}{$instr->{nr}} = $instr unless exists $self->{instruments}{$instr->{nr}}; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
sub write { #_{ |
100
|
|
|
|
|
|
|
#_{ POD |
101
|
|
|
|
|
|
|
=head2 write |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
$orc->write('filename.orc', $score); |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
This method should not be called directly by the end user. The end user should call L instead. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
C<$score> is needed because some instruments need access to the score (notably for the table functions C). |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=cut |
110
|
|
|
|
|
|
|
#_} |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
113
|
0
|
|
|
|
|
|
my $filename_without_suffix = shift; |
114
|
0
|
|
|
|
|
|
my $score = shift; |
115
|
|
|
|
|
|
|
|
116
|
0
|
0
|
|
|
|
|
croak "$self is a " . ref($self) unless $self->isa('Csound::Orchestra'); |
117
|
0
|
0
|
|
|
|
|
croak "score is not defined" unless defined $score; |
118
|
0
|
0
|
|
|
|
|
croak "score is not a Csound::Score but a $score" unless $score->isa('Csound::Score'); |
119
|
|
|
|
|
|
|
|
120
|
0
|
0
|
|
|
|
|
croak "No filename specified" unless $filename_without_suffix; |
121
|
|
|
|
|
|
|
|
122
|
0
|
0
|
|
|
|
|
open (my $orc_fh, '>', "$filename_without_suffix.orc") or croak "Could not open $filename_without_suffix.orc"; |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
$self->_write_header ($orc_fh); |
125
|
0
|
|
|
|
|
|
$self->_write_instruments($orc_fh, $score); |
126
|
|
|
|
|
|
|
|
127
|
0
|
|
|
|
|
|
close $orc_fh; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
} #_} |
130
|
|
|
|
|
|
|
sub _write_header { #_{ |
131
|
|
|
|
|
|
|
#_{ POD |
132
|
|
|
|
|
|
|
=head2 _write_header |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
An internal function. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
L |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=cut |
139
|
|
|
|
|
|
|
#_} |
140
|
|
|
|
|
|
|
|
141
|
0
|
|
|
0
|
|
|
my $self = shift; |
142
|
0
|
0
|
|
|
|
|
croak unless $self->isa('Csound::Orchestra'); |
143
|
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
|
my $fh_orc = shift; |
145
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
print $fh_orc < |
147
|
|
|
|
|
|
|
sr = 44100 |
148
|
|
|
|
|
|
|
kr = 4410 |
149
|
|
|
|
|
|
|
ksmps = 10 |
150
|
|
|
|
|
|
|
nchnls = 2 |
151
|
|
|
|
|
|
|
;0dbfs = 1 |
152
|
|
|
|
|
|
|
HEADER |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
} #_} |
155
|
|
|
|
|
|
|
sub _write_instruments { #_{ |
156
|
|
|
|
|
|
|
#_{ POD |
157
|
|
|
|
|
|
|
=head2 _write_instruments |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
An internal function. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=cut |
163
|
|
|
|
|
|
|
#_} |
164
|
|
|
|
|
|
|
|
165
|
0
|
|
|
0
|
|
|
my $self = shift; |
166
|
0
|
0
|
|
|
|
|
croak 'self is not a Csound::Orchestra' unless $self->isa('Csound::Orchestra'); |
167
|
|
|
|
|
|
|
|
168
|
0
|
|
|
|
|
|
my $fh_orc = shift; |
169
|
|
|
|
|
|
|
|
170
|
0
|
|
|
|
|
|
my $score = shift; |
171
|
0
|
0
|
|
|
|
|
croak "score needed, but is undefined" unless defined $score; |
172
|
0
|
0
|
|
|
|
|
croak "score needed" unless $score -> isa('Csound::Score'); |
173
|
|
|
|
|
|
|
|
174
|
0
|
|
|
|
|
|
for my $instr_no (sort keys %{$self->{instruments}}) { |
|
0
|
|
|
|
|
|
|
175
|
0
|
|
|
|
|
|
print $fh_orc "\n" . $self->{instruments}{$instr_no}->orchestra_text($score); |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
} #_} |
180
|
|
|
|
|
|
|
#_} |
181
|
|
|
|
|
|
|
#_{ POD: Copyright |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 Copyright |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Copyright © 2017 René Nyffenegger, Switzerland. All rights reserved. |
186
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
187
|
|
|
|
|
|
|
under the terms of the the Artistic License (2.0). You may obtain a |
188
|
|
|
|
|
|
|
copy of the full license at: L |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=cut |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
#_} |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
'tq84'; |