World

Struct World 

Source
pub struct World { /* private fields */ }
Expand description

The world represents all Lilv state. It is used to discover/load/cache LV2 data (plugins, UIs, and extensions).

Implementations§

Source§

impl World

Source

pub fn new() -> Self

Initializes a new, empty world.

§Panics

Panics if the world could not be created.

Examples found in repository?
examples/lv2ls.rs (line 4)
3fn main() {
4    let world = World::new();
5    world.load_all();
6
7    let show_names = false;
8
9    let print = |plugin: Plugin| {
10        if show_names {
11            String::from(plugin.name().as_str().unwrap())
12        } else {
13            String::from(plugin.uri().as_uri().unwrap())
14        }
15    };
16
17    let plugins = world
18        .plugins()
19        .iter()
20        .filter(Plugin::verify)
21        .map(print)
22        .collect::<Vec<_>>();
23
24    debug_assert_eq!(world.plugins().count(), plugins.len());
25
26    for uri in plugins {
27        println!("{}", uri);
28    }
29}
More examples
Hide additional examples
examples/lv2info.rs (line 236)
235fn main() {
236    let w = World::new();
237    w.load_all();
238
239    let nodes = Nodes {
240        control_class: w.new_uri("http://lv2plug.in/ns/lv2core#ControlPort"),
241        event_class: w.new_uri("http://lv2plug.in/ns/ext/atom#AtomPort"),
242        group_pred: w.new_uri("http://lv2plug.in/ns/ext/port-groups#group"),
243        label_pred: w.new_uri("http://www.w3.org/2000/01/rdf-schema#label"),
244        preset_class: w.new_uri("http://lv2plug.in/ns/ext/presets#Preset"),
245        designation_pred: w.new_uri("http://lv2plug.in/ns/lv2core#designation"),
246        supports_event_pred: w.new_uri("http://lv2plug.in/ns/ext/atom#supportsEvent"),
247    };
248
249    for p in w.plugins().iter().filter(Plugin::verify) {
250        print_plugin(&w, &p, &nodes);
251    }
252}
Source

pub fn with_load_all() -> World

Loads a new world with all the installed LV2 bundles on the system.

§Example
let world = lilv::World::new();
world.load_all();
Source§

impl World

Source

pub fn plugin_class(&self) -> Option<Class>

Get the parent of all other plugin classes, lv2:Plugin.

Source

pub fn plugins(&self) -> Plugins

An iterable over all the plugins in the world.

Examples found in repository?
examples/lv2ls.rs (line 18)
3fn main() {
4    let world = World::new();
5    world.load_all();
6
7    let show_names = false;
8
9    let print = |plugin: Plugin| {
10        if show_names {
11            String::from(plugin.name().as_str().unwrap())
12        } else {
13            String::from(plugin.uri().as_uri().unwrap())
14        }
15    };
16
17    let plugins = world
18        .plugins()
19        .iter()
20        .filter(Plugin::verify)
21        .map(print)
22        .collect::<Vec<_>>();
23
24    debug_assert_eq!(world.plugins().count(), plugins.len());
25
26    for uri in plugins {
27        println!("{}", uri);
28    }
29}
More examples
Hide additional examples
examples/lv2info.rs (line 249)
235fn main() {
236    let w = World::new();
237    w.load_all();
238
239    let nodes = Nodes {
240        control_class: w.new_uri("http://lv2plug.in/ns/lv2core#ControlPort"),
241        event_class: w.new_uri("http://lv2plug.in/ns/ext/atom#AtomPort"),
242        group_pred: w.new_uri("http://lv2plug.in/ns/ext/port-groups#group"),
243        label_pred: w.new_uri("http://www.w3.org/2000/01/rdf-schema#label"),
244        preset_class: w.new_uri("http://lv2plug.in/ns/ext/presets#Preset"),
245        designation_pred: w.new_uri("http://lv2plug.in/ns/lv2core#designation"),
246        supports_event_pred: w.new_uri("http://lv2plug.in/ns/ext/atom#supportsEvent"),
247    };
248
249    for p in w.plugins().iter().filter(Plugin::verify) {
250        print_plugin(&w, &p, &nodes);
251    }
252}
Source§

impl World

Source

pub fn set_option(&self, uri: &str, value: &Node)

Sets an option for the world.

§Panics

Panics if uri could not be converted to a CString.

Source§

impl World

Source

pub fn new_uri(&self, uri: &str) -> Node

Creates a new URI value.

§Panics

Panics on failure.

