line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#_{ Encoding and name |
2
|
|
|
|
|
|
|
=encoding utf8 |
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Csound - Create Csound scores and instruments |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=cut |
8
|
|
|
|
|
|
|
#_} |
9
|
|
|
|
|
|
|
package Csound; |
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
117180
|
use warnings; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
78
|
|
12
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
49
|
|
13
|
2
|
|
|
2
|
|
518
|
use utf8; |
|
2
|
|
|
|
|
24
|
|
|
2
|
|
|
|
|
12
|
|
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
2
|
|
52
|
use Carp; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
746
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = 0.01; |
18
|
|
|
|
|
|
|
#_{ Synopsis |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
use Csound::Composition; |
23
|
|
|
|
|
|
|
use Csound::Instrument; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $composition = Csound::Composition->new(); |
26
|
|
|
|
|
|
|
my $instrument_one = Csound::Instrument->new(…); |
27
|
|
|
|
|
|
|
my $instrument_two = Csound::Instrument->new(…); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# go from there … |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=cut |
32
|
|
|
|
|
|
|
#_} |
33
|
|
|
|
|
|
|
#_{ Methods |
34
|
|
|
|
|
|
|
#_{ |
35
|
|
|
|
|
|
|
=head1 METHODS |
36
|
|
|
|
|
|
|
=cut |
37
|
|
|
|
|
|
|
#_} |
38
|
|
|
|
|
|
|
sub is_note { #_{ |
39
|
|
|
|
|
|
|
#_{ POD |
40
|
|
|
|
|
|
|
=head2 is_note |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
$is_a_note = Csound::is_note('d5'); |
43
|
|
|
|
|
|
|
$is_a_note = Csound::is_note('f11'); |
44
|
|
|
|
|
|
|
$is_a_note = Csound::is_note('c♯4'); |
45
|
|
|
|
|
|
|
$is_a_note = Csound::is_note('b♭9'); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
$is_not_a_note = Csound::is_note('foo'); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=cut |
50
|
|
|
|
|
|
|
#_} |
51
|
|
|
|
|
|
|
|
52
|
7
|
|
|
7
|
0
|
80
|
my $possible_note = shift; |
53
|
|
|
|
|
|
|
|
54
|
7
|
50
|
|
|
|
15
|
carp "Pass a possible note" unless $possible_note; |
55
|
|
|
|
|
|
|
|
56
|
7
|
100
|
|
|
|
54
|
return 1 if ($possible_note =~ /^[a-g][♯♭]?[12]?\d$/); |
57
|
3
|
|
|
|
|
9
|
return 0; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
} #_} |
60
|
|
|
|
|
|
|
sub note_to_pch { |
61
|
|
|
|
|
|
|
#_{ POD |
62
|
|
|
|
|
|
|
=head2 note_to_pch |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
my $pch = Csound::note_to_pch('d♯4'); # returns 4.03 |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=cut |
68
|
|
|
|
|
|
|
#_} |
69
|
|
|
|
|
|
|
|
70
|
22
|
|
|
22
|
0
|
38
|
my $note = shift; |
71
|
|
|
|
|
|
|
|
72
|
22
|
50
|
|
|
|
184
|
croak "note is not a note" unless $note =~ /^([a-g])([♯♭]?)([12]?\d)$/; |
73
|
|
|
|
|
|
|
|
74
|
22
|
|
|
|
|
49
|
my $letter = $1; |
75
|
22
|
|
50
|
|
|
52
|
my $sign = $2 // ''; |
76
|
22
|
|
|
|
|
30
|
my $octave = $3; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
22
|
|
|
|
|
23
|
my $note_nr; |
81
|
22
|
100
|
|
|
|
43
|
$note_nr = 0 if $letter eq 'c'; |
82
|
22
|
100
|
|
|
|
36
|
$note_nr = 2 if $letter eq 'd'; |
83
|
22
|
100
|
|
|
|
34
|
$note_nr = 4 if $letter eq 'e'; |
84
|
22
|
100
|
|
|
|
35
|
$note_nr = 5 if $letter eq 'f'; |
85
|
22
|
100
|
|
|
|
30
|
$note_nr = 7 if $letter eq 'g'; |
86
|
22
|
100
|
|
|
|
35
|
$note_nr = 9 if $letter eq 'a'; |
87
|
22
|
100
|
|
|
|
32
|
$note_nr = 11 if $letter eq 'b'; |
88
|
|
|
|
|
|
|
|
89
|
22
|
|
|
|
|
34
|
$note_nr += 12*$octave; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# = ((ord($letter) - ord('c')) ) + 12 * $octave; |
92
|
|
|
|
|
|
|
|
93
|
22
|
100
|
|
|
|
36
|
$note_nr-- if $sign eq '♭'; |
94
|
22
|
100
|
|
|
|
34
|
$note_nr++ if $sign eq '♯'; |
95
|
|
|
|
|
|
|
|
96
|
22
|
|
|
|
|
27
|
my $fract_out = $note_nr % 12; |
97
|
22
|
|
|
|
|
40
|
my $octave_out = ($note_nr - $fract_out)/12; |
98
|
|
|
|
|
|
|
|
99
|
22
|
|
|
|
|
137
|
return sprintf("%d.%02d", $octave_out, $fract_out); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
#_} |
104
|
|
|
|
|
|
|
#_{ POD: Copyright |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 Copyright |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Copyright © 2017 René Nyffenegger, Switzerland. All rights reserved. |
109
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
110
|
|
|
|
|
|
|
under the terms of the the Artistic License (2.0). You may obtain a |
111
|
|
|
|
|
|
|
copy of the full license at: L |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=cut |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
#_} |
116
|
|
|
|
|
|
|
#_{ Source Code |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 Source Code |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
The source code is on L<< github|https://github.com/ReneNyffenegger/perl-Csound >>. Meaningful pull requests are welcome. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=cut |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
#_} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
'tq84'; |