def test_node_registry(self):
     copy1 = Synth(nodeid=self.synth.nodeid, new=False)
     copy2 = Synth(nodeid=self.custom_nodeid, new=False)
     self.assertIs(self.synth, copy1)
     self.assertIs(self.synth, copy2)
     self.assertIs(copy1, copy2)
     del copy1, copy2
Beispiel #2
0
 def test_reuse_nodeid(self):
     with self.assertWarnsRegex(
         UserWarning, "SynthDesc 's2' is unknown", msg="SynthDesc seems to be known"
     ):
         synth1 = Synth("s2", {"amp": 0.0})
         nodeid = synth1.nodeid
         synth1.free()
         synth1.wait(timeout=1)
         group = Group(nodeid=nodeid)
         with self.assertRaisesRegex(RuntimeError, "Tried to get "):
             Synth("s2", nodeid=nodeid)
         group.free()
         group.wait(timeout=1)
         synth2 = Synth("s2", nodeid=nodeid)
         synth2.free()
         synth2.wait(timeout=1)
Beispiel #3
0
    def test_wait(self):
        duration = 0.15
        tol = 0.05

        def check(synth):
            self.assertEqual(synth.is_playing, None)
            self.assertEqual(synth.started, True)
            self.assertEqual(synth.freed, False)
            self.assertEqual(synth.group, self.sc.server.default_group.nodeid)
            t_wait_for_notification = time.time()
            while not synth.is_playing:
                if time.time() - t_wait_for_notification > 0.15:
                    self.fail("Waiting for /n_go notification took too long.")
            self.assertEqual(synth.is_playing, True)
            self.assertEqual(synth.started, True)
            self.assertEqual(synth.freed, False)
            synth.wait(timeout=1)
            time_played = time.time() - t0
            self.assertEqual(synth.is_playing, False)
            self.assertEqual(synth.started, False)
            self.assertEqual(synth.freed, True)
            self.assertEqual(synth.group, None)
            self.assertLessEqual(time_played, duration + tol)
            self.assertGreaterEqual(time_played, duration - tol)

        t0 = time.time()
        with self.assertWarnsRegex(
            UserWarning, "SynthDesc 's1' is unknown", msg="SynthDesc seems to be known"
        ):
            s1_synth = Synth("s1", controls={"dur": duration, "amp": 0.0})
        check(s1_synth)
        t0 = time.time()
        s1_synth.new()
        check(s1_synth)
 def update_synth(self) -> None:
     """Update volume Synth"""
     amp = 0.0 if self._muted else dbamp(self._volume)
     active = amp != 1.0
     if active:
         if self._server.is_running:
             if self._synth is None:
                 if self._synth_name is None:
                     warnings.warn(
                         "Cannot set volume. Volume SynthDef unknown. Is the default sclang running?"
                     )
                     return
                 controls = {
                     "volumeAmp": amp,
                     "volumeLag": self._lag,
                     "bus": self._server.output_bus.idxs[0],
                 }
                 self._synth = Synth(
                     self._synth_name,
                     add_action=AddAction.AFTER,
                     target=self._server.default_group,
                     controls=controls,
                     server=self._server,
                 )
             else:
                 self._synth.set("volumeAmp", amp)
     else:
         if self._synth is not None:
             self._synth.release()
             self._synth = None
 def test_setattr(self):
     with self.assertWarnsRegex(UserWarning,
                                "SynthDesc 's2' is unknown",
                                msg="SynthDesc seems to be known"):
         synth1 = Synth("s2", controls={"amp": 0.0}, target=self.group)
     with self.assertWarnsRegex(UserWarning,
                                "SynthDesc 's2' is unknown",
                                msg="SynthDesc seems to be known"):
         synth2 = Synth("s2", controls={"amp": 0.0}, target=self.group)
     GroupTest.sc.server.sync()
     cmd_args = {"pan": -1.0, "num": 1}
     for name, value in cmd_args.items():
         self.group.set(name, value)
     GroupTest.sc.server.sync()
     self.assertEqual(synth1.group, self.group.nodeid)
     self.assertEqual(synth2.group, self.group.nodeid)
     for name, value in cmd_args.items():
         self.assertAlmostEqual(synth1.get(name), value)
         self.assertAlmostEqual(synth2.get(name), value)
 def setUp(self) -> None:
     self.assertIsNotNone(SynthTestWithSClang.sc.lang)
     self.custom_nodeid = 42
     self.all_synth_args = {
         "freq": 400,
         "amp": 0.3,
         "num": 4,
         "pan": 0,
         "lg": 0.1
     }
     self.synth = Synth("s2", nodeid=self.custom_nodeid)
 def setUp(self) -> None:
     with self.assertRaises(RuntimeError):
         SynthTest.sc.lang
     self.custom_nodeid = 42
     self.synth_args = {"amp": 0.0, "num": 3}
     warnings.simplefilter("always", UserWarning)
     with self.assertWarnsRegex(UserWarning,
                                "SynthDesc 's2' is unknown",
                                msg="SynthDesc seems to be known"):
         self.synth = Synth("s2",
                            controls=self.synth_args,
                            nodeid=self.custom_nodeid)
     self.assertIsNone(self.synth._synth_desc)
     self.sc.server.sync()
