sonusai 1.0.7__py3-none-any.whl → 1.0.9__py3-none-any.whl

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,8 +1,5 @@
1
- # sai_rand
2
- # sai_rand_choice
3
- # sai_rand_choice_nr
4
- # sai_sequence
5
- # sai_expand
1
+ from numpy.ma.core import choose
2
+ from urllib3.filepost import choose_boundary
6
3
 
7
4
  from ..datatypes import AudioT
8
5
  from ..datatypes import Effects
@@ -28,40 +25,11 @@ def get_effect_rules(location: str, config: dict, test: bool = False) -> dict[st
28
25
  return rules
29
26
 
30
27
 
31
- def sai_expand(text: str) -> list[str]:
32
- import re
33
-
34
- # search pattern
35
- pattern = re.compile(r"sai_expand\((.+?)\)")
36
-
37
- # initialize with input
38
- expanded = [text]
39
-
40
- # look for pattern
41
- result = re.search(pattern, text)
42
-
43
- # if found
44
- if result:
45
- # remove entry we are expanding
46
- expanded.pop()
47
-
48
- # convert match into list stripped of whitespace
49
- values = result.group(1).replace(" ", "").split(",")
50
-
51
- # loop over values
52
- for value in values:
53
- # replace pattern with value
54
- replacement = re.sub(pattern, value, text, count=1)
55
-
56
- # extend result with expand of replacement (for handling multiple expands in a single rule)
57
- expanded.extend(sai_expand(replacement))
58
-
59
- return expanded
60
-
61
-
62
28
  def _expand_effect_rules(expanded_rules: list[dict], rule: dict) -> list[dict]:
63
29
  from copy import deepcopy
64
30
 
31
+ from .parse import sai_expand
32
+
65
33
  for key in ("pre", "post"):
66
34
  if key in rule:
67
35
  value = rule[key]
@@ -274,8 +242,8 @@ def evaluate_sai_random_float(text: str) -> str:
274
242
  return resolved
275
243
 
276
244
 
277
- def evaluate_sai_random_ir(mixdb: MixtureDatabase, text: str) -> str:
278
- """Evaluate 'sai_rand' directive for ir
245
+ def evaluate_sai_choose_ir(mixdb: MixtureDatabase, text: str) -> str:
246
+ """Evaluate 'sai_choose' directive for ir
279
247
 
280
248
  :param mixdb: Mixture database
281
249
  :param text: Text to evaluate
@@ -285,11 +253,11 @@ def evaluate_sai_random_ir(mixdb: MixtureDatabase, text: str) -> str:
285
253
  from random import choice
286
254
  from random import randint
287
255
 
288
- rand_pattern = re.compile(r"^ir sai_rand$")
289
- rand_range_pattern = re.compile(r"^ir sai_rand\(([-+]?\d+),\s*([-+]?\d+)\)$")
290
- rand_tag_pattern = re.compile(r"^ir sai_rand\((\w+)\)$")
256
+ choose_pattern = re.compile(r"^ir sai_choose\(\)$")
257
+ choose_range_pattern = re.compile(r"^ir sai_choose\(([-+]?\d+),\s*([-+]?\d+)\)$")
258
+ choose_tag_pattern = re.compile(r"^ir sai_choose\((\w+)\)$")
291
259
 
292
- def rand_range_repl(m) -> str:
260
+ def choose_range_repl(m) -> str:
293
261
  lower = int(m.group(1))
294
262
  upper = int(m.group(2))
295
263
  if (
@@ -304,22 +272,22 @@ def evaluate_sai_random_ir(mixdb: MixtureDatabase, text: str) -> str:
304
272
  raise ValueError(f"Invalid rule: '{text}'. Values must be integers between 0 and {mixdb.num_ir_files - 1}.")
305
273
  return f"ir {randint(lower, upper)}" # noqa: S311
306
274
 
307
- def rand_tag_repl(m) -> str:
275
+ def choose_tag_repl(m) -> str:
308
276
  return m.group(1)
309
277
 
310
- if re.match(rand_pattern, text):
278
+ if re.match(choose_pattern, text):
311
279
  return f"ir {randint(0, mixdb.num_ir_files - 1)}" # noqa: S311
312
280
 
313
- if re.match(rand_range_pattern, text):
281
+ if re.match(choose_range_pattern, text):
314
282
  try:
315
- return f"ir {eval(re.sub(rand_range_pattern, rand_range_repl, text))}" # noqa: S307
283
+ return f"ir {eval(re.sub(choose_range_pattern, choose_range_repl, text))}" # noqa: S307
316
284
  except Exception as e:
317
285
  raise ValueError(
318
286
  f"Invalid rule: '{text}'. Values must be integers between 0 and {mixdb.num_ir_files - 1}."
319
287
  ) from e
320
288
 
321
- if re.match(rand_tag_pattern, text):
322
- tag = re.sub(rand_tag_pattern, rand_tag_repl, text)
289
+ if re.match(choose_tag_pattern, text):
290
+ tag = re.sub(choose_tag_pattern, choose_tag_repl, text)
323
291
  if tag in mixdb.ir_tags:
324
292
  return f"ir {choice(mixdb.ir_file_ids_for_tag(tag))}" # noqa: S311
325
293
 
@@ -336,10 +304,9 @@ def effects_from_rules(mixdb: MixtureDatabase, rules: Effects) -> Effects:
336
304
  entries = getattr(effects, key)
337
305
  for idx, entry in enumerate(entries):
338
306
  if entry.find("sai_rand") != -1:
339
- if entry.startswith("ir"):
340
- entries[idx] = evaluate_sai_random_ir(mixdb, entry)
341
- else:
342
- entries[idx] = evaluate_sai_random_float(entry)
307
+ entries[idx] = evaluate_sai_random_float(entry)
308
+ if entry.startswith("ir sai_choose"):
309
+ entries[idx] = evaluate_sai_choose_ir(mixdb, entry)
343
310
  setattr(effects, key, entries)
344
311
 
345
312
  return effects