Skip to main content

midi_control/vendor/
arturia.rs

1//
2// (c) 2020-2022 Hubert Figuière
3//
4// SPDX-License-Identifier: LGPL-3.0-or-later
5
6//! Arturia device support
7//!
8//! This is done without any warranty or any documentation or support
9//! from the vendor (albeit I'd love this to change)
10//!
11#![doc = include_str!("../../doc/arturia.md")]
12
13use crate::sysex;
14
15/// Arturia extended manufacturer ID
16pub const EXTENDED_ID_VALUE: sysex::ManufacturerId = sysex::ManufacturerId::ExtId(0x20, 0x6b);
17
18/// Arturia_v2 protocol
19///
20/// SysEx messages using [`EXTENDED_ID_VALUE`]
21/// starts with `0x7f`, [`PRODUCT_ID`][v2::PRODUCT_ID]
22pub mod v2 {
23    use super::EXTENDED_ID_VALUE;
24    use crate::consts;
25    use crate::message::{MidiMessage, SysExEvent};
26
27    /// Define the product id for the command.
28    /// This is defining the protocol.
29    pub const PRODUCT_ID: u8 = 0x42;
30
31    /// Verbs for the command
32    pub mod verb {
33        /// Used to query a value from the device.
34        pub const GET: u8 = 0x01;
35        /// Use to set a value on the device, or the device to tell the live.
36        pub const SET: u8 = 0x02;
37        /// Select the device memory to read.
38        pub const READ_MEM: u8 = 0x05;
39        /// Select the device memory to write to.
40        pub const WRITE_MEM: u8 = 0x06;
41    }
42
43    /// Param for the command
44    pub mod param {
45        /// Mode of the controller.
46        pub const MODE: u8 = 0x01;
47        /// Set the channel
48        pub const CHANNEL: u8 = 0x02;
49        /// Set the cc number (what about not CC?)
50        pub const CC_NUM: u8 = 0x03;
51        /// Lower range
52        pub const FROM: u8 = 0x04;
53        /// Higher range
54        pub const TO: u8 = 0x05;
55        /// Colour
56        pub const COLOUR: u8 = 0x10;
57        // ????
58        // 0x40
59    }
60
61    #[repr(u8)]
62    #[derive(Clone, Copy)]
63    /// Values of the controls.
64    pub enum Control {
65        Pad1 = 112,
66        Pad2,
67        Pad3,
68        Pad4,
69        Pad5,
70        Pad6,
71        Pad7,
72        Pad8,
73        Pad9,
74        Pad10,
75        Pad11,
76        Pad12,
77        Pad13,
78        Pad14,
79        Pad15,
80        Pad16,
81    }
82
83    #[repr(u8)]
84    /// The colour of the pad, as the numerical value for the message.
85    pub enum Colour {
86        Red = 1,
87        Green = 4,
88        Yellow = 5,
89        Blue = 16,
90        Purple = 17,
91        Cyan = 20,
92        White = 127,
93    }
94
95    /// Build a [SysEx message][MidiMessage::SysEx] to query a value.
96    ///
97    /// * `param_id` is the id on the item
98    /// * `item_id` is a control (logical)
99    ///
100    /// Return a [`MidiMessage`]
101    pub fn get_value(param_id: u8, item_id: u8) -> MidiMessage {
102        MidiMessage::SysEx(SysExEvent::new_manufacturer(
103            EXTENDED_ID_VALUE,
104            &[
105                0x7f,
106                PRODUCT_ID,
107                verb::GET,
108                0x00,
109                param_id,
110                item_id,
111                consts::EOX,
112            ],
113        ))
114    }
115
116    /// Build a [SysEx message][MidiMessage::SysEx] to set a value.
117    ///
118    /// * `param_id` is the id on the item
119    /// * `item_id` is a control (logical)
120    /// * `value` the value
121    ///
122    /// Return a [`MidiMessage`]
123    pub fn set_value(param_id: u8, item_id: u8, value: u8) -> MidiMessage {
124        MidiMessage::SysEx(SysExEvent::new_manufacturer(
125            EXTENDED_ID_VALUE,
126            &[
127                0x7f,
128                PRODUCT_ID,
129                verb::SET,
130                0x00,
131                param_id,
132                item_id,
133                value,
134                consts::EOX,
135            ],
136        ))
137    }
138}