|
| 1 | +# osc-adapter-osc-types |
| 2 | + |
| 3 | +⚠️ **EXPERIMENTAL** ⚠️ |
| 4 | +This crate is experimental and APIs may change significantly between versions. |
| 5 | + |
| 6 | +Bidirectional adapter between `osc-ir` intermediate representation and `rust-osc-types` for seamless conversion between OSC data formats. |
| 7 | + |
| 8 | +## Features |
| 9 | + |
| 10 | +- **Bidirectional Conversion**: Convert between `IrValue` and OSC types from `rust-osc-types` |
| 11 | +- **OSC Version Support**: Support for both OSC 1.0 and OSC 1.1 via feature flags |
| 12 | +- **Message Conversion**: Convert OSC messages to/from IR representation |
| 13 | +- **Type Preservation**: Maintain type information during conversion |
| 14 | +- **no_std Compatible**: Works in no_std environments with `alloc` |
| 15 | + |
| 16 | +## Usage |
| 17 | + |
| 18 | +Add this to your `Cargo.toml`: |
| 19 | + |
| 20 | +```toml |
| 21 | +[dependencies] |
| 22 | +osc-adapter-osc-types = { version = "0.1.0-alpha.1", features = ["osc10"] } |
| 23 | +``` |
| 24 | + |
| 25 | +### OSC 1.0 Support |
| 26 | + |
| 27 | +```toml |
| 28 | +[dependencies] |
| 29 | +osc-adapter-osc-types = { version = "0.1.0-alpha.1", features = ["osc10"] } |
| 30 | +``` |
| 31 | + |
| 32 | +### OSC 1.1 Support |
| 33 | + |
| 34 | +```toml |
| 35 | +[dependencies] |
| 36 | +osc-adapter-osc-types = { version = "0.1.0-alpha.1", features = ["osc11"] } |
| 37 | +``` |
| 38 | + |
| 39 | +### Basic Example |
| 40 | + |
| 41 | +```rust |
| 42 | +use osc_adapter_osc_types::{osc_to_ir, ir_to_osc}; |
| 43 | +use osc_ir::IrValue; |
| 44 | + |
| 45 | +// Convert OSC message to IR |
| 46 | +let osc_msg = /* your OSC message */; |
| 47 | +let ir_value = osc_to_ir(&osc_msg); |
| 48 | + |
| 49 | +// Convert back to OSC |
| 50 | +let restored_osc = ir_to_osc(&ir_value); |
| 51 | +``` |
| 52 | + |
| 53 | +### Message Conversion |
| 54 | + |
| 55 | +```rust |
| 56 | +use osc_adapter_osc_types::{message_to_ir, ir_to_message}; |
| 57 | +use osc_ir::IrValue; |
| 58 | + |
| 59 | +// Create an OSC message representation in IR |
| 60 | +let address = "/oscillator/frequency"; |
| 61 | +let args = vec![ |
| 62 | + IrValue::from(440.0), // frequency |
| 63 | + IrValue::from("sine") // waveform |
| 64 | +]; |
| 65 | + |
| 66 | +let ir_message = message_to_ir(address, args); |
| 67 | + |
| 68 | +// Convert IR back to OSC message format |
| 69 | +if let Some((addr, arguments)) = ir_to_message(&ir_message) { |
| 70 | + println!("Address: {}", addr); |
| 71 | + println!("Arguments: {:?}", arguments); |
| 72 | +} |
| 73 | +``` |
| 74 | + |
| 75 | +### Type Conversions |
| 76 | + |
| 77 | +The adapter handles conversion between OSC types and IR values: |
| 78 | + |
| 79 | +- **Integers**: `i32` ↔ `IrValue::Integer` |
| 80 | +- **Floats**: `f32` ↔ `IrValue::Float` |
| 81 | +- **Strings**: `String` ↔ `IrValue::String` |
| 82 | +- **Binary Data**: `Vec<u8>` ↔ `IrValue::Binary` |
| 83 | +- **Arrays**: OSC arrays ↔ `IrValue::Array` |
| 84 | +- **Timestamps**: OSC timetags ↔ `IrValue::Timestamp` |
| 85 | + |
| 86 | +## Feature Flags |
| 87 | + |
| 88 | +- `osc10`: Enable OSC 1.0 support (basic types, bundles, timetags) |
| 89 | +- `osc11`: Enable OSC 1.1 support (includes OSC 1.0 plus additional types) |
| 90 | + |
| 91 | +Choose the appropriate feature flag based on the OSC version you need to support. |
| 92 | + |
| 93 | +## API Reference |
| 94 | + |
| 95 | +### Core Functions |
| 96 | + |
| 97 | +- `osc_to_ir(osc: &OscType) -> IrValue` - Convert OSC type to IR |
| 98 | +- `ir_to_osc(ir: &IrValue) -> OscType` - Convert IR to OSC type |
| 99 | +- `message_to_ir(address: &str, args: Vec<IrValue>) -> IrValue` - Create IR message |
| 100 | +- `ir_to_message(ir: &IrValue) -> Option<(&str, &[IrValue])>` - Extract message from IR |
| 101 | + |
| 102 | +## Compatibility |
| 103 | + |
| 104 | +This adapter is designed to work with: |
| 105 | +- `osc-ir` for intermediate representation |
| 106 | +- `rust-osc-types` for OSC protocol implementation |
| 107 | +- Both `osc-codec-json` and `osc-codec-msgpack` for serialization |
| 108 | + |
| 109 | +## License |
| 110 | + |
| 111 | +Licensed under either of |
| 112 | + |
| 113 | + * Apache License, Version 2.0 ([LICENSE-APACHE](../LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) |
| 114 | + * MIT license ([LICENSE-MIT](../LICENSE-MIT) or http://opensource.org/licenses/MIT) |
| 115 | + |
| 116 | +at your option. |
0 commit comments