pub unsafe fn instantiate(
        &self,
        features: Arc<Features>,
        sample_rate: f64,
    ) -> Result<Instance, InstantiateError> {
        let min_block_size = features.min_block_length();
        let max_block_size = features.max_block_length();

        let (instance_to_worker_sender, instance_to_worker_receiver) = worker::instantiate_queue();
        let (worker_to_instance_sender, worker_to_instance_receiver) = worker::instantiate_queue();
        let mut instance_to_worker_sender = Box::new(instance_to_worker_sender);
        let instance_to_worker_sender_ptr: *mut Producer<u8> = instance_to_worker_sender.as_mut();
        let mut worker_schedule = Box::new(lv2_sys::LV2_Worker_Schedule {
            handle: instance_to_worker_sender_ptr.cast(),
            schedule_work: Some(worker::schedule_work),
        });

        let worker_schedule_ptr: *mut LV2_Worker_Schedule = worker_schedule.as_mut();
        let worker_feature = LV2Feature {
            uri: lv2_sys::LV2_WORKER__schedule.as_ptr() as *mut i8,
            data: worker_schedule_ptr.cast(),
        };

        let iter_features = features.iter_features(&worker_feature);

        let mut instance = self
            .inner
            .instantiate(sample_rate, iter_features)
            .ok_or(InstantiateError::UnknownError)?;

        let control_inputs = Controls::new(self.ports_with_type(PortType::ControlInput));
        let control_outputs = Controls::new(self.ports_with_type(PortType::ControlOutput));
        let mut audio_inputs = Vec::new();
        let mut audio_outputs = Vec::new();
        let mut atom_sequence_inputs = Vec::new();
        let mut atom_sequence_outputs = Vec::new();
        let mut cv_inputs = Vec::new();
        let mut cv_outputs = Vec::new();
        for port in self.ports() {
            match port.port_type {
                PortType::ControlInput => instance
                    .connect_port(port.index.0, control_inputs.value_ptr(port.index).unwrap()),
                PortType::ControlOutput => instance
                    .connect_port(port.index.0, control_outputs.value_ptr(port.index).unwrap()),
                PortType::AudioInput => audio_inputs.push(port.index),
                PortType::AudioOutput => audio_outputs.push(port.index),
                PortType::AtomSequenceInput => atom_sequence_inputs.push(port.index),
                PortType::AtomSequenceOutput => atom_sequence_outputs.push(port.index),
                PortType::CVInput => cv_inputs.push(port.index),
                PortType::CVOutput => cv_outputs.push(port.index),
            }
        }

        let mut inner = instance.activate();
        #[allow(clippy::mutex_atomic)]
        let is_alive = Arc::new(Mutex::new(true));

        let worker_interface =
            worker::maybe_get_worker_interface(&self.inner, &self.common_uris, &mut inner);
        if let Some(worker_interface) = worker_interface.as_ref() {
            let worker = worker::Worker::new(
                is_alive.clone(),
                *worker_interface,
                inner.instance().handle(),
                instance_to_worker_receiver,
                worker_to_instance_sender,
            );
            features.worker_manager().add_worker(worker);
        }

        Ok(Instance {
            inner,
            min_block_size,
            max_block_size,
            control_inputs,
            control_outputs,
            audio_inputs,
            audio_outputs,
            atom_sequence_inputs,
            atom_sequence_outputs,
            cv_inputs,
            cv_outputs,
            worker_interface,
            worker_to_instance_receiver,
            _worker_schedule: worker_schedule,
            _instance_to_worker_sender: instance_to_worker_sender,
            is_alive,
            _features: features,
        })
    }
/// Create a new instance of the plugin.
///
/// # Errors
/// Returns an error if the plugin could not be instantiated.
///
/// # Safety
/// Running plugin code is unsafe.
Create a new instance of the plugin.
Create a new instance of the plugin .
pub unsafe fn instantiate(
        &self,
        features: Arc<Features>,
        sample_rate: f64,
    ) -> Result<Instance, InstantiateError> {
        let min_block_size = features.min_block_length();
        let max_block_size = features.max_block_length();
        let (instance_to_worker_sender, instance_to_worker_receiver) = worker::instantiate_queue();
        let (worker_to_instance_sender, worker_to_instance_receiver) = worker::instantiate_queue();
        let mut instance_to_worker_sender = Box::new(instance_to_worker_sender);
        let instance_to_worker_sender_ptr: *mut Producer<u8> = instance_to_worker_sender.as_mut();
        let mut worker_schedule = Box::new(lv2_sys::LV2_Worker_Schedule {
            handle: instance_to_worker_sender_ptr.cast(),
            schedule_work: Some(worker::schedule_work),
        });
        let worker_schedule_ptr: *mut LV2_Worker_Schedule = worker_schedule.as_mut();
        let worker_feature = LV2Feature {
            uri: lv2_sys::LV2_WORKER__schedule.as_ptr() as *mut i8,
            data: worker_schedule_ptr.cast(),
        };
        let iter_features = features.iter_features(&worker_feature);
        let mut instance = self
            .inner
            .instantiate(sample_rate, iter_features)
            .ok_or(InstantiateError::UnknownError)?;
        let control_inputs = Controls::new(self.ports_with_type(PortType::ControlInput));
        let control_outputs = Controls::new(self.ports_with_type(PortType::ControlOutput));
        let mut audio_inputs = Vec::new();
        let mut audio_outputs = Vec::new();
        let mut atom_sequence_inputs = Vec::new();
        let mut atom_sequence_outputs = Vec::new();
        let mut cv_inputs = Vec::new();
        let mut cv_outputs = Vec::new();
        for port in self.ports() {
            match port.port_type {
                PortType::ControlInput => instance
                    .connect_port(port.index.0, control_inputs.value_ptr(port.index).unwrap()),
                PortType::ControlOutput => instance
                    .connect_port(port.index.0, control_outputs.value_ptr(port.index).unwrap()),
                PortType::AudioInput => audio_inputs.push(port.index),
                PortType::AudioOutput => audio_outputs.push(port.index),
                PortType::AtomSequenceInput => atom_sequence_inputs.push(port.index),
                PortType::AtomSequenceOutput => atom_sequence_outputs.push(port.index),
                PortType::CVInput => cv_inputs.push(port.index),
                PortType::CVOutput => cv_outputs.push(port.index),
            }
        }
        let mut inner = instance.activate();
        #[allow(clippy::mutex_atomic)]
        let is_alive = Arc::new(Mutex::new(true));
        let worker_interface =
            worker::maybe_get_worker_interface(&self.inner, &self.common_uris, &mut inner);
        if let Some(worker_interface) = worker_interface.as_ref() {
            let worker = worker::Worker::new(
                is_alive.clone(),
                *worker_interface,
                inner.instance().handle(),
                instance_to_worker_receiver,
                worker_to_instance_sender,
            );
            features.worker_manager().add_worker(worker);
        }
        Ok(Instance {
            inner,
            min_block_size,
            max_block_size,
            control_inputs,
            control_outputs,
            audio_inputs,
            audio_outputs,
            atom_sequence_inputs,
            atom_sequence_outputs,
            cv_inputs,
            cv_outputs,
            worker_interface,
            worker_to_instance_receiver,
            _worker_schedule: worker_schedule,
            _instance_to_worker_sender: instance_to_worker_sender,
            is_alive,
            _features: features,
        })
    }
