Csound.pm

filter: Statementstmt 100% 37 / 37 Branchbran 91.6% 22 / 24 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 2 totaltotal 91.6% 66 / 72 CC 14 SCAR 21.1
CC
14
Cov
95%
note_to_pch
12.0
is_note
3.0
BEGIN
1.0
CRAP 8.3
« Csound/Orchestra.pm ↑ Summary Csound/Composition.pm »
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 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 3 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 7 ▶sub is_note { #_{
Subroutine is_note: called CC=3 SCAR=11.0
Pod undocumented
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 my $possible_note = shift;
53  
54 7 ▶ carp "Pass a possible note" unless $possible_note;
Branch: 1 branch
BranchTrueFalseTotal
unless $possible_note 0 7 7
55  
56 7 ▶ return 1 if ($possible_note =~ /^[a-g][♯♭]?[12]?\d$/);
Branch: 1 branch
BranchTrueFalseTotal
if $possible_note =~ /^[a-g][\x{266f}\x{266d}]?[12]?\d$/ 4 3 7
57 3 return 0;
58  
59 } #_}
60 22 ▶sub note_to_pch {
Subroutine note_to_pch: called CC=12 SCAR=24.9
Pod undocumented
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 my $note = shift;
71  
72 22 ▶ croak "note is not a note" unless $note =~ /^([a-g])([♯♭]?)([12]?\d)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $note =~ /^([a-g])([\x{266f}\x{266d}]?)([12]?\d)$/ 0 22 22
73  
74 22 my $letter = $1;
75 22 ▶ my $sign = $2 // '';
Condition50%1/2
$2 // ""
l!l
220
MC/DC0%0/1
$2 // ""
$2
Truth table50%1/2
A
A= $2
Aresult
11
00
76 22 my $octave = $3;
77  
78  
79  
80 22 my $note_nr;
81 22 ▶ $note_nr = 0 if $letter eq 'c';
Branch: 1 branch
BranchTrueFalseTotal
if $letter eq "c" 4 18 22
82 22 ▶ $note_nr = 2 if $letter eq 'd';
Branch: 1 branch
BranchTrueFalseTotal
if $letter eq "d" 3 19 22
83 22 ▶ $note_nr = 4 if $letter eq 'e';
Branch: 1 branch
BranchTrueFalseTotal
if $letter eq "e" 3 19 22
84 22 ▶ $note_nr = 5 if $letter eq 'f';
Branch: 1 branch
BranchTrueFalseTotal
if $letter eq "f" 3 19 22
85 22 ▶ $note_nr = 7 if $letter eq 'g';
Branch: 1 branch
BranchTrueFalseTotal
if $letter eq "g" 3 19 22
86 22 ▶ $note_nr = 9 if $letter eq 'a';
Branch: 1 branch
BranchTrueFalseTotal
if $letter eq "a" 3 19 22
87 22 ▶ $note_nr = 11 if $letter eq 'b';
Branch: 1 branch
BranchTrueFalseTotal
if $letter eq "b" 3 19 22
88  
89 22 $note_nr += 12*$octave;
90
91 # = ((ord($letter) - ord('c')) ) + 12 * $octave;
92  
93 22 ▶ $note_nr-- if $sign eq '♭';
Branch: 1 branch
BranchTrueFalseTotal
if $sign eq "\x{266d}" 7 15 22
94 22 ▶ $note_nr++ if $sign eq '♯';
Branch: 1 branch
BranchTrueFalseTotal
if $sign eq "\x{266f}" 7 15 22
95  
96 22 my $fract_out = $note_nr % 12;
97 22 my $octave_out = ($note_nr - $fract_out)/12;
98  
99 22 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<http://www.perlfoundation.org/artistic_license_2_0>
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 3 'tq84';
« Csound/Orchestra.pm ↑ Summary Csound/Composition.pm »