1 | <?php |
||
7 | class HarmonicCalculator |
||
8 | { |
||
9 | private $minDistance = 1.0; |
||
10 | private $maxDistance = 120.0; |
||
11 | |||
12 | /** |
||
13 | * Returns a list of possible harmonics that produce a given sounding note. |
||
14 | * |
||
15 | * @param Note $soundingNote The desired sounding note of |
||
16 | * the harmonic. |
||
17 | * @param InstrumentInterface $instrument The instrument. |
||
18 | * @param float $tolerance The maximum deviation (cents) |
||
19 | * between the desired sounding |
||
20 | * note and a natural harmonic. |
||
21 | * |
||
22 | * @return Harmonic[] |
||
23 | */ |
||
24 | public function findHarmonics(Note $soundingNote, InstrumentInterface $instrument, float $tolerance = 50.0): array |
||
41 | |||
42 | /** |
||
43 | * Set the minimum and maximum distance between harmonic stops (in mm). |
||
44 | * |
||
45 | * @param float $minDistance |
||
46 | * @param float $maxDistance |
||
47 | */ |
||
48 | public function setDistanceConstraints(float $minDistance, float $maxDistance) |
||
53 | |||
54 | /** |
||
55 | * Check that the harmonic is within the configured distance constraints. |
||
56 | * |
||
57 | * @see HarmonicCalculator::setDistanceConstraints() |
||
58 | * |
||
59 | * @param \ExtendedStrings\Strings\Harmonic $harmonic |
||
60 | * |
||
61 | * @return bool |
||
62 | */ |
||
63 | private function validateDistance(Harmonic $harmonic): bool |
||
72 | |||
73 | /** |
||
74 | * Calculate the physical distance between two nodes of a harmonic. |
||
75 | * |
||
76 | * @param \ExtendedStrings\Strings\Harmonic $harmonic |
||
77 | * |
||
78 | * @return float |
||
79 | */ |
||
80 | private function getPhysicalDistance(Harmonic $harmonic): float |
||
91 | |||
92 | /** |
||
93 | * Find the artificial harmonics that produce the given sounding note. |
||
94 | * |
||
95 | * @param \ExtendedStrings\Strings\Note $soundingNote |
||
96 | * @param \ExtendedStrings\Strings\VibratingStringInterface $string |
||
97 | * |
||
98 | * @return Harmonic[] |
||
99 | */ |
||
100 | private function findArtificialHarmonics(Note $soundingNote, VibratingStringInterface $string): array |
||
118 | |||
119 | /** |
||
120 | * Find the natural harmonics that produce the given sounding note. |
||
121 | * |
||
122 | * @param \ExtendedStrings\Strings\Note $soundingNote |
||
123 | * @param \ExtendedStrings\Strings\InstrumentStringInterface $string |
||
124 | * @param float $tolerance |
||
125 | * |
||
126 | * @return Harmonic[] |
||
127 | */ |
||
128 | private function findNaturalHarmonics(Note $soundingNote, InstrumentStringInterface $string, float $tolerance = 50.0): array |
||
150 | } |
||
151 |