Struct lilv::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)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
fn main() {
    let world = World::new();
    world.load_all();

    let show_names = false;

    let print = |plugin: Plugin| {
        if show_names {
            String::from(plugin.name().as_str().unwrap())
        } else {
            String::from(plugin.uri().as_uri().unwrap())
        }
    };

    let plugins = world
        .plugins()
        .iter()
        .filter(Plugin::verify)
        .map(print)
        .collect::<Vec<_>>();

    debug_assert_eq!(world.plugins().count(), plugins.len());

    for uri in plugins {
        println!("{}", uri);
    }
}
More examples
Hide additional examples
examples/lv2info.rs (line 236)
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
fn main() {
    let w = World::new();
    w.load_all();

    let nodes = Nodes {
        control_class: w.new_uri("http://lv2plug.in/ns/lv2core#ControlPort"),
        event_class: w.new_uri("http://lv2plug.in/ns/ext/atom#AtomPort"),
        group_pred: w.new_uri("http://lv2plug.in/ns/ext/port-groups#group"),
        label_pred: w.new_uri("http://www.w3.org/2000/01/rdf-schema#label"),
        preset_class: w.new_uri("http://lv2plug.in/ns/ext/presets#Preset"),
        designation_pred: w.new_uri("http://lv2plug.in/ns/lv2core#designation"),
        supports_event_pred: w.new_uri("http://lv2plug.in/ns/ext/atom#supportsEvent"),
    };

    for p in w.plugins().iter().filter(Plugin::verify) {
        print_plugin(&w, &p, &nodes);
    }
}
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)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
fn main() {
    let world = World::new();
    world.load_all();

    let show_names = false;

    let print = |plugin: Plugin| {
        if show_names {
            String::from(plugin.name().as_str().unwrap())
        } else {
            String::from(plugin.uri().as_uri().unwrap())
        }
    };

    let plugins = world
        .plugins()
        .iter()
        .filter(Plugin::verify)
        .map(print)
        .collect::<Vec<_>>();

    debug_assert_eq!(world.plugins().count(), plugins.len());

    for uri in plugins {
        println!("{}", uri);
    }
}
More examples
Hide additional examples
examples/lv2info.rs (line 249)
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
fn main() {
    let w = World::new();
    w.load_all();

    let nodes = Nodes {
        control_class: w.new_uri("http://lv2plug.in/ns/lv2core#ControlPort"),
        event_class: w.new_uri("http://lv2plug.in/ns/ext/atom#AtomPort"),
        group_pred: w.new_uri("http://lv2plug.in/ns/ext/port-groups#group"),
        label_pred: w.new_uri("http://www.w3.org/2000/01/rdf-schema#label"),
        preset_class: w.new_uri("http://lv2plug.in/ns/ext/presets#Preset"),
        designation_pred: w.new_uri("http://lv2plug.in/ns/lv2core#designation"),
        supports_event_pred: w.new_uri("http://lv2plug.in/ns/ext/atom#supportsEvent"),
    };

    for p in w.plugins().iter().filter(Plugin::verify) {
        print_plugin(&w, &p, &nodes);
    }
}
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)
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
fn main() {
    let w = World::new();
    w.load_all();

    let nodes = Nodes {
        control_class: w.new_uri("http://lv2plug.in/ns/lv2core#ControlPort"),
        event_class: w.new_uri("http://lv2plug.in/ns/ext/atom#AtomPort"),
        group_pred: w.new_uri("http://lv2plug.in/ns/ext/port-groups#group"),
        label_pred: w.new_uri("http://www.w3.org/2000/01/rdf-schema#label"),
        preset_class: w.new_uri("http://lv2plug.in/ns/ext/presets#Preset"),
        designation_pred: w.new_uri("http://lv2plug.in/ns/lv2core#designation"),
        supports_event_pred: w.new_uri("http://lv2plug.in/ns/ext/atom#supportsEvent"),
    };

    for p in w.plugins().iter().filter(Plugin::verify) {
        print_plugin(&w, &p, &nodes);
    }
}
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)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
fn main() {
    let world = World::new();
    world.load_all();

    let show_names = false;

    let print = |plugin: Plugin| {
        if show_names {
            String::from(plugin.name().as_str().unwrap())
        } else {
            String::from(plugin.uri().as_uri().unwrap())
        }
    };

    let plugins = world
        .plugins()
        .iter()
        .filter(Plugin::verify)
        .map(print)
        .collect::<Vec<_>>();

    debug_assert_eq!(world.plugins().count(), plugins.len());

    for uri in plugins {
        println!("{}", uri);
    }
}
More examples
Hide additional examples
examples/lv2info.rs (line 237)
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
fn main() {
    let w = World::new();
    w.load_all();

    let nodes = Nodes {
        control_class: w.new_uri("http://lv2plug.in/ns/lv2core#ControlPort"),
        event_class: w.new_uri("http://lv2plug.in/ns/ext/atom#AtomPort"),
        group_pred: w.new_uri("http://lv2plug.in/ns/ext/port-groups#group"),
        label_pred: w.new_uri("http://www.w3.org/2000/01/rdf-schema#label"),
        preset_class: w.new_uri("http://lv2plug.in/ns/ext/presets#Preset"),
        designation_pred: w.new_uri("http://lv2plug.in/ns/lv2core#designation"),
        supports_event_pred: w.new_uri("http://lv2plug.in/ns/ext/atom#supportsEvent"),
    };

    for p in w.plugins().iter().filter(Plugin::verify) {
        print_plugin(&w, &p, &nodes);
    }
}
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)
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
fn print_plugin(world: &World, p: &Plugin, nodes: &Nodes) {
    println!("{}\n", p.uri().as_uri().unwrap());
    println!("\tName:              {}", p.name().as_str().unwrap());
    println!(
        "\tClass:             {}",
        p.class().label().as_str().unwrap()
    );

    if let Some(val) = p.author_name() {
        println!("\tAuthor:            {}", val.as_str().unwrap());
    }

    if let Some(val) = p.author_email() {
        println!("\tAuthor Email:      {}", val.as_str().unwrap());
    }

    if let Some(val) = p.author_homepage() {
        println!("\tAuthor Homepage:   {}", val.as_uri().unwrap());
    }

    if let Some(latency_port) = p.latency_port_index() {
        println!(
            "\tHas latency:       yes, reported by port {}",
            latency_port
        );
    } else {
        println!("\tHas latency:       no");
    }

    println!("\tBundle:            {}", p.bundle_uri().as_uri().unwrap());
    println!(
        "\tBinary:            {}",
        p.library_uri().map_or("<none>".to_string(), |node| node
            .as_uri()
            .unwrap()
            .to_string())
    );

    if let Some(uis) = p.uis() {
        println!("\tUIs:");

        for ui in uis {
            println!("\t\t{}", ui.uri().as_uri().unwrap());

            for tyep in ui.classes() {
                println!("\t\t\tClass:  {}", tyep.as_uri().unwrap());
            }

            println!(
                "\t\t\tBinary: {}",
                ui.binary_uri().unwrap().as_uri().unwrap()
            );
            println!(
                "\t\t\tBundle: {}",
                ui.bundle_uri().unwrap().as_uri().unwrap()
            );
        }
    }

    print!("\tData URIs:         ");

    for (i, uri) in p.data_uris().iter().enumerate() {
        if i != 0 {
            print!("\n\t                   ");
        }

        print!("{}", uri.as_uri().unwrap());
    }

    println!();

    let features = p.required_features();
    print!("\tRequired Features: ");

    for (i, feature) in features.iter().enumerate() {
        if i != 0 {
            print!("\n\t                   ");
        }
        print!("{}", feature.as_uri().unwrap());
    }
    println!();

    let features = p.optional_features();
    print!("\tOptional Features: ");

    for (i, feature) in features.iter().enumerate() {
        if i != 0 {
            print!("\n\t                   ");
        }
        print!("{}", feature.as_uri().unwrap());
    }
    println!();

    if let Some(data) = p.extension_data() {
        print!("\tExtension Data:    ");

        for (i, d) in data.iter().enumerate() {
            if i != 0 {
                print!("\n\t                   ");
            }
            print!("{}", d.as_uri().unwrap());
        }
        println!();
    }

    if let Some(presets) = p.related(Some(&nodes.preset_class)) {
        if presets.count() != 0 {
            println!("\tPresets: ");

            for preset in presets {
                world.load_resource(&preset).unwrap();

                let titles = world.find_nodes(Some(&preset), &nodes.label_pred, None);
                if titles.count() > 0 {
                    if let Some(title) = titles.iter().next() {
                        println!("\t         {}", title.as_str().unwrap());
                    } else {
                        println!("\t         <{}>", preset.as_uri().unwrap());
                    }
                } else {
                    println!("\t         <{}>", preset.as_uri().unwrap());
                }
            }
        }
    }

    let num_ports = p.ports_count();
    let port_ranges = p.port_ranges_float();
    assert_eq!(num_ports, port_ranges.len());
    for (i, pr) in port_ranges.iter().enumerate() {
        print_port(p, i, pr, nodes);
    }
}
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)
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
fn print_plugin(world: &World, p: &Plugin, nodes: &Nodes) {
    println!("{}\n", p.uri().as_uri().unwrap());
    println!("\tName:              {}", p.name().as_str().unwrap());
    println!(
        "\tClass:             {}",
        p.class().label().as_str().unwrap()
    );

    if let Some(val) = p.author_name() {
        println!("\tAuthor:            {}", val.as_str().unwrap());
    }

    if let Some(val) = p.author_email() {
        println!("\tAuthor Email:      {}", val.as_str().unwrap());
    }

    if let Some(val) = p.author_homepage() {
        println!("\tAuthor Homepage:   {}", val.as_uri().unwrap());
    }

    if let Some(latency_port) = p.latency_port_index() {
        println!(
            "\tHas latency:       yes, reported by port {}",
            latency_port
        );
    } else {
        println!("\tHas latency:       no");
    }

    println!("\tBundle:            {}", p.bundle_uri().as_uri().unwrap());
    println!(
        "\tBinary:            {}",
        p.library_uri().map_or("<none>".to_string(), |node| node
            .as_uri()
            .unwrap()
            .to_string())
    );

    if let Some(uis) = p.uis() {
        println!("\tUIs:");

        for ui in uis {
            println!("\t\t{}", ui.uri().as_uri().unwrap());

            for tyep in ui.classes() {
                println!("\t\t\tClass:  {}", tyep.as_uri().unwrap());
            }

            println!(
                "\t\t\tBinary: {}",
                ui.binary_uri().unwrap().as_uri().unwrap()
            );
            println!(
                "\t\t\tBundle: {}",
                ui.bundle_uri().unwrap().as_uri().unwrap()
            );
        }
    }

    print!("\tData URIs:         ");

    for (i, uri) in p.data_uris().iter().enumerate() {
        if i != 0 {
            print!("\n\t                   ");
        }

        print!("{}", uri.as_uri().unwrap());
    }

    println!();

    let features = p.required_features();
    print!("\tRequired Features: ");

    for (i, feature) in features.iter().enumerate() {
        if i != 0 {
            print!("\n\t                   ");
        }
        print!("{}", feature.as_uri().unwrap());
    }
    println!();

    let features = p.optional_features();
    print!("\tOptional Features: ");

    for (i, feature) in features.iter().enumerate() {
        if i != 0 {
            print!("\n\t                   ");
        }
        print!("{}", feature.as_uri().unwrap());
    }
    println!();

    if let Some(data) = p.extension_data() {
        print!("\tExtension Data:    ");

        for (i, d) in data.iter().enumerate() {
            if i != 0 {
                print!("\n\t                   ");
            }
            print!("{}", d.as_uri().unwrap());
        }
        println!();
    }

    if let Some(presets) = p.related(Some(&nodes.preset_class)) {
        if presets.count() != 0 {
            println!("\tPresets: ");

            for preset in presets {
                world.load_resource(&preset).unwrap();

                let titles = world.find_nodes(Some(&preset), &nodes.label_pred, None);
                if titles.count() > 0 {
                    if let Some(title) = titles.iter().next() {
                        println!("\t         {}", title.as_str().unwrap());
                    } else {
                        println!("\t         <{}>", preset.as_uri().unwrap());
                    }
                } else {
                    println!("\t         <{}>", preset.as_uri().unwrap());
                }
            }
        }
    }

    let num_ports = p.ports_count();
    let port_ranges = p.port_ranges_float();
    assert_eq!(num_ports, port_ranges.len());
    for (i, pr) in port_ranges.iter().enumerate() {
        print_port(p, i, pr, nodes);
    }
}
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.

Trait Implementations§

source§

impl Default for World

source§

fn default() -> World

Return a new empty world.

Auto Trait Implementations§

§

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.