hum 1.0.7__tar.gz → 1.0.9__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hum
3
- Version: 1.0.7
3
+ Version: 1.0.9
4
4
  Summary: A python synthesizer for creating and manipulating audio signals.
5
5
  Home-page: https://github.com/thorwhalen/hum
6
6
  License: mit
@@ -17,11 +17,14 @@ def estimate_chunk_frequency(chk: Iterable, sr: int):
17
17
  # Find peaks in the FFT result
18
18
  peaks, _ = find_peaks(np.abs(yf[: N // 2]), height=0)
19
19
 
20
- # Get the frequencies of the peaks
21
- peak_freqs = xf[peaks]
22
-
23
- # Return the frequency with the highest amplitude
24
- return peak_freqs[np.argmax(np.abs(yf[peaks]))]
20
+ if len(peaks) > 0:
21
+ # Get the frequencies of the peaks
22
+ peak_freqs = xf[peaks]
23
+
24
+ # Return the frequency with the highest amplitude
25
+ return peak_freqs[np.argmax(np.abs(yf[peaks]))]
26
+ else:
27
+ return None
25
28
 
26
29
 
27
30
  def estimate_frequencies(wf: Iterable, sr: int, chunker: int | Callable):
@@ -770,7 +770,9 @@ class Synth(MutableMapping):
770
770
 
771
771
  for k, v in updates.items():
772
772
  if self._has_value_trans and k in self._value_trans:
773
+ before_v = v
773
774
  v = self._value_trans[k](v)
775
+ print(f"{before_v} -> {v}")
774
776
  if k in self._dials:
775
777
  live_updates[k] = v
776
778
  elif k in self._settings:
@@ -1101,6 +1103,14 @@ class Synth(MutableMapping):
1101
1103
 
1102
1104
  for key, val in updates.items():
1103
1105
  target = raw_params[key] if raw_params else self.knobs[key]
1106
+
1107
+ if self._has_value_trans:
1108
+ if not isinstance(val, dict):
1109
+ val = self._value_trans[key](val)
1110
+ else:
1111
+ if "value" in val:
1112
+ val["value"] = self._value_trans[key](val["value"])
1113
+
1104
1114
  if isinstance(target, SigTo):
1105
1115
  if isinstance(val, dict):
1106
1116
  for attr in ["value", "time", "mul", "add"]:
@@ -14,6 +14,11 @@ import numpy as np
14
14
  T = TypeVar("T")
15
15
 
16
16
 
17
+ def return_none(*args, **kwargs):
18
+ """Return None for any arguments."""
19
+ return None
20
+
21
+
17
22
  def simple_chunker(
18
23
  a: Iterable[T], chk_size: int, *, include_tail: bool = True
19
24
  ) -> Iterator[Tuple[T, ...]]:
@@ -113,6 +118,10 @@ def round_numbers(items, round_to=0.001, *, index_of_item_number=None, egress=No
113
118
  yield egress(item)
114
119
 
115
120
 
121
+ # ----------------------------------------------------------------------------------
122
+ # Frequency snappers
123
+ # ----------------------------------------------------------------------------------
124
+
116
125
  from bisect import bisect_left
117
126
  from math import log2
118
127
 
@@ -162,6 +171,7 @@ class SnapToChromatic:
162
171
 
163
172
  DFLT_OCTAVE_RANGE = (0, 10)
164
173
  DFLT_TUNING = 440.0 # A4 tuning frequency
174
+ DFLT_SCALE_MIDI_NOTES = (0, 2, 4, 5, 7, 9, 11) # C major scale
165
175
 
166
176
 
167
177
  def tempered_semitone_frequencies(
@@ -201,9 +211,30 @@ def tempered_semitone_frequencies(
201
211
  return sorted(gen_freqs())
202
212
 
203
213
 
214
+ def scale_frequencies(
215
+ scale: Iterable[Union[float, int]] = DFLT_SCALE_MIDI_NOTES,
216
+ *,
217
+ tuning=DFLT_TUNING,
218
+ octave_range=DFLT_OCTAVE_RANGE,
219
+ ):
220
+ """
221
+ Get frequencies for a given scale.
222
+
223
+ :param scale: A list of integers representing the scale.
224
+ For example, (0, 2, 4, 5, 7, 9, 11) corresponds to the C major scale.
225
+ :param tuning: The tuning frequency (default is 440 Hz).
226
+ :param octave_range: A tuple of two integers representing the range of octaves.
227
+ :return: A list of frequencies corresponding to the notes in the given scale.
228
+ """
229
+ chromatic_scale = tempered_semitone_frequencies(
230
+ tuning=tuning, octave_range=octave_range
231
+ )
232
+ return [chromatic_scale[i] for i in range(len(chromatic_scale)) if i % 12 in scale]
233
+
234
+
204
235
  # TODO: Add string_to_scale_map argument to convert string to midi note array scale
205
236
  def scale_snapper(
206
- scale: Iterable[Union[float, int]] = (0, 2, 4, 5, 7, 9, 11),
237
+ scale: Iterable[Union[float, int]] = DFLT_SCALE_MIDI_NOTES,
207
238
  *,
208
239
  tuning=DFLT_TUNING,
209
240
  octave_range=DFLT_OCTAVE_RANGE,
@@ -245,15 +276,14 @@ def scale_snapper(
245
276
  493.8833...
246
277
 
247
278
  """
248
- chromatic_scale = tempered_semitone_frequencies(
249
- tuning=tuning, octave_range=octave_range
279
+ _scale_frequencies = scale_frequencies(
280
+ scale=scale, tuning=tuning, octave_range=octave_range
250
281
  )
251
- # keep all elements of chromatic_scale that have index in midi_notes module 12
252
- scale_frequencies = [
253
- chromatic_scale[i] for i in range(len(chromatic_scale)) if i % 12 in scale
254
- ]
255
282
  # create a ListSnapper object
256
- return ListSnapper(scale_frequencies)
283
+ return ListSnapper(_scale_frequencies)
284
+
285
+
286
+ # ----------------------------------------------------------------------------------
257
287
 
258
288
 
259
289
  def getmodulename(obj, default=""):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hum
3
- Version: 1.0.7
3
+ Version: 1.0.9
4
4
  Summary: A python synthesizer for creating and manipulating audio signals.
5
5
  Home-page: https://github.com/thorwhalen/hum
6
6
  License: mit
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = hum
3
- version = 1.0.7
3
+ version = 1.0.9
4
4
  url = https://github.com/thorwhalen/hum
5
5
  platforms = any
6
6
  description_file = README.md
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes