1use std::{
2 error::Error as StdError,
3 fmt::{Display, Formatter, Result as FmtResult},
4 result::Result as StdResult,
5};
6
7pub type Chan = u32;
9
10pub type Key = u32;
12
13pub type Vel = u32;
15
16pub type Ctrl = u32;
18
19pub type Val = u32;
21
22pub type Prog = u32;
24
25pub type Bank = u32;
27
28pub type FontId = u32;
30
31pub type PresetId = u32;
33
34pub type Result<T> = StdResult<T, Error>;
36
37pub type Status = Result<()>;
39
40#[derive(Debug, Clone, PartialEq, Eq, Hash)]
42pub enum Error {
43 Alloc,
44 Fluid(String),
45 Path,
46}
47
48impl StdError for Error {}
49
50impl Display for Error {
51 fn fmt(&self, f: &mut Formatter) -> FmtResult {
52 use self::Error::*;
53 match self {
54 Alloc => "Allocation error".fmt(f),
55 Fluid(error) => {
56 "Fluidlite error: ".fmt(f)?;
57 error.fmt(f)
58 }
59 Path => "Invalid path".fmt(f),
60 }
61 }
62}
63
64pub(crate) fn result_from_ptr<T>(ptr: *mut T) -> Result<*mut T> {
65 if ptr.is_null() {
66 Err(Error::Alloc)
67 } else {
68 Ok(ptr)
69 }
70}
71
72pub(crate) fn option_from_ptr<T>(ptr: *mut T) -> Option<*mut T> {
73 if ptr.is_null() {
74 None
75 } else {
76 Some(ptr)
77 }
78}