pub unsafe fn instantiate ( & self , features : Arc < Features > , sample_rate : f64 , ) -> Result < Instance , InstantiateError > { let min_block_size = features . min_block_length ( ) ; let max_block_size = features . max_block_length ( ) ; let ( instance_to_worker_sender , instance_to_worker_receiver ) = worker :: instantiate_queue ( ) ; let ( worker_to_instance_sender , worker_to_instance_receiver ) = worker :: instantiate_queue ( ) ; let mut instance_to_worker_sender = Box :: new ( instance_to_worker_sender ) ; let instance_to_worker_sender_ptr : * mut Producer < u8 > = instance_to_worker_sender . as_mut ( ) ; let mut worker_schedule = Box :: new ( lv2_sys :: LV2_Worker_Schedule { handle : instance_to_worker_sender_ptr . cast ( ) , schedule_work : Some ( worker :: schedule_work ) , } ) ; let worker_schedule_ptr : * mut LV2_Worker_Schedule = worker_schedule . as_mut ( ) ; let worker_feature = LV2Feature { uri : lv2_sys :: LV2_WORKER__schedule . as_ptr ( ) as * mut i8 , data : worker_schedule_ptr . cast ( ) , } ; let iter_features = features . iter_features ( & worker_feature ) ; let mut instance = self . inner . instantiate ( sample_rate , iter_features ) . ok_or ( InstantiateError :: UnknownError ) ? ; let control_inputs = Controls :: new ( self . ports_with_type ( PortType :: ControlInput ) ) ; let control_outputs = Controls :: new ( self . ports_with_type ( PortType :: ControlOutput ) ) ; let mut audio_inputs = Vec :: new ( ) ; let mut audio_outputs = Vec :: new ( ) ; let mut atom_sequence_inputs = Vec :: new ( ) ; let mut atom_sequence_outputs = Vec :: new ( ) ; let mut cv_inputs = Vec :: new ( ) ; let mut cv_outputs = Vec :: new ( ) ; for port in self . ports ( ) { match port . port_type { PortType :: ControlInput => instance . connect_port ( port . index . 0 , control_inputs . value_ptr ( port . index ) . unwrap ( ) ) , PortType :: ControlOutput => instance . connect_port ( port . index . 0 , control_outputs . value_ptr ( port . index ) . unwrap ( ) ) , PortType :: AudioInput => audio_inputs . push ( port . index ) , PortType :: AudioOutput => audio_outputs . push ( port . index ) , PortType :: AtomSequenceInput => atom_sequence_inputs . push ( port . index ) , PortType :: AtomSequenceOutput => atom_sequence_outputs . push ( port . index ) , PortType :: CVInput => cv_inputs . push ( port . index ) , PortType :: CVOutput => cv_outputs . push ( port . index ) , } } let mut inner = instance . activate ( ) ; # [ allow ( clippy mutex_atomic ) ] let is_alive = Arc :: new ( Mutex :: new ( true ) ) ; let worker_interface = worker :: maybe_get_worker_interface ( & self . inner , & self . common_uris , & mut inner ) ; if let Some ( worker_interface ) = worker_interface . as_ref ( ) { let worker = worker :: Worker :: new ( is_alive . clone ( ) , * worker_interface , inner . instance ( ) . handle ( ) , instance_to_worker_receiver , worker_to_instance_sender , ) ; features . worker_manager ( ) . add_worker ( worker ) ; } Ok ( Instance { inner , min_block_size , max_block_size , control_inputs , control_outputs , audio_inputs , audio_outputs , atom_sequence_inputs , atom_sequence_outputs , cv_inputs , cv_outputs , worker_interface , worker_to_instance_receiver , _worker_schedule : worker_schedule , _instance_to_worker_sender : instance_to_worker_sender , is_alive , _features : features , } ) }
Create a new instance of the plugin.
Create a new instance of the plugin .
&self
features
Arc<Features>
sample_rate
f64
&self
features
Arc<Features>
sample_rate
f64
errors
Returns an error if the plugin could not be instantiated.
Returns an error if the plugin could not be instantiated .
safety
Running plugin code is unsafe.
Running plugin code is unsafe .