Examples found in repository?
examples/lv2info.rs (line 240)
235fn main() {
236    let w = World::new();
237    w.load_all();
238
239    let nodes = Nodes {
240        control_class: w.new_uri("http://lv2plug.in/ns/lv2core#ControlPort"),
241        event_class: w.new_uri("http://lv2plug.in/ns/ext/atom#AtomPort"),
242        group_pred: w.new_uri("http://lv2plug.in/ns/ext/port-groups#group"),
243        label_pred: w.new_uri("http://www.w3.org/2000/01/rdf-schema#label"),
244        preset_class: w.new_uri("http://lv2plug.in/ns/ext/presets#Preset"),
245        designation_pred: w.new_uri("http://lv2plug.in/ns/lv2core#designation"),
246        supports_event_pred: w.new_uri("http://lv2plug.in/ns/ext/atom#supportsEvent"),
247    };
248
249    for p in w.plugins().iter().filter(Plugin::verify) {
250        print_plugin(&w, &p, &nodes);
251    }
252}
Source

pub fn new_file_uri(&self, host: Option<&str>, path: &str) -> Node

Creates a new file URI value.

§Panics

Panics on failure.

Source

pub fn new_string(&self, string: &str) -> Node

Creates a new string value (with no language).

§Panics

Panics on failure.

Source

pub fn new_int(&self, value: i32) -> Node

Creates a new integer value.

§Panics

Panics on failure.

Source

pub fn new_float(&self, value: f32) -> Node

Creates a new floating point value.

§Panics

Panics on failure.

Source

pub fn new_bool(&self, value: bool) -> Node

Creates a new boolean value.

§Panics

Panics on failure.

Source§

impl World

Source

pub fn load_all(&self)

Loads all installed LV2 bundles on the system.

§Example
let world = lilv::World::new();
world.load_all();
Examples found in repository?
examples/lv2ls.rs (line 5)
3fn main() {
4    let world = World::new();
5    world.load_all();
6
7    let show_names = false;
8
9    let print = |plugin: Plugin| {
10        if show_names {
11            String::from(plugin.name().as_str().unwrap())
12        } else {
13            String::from(plugin.uri().as_uri().unwrap())
14        }
15    };
16
17    let plugins = world
18        .plugins()
19        .iter()
20        .filter(Plugin::verify)
21        .map(print)
22        .collect::<Vec<_>>();
23
24    debug_assert_eq!(world.plugins().count(), plugins.len());
25
26    for uri in plugins {
27        println!("{}", uri);
28    }
29}
More examples
Hide additional examples
examples/lv2info.rs (line 237)
235fn main() {
236    let w = World::new();
237    w.load_all();
238
239    let nodes = Nodes {
240        control_class: w.new_uri("http://lv2plug.in/ns/lv2core#ControlPort"),
241        event_class: w.new_uri("http://lv2plug.in/ns/ext/atom#AtomPort"),
242        group_pred: w.new_uri("http://lv2plug.in/ns/ext/port-groups#group"),
243        label_pred: w.new_uri("http://www.w3.org/2000/01/rdf-schema#label"),
244        preset_class: w.new_uri("http://lv2plug.in/ns/ext/presets#Preset"),
245        designation_pred: w.new_uri("http://lv2plug.in/ns/lv2core#designation"),
246        supports_event_pred: w.new_uri("http://lv2plug.in/ns/ext/atom#supportsEvent"),
247    };
248
249    for p in w.plugins().iter().filter(Plugin::verify) {
250        print_plugin(&w, &p, &nodes);
251    }
252}
Source

pub fn load_bundle(&self, bundle_uri: &Node)

Loads a specific bundle. bundle_uri must be a fully qualified URI to the bundle directory, with the trailing slash, eg file:///usr/lib/lv2/foo.lv2/.

Source

pub fn load_specifications(&self)

Loads all specifications from currently loaded bundles.

This is for hosts that explicitly load specific bundles, its use is not necessary when using load_all. This function parses the specifications and adds them to the model.

Source

pub fn load_plugin_classes(&self)

Load all plugin classes from currently loaded specifications.

Must be called after load_specifications. This is for hosts that explicitly load specific bundles; its use is not necessary when using load_all.

Source

pub unsafe fn unload_bundle(&self, bundle_uri: &Node) -> bool

Unload a specific bundle.

This unloads statements loaded by load_bundle. Note this is not necessarily all information loaded from the bundle. If any resources have been separately loaded with load_resource, they must be separately unloaded with unload_resource.

§Safety

Unloading bundles that are in use by the host will cause undefined behaviour.

Source

pub fn load_resource(&self, resource: &Node) -> Option<usize>

Load all the data associated with the given resource.

§Return

The number of files parsed.

