1 | <?php |
||
7 | class HarmonicCalculator |
||
8 | { |
||
9 | private $minStopDistance = 1.0; |
||
10 | private $maxStopDistance = 120.0; |
||
11 | private $minBowedDistance = 20.0; |
||
12 | private $maxSoundingNoteDifference = 50.0; |
||
13 | |||
14 | /** |
||
15 | * Returns a list of possible harmonics that produce a given sounding note. |
||
16 | * |
||
17 | * @param Note $soundingNote The desired sounding note of |
||
18 | * the harmonic. |
||
19 | * @param InstrumentInterface $instrument The instrument. |
||
20 | * |
||
21 | * @return Harmonic[] |
||
22 | */ |
||
23 | public function findHarmonics(Note $soundingNote, InstrumentInterface $instrument): array |
||
40 | |||
41 | /** |
||
42 | * Set constraints on the physical distance between harmonic stops. |
||
43 | * |
||
44 | * @param float $minStopDistance The minimum distance between stops (mm). |
||
45 | * @param float $maxStopDistance The maximum distance between stops (mm). |
||
46 | * @param float $minBowedDistance The minimum distance between the upper |
||
47 | * harmonic stop and the bridge (mm). |
||
48 | */ |
||
49 | public function setPhysicalDistanceConstraints(float $minStopDistance, float $maxStopDistance, float $minBowedDistance) |
||
55 | |||
56 | /** |
||
57 | * Set the max difference between the sounding note and natural harmonics. |
||
58 | * |
||
59 | * @param float $difference The difference in cents (default: 50.0). |
||
60 | */ |
||
61 | public function setMaxSoundingNoteDifference(float $difference) |
||
65 | |||
66 | /** |
||
67 | * Check that the harmonic is within the configured distance constraints. |
||
68 | * |
||
69 | * @see HarmonicCalculator::setPhysicalDistanceConstraints() |
||
70 | * |
||
71 | * @param \ExtendedStrings\Strings\Harmonic $harmonic |
||
72 | * |
||
73 | * @return bool |
||
74 | */ |
||
75 | private function validatePhysicalDistance(Harmonic $harmonic): bool |
||
87 | |||
88 | /** |
||
89 | * Find the physical distance between the stops of a harmonic. |
||
90 | * |
||
91 | * @param \ExtendedStrings\Strings\Harmonic $harmonic |
||
92 | * |
||
93 | * @return float |
||
94 | */ |
||
95 | private function getPhysicalDistanceBetweenStops(Harmonic $harmonic): float |
||
100 | |||
101 | /** |
||
102 | * Find the physical distance between a harmonic's half-stop and the bridge. |
||
103 | * |
||
104 | * @param \ExtendedStrings\Strings\Harmonic $harmonic |
||
105 | * |
||
106 | * @return float |
||
107 | */ |
||
108 | private function getBowedDistance(Harmonic $harmonic): float |
||
112 | |||
113 | /** |
||
114 | * Find the physical length of the harmonic's string. |
||
115 | * |
||
116 | * @param Harmonic $harmonic |
||
117 | * |
||
118 | * @return float |
||
119 | */ |
||
120 | private function getPhysicalStringLength(Harmonic $harmonic): float |
||
128 | |||
129 | /** |
||
130 | * Find the artificial harmonics that produce the given sounding note. |
||
131 | * |
||
132 | * @param \ExtendedStrings\Strings\Note $soundingNote |
||
133 | * @param \ExtendedStrings\Strings\VibratingStringInterface $string |
||
134 | * |
||
135 | * @return Harmonic[] |
||
136 | */ |
||
137 | private function findArtificialHarmonics(Note $soundingNote, VibratingStringInterface $string): array |
||
155 | |||
156 | /** |
||
157 | * Find the natural harmonics that produce the given sounding note. |
||
158 | * |
||
159 | * @param \ExtendedStrings\Strings\Note $soundingNote |
||
160 | * @param \ExtendedStrings\Strings\InstrumentStringInterface $string |
||
161 | * |
||
162 | * @return Harmonic[] |
||
163 | */ |
||
164 | private function findNaturalHarmonics(Note $soundingNote, InstrumentStringInterface $string): array |
||
186 | } |
||
187 |