Beispiel #8
0
 def setUp(self) -> None:
     self.assertIsNotNone(VolumeTest.sc.lang)
     VolumeTest.sc.server.unmute()
     self.assertFalse(VolumeTest.sc.server.muted)
     vol_synth = VolumeTest.sc.server._volume._synth
     if vol_synth is not None:
         vol_synth.wait(timeout=1)
     del vol_synth
     self.assertIsNone(VolumeTest.sc.server._volume._synth)
     self.custom_nodeid = 42
     self.all_synth_args = {
         "freq": 400,
         "amp": 0.3,
         "num": 4,
         "pan": 0,
         "lg": 0.1
     }
     self.synth = Synth("s2", nodeid=self.custom_nodeid)
Beispiel #9
0
 def test_duplicate(self):
     self.assertNotIn("/s_new", self.sc.server.fails)
     with self.assertWarnsRegex(
         UserWarning, "SynthDesc 's2' is unknown", msg="SynthDesc seems to be known"
     ):
         synth1 = Synth("s2", controls={"amp": 0.0})
         wait_t0 = time.time()
         synth1.new(controls={"amp": 0.0})
         while not "/s_new" in self.sc.server.fails:
             self.assertLessEqual(time.time() - wait_t0, 0.5)
         self.assertEqual(self.sc.server.fails["/s_new"].get(), "duplicate node ID")
         synth1.free()
         synth1.wait(timeout=1)
         synth1.new({"amp": 0.0})
         synth1.free()
         synth1.wait(timeout=1)
         with self.assertRaises(Empty):
             self.sc.server.fails["/s_new"].get(timeout=0.5)
    def start(
        self,
        timetag: float = 0,
        duration: Optional[float] = None,
        node: Union[Node, int] = 0,
        bus: int = 0,
    ):
        """Start the recording.

        Parameters
        ----------
        timetag : float, by default 0 (immediately)
            Time (or time offset when <1e6) to start
        duration : float, optional
            Length of the recording, by default until stopped.
        node : Union[Node, int], optional
            Node that should be recorded, by default 0
        bus : int, by default 0
            Bus that should be recorded

        Raises
        ------
        RuntimeError
            When trying to start a recording unprepared.
        """
        if self._state != RecorderState.PREPARED:
            raise RuntimeError(
                f"Recorder state must be PREPARED but is {self._state}")
        args = dict(bus=bus,
                    duration=duration or -1,
                    bufnum=self._record_buffer.bufnum)

        with self._server.bundler(timetag=timetag):
            self._record_synth = Synth(
                self._synth_name,
                controls=args,
                server=self._server,
                target=node,
                add_action=AddAction.TO_TAIL,
            )
        self._state = RecorderState.RECORDING
Beispiel #11
0
    def test_fast_wait(self):
        duration = 0.15
        tol = 0.05

        def check(synth):
            self.assertEqual(synth.is_playing, False)
            self.assertEqual(synth.started, False)
            self.assertEqual(synth.freed, True)
            time_played = time.time() - t0
            self.assertLessEqual(time_played, duration + tol)
            self.assertGreaterEqual(time_played, duration - tol)

        t0 = time.time()
        with self.assertWarnsRegex(
            UserWarning, "SynthDesc 's1' is unknown", msg="SynthDesc seems to be known"
        ):
            s1_synth = Synth("s1", controls={"dur": duration, "amp": 0.0})
        s1_synth.wait(timeout=1)
        check(s1_synth)

        t0 = time.time()
        s1_synth.new()
        s1_synth.wait(timeout=1)
        check(s1_synth)
Beispiel #12
0
 def test_too_many_arguments(self):
     with self.assertRaises(TypeError):
         Synth("s2", {"amp": 0.0}, "this is too much!")
     with self.assertRaises(TypeError):
         Group(101, "this is too much!")