18
18
import numpy as np
19
19
from numpy import logical_and , logical_not , logical_or , logical_xor
20
20
21
- from auto_editor .analyze import (
22
- LevelError ,
23
- mut_remove_large ,
24
- mut_remove_small ,
25
- to_threshold ,
26
- )
21
+ from auto_editor .analyze import LevelError , mut_remove_large , mut_remove_small
27
22
from auto_editor .lib .contracts import *
28
23
from auto_editor .lib .data_structs import *
29
24
from auto_editor .lib .err import MyError
@@ -690,6 +685,9 @@ def palet_map(proc: Proc, seq: Any) -> Any:
690
685
return Quoted (tuple (map (proc , seq .val )))
691
686
if isinstance (seq , list | range ):
692
687
return list (map (proc , seq ))
688
+ elif isinstance (seq , np .ndarray ):
689
+ vectorized_proc = np .vectorize (proc )
690
+ return vectorized_proc (seq )
693
691
return proc (seq )
694
692
695
693
@@ -1469,6 +1467,16 @@ def edit_all() -> np.ndarray:
1469
1467
return env ["@levels" ].all ()
1470
1468
1471
1469
1470
+ def audio_levels (stream : int ) -> np .ndarray :
1471
+ if "@levels" not in env :
1472
+ raise MyError ("Can't use `audio` if there's no input media" )
1473
+
1474
+ try :
1475
+ return env ["@levels" ].audio (stream )
1476
+ except LevelError as e :
1477
+ raise MyError (e )
1478
+
1479
+
1472
1480
def edit_audio (
1473
1481
threshold : float = 0.04 ,
1474
1482
stream : object = Sym ("all" ),
@@ -1491,7 +1499,7 @@ def edit_audio(
1491
1499
1492
1500
try :
1493
1501
for s in stream_range :
1494
- audio_list = to_threshold ( levels .audio (s ), threshold )
1502
+ audio_list = levels .audio (s ) >= threshold
1495
1503
if stream_data is None :
1496
1504
stream_data = audio_list
1497
1505
else :
@@ -1521,7 +1529,7 @@ def edit_motion(
1521
1529
levels = env ["@levels" ]
1522
1530
strict = env ["@filesetup" ].strict
1523
1531
try :
1524
- return to_threshold ( levels .motion (stream , blur , width ), threshold )
1532
+ return levels .motion (stream , blur , width ) >= threshold
1525
1533
except LevelError as e :
1526
1534
return raise_ (e ) if strict else levels .all ()
1527
1535
@@ -1582,7 +1590,7 @@ def my_eval(env: Env, node: object) -> Any:
1582
1590
return ref (oper , my_eval (env , node [1 ]))
1583
1591
1584
1592
raise MyError (
1585
- f"Tried to run: { print_str (oper )} with args: { print_str (node [1 :])} "
1593
+ f"{ print_str (oper )} is not a function. Tried to run with args: { print_str (node [1 :])} "
1586
1594
)
1587
1595
1588
1596
if type (oper ) is Syntax :
@@ -1617,6 +1625,7 @@ def my_eval(env: Env, node: object) -> Any:
1617
1625
# edit procedures
1618
1626
"none" : Proc ("none" , edit_none , (0 , 0 )),
1619
1627
"all/e" : Proc ("all/e" , edit_all , (0 , 0 )),
1628
+ "audio-levels" : Proc ("audio-levels" , audio_levels , (1 , 1 ), is_nat ),
1620
1629
"audio" : Proc ("audio" , edit_audio , (0 , 4 ),
1621
1630
is_threshold , orc (is_nat , Sym ("all" )), is_nat ,
1622
1631
{"threshold" : 0 , "stream" : 1 , "minclip" : 2 , "mincut" : 2 }
0 commit comments