Beispiel #1
0
 def test_01(self):
     session = nonrealtimetools.Session()
     bus_one = session.add_bus()
     bus_two = session.add_bus()
     with session.at(0):
         bus_one.set_(10)
     with session.at(2):
         bus_one.set_(20)
         bus_two.set_(30)
     with session.at(3):
         bus_two.set_(40)
     assert session.to_osc_bundles() == [
         osctools.OscBundle(
             timestamp=0.0,
             contents=(
                 osctools.OscMessage('/c_set', 0, 10.0),
                 )
             ),
         osctools.OscBundle(
             timestamp=2.0,
             contents=(
                 osctools.OscMessage('/c_set', 0, 20.0, 1, 30.0),
                 )
             ),
         osctools.OscBundle(
             timestamp=3.0,
             contents=(
                 osctools.OscMessage('/c_set', 1, 40.0),
                 osctools.OscMessage(0),
                 )
             )
         ]
Beispiel #2
0
 def test_04(self):
     session = nonrealtimetools.Session()
     with session.at(0):
         session.add_synth(
             duration=1,
             synthdef=self.build_gate_synthdef(),
         )
     assert session.to_osc_bundles(duration=2) == [
         osctools.OscBundle(
             timestamp=0.0,
             contents=(
                 osctools.OscMessage(
                     '/d_recv',
                     bytearray(
                         b'SCgf\x00\x00\x00\x02\x00\x01 fc663c6d1f8badaed1bd3e25cf2220f0\x00\x00\x00\x08?\x80\x00\x00\x00\x00\x00\x00@\x00\x00\x00\xc2\xc6\x00\x00<#\xd7\n@\xa0\x00\x00\xc0\x80\x00\x00C\xdc\x00\x00\x00\x00\x00\x01?\x80\x00\x00\x00\x00\x00\x01\x04gate\x00\x00\x00\x00\x00\x00\x00\x05\x07Control\x01\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x01\x06EnvGen\x02\x00\x00\x00\x11\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\x00\x00\x00\x00\xff\xff\xff\xff\x00\x00\x00\x01\xff\xff\xff\xff\x00\x00\x00\x00\xff\xff\xff\xff\x00\x00\x00\x01\xff\xff\xff\xff\x00\x00\x00\x01\xff\xff\xff\xff\x00\x00\x00\x02\xff\xff\xff\xff\x00\x00\x00\x00\xff\xff\xff\xff\x00\x00\x00\x03\xff\xff\xff\xff\x00\x00\x00\x00\xff\xff\xff\xff\x00\x00\x00\x04\xff\xff\xff\xff\x00\x00\x00\x05\xff\xff\xff\xff\x00\x00\x00\x06\xff\xff\xff\xff\x00\x00\x00\x01\xff\xff\xff\xff\x00\x00\x00\x00\xff\xff\xff\xff\x00\x00\x00\x05\xff\xff\xff\xff\x00\x00\x00\x06\x02\x03Saw\x02\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\xff\xff\xff\xff\x00\x00\x00\x07\x02\x0cBinaryOpUGen\x02\x00\x00\x00\x02\x00\x00\x00\x01\x00\x02\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x02\x03Out\x02\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\x00\x00\x00\x01\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00'
                     )),
                 osctools.OscMessage('/s_new',
                                     'fc663c6d1f8badaed1bd3e25cf2220f0',
                                     1000, 0, 0),
             )),
         osctools.OscBundle(timestamp=1.0,
                            contents=(osctools.OscMessage(
                                '/n_set', 1000, 'gate', 0), )),
         osctools.OscBundle(timestamp=2.0,
                            contents=(osctools.OscMessage(0), )),
     ]
Beispiel #3
0
 def test_03(self):
     session = nonrealtimetools.Session()
     synthdef = self.build_duration_synthdef()
     with session.at(0):
         session.add_synth(
             duration=1,
             synthdef=self.build_duration_synthdef(),
         )
     assert session.to_osc_bundles() == [
         osctools.OscBundle(
             timestamp=0.0,
             contents=(
                 osctools.OscMessage('/d_recv',
                                     bytearray(synthdef.compile())),
                 osctools.OscMessage('/s_new',
                                     '448a8d487adfc99ec697033edc2a1227',
                                     1000, 0, 0),
             )),
         osctools.OscBundle(timestamp=1.0,
                            contents=(
                                osctools.OscMessage('/n_free', 1000),
                                osctools.OscMessage(0),
                            )),
     ]
     exit_code, _ = session.render(
         self.output_filepath,
         output_bus_channel_count=1,
     )
     self.assert_ok(exit_code, 1., 44100, 1)
     soundfile = soundfiletools.SoundFile(self.output_filepath)
     for i in range(1, 100):
         value = float(i) / 100
         assert self.round(soundfile.at_percent(value)[0]) == value
Beispiel #4
0
 def send_messages(self):
     from supriya.tools import osctools
     from supriya.tools import requesttools
     messages = []
     prototype = (osctools.OscMessage, osctools.OscBundle)
     for message in self._messages:
         if not isinstance(message, prototype):
             message = message.to_osc_message()
         messages.append(message)
     if self._sync and not self._synchronizing_request:
         sync_id = self._server.next_sync_id
         sync_request = requesttools.SyncRequest(sync_id=sync_id, )
         message = sync_request.to_osc_message()
         messages.append(message)
     if 1 < len(messages) or self._timestamp is not None:
         self._result = osctools.OscBundle(
             timestamp=self._timestamp,
             contents=messages,
         )
     else:
         self._result = messages[0]
     if not self._send_to_server:
         return
     if self._sync:
         sync_request = self._synchronizing_request or sync_request
         sync_request.communicate(
             message=self.result,
             server=self._server,
         )
     else:
         self._server.send_message(self._result)
Beispiel #5
0
 def to_osc_bundle(self, with_textual_osc_command=False):
     contents = []
     for x in self.contents:
         if isinstance(x, type(self)):
             contents.append(x.to_osc_bundle(with_textual_osc_command))
         else:
             contents.append(x.to_osc_message(with_textual_osc_command))
     bundle = osctools.OscBundle(
         timestamp=self.timestamp,
         contents=contents,
     )
     return bundle
Beispiel #6
0
 def _to_non_xrefd_osc_bundles(
     self,
     duration=None,
 ):
     id_mapping = self._build_id_mapping()
     if self.duration == float('inf'):
         assert duration is not None and 0 < duration < float('inf')
     duration = duration or self.duration
     offsets = self.offsets[1:]
     if duration not in offsets:
         offsets.append(duration)
         offsets.sort()
     buffer_settings = self._collect_buffer_settings(id_mapping, )
     bus_settings = self._collect_bus_settings(id_mapping)
     is_last_offset = False
     osc_bundles = []
     buffer_open_states = {}
     visited_synthdefs = set()
     for offset in offsets:
         osc_messages = []
         if offset == duration:
             is_last_offset = True
         requests = self._collect_requests_at_offset(
             buffer_open_states,
             buffer_settings,
             bus_settings,
             duration,
             id_mapping,
             is_last_offset,
             offset,
             visited_synthdefs,
         )
         osc_messages.extend(_.to_osc_message(True) for _ in requests)
         if is_last_offset:
             osc_messages.append(osctools.OscMessage(0))
         if osc_messages:
             osc_bundle = osctools.OscBundle(
                 timestamp=float(offset),
                 contents=osc_messages,
             )
             osc_bundles.append(osc_bundle)
         if is_last_offset:
             break
     return osc_bundles