| 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
| |||||||||||||
| 55 | |||||||||||||
| 56 | 7 | ▶ | return 1 if ($possible_note =~ /^[a-g][♯♭]?[12]?\d$/); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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
| |||||||||||||
| 73 | |||||||||||||
| 74 | 22 | my $letter = $1; | |||||||||||
| 75 | 22 | ▶ | my $sign = $2 // ''; | ||||||||||
|
Condition50%1/2
$2 // ""
MC/DC0%0/1
$2 // ""
$2
Truth table50%1/2
A
A= $2
| |||||||||||||
| 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
| |||||||||||||
| 82 | 22 | ▶ | $note_nr = 2 if $letter eq 'd'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 83 | 22 | ▶ | $note_nr = 4 if $letter eq 'e'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 84 | 22 | ▶ | $note_nr = 5 if $letter eq 'f'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 85 | 22 | ▶ | $note_nr = 7 if $letter eq 'g'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 86 | 22 | ▶ | $note_nr = 9 if $letter eq 'a'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 87 | 22 | ▶ | $note_nr = 11 if $letter eq 'b'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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
| |||||||||||||
| 94 | 22 | ▶ | $note_nr++ if $sign eq '♯'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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'; | |||||||||||