| 1 | #_{ Encoding and name | ||||||||||
| 2 | =encoding utf8 | ||||||||||
| 3 | =head1 NAME | ||||||||||
| 4 | |||||||||||
| 5 | Csound::ScoreStatement | ||||||||||
| 6 | |||||||||||
| 7 | =cut | ||||||||||
| 8 | #_} | ||||||||||
| 9 | |||||||||||
| 10 | package Csound::Score; | ||||||||||
| 11 | |||||||||||
| 12 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 2 | ▶ | use utf8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 2 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | |||||||||||
| 18 | 2 | ▶ | use Csound; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 2 | ▶ | use Csound::Orchestra; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 2 | ▶ | use Csound::ScoreStatement::f; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | |||||||||||
| 22 | 2 | our $VERSION = $Csound::VERSION; | |||||||||
| 23 | #_{ Synopsis | ||||||||||
| 24 | |||||||||||
| 25 | =head1 SYNOPSIS | ||||||||||
| 26 | |||||||||||
| 27 | use Csound::Score; | ||||||||||
| 28 | |||||||||||
| 29 | ... | ||||||||||
| 30 | |||||||||||
| 31 | =cut | ||||||||||
| 32 | #_} | ||||||||||
| 33 | #_{ Description | ||||||||||
| 34 | =head DESCRIPTION | ||||||||||
| 35 | |||||||||||
| 36 | Scores | ||||||||||
| 37 | |||||||||||
| 38 | =cut | ||||||||||
| 39 | #_} | ||||||||||
| 40 | #_{ Methods | ||||||||||
| 41 | #_{ | ||||||||||
| 42 | =head1 METHODS | ||||||||||
| 43 | =cut | ||||||||||
| 44 | #_} | ||||||||||
| 45 | 1 | ▶ | sub new { #_{ | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 46 | #_{ POD | ||||||||||
| 47 | =head2 new | ||||||||||
| 48 | |||||||||||
| 49 | my $score = Csound::Score->new(); | ||||||||||
| 50 | |||||||||||
| 51 | =cut | ||||||||||
| 52 | #_} | ||||||||||
| 53 | |||||||||||
| 54 | 1 | my $class = shift; | |||||||||
| 55 | # my $params = shift // {}; | ||||||||||
| 56 | |||||||||||
| 57 | 1 | my $self = {}; | |||||||||
| 58 | |||||||||||
| 59 | 1 | bless $self, $class; | |||||||||
| 60 | |||||||||||
| 61 | # $self->{orchestra} = Csound::Orchestra->new(); | ||||||||||
| 62 | 1 | $self->{i_stmts} = []; | |||||||||
| 63 | 1 | $self->{f_stmts} = {}; | |||||||||
| 64 | |||||||||||
| 65 | 1 | return $self; | |||||||||
| 66 | |||||||||||
| 67 | } #_} | ||||||||||
| 68 | 0 | ▶ | sub play { #_{ | ||||||||
|
Subroutine
play: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||
| 69 | #_{ POD | ||||||||||
| 70 | =head2 play | ||||||||||
| 71 | |||||||||||
| 72 | my $instr = Csound::Instrument->new(…) | ||||||||||
| 73 | … | ||||||||||
| 74 | |||||||||||
| 75 | $orchestra->play($instr, $t_start, $t_len, "c♯3"); | ||||||||||
| 76 | |||||||||||
| 77 | =cut | ||||||||||
| 78 | #_} | ||||||||||
| 79 | |||||||||||
| 80 | 0 | my $self = shift; | |||||||||
| 81 | 0 | my $instr = shift; | |||||||||
| 82 | |||||||||||
| 83 | 0 | my $t_start = shift; | |||||||||
| 84 | 0 | my $t_len = shift; | |||||||||
| 85 | |||||||||||
| 86 | 0 | ▶ | if ($instr->plays_note()) { #_{ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 87 | 0 | my $note = $_[0]; | |||||||||
| 88 | |||||||||||
| 89 | 0 | ▶ | croak 'instrument plays a note, but none was given' unless defined $note; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 90 | |||||||||||
| 91 | 0 | ▶ | croak "instrument plays a note, but $note is none" unless Csound::is_note($note); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 92 | } #_} | ||||||||||
| 93 | |||||||||||
| 94 | 0 | ▶ | die unless $self->isa('Csound::Score'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 95 | |||||||||||
| 96 | 0 | ▶ | croak "First argument is not an instrument" unless $instr->isa('Csound::Instrument'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 97 | |||||||||||
| 98 | # $self->{orchestra}->use_instrument($instr); | ||||||||||
| 99 | |||||||||||
| 100 | 0 | my $i; | |||||||||
| 101 | 0 | ▶ | if ($instr->plays_note) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 102 | 0 | my $note = shift; | |||||||||
| 103 | 0 | ▶ | croak "Instrument plays notes, but $note is not a note" unless Csound::is_note($note); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 104 | 0 | my $pch = Csound::note_to_pch($note); | |||||||||
| 105 | 0 | $i = $instr->i($t_start, $t_len, $pch, @_); | |||||||||
| 106 | } | ||||||||||
| 107 | else { | ||||||||||
| 108 | 0 | $i = $instr->i($t_start, $t_len, @_); | |||||||||
| 109 | } | ||||||||||
| 110 | |||||||||||
| 111 | 0 | ▶ | die "i is not an Csound::ScoreStatement::i" unless $i->isa('Csound::ScoreStatement::i'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 112 | |||||||||||
| 113 | 0 | push @{$self->{i_stmts}}, $i; | |||||||||
| 114 | |||||||||||
| 115 | 0 | return $self; | |||||||||
| 116 | |||||||||||
| 117 | } #_} | ||||||||||
| 118 | 3 | ▶ | sub f { #_{ | ||||||||
|
Subroutine
f: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 119 | #_{ POD | ||||||||||
| 120 | =head2 f | ||||||||||
| 121 | |||||||||||
| 122 | Create a L<< Csound::ScoreStatement::f >>. | ||||||||||
| 123 | |||||||||||
| 124 | Probably called from L<< Csound::Instrument/orchestra_text >> | ||||||||||
| 125 | |||||||||||
| 126 | =cut | ||||||||||
| 127 | #_} | ||||||||||
| 128 | |||||||||||
| 129 | 3 | my $self = shift; | |||||||||
| 130 | |||||||||||
| 131 | 3 | my @f_parameters = @_; | |||||||||
| 132 | |||||||||||
| 133 | 3 | ▶ | croak unless $self->isa('Csound::Score'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 134 | |||||||||||
| 135 | |||||||||||
| 136 | 3 | my $f_key =join '/', @f_parameters; | |||||||||
| 137 | 3 | ▶ | if (exists $self->{f_stmts}{$f_key}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 138 | 1 | return $self->{f_stmts}{$f_key}; | |||||||||
| 139 | } | ||||||||||
| 140 | |||||||||||
| 141 | 2 | $self->{f_stmts}{$f_key} = Csound::ScoreStatement::f->new(@f_parameters); | |||||||||
| 142 | |||||||||||
| 143 | 2 | return $self->{f_stmts}{$f_key}; | |||||||||
| 144 | |||||||||||
| 145 | } #_} | ||||||||||
| 146 | 0 | ▶ | sub t { #_{ | ||||||||
|
Subroutine
t: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 147 | 0 | my $self = shift; | |||||||||
| 148 | 0 | my $t = shift; | |||||||||
| 149 | |||||||||||
| 150 | 0 | ▶ | croak "need Csound::ScoreStatement::t" unless $t->isa('Csound::ScoreStatement::t'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 151 | |||||||||||
| 152 | 0 | $self->{t} = $t; | |||||||||
| 153 | } #_} | ||||||||||
| 154 | 0 | ▶ | sub write { #_{ | ||||||||
|
Subroutine
write: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 155 | #_{ POD | ||||||||||
| 156 | =head2 write | ||||||||||
| 157 | |||||||||||
| 158 | $score->write('filename'); | ||||||||||
| 159 | |||||||||||
| 160 | Writes C<filename.sco> and C<filename.orc>. | ||||||||||
| 161 | |||||||||||
| 162 | C<filename.orc> is written by calling C<< $self->{orchestra}->write("$filename.orc") >> which | ||||||||||
| 163 | in turn is called by C<< $composition -> write($filename) >>. | ||||||||||
| 164 | |||||||||||
| 165 | |||||||||||
| 166 | =cut | ||||||||||
| 167 | #_} | ||||||||||
| 168 | |||||||||||
| 169 | 0 | my $self = shift; | |||||||||
| 170 | 0 | my $filename = shift; | |||||||||
| 171 | |||||||||||
| 172 | |||||||||||
| 173 | 0 | ▶ | open (my $sco_fh, '>', "$filename.sco") or croak "Could not open $filename.sco"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 174 | |||||||||||
| 175 | 0 | $self->_write_f_statements($sco_fh); | |||||||||
| 176 | 0 | print $sco_fh "\n"; | |||||||||
| 177 | |||||||||||
| 178 | 0 | ▶ | if ($self->{t}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 179 | 0 | print $sco_fh $self->{t}->score_text, "\n"; | |||||||||
| 180 | } | ||||||||||
| 181 | |||||||||||
| 182 | 0 | $self->_write_i_statements($sco_fh); | |||||||||
| 183 | |||||||||||
| 184 | 0 | print $sco_fh "\ne\n"; | |||||||||
| 185 | 0 | close $sco_fh; | |||||||||
| 186 | } #_} | ||||||||||
| 187 | 0 | ▶ | sub _write_f_statements { #_{ | ||||||||
|
Subroutine
_write_f_statements: not called CC=2 SCAR=17.9
| |||||||||||
| 188 | 0 | my $self = shift; | |||||||||
| 189 | 0 | my $fh = shift; | |||||||||
| 190 | |||||||||||
| 191 | 0 | for my $f_key (sort {$self->{f_stmts}{$a}->{table_nr} <=> $self->{f_stmts}{$b}->{table_nr}} keys %{$self->{f_stmts}}) { | |||||||||
| 192 | 0 | print $fh $self->{f_stmts}{$f_key}->score_text(), "\n"; | |||||||||
| 193 | } | ||||||||||
| 194 | } #_} | ||||||||||
| 195 | 0 | ▶ | sub _write_i_statements { #_{ | ||||||||
|
Subroutine
_write_i_statements: not called CC=2 SCAR=17.9
| |||||||||||
| 196 | 0 | my $self = shift; | |||||||||
| 197 | 0 | my $fh = shift; | |||||||||
| 198 | |||||||||||
| 199 | 0 | for my $i (@{$self->{i_stmts}}) { | |||||||||
| 200 | 0 | print $fh $i->score_text(), "\n"; | |||||||||
| 201 | } | ||||||||||
| 202 | } #_} | ||||||||||
| 203 | #_} | ||||||||||
| 204 | #_{ POD: Copyright | ||||||||||
| 205 | |||||||||||
| 206 | =head1 Copyright | ||||||||||
| 207 | |||||||||||
| 208 | Copyright © 2017 René Nyffenegger, Switzerland. All rights reserved. | ||||||||||
| 209 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 210 | under the terms of the the Artistic License (2.0). You may obtain a | ||||||||||
| 211 | copy of the full license at: L<http://www.perlfoundation.org/artistic_license_2_0> | ||||||||||
| 212 | |||||||||||
| 213 | =cut | ||||||||||
| 214 | |||||||||||
| 215 | #_} | ||||||||||
| 216 | |||||||||||
| 217 | 2 | 'tq84'; | |||||||||