Skip to content

WIP: Implement Options and BufSize extensions #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 54 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
f9864a2
wip
prokopyl Aug 6, 2021
a464d4d
Even more wip
prokopyl Aug 7, 2021
b8bad34
Even more wip again
prokopyl Aug 7, 2021
67a75ce
Fix things, break even more
prokopyl Aug 8, 2021
cbc82c4
Fix more things
prokopyl Aug 8, 2021
3d462e0
Fixed almost everything
prokopyl Aug 8, 2021
44c81d3
Add VecSpace
prokopyl Aug 8, 2021
e2c099f
Fix almost everything
prokopyl Aug 8, 2021
c0913a7
It builds!
prokopyl Aug 17, 2021
eaf1d4b
Some refactorings
prokopyl Aug 17, 2021
e462d00
Some more refactorings
prokopyl Aug 18, 2021
be0ef55
Wip fix
prokopyl Aug 18, 2021
155b4e4
Some fixes
prokopyl Aug 19, 2021
69ed4e1
Fix all tests
prokopyl Sep 4, 2021
0187034
Move atoms to separate atoms subdir
prokopyl Sep 4, 2021
89d9b97
Fix build
prokopyl Sep 4, 2021
00edd9c
Move extensions to allocator to own trait
prokopyl Sep 5, 2021
999df14
Remove "boxed" space helper
prokopyl Sep 5, 2021
aa46e6c
Introduce SpaceReader to cleanup clunky methods on Space struct
prokopyl Sep 6, 2021
95e7f17
Various fixes and improvements
prokopyl Sep 7, 2021
355b898
Remove type param on space reader
prokopyl Sep 7, 2021
5853d5f
Remove default type param on Space type
prokopyl Sep 7, 2021
b486dc4
Add lots of docs
prokopyl Sep 8, 2021
0165d69
Some more tests and fixes
prokopyl Sep 8, 2021
f572097
WIP
prokopyl Sep 9, 2021
aae2304
WIP: replace lifetimes in Atom trait with GAT workaround
prokopyl Sep 9, 2021
c59416b
More WIP
prokopyl Sep 10, 2021
1df4e4c
More WIP 2
prokopyl Sep 10, 2021
2e4f411
Fixed everything
prokopyl Sep 11, 2021
91b3075
Remove unnecessary Atom::read lifetimes
prokopyl Sep 11, 2021
5fc58bf
Remove more unnecessary lifetimes
prokopyl Sep 11, 2021
0011183
Replace Option with Result in many atom read/write operation
prokopyl Sep 12, 2021
4b7dd6c
Doc & test fixes
prokopyl Sep 12, 2021
8c2e516
Change Sequence to hold its unit in a generic type rather than having…
prokopyl Sep 12, 2021
c6aff29
Split Atom error type
prokopyl Sep 21, 2021
d9abd29
Properly split alignment errors
prokopyl Sep 23, 2021
767519e
Some more docs and some fewer errors
prokopyl Sep 23, 2021
89bb24f
Remove some unneeded methods
prokopyl Sep 25, 2021
ad1172f
Remove some more unneeded methods, add some docs and rename SpaceAllo…
prokopyl Sep 25, 2021
5478673
Various module refactorings
prokopyl Sep 25, 2021
d37c11f
Remove unsafe copy/clone impl on UnidentifiedAtom
prokopyl Sep 26, 2021
6f9330d
Add some more docs
prokopyl Sep 26, 2021
a340168
Write more docs
prokopyl Sep 27, 2021
16a5c0a
Rename AtomSpaceWriter to AtomWriter, and add more docs
prokopyl Sep 29, 2021
2dbeabd
Implemented proper error messages for AtomError
prokopyl Sep 29, 2021
d6ee079
Some clippy fixes
prokopyl Sep 29, 2021
6152505
Fix tests, add more docs
prokopyl Oct 1, 2021
1f46b60
Finished all clippy-required docs!
prokopyl Oct 1, 2021
328abe4
Initial WIP on implementing lv2-options and lv2-buf-size (squashed & …
prokopyl Sep 11, 2021
47a36bb
Fix everything
prokopyl Sep 11, 2021
e19ffbe
Option collections now work!
prokopyl Sep 12, 2021
a6d22fd
Post-merge fixes
prokopyl Oct 1, 2021
82278dc
Merge option values and option serializer into a single struct, and a…
prokopyl Oct 2, 2021
33111ed
Minor fix
prokopyl Oct 2, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ maintenance = { status = "actively-developed" }
version = "2.0.0"
optional = true

[dependencies.lv2-buf-size]
version = "0.1.0"
optional = true

[dependencies.lv2-core]
version = "3.0.0"
optional = true
Expand All @@ -27,6 +31,10 @@ optional = true
version = "1.2.0"
optional = true

[dependencies.lv2-options]
version = "0.1.0"
optional = true

[dependencies.lv2-time]
version = "0.1.3"
optional = true
Expand Down Expand Up @@ -71,8 +79,10 @@ plugin = [
]
full = [
"lv2-atom",
"lv2-buf-size",
"lv2-core",
"lv2-midi",
"lv2-options",
"lv2-time",
"lv2-units",
"urid",
Expand All @@ -86,9 +96,12 @@ wmidi = ["lv2-midi", "lv2-midi/wmidi"]
[workspace]
members = [
"atom",
"buf-size",
"core",
"core/derive",
"midi",
"options",
"options/derive",
"state",
"sys",
"sys/tool",
Expand All @@ -110,9 +123,11 @@ lto = true
[patch.crates-io]
lv2 = { path = "." }
lv2-atom = { path = "atom" }
lv2-buf-size = { path = "buf-size" }
lv2-core = { path = "core" }
lv2-core-derive = { path = "core/derive" }
lv2-midi = { path = "midi" }
lv2-options = { path = "options" }
lv2-state = { path = "state" }
lv2-sys = { path = "sys" }
lv2-time = { path = "time" }
Expand Down
29 changes: 29 additions & 0 deletions atom/src/atoms.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
pub mod chunk;
pub mod object;
pub mod scalar;
pub mod sequence;
pub mod string;
pub mod tuple;
pub mod vector;

use urid::*;

/// An URID collection of all standard atom types, provided for convenience.
#[derive(Clone, URIDCollection)]
pub struct AtomURIDCollection {
pub blank: URID<object::Blank>,
pub double: URID<scalar::Double>,
pub float: URID<scalar::Float>,
pub int: URID<scalar::Int>,
pub long: URID<scalar::Long>,
pub urid: URID<scalar::AtomURID>,
pub bool: URID<scalar::Bool>,
pub vector: URID<vector::Vector>,
pub chunk: URID<chunk::Chunk>,
pub literal: URID<string::Literal>,
pub object: URID<object::Object>,
pub property: URID<object::Property>,
pub string: URID<string::String>,
pub tuple: URID<tuple::Tuple>,
pub sequence: URID<sequence::Sequence>,
}
125 changes: 125 additions & 0 deletions atom/src/atoms/chunk.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
//! An atom containing memory of undefined type.
//!
//! This contents of this atom is considered as a simple blob of data. It used, for example, by the host to transmit the size of a writable atom port. Since it is so simple, it does not need a reading or writing parameter.
//!
//! # Example
//! ```
//! use lv2_core::prelude::*;
//! use lv2_atom::prelude::*;
//!
//! use lv2_atom::space::{AtomSpace, AtomWriter, SpaceWriter};
//!
//! #[derive(PortCollection)]
//! struct MyPorts {
//! input: InputPort<AtomPort>,
//! output: OutputPort<AtomPort>,
//! }
//!
//! fn run(ports: &mut MyPorts, urids: &AtomURIDCollection) {
//! let in_chunk: &AtomSpace = ports.input.read(urids.chunk).unwrap();
//! let mut out_chunk: AtomWriter = ports.output.write(urids.chunk).unwrap();
//!
//! let bytes = in_chunk.as_bytes();
//! out_chunk.write_bytes(bytes).unwrap();
//! }
//! ```
//!
//! # Specification
//!
//! [http://lv2plug.in/ns/ext/atom/atom.html#Chunk](http://lv2plug.in/ns/ext/atom/atom.html#Chunk)
use crate::space::error::{AtomReadError, AtomWriteError};
use crate::space::*;
use crate::AtomWriter;
use crate::{Atom, AtomHandle};
use urid::UriBound;

/// An atom containing an arbitrary byte buffer.
///
/// [See also the module documentation.](index.html)
pub struct Chunk;

unsafe impl UriBound for Chunk {
const URI: &'static [u8] = sys::LV2_ATOM__Chunk;
}

pub struct ChunkReaderHandle;
impl<'a> AtomHandle<'a> for ChunkReaderHandle {
type Handle = &'a AtomSpace;
}

pub struct ChunkWriterHandle;
impl<'a> AtomHandle<'a> for ChunkWriterHandle {
type Handle = AtomWriter<'a>;
}

impl Atom for Chunk {
type ReadHandle = ChunkReaderHandle;
type WriteHandle = ChunkWriterHandle;

#[inline]
unsafe fn read(
body: &AtomSpace,
) -> Result<<Self::ReadHandle as AtomHandle>::Handle, AtomReadError> {
Ok(body)
}

#[inline]
fn write(
frame: AtomWriter,
) -> Result<<Self::WriteHandle as AtomHandle>::Handle, AtomWriteError> {
Ok(frame)
}
}

#[cfg(test)]
mod tests {
use crate::atoms::chunk::*;
use crate::*;

#[test]
fn test_chunk_and_slice_writer() {
const SLICE_LENGTH: usize = 42;

let map = HashURIDMapper::new();
let urids = crate::atoms::AtomURIDCollection::from_map(&map).unwrap();

let mut raw_space = VecSpace::<AtomHeader>::new_with_capacity(64);
let raw_space = raw_space.as_space_mut();

// writing
{
let mut space = SpaceCursor::new(raw_space.as_bytes_mut());
let mut writer = space.write_atom(urids.chunk).unwrap();
let data = writer.allocate(SLICE_LENGTH).unwrap();

for (i, value) in data.iter_mut().enumerate() {
*value = i as u8;
}

space.write_value(41u8).unwrap();
}

// verifying
{
let atom = unsafe { raw_space.read().next_atom() }.unwrap();
assert_eq!(atom.header().size_of_body(), SLICE_LENGTH);
assert_eq!(atom.header().urid(), urids.chunk.get());

let data = atom.body().as_bytes();
for (i, value) in data.iter().enumerate() {
assert_eq!(*value as usize, i);
}
}

// reading
{
let data =
unsafe { Chunk::read(raw_space.read().next_atom().unwrap().body()) }.unwrap();
assert_eq!(data.bytes_len(), SLICE_LENGTH);

for (i, value) in data.as_bytes().iter().enumerate() {
assert_eq!(*value as usize, i);
}
}
}
}
Loading