Examples found in repository?
examples/lv2info.rs (line 211)
101fn print_plugin(world: &World, p: &Plugin, nodes: &Nodes) {
102    println!("{}\n", p.uri().as_uri().unwrap());
103    println!("\tName:              {}", p.name().as_str().unwrap());
104    println!(
105        "\tClass:             {}",
106        p.class().label().as_str().unwrap()
107    );
108
109    if let Some(val) = p.author_name() {
110        println!("\tAuthor:            {}", val.as_str().unwrap());
111    }
112
113    if let Some(val) = p.author_email() {
114        println!("\tAuthor Email:      {}", val.as_str().unwrap());
115    }
116
117    if let Some(val) = p.author_homepage() {
118        println!("\tAuthor Homepage:   {}", val.as_uri().unwrap());
119    }
120
121    if let Some(latency_port) = p.latency_port_index() {
122        println!(
123            "\tHas latency:       yes, reported by port {}",
124            latency_port
125        );
126    } else {
127        println!("\tHas latency:       no");
128    }
129
130    println!("\tBundle:            {}", p.bundle_uri().as_uri().unwrap());
131    println!(
132        "\tBinary:            {}",
133        p.library_uri().map_or("<none>".to_string(), |node| node
134            .as_uri()
135            .unwrap()
136            .to_string())
137    );
138
139    if let Some(uis) = p.uis() {
140        println!("\tUIs:");
141
142        for ui in uis {
143            println!("\t\t{}", ui.uri().as_uri().unwrap());
144
145            for tyep in ui.classes() {
146                println!("\t\t\tClass:  {}", tyep.as_uri().unwrap());
147            }
148
149            println!(
150                "\t\t\tBinary: {}",
151                ui.binary_uri().unwrap().as_uri().unwrap()
152            );
153            println!(
154                "\t\t\tBundle: {}",
155                ui.bundle_uri().unwrap().as_uri().unwrap()
156            );
157        }
158    }
159
160    print!("\tData URIs:         ");
161
162    for (i, uri) in p.data_uris().iter().enumerate() {
163        if i != 0 {
164            print!("\n\t                   ");
165        }
166
167        print!("{}", uri.as_uri().unwrap());
168    }
169
170    println!();
171
172    let features = p.required_features();
173    print!("\tRequired Features: ");
174
175    for (i, feature) in features.iter().enumerate() {
176        if i != 0 {
177            print!("\n\t                   ");
178        }
179        print!("{}", feature.as_uri().unwrap());
180    }
181    println!();
182
183    let features = p.optional_features();
184    print!("\tOptional Features: ");
185
186    for (i, feature) in features.iter().enumerate() {
187        if i != 0 {
188            print!("\n\t                   ");
189        }
190        print!("{}", feature.as_uri().unwrap());
191    }
192    println!();
193
194    if let Some(data) = p.extension_data() {
195        print!("\tExtension Data:    ");
196
197        for (i, d) in data.iter().enumerate() {
198            if i != 0 {
199                print!("\n\t                   ");
200            }
201            print!("{}", d.as_uri().unwrap());
202        }
203        println!();
204    }
205
206    if let Some(presets) = p.related(Some(&nodes.preset_class)) {
207        if presets.count() != 0 {
208            println!("\tPresets: ");
209
210            for preset in presets {
211                world.load_resource(&preset).unwrap();
212
213                let titles = world.find_nodes(Some(&preset), &nodes.label_pred, None);
214                if titles.count() > 0 {
215                    if let Some(title) = titles.iter().next() {
216                        println!("\t         {}", title.as_str().unwrap());
217                    } else {
218                        println!("\t         <{}>", preset.as_uri().unwrap());
219                    }
220                } else {
221                    println!("\t         <{}>", preset.as_uri().unwrap());
222                }
223            }
224        }
225    }
226
227    let num_ports = p.ports_count();
228    let port_ranges = p.port_ranges_float();
229    assert_eq!(num_ports, port_ranges.len());
230    for (i, pr) in port_ranges.iter().enumerate() {
231        print_port(p, i, pr, nodes);
232    }
233}
Source

pub unsafe fn unload_resource(&self, resource: &Node) -> bool

Unload all the data associated with the given resource.

§Safety

Unloading resources that are in use by the host will cause undefined behaviour.

Source§

impl World

Source

pub fn find_nodes( &self, subject: Option<&Node>, predicate: &Node, object: Option<&Node>, ) -> Nodes

Find nodes matching a triple pattern. Either subject or object may be None, but not both.

Examples found in repository?
examples/lv2info.rs (line 213)
101fn print_plugin(world: &World, p: &Plugin, nodes: &Nodes) {
102    println!("{}\n", p.uri().as_uri().unwrap());
103    println!("\tName:              {}", p.name().as_str().unwrap());
104    println!(
105        "\tClass:             {}",
106        p.class().label().as_str().unwrap()
107    );
108
109    if let Some(val) = p.author_name() {
110        println!("\tAuthor:            {}", val.as_str().unwrap());
111    }
112
113    if let Some(val) = p.author_email() {
114        println!("\tAuthor Email:      {}", val.as_str().unwrap());
115    }
116
117    if let Some(val) = p.author_homepage() {
118        println!("\tAuthor Homepage:   {}", val.as_uri().unwrap());
119    }
120
121    if let Some(latency_port) = p.latency_port_index() {
122        println!(
123            "\tHas latency:       yes, reported by port {}",
124            latency_port
125        );
126    } else {
127        println!("\tHas latency:       no");
128    }
129
130    println!("\tBundle:            {}", p.bundle_uri().as_uri().unwrap());
131    println!(
132        "\tBinary:            {}",
133        p.library_uri().map_or("<none>".to_string(), |node| node
134            .as_uri()
135            .unwrap()
136            .to_string())
137    );
138
139    if let Some(uis) = p.uis() {
140        println!("\tUIs:");
141
142        for ui in uis {
143            println!("\t\t{}", ui.uri().as_uri().unwrap());
144
145            for tyep in ui.classes() {
146                println!("\t\t\tClass:  {}", tyep.as_uri().unwrap());
147            }
148
149            println!(
150                "\t\t\tBinary: {}",
151                ui.binary_uri().unwrap().as_uri().unwrap()
152            );
153            println!(
154                "\t\t\tBundle: {}",
155                ui.bundle_uri().unwrap().as_uri().unwrap()
156            );
157        }
158    }
159
160    print!("\tData URIs:         ");
161
162    for (i, uri) in p.data_uris().iter().enumerate() {
163        if i != 0 {
164            print!("\n\t                   ");
165        }
166
167        print!("{}", uri.as_uri().unwrap());
168    }
169
170    println!();
171
172    let features = p.required_features();
173    print!("\tRequired Features: ");
174
175    for (i, feature) in features.iter().enumerate() {
176        if i != 0 {
177            print!("\n\t                   ");
178        }
179        print!("{}", feature.as_uri().unwrap());
180    }
181    println!();
182
183    let features = p.optional_features();
184    print!("\tOptional Features: ");
185
186    for (i, feature) in features.iter().enumerate() {
187        if i != 0 {
188            print!("\n\t                   ");
189        }
190        print!("{}", feature.as_uri().unwrap());
191    }
192    println!();
193
194    if let Some(data) = p.extension_data() {
195        print!("\tExtension Data:    ");
196
197        for (i, d) in data.iter().enumerate() {
198            if i != 0 {
199                print!("\n\t                   ");
200            }
201            print!("{}", d.as_uri().unwrap());
202        }
203        println!();
204    }
205
206    if let Some(presets) = p.related(Some(&nodes.preset_class)) {
207        if presets.count() != 0 {
208            println!("\tPresets: ");
209
210            for preset in presets {
211                world.load_resource(&preset).unwrap();
212
213                let titles = world.find_nodes(Some(&preset), &nodes.label_pred, None);
214                if titles.count() > 0 {
215                    if let Some(title) = titles.iter().next() {
216                        println!("\t         {}", title.as_str().unwrap());
217                    } else {
218                        println!("\t         <{}>", preset.as_uri().unwrap());
219                    }
220                } else {
221                    println!("\t         <{}>", preset.as_uri().unwrap());
222                }
223            }
224        }
225    }
226
227    let num_ports = p.ports_count();
228    let port_ranges = p.port_ranges_float();
229    assert_eq!(num_ports, port_ranges.len());
230    for (i, pr) in port_ranges.iter().enumerate() {
231        print_port(p, i, pr, nodes);
232    }
233}
Source

pub fn get( &self, subject: Option<&Node>, predicate: Option<&Node>, object: Option<&Node>, ) -> Option<Node>

Find a single node that matches a pattern. Exactly one of subject, predicate, or object must be None.

Source

pub fn ask( &self, subject: Option<&Node>, predicate: Option<&Node>, object: Option<&Node>, ) -> bool

Returns true iff a statement matching a certain pattern exists.

Source

pub fn symbol(&self, subject: &Node) -> Option<Node>

Get an LV2 symbol for some subject.

This will return the lv2:symbol property of the subject if it is given explicitly. Otherwise it will attempt to derive a symbol from the URI.

Source§

impl World

Source

pub fn as_ptr(&self) -> *mut LilvWorldImpl

Get the underlying pointer to the World.

Trait Implementations§

Source§

impl Default for World

Source§

fn default() -> World

Return a new empty world.

Auto Trait Implementations§

§

impl Freeze for World

§

impl !RefUnwindSafe for World

§

impl Send for World

§

impl Sync for World

§

impl Unpin for World

§

impl !UnwindSafe for World

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.