Advertisement
Guest User

Untitled

a guest
May 25th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 83.69 KB | None | 0 0
  1. /*
  2. * Command line: opannotate --source
  3. *
  4. * Interpretation of command line:
  5. * Output annotated source file with samples
  6. * Output all files
  7. *
  8. * CPU: AMD64 generic, speed 4100 MHz (estimated)
  9. * Counted CPU_CLK_UNHALTED events (CPU Clocks not Halted) with a unit mask of 0x00 (No unit mask) count 100000
  10. */
  11. /*
  12. * Total samples for file : "/build/rust/src/rustc-1.26.0-src/src/libcore/slice/mod.rs"
  13. *
  14. * 222897 21.8343
  15. */
  16.  
  17.  
  18. /* <[T] as core::slice::SliceExt>::len total: 2 2.0e-04 */
  19. /* <[T] as core::slice::SliceExt>::iter_mut total: 1 9.8e-05 */
  20. /* <[T] as core::slice::SliceExt>::as_mut_ptr total: 1 9.8e-05 */
  21. /* core::slice::<impl core::ops::index::Index<I> for [T]>::index total: 67038 6.5668 */
  22. /* core::slice::<impl core::ops::index::IndexMut<I> for [T]>::index_mut total: 32753 3.2084 */
  23. /* <usize as core::slice::SliceIndex<[T]>>::index total: 32818 3.2147 */
  24. /* <usize as core::slice::SliceIndex<[T]>>::index_mut total: 17654 1.7293 */
  25. /* core::slice::size_from_ptr total: 35 0.0034 */
  26. /* <core::slice::IterMut<'a, T> as core::iter::iterator::Iterator>::next total: 113 0.0111 */
  27. /* core::slice::from_raw_parts total: 48359 4.7371 */
  28. /* core::slice::from_raw_parts total: 1 9.8e-05 */
  29. /* core::slice::from_raw_parts_mut total: 24121 2.3628 */
  30. /* core::slice::from_raw_parts_mut total: 1 9.8e-05 */
  31. /*
  32. * Total samples for file : "/build/rust/src/rustc-1.26.0-src/src/liballoc/vec.rs"
  33. *
  34. * 181207 17.7505
  35. */
  36.  
  37.  
  38. /* <alloc::vec::Vec<T> as core::ops::index::Index<I>>::index total: 63174 6.1883 */
  39. /* <alloc::vec::Vec<T> as core::ops::index::IndexMut<I>>::index_mut total: 33060 3.2385 */
  40. /* <alloc::vec::Vec<T> as core::ops::deref::Deref>::deref total: 58420 5.7226 */
  41. /* <alloc::vec::Vec<T> as core::ops::deref::DerefMut>::deref_mut total: 26553 2.6010 */
  42. /*
  43. * Total samples for file : "/build/rust/src/rustc-1.26.0-src/src/libcore/ptr.rs"
  44. *
  45. * 173299 16.9758
  46. */
  47.  
  48.  
  49. /* core::ptr::null_mut total: 580 0.0568 */
  50. /* core::ptr::swap_nonoverlapping total: 5779 0.5661 */
  51. /* core::ptr::swap_nonoverlapping_bytes total: 15746 1.5424 */
  52. /* core::ptr::<impl *mut T>::is_null total: 77205 7.5628 */
  53. /* core::ptr::<impl *mut T>::offset total: 43 0.0042 */
  54. /* core::ptr::<impl *mut T>::offset total: 54173 5.3066 */
  55. /* <core::ptr::Unique<T>>::as_ptr total: 19773 1.9369 */
  56. /*
  57. * Total samples for file : "/home/cyrus/projects/piano/src/string.rs"
  58. *
  59. * 124694 12.2146
  60. */
  61.  
  62.  
  63. :pub struct String {
  64. : length: usize,
  65. : dispersion: f32,
  66. : loss: f32,
  67. : termination_points: usize,
  68. : termination_force: f32,
  69. : y: Vec<f32>,
  70. : v: Vec<f32>
  71. :}
  72. :
  73. :pub fn new(length: usize, dispersion: f32, loss: f32, termination_points: usize) -> String {
  74. : let y: Vec<f32> = vec![0_f32; length];
  75. : let mut v: Vec<f32> = vec![0_f32; length];
  76. : v[10] = -10_f32;
  77. : let termination_force = 1_f32/(termination_points as f32);
  78. : String {
  79. : length: length-1,
  80. : dispersion,
  81. : loss,
  82. : termination_points,
  83. : termination_force,
  84. : y,
  85. : v
  86. : }
  87. :}
  88. :
  89. 3 2.9e-04 :pub fn update(s: &mut String) -> (f32, f32) { /* piano::string::update total: 124694 12.2146 */
  90. 17893 1.7527 : for i in 0..s.length-1 { // calculate forces
  91. 25503 2.4982 : let energy = (s.y[i]-s.y[i+1])*s.dispersion;
  92. 16699 1.6358 : s.v[i+1] = (s.v[i+1] + energy) * s.loss;
  93. 17379 1.7024 : s.v[i] = s.v[i] - energy;
  94. : }
  95. 19212 1.8819 : for i in 0..s.length { // apply forces
  96. 26570 2.6027 : s.y[i] = s.y[i] + s.v[i]; // might be better to do loss here
  97. : }
  98. 375 0.0367 : for i in 0..s.termination_points { // soft terminations
  99. 512 0.0502 : s.y[(s.length+i-i*2)] = s.y[(s.length+i-i*2)]*(s.termination_force*i as f32);
  100. 305 0.0299 : s.y[i] = s.y[i]*(s.termination_force*(i as f32));
  101. : }
  102. 30 0.0029 : let force_left = s.v[0];
  103. 35 0.0034 : let force_right = s.v[s.length];
  104. 20 0.0020 : s.y[0] = 0_f32;
  105. 49 0.0048 : s.y[s.length] = 0_f32;
  106. 43 0.0042 : s.v[0] = 0_f32;
  107. 37 0.0036 : s.v[s.length] = 0_f32;
  108. 24 0.0024 : (force_left, force_right) // return v forces at termination points
  109. 5 4.9e-04 :}
  110. /*
  111. * Total samples for file : "/build/rust/src/rustc-1.26.0-src/src/libcore/num/mod.rs"
  112. *
  113. * 98838 9.6819
  114. */
  115.  
  116.  
  117. /* core::num::<impl usize>::checked_add total: 39118 3.8319 */
  118. /* core::num::<impl usize>::overflowing_add total: 59720 5.8500 */
  119. /*
  120. * Total samples for file : "/build/rust/src/rustc-1.26.0-src/src/libcore/iter/range.rs"
  121. *
  122. * 48902 4.7903
  123. */
  124.  
  125.  
  126. /* <usize as core::iter::range::Step>::add_usize total: 21476 2.1037 */
  127. /* core::iter::range::<impl core::iter::iterator::Iterator for core::ops::range::Range<A>>::next total: 15126 1.4817 */
  128. /* <T as core::iter::range::PrivateTryFromUsize>::private_try_from total: 12300 1.2049 */
  129. /*
  130. * Total samples for file : "/build/rust/src/rustc-1.26.0-src/src/liballoc/raw_vec.rs"
  131. *
  132. * 40403 3.9577
  133. */
  134.  
  135.  
  136. /* <alloc::raw_vec::RawVec<T, A>>::ptr total: 40403 3.9577 */
  137. /*
  138. * Total samples for file : "/build/rust/src/rustc-1.26.0-src/src/libcore/result.rs"
  139. *
  140. * 27543 2.6980
  141. */
  142.  
  143.  
  144. /* <core::result::Result<T, E>>::map_err total: 27543 2.6980 */
  145. /*
  146. * Total samples for file : "/build/rust/src/rustc-1.26.0-src/src/libcore/convert.rs"
  147. *
  148. * 13005 1.2739
  149. */
  150.  
  151.  
  152. /* <T as core::convert::From<T>>::from total: 2272 0.2226 */
  153. /* <T as core::convert::TryFrom<U>>::try_from total: 10733 1.0514 */
  154. /*
  155. * Total samples for file : "/build/rust/src/rustc-1.26.0-src/src/libcore/mem.rs"
  156. *
  157. * 8132 0.7966
  158. */
  159.  
  160.  
  161. /* core::mem::size_of total: 2942 0.2882 */
  162. /* core::mem::size_of total: 47 0.0046 */
  163. /* core::mem::size_of total: 1446 0.1416 */
  164. /* core::mem::align_of total: 1 9.8e-05 */
  165. /* core::mem::uninitialized total: 1370 0.1342 */
  166. /* core::mem::swap total: 2326 0.2278 */
  167. /*
  168. * Total samples for file : "/build/rust/src/rustc-1.26.0-src/src/libcore/cmp.rs"
  169. *
  170. * 2880 0.2821
  171. */
  172.  
  173.  
  174. /* core::cmp::impls::<impl core::cmp::PartialOrd for usize>::lt total: 2880 0.2821 */
  175. /*
  176. * Total samples for file : "/home/cyrus/projects/piano/src/lib.rs"
  177. *
  178. * 104 0.0102
  179. */
  180.  
  181.  
  182. :const POINTS: usize = 200;
  183. :
  184. :#[macro_use]
  185. :extern crate vst;
  186. :use vst::plugin::{Info, Plugin};
  187. :use vst::buffer::AudioBuffer;
  188. :use vst::event::Event;
  189. :use vst::api::Events;
  190. :mod string;
  191. :
  192. :struct Piano {
  193. : string: string::String,
  194. :}
  195. :
  196. :impl Default for Piano {
  197. : fn default() -> Piano {
  198. : Piano {
  199. : string: string::new(POINTS, 1_f32, 1_f32, 3)
  200. : }
  201. : }
  202. :}
  203. :
  204. :impl Plugin for Piano {
  205. : fn init(&mut self) {
  206. : //let mut self.string = string::new(500, 1_f32, 1_f32, 3);
  207. : }
  208. : fn get_info(&self) -> Info {
  209. : Info {
  210. : name: "Piano".to_string(),
  211. : unique_id: 0,
  212. : inputs: 0,
  213. : outputs: 1,
  214. : ..Default::default()
  215. : }
  216. : }
  217. : fn process_events(&mut self, events: &Events) {
  218. : for event in events.events() {
  219. : match event {
  220. : Event::Midi(ev) => {
  221. : //midi stuff
  222. : self.string = string::new(POINTS, 1_f32, 1_f32, 3);
  223. : }, _ => ()
  224. : }
  225. : }
  226. : }
  227. 3 2.9e-04 : fn process(&mut self, buffer: &mut AudioBuffer<f32>) { /* <piano::Piano as vst::plugin::Plugin>::process total: 104 0.0102 */
  228. : let (_, output_buffer) = buffer.split();
  229. 4 3.9e-04 : for output_channel in output_buffer.into_iter() {
  230. 74 0.0072 : for output_sample in output_channel {
  231. 8 7.8e-04 : let (left, right) = string::update(&mut self.string);
  232. 14 0.0014 : *output_sample = left/10_f32
  233. : }
  234. : }
  235. 1 9.8e-05 : }
  236. :}
  237. :
  238. :plugin_main!(Piano);
  239. :
  240. :#[cfg(test)]
  241. :mod tests {
  242. : use string;
  243. : #[test]
  244. : fn test_string_setup() {
  245. : let mut string = string::new(100, 1_f32, 1_f32, 3);
  246. : }
  247. : #[test]
  248. : fn test_string_update() {
  249. : let mut string = string::new(100, 1_f32, 1_f32, 3);
  250. : string::update(&mut string);
  251. : }
  252. :}
  253. /*
  254. * Total samples for file : "/build/gcc/src/gcc/libstdc++-v3/libsupc++/new_op.cc"
  255. *
  256. * 101 0.0099
  257. */
  258.  
  259.  
  260. /* operator new(unsigned long) total: 101 0.0099 */
  261. /*
  262. * Total samples for file : "/build/rust/src/rustc-1.26.0-src/src/libcore/iter/traits.rs"
  263. *
  264. * 64 0.0063
  265. */
  266.  
  267.  
  268. /* <I as core::iter::traits::IntoIterator>::into_iter total: 64 0.0063 */
  269. /*
  270. * Total samples for file : "/build/gcc/src/gcc/libstdc++-v3/libsupc++/del_op.cc"
  271. *
  272. * 42 0.0041
  273. */
  274.  
  275.  
  276. /* operator delete(void*) total: 42 0.0041 */
  277. /*
  278. * Total samples for file : "/home/cyrus/.cargo/registry/src/github.com-1ecc6299db9ec823/vst-0.0.1/src/buffer.rs"
  279. *
  280. * 11 0.0011
  281. */
  282.  
  283.  
  284. ://! Buffers to safely work with audio samples.
  285. :
  286. :use num_traits::Float;
  287. :
  288. :use std::slice;
  289. :use std::iter::Zip;
  290. :
  291. :/// `AudioBuffer` contains references to the audio buffers for all input and output channels
  292. :pub struct AudioBuffer<'a, T: 'a + Float> {
  293. : inputs: &'a [*const T],
  294. : outputs: &'a mut [*mut T],
  295. : samples: usize,
  296. :}
  297. :
  298. :impl<'a, T: 'a + Float> AudioBuffer<'a, T> {
  299. : /// Create an `AudioBuffer` from slices of raw pointers. Useful in a Rust VST host.
  300. : #[inline]
  301. : pub fn new(inputs: &'a [*const T], outputs: &'a mut [*mut T], samples: usize) -> Self {
  302. : Self {
  303. : inputs: inputs,
  304. : outputs: outputs,
  305. : samples: samples,
  306. : }
  307. : }
  308. :
  309. : /// Create an `AudioBuffer` from raw pointers.
  310. : /// Only really useful for interacting with the VST API.
  311. : #[inline]
  312. 1 9.8e-05 : pub unsafe fn from_raw(
  313. /* <vst::buffer::AudioBuffer<'a, T>>::from_raw total: 1 9.8e-05 */
  314. : input_count: usize,
  315. : output_count: usize,
  316. : inputs_raw: *const *const T,
  317. : outputs_raw: *mut *mut T,
  318. : samples: usize,
  319. : ) -> Self {
  320. : Self {
  321. : inputs: slice::from_raw_parts(inputs_raw, input_count),
  322. : outputs: slice::from_raw_parts_mut(outputs_raw, output_count),
  323. : samples: samples,
  324. : }
  325. : }
  326. :
  327. : /// The number of input channels that this buffer was created for
  328. : #[inline]
  329. : pub fn input_count(&self) -> usize {
  330. : self.inputs.len()
  331. : }
  332. :
  333. : /// The number of output channels that this buffer was created for
  334. : #[inline]
  335. : pub fn output_count(&self) -> usize {
  336. : self.outputs.len()
  337. : }
  338. :
  339. : /// The number of samples in this buffer (same for all channels)
  340. : #[inline]
  341. : pub fn samples(&self) -> usize {
  342. : self.samples
  343. : }
  344. :
  345. : /// The raw inputs to pass to processReplacing
  346. : #[inline]
  347. : pub(crate) fn raw_inputs(&self) -> &[*const T] {
  348. : self.inputs
  349. : }
  350. :
  351. : /// The raw outputs to pass to processReplacing
  352. : #[inline]
  353. : pub(crate) fn raw_outputs(&mut self) -> &mut [*mut T] {
  354. : &mut self.outputs
  355. : }
  356. :
  357. : /// Split this buffer into separate inputs and outputs.
  358. : #[inline]
  359. 1 9.8e-05 : pub fn split<'b>(&'b mut self) -> (Inputs<'b, T>, Outputs<'b, T>)
  360. /* <vst::buffer::AudioBuffer<'a, T>>::split total: 3 2.9e-04 */
  361. : where
  362. : 'a: 'b,
  363. : {
  364. 1 9.8e-05 : (
  365. : Inputs {
  366. : bufs: self.inputs,
  367. : samples: self.samples,
  368. : },
  369. : Outputs {
  370. 1 9.8e-05 : bufs: self.outputs,
  371. : samples: self.samples,
  372. : },
  373. : )
  374. : }
  375. :
  376. : /// Zip together buffers.
  377. : #[inline]
  378. : pub fn zip<'b>(&'b mut self) -> Zip<InputIterator<'b, T>, OutputIterator<'b, T>>
  379. : where
  380. : 'a: 'b,
  381. : {
  382. : let (inputs, outputs) = self.split();
  383. : inputs.into_iter().zip(outputs)
  384. : }
  385. :}
  386. :
  387. :use std::ops::{Index, IndexMut};
  388. :
  389. :/// Wrapper type to access the buffers for the input channels of an `AudioBuffer` in a safe way.
  390. :/// Behaves like a slice.
  391. :#[derive(Copy, Clone)]
  392. :pub struct Inputs<'a, T: 'a> {
  393. : bufs: &'a [*const T],
  394. : samples: usize,
  395. :}
  396. :
  397. :impl<'a, T> Inputs<'a, T> {
  398. : /// Number of channels
  399. : pub fn len(&self) -> usize {
  400. : self.bufs.len()
  401. : }
  402. :
  403. : /// Returns true if the buffer is empty
  404. : pub fn is_empty(&self) -> bool {
  405. : self.len() == 0
  406. : }
  407. :
  408. : /// Access channel at the given index, unchecked
  409. : pub fn get(&self, i: usize) -> &'a [T] {
  410. : unsafe { slice::from_raw_parts(self.bufs[i], self.samples) }
  411. : }
  412. :
  413. : /// Split borrowing at the given index, like for slices
  414. : pub fn split_at(&self, i: usize) -> (Inputs<'a, T>, Inputs<'a, T>) {
  415. : let (l, r) = self.bufs.split_at(i);
  416. : (
  417. : Inputs {
  418. : bufs: l,
  419. : samples: self.samples,
  420. : },
  421. : Inputs {
  422. : bufs: r,
  423. : samples: self.samples,
  424. : },
  425. : )
  426. : }
  427. :}
  428. :
  429. :impl<'a, T> Index<usize> for Inputs<'a, T> {
  430. : type Output = [T];
  431. :
  432. : fn index(&self, i: usize) -> &Self::Output {
  433. : self.get(i)
  434. : }
  435. :}
  436. :
  437. :/// Iterator over buffers for input channels of an `AudioBuffer`.
  438. :pub struct InputIterator<'a, T: 'a> {
  439. : data: Inputs<'a, T>,
  440. : i: usize,
  441. :}
  442. :
  443. :impl<'a, T> Iterator for InputIterator<'a, T> {
  444. : type Item = &'a [T];
  445. :
  446. : fn next(&mut self) -> Option<Self::Item> {
  447. : if self.i < self.data.len() {
  448. : let val = self.data.get(self.i);
  449. : self.i += 1;
  450. : Some(val)
  451. : } else {
  452. : None
  453. : }
  454. : }
  455. :}
  456. :
  457. :impl<'a, T: Sized> IntoIterator for Inputs<'a, T> {
  458. : type Item = &'a [T];
  459. : type IntoIter = InputIterator<'a, T>;
  460. :
  461. : fn into_iter(self) -> Self::IntoIter {
  462. : InputIterator { data: self, i: 0 }
  463. : }
  464. :}
  465. :
  466. :/// Wrapper type to access the buffers for the output channels of an `AudioBuffer` in a safe way.
  467. :/// Behaves like a slice.
  468. :#[derive(Copy, Clone)]
  469. :pub struct Outputs<'a, T: 'a> {
  470. : bufs: &'a [*mut T],
  471. : samples: usize,
  472. :}
  473. :
  474. :impl<'a, T> Outputs<'a, T> {
  475. : /// Number of channels
  476. : pub fn len(&self) -> usize {
  477. /* <vst::buffer::Outputs<'a, T>>::len total: 1 9.8e-05 */
  478. : self.bufs.len()
  479. 1 9.8e-05 : }
  480. :
  481. : /// Returns true if the buffer is empty
  482. : pub fn is_empty(&self) -> bool {
  483. : self.len() == 0
  484. : }
  485. :
  486. : /// Access channel at the given index, unchecked
  487. : pub fn get(&self, i: usize) -> &'a [T] {
  488. : unsafe { slice::from_raw_parts(self.bufs[i], self.samples) }
  489. : }
  490. :
  491. : /// Mutably access channel at the given index, unchecked
  492. : pub fn get_mut(&self, i: usize) -> &'a mut [T] {
  493. : unsafe { slice::from_raw_parts_mut(self.bufs[i], self.samples) }
  494. : }
  495. :
  496. : /// Split borrowing at the given index, like for slices
  497. : pub fn split_at_mut(&mut self, i: usize) -> (Outputs<'a, T>, Outputs<'a, T>) {
  498. : let (l, r) = self.bufs.split_at(i);
  499. : (
  500. : Outputs {
  501. : bufs: l,
  502. : samples: self.samples,
  503. : },
  504. : Outputs {
  505. : bufs: r,
  506. : samples: self.samples,
  507. : },
  508. : )
  509. : }
  510. :}
  511. :
  512. :impl<'a, T> Index<usize> for Outputs<'a, T> {
  513. : type Output = [T];
  514. :
  515. : fn index(&self, i: usize) -> &Self::Output {
  516. : self.get(i)
  517. : }
  518. :}
  519. :
  520. :impl<'a, T> IndexMut<usize> for Outputs<'a, T> {
  521. : fn index_mut(&mut self, i: usize) -> &mut Self::Output {
  522. : self.get_mut(i)
  523. : }
  524. :}
  525. :
  526. :/// Iterator over buffers for output channels of an `AudioBuffer`.
  527. :pub struct OutputIterator<'a, T: 'a> {
  528. : data: Outputs<'a, T>,
  529. : i: usize,
  530. :}
  531. :
  532. :impl<'a, T> Iterator for OutputIterator<'a, T> {
  533. : type Item = &'a mut [T];
  534. :
  535. 2 2.0e-04 : fn next(&mut self) -> Option<Self::Item> {
  536. /* <vst::buffer::OutputIterator<'a, T> as core::iter::iterator::Iterator>::next total: 4 3.9e-04 */
  537. : if self.i < self.data.len() {
  538. 1 9.8e-05 : let val = self.data.get_mut(self.i);
  539. 1 9.8e-05 : self.i += 1;
  540. : Some(val)
  541. : } else {
  542. : None
  543. : }
  544. : }
  545. :}
  546. :
  547. :impl<'a, T: Sized> IntoIterator for Outputs<'a, T> {
  548. : type Item = &'a mut [T];
  549. : type IntoIter = OutputIterator<'a, T>;
  550. :
  551. 2 2.0e-04 : fn into_iter(self) -> Self::IntoIter {
  552. /* <vst::buffer::Outputs<'a, T> as core::iter::traits::IntoIterator>::into_iter total: 2 2.0e-04 */
  553. : OutputIterator { data: self, i: 0 }
  554. : }
  555. :}
  556. :
  557. :use event::{Event, MidiEvent};
  558. :use api;
  559. :use std::mem;
  560. :use std::borrow::Borrow;
  561. :
  562. :/// This buffer is used for sending midi events through the VST interface.
  563. :/// The purpose of this is to convert outgoing midi events from `event::Event` to `api::Events`.
  564. :/// It only allocates memory in new() and reuses the memory between calls.
  565. :pub struct SendEventBuffer {
  566. : buf: Vec<u8>,
  567. : api_events: Vec<api::SysExEvent>,
  568. :}
  569. :
  570. :impl Default for SendEventBuffer {
  571. : fn default() -> Self {
  572. : SendEventBuffer::new(1024)
  573. : }
  574. :}
  575. :
  576. :impl SendEventBuffer {
  577. : /// Creates a buffer for sending up to the given number of midi events per frame
  578. : #[inline]
  579. : pub fn new(capacity: usize) -> Self {
  580. : let header_size = mem::size_of::<api::Events>() - (mem::size_of::<*mut api::Event>() * 2);
  581. : let body_size = mem::size_of::<*mut api::Event>() * capacity;
  582. : let mut buf = vec![0u8; header_size + body_size];
  583. : let api_events = vec![unsafe { mem::zeroed::<api::SysExEvent>() }; capacity];
  584. : {
  585. : let ptrs = {
  586. : let e = Self::buf_as_api_events(&mut buf);
  587. : e.num_events = capacity as i32;
  588. : e.events_raw_mut()
  589. : };
  590. : for (ptr, event) in ptrs.iter_mut().zip(&api_events) {
  591. : let (ptr, event): (&mut *const api::SysExEvent, &api::SysExEvent) = (ptr, event);
  592. : *ptr = event;
  593. : }
  594. : }
  595. : Self {
  596. : buf: buf,
  597. : api_events: api_events,
  598. : }
  599. : }
  600. :
  601. : #[inline]
  602. : fn buf_as_api_events(buf: &mut [u8]) -> &mut api::Events {
  603. : unsafe { &mut *(buf.as_mut_ptr() as *mut api::Events) }
  604. : }
  605. :
  606. : /// Use this for sending events to a host or plugin.
  607. : ///
  608. : /// # Example
  609. : /// ```no_run
  610. : /// # use vst::plugin::{Info, Plugin, HostCallback};
  611. : /// # use vst::buffer::{AudioBuffer, SendEventBuffer};
  612. : /// # use vst::host::Host;
  613. : /// # struct ExamplePlugin { host: HostCallback, send_buffer: SendEventBuffer }
  614. : /// # impl Plugin for ExamplePlugin {
  615. : /// # fn get_info(&self) -> Info { Default::default() }
  616. : /// #
  617. : /// // Processor that clips samples above 0.4 or below -0.4:
  618. : /// fn process(&mut self, buffer: &mut AudioBuffer<f32>){
  619. : /// let events = vec![
  620. : /// // ...
  621. : /// ];
  622. : /// self.send_buffer.store(&events);
  623. : /// self.host.process_events(self.send_buffer.events());
  624. : /// }
  625. : /// # }
  626. : /// ```
  627. : pub fn store<'a, T: IntoIterator<Item = U>, U: Borrow<Event<'a>>>(&mut self, events: T) {
  628. : let count = events
  629. : .into_iter()
  630. : .zip(self.api_events.iter_mut())
  631. : .map(|(event, out)| {
  632. : let (event, out): (&Event, &mut api::SysExEvent) = (event.borrow(), out);
  633. : match *event {
  634. : Event::Midi(ev) => {
  635. : Self::store_midi_impl(out, &ev);
  636. : }
  637. : Event::SysEx(ev) => {
  638. : *out = api::SysExEvent {
  639. : event_type: api::EventType::SysEx,
  640. : byte_size: mem::size_of::<api::SysExEvent>() as i32,
  641. : delta_frames: ev.delta_frames,
  642. : _flags: 0,
  643. : data_size: ev.payload.len() as i32,
  644. : _reserved1: 0,
  645. : system_data: ev.payload.as_ptr() as *const u8 as *mut u8,
  646. : _reserved2: 0,
  647. : };
  648. : }
  649. : Event::Deprecated(e) => {
  650. : let out = unsafe { &mut *(out as *mut _ as *mut _) };
  651. : *out = e;
  652. : }
  653. : };
  654. : })
  655. : .count();
  656. : self.set_num_events(count);
  657. : }
  658. :
  659. : /// Use this for sending midi events to a host or plugin.
  660. : /// Like store() but for when you're not sending any SysExEvents, only MidiEvents.
  661. : pub fn store_midi<T: IntoIterator<Item = U>, U: Borrow<MidiEvent>>(&mut self, events: T) {
  662. : let count = events
  663. : .into_iter()
  664. : .zip(self.api_events.iter_mut())
  665. : .map(|(event, out)| {
  666. : let (ev, out): (&MidiEvent, &mut api::SysExEvent) = (event.borrow(), out);
  667. : Self::store_midi_impl(out, ev);
  668. : })
  669. : .count();
  670. : self.set_num_events(count);
  671. : }
  672. :
  673. : fn store_midi_impl(out: &mut api::SysExEvent, ev: &MidiEvent) {
  674. : use api::flags::REALTIME_EVENT;
  675. : let out = unsafe { &mut *(out as *mut _ as *mut _) };
  676. : *out = api::MidiEvent {
  677. : event_type: api::EventType::Midi,
  678. : byte_size: mem::size_of::<api::MidiEvent>() as i32,
  679. : delta_frames: ev.delta_frames,
  680. : flags: if ev.live { REALTIME_EVENT.bits() } else { 0 },
  681. : note_length: ev.note_length.unwrap_or(0),
  682. : note_offset: ev.note_offset.unwrap_or(0),
  683. : midi_data: ev.data,
  684. : _midi_reserved: 0,
  685. : detune: ev.detune,
  686. : note_off_velocity: ev.note_off_velocity,
  687. : _reserved1: 0,
  688. : _reserved2: 0,
  689. : };
  690. : }
  691. :
  692. : fn set_num_events(&mut self, events_len: usize) {
  693. : use std::cmp::min;
  694. : let e = Self::buf_as_api_events(&mut self.buf);
  695. : e.num_events = min(self.api_events.len(), events_len) as i32;
  696. : }
  697. :
  698. : /// Use this for sending midi events to a host or plugin.
  699. : /// See `store()`
  700. : #[inline]
  701. : pub fn events(&self) -> &api::Events {
  702. : unsafe { &*(self.buf.as_ptr() as *const api::Events) }
  703. : }
  704. :}
  705. :
  706. :#[cfg(test)]
  707. :mod tests {
  708. : use buffer::AudioBuffer;
  709. :
  710. : /// Size of buffers used in tests.
  711. : const SIZE: usize = 1024;
  712. :
  713. : /// Test that creating and zipping buffers works.
  714. : ///
  715. : /// This test creates a channel for 2 inputs and 2 outputs.
  716. : /// The input channels are simply values
  717. : /// from 0 to `SIZE-1` (e.g. [0, 1, 2, 3, 4, .. , SIZE - 1])
  718. : /// and the output channels are just 0.
  719. : /// This test assures that when the buffers are zipped together,
  720. : /// the input values do not change.
  721. : #[test]
  722. : fn buffer_zip() {
  723. : let in1: Vec<f32> = (0..SIZE).map(|x| x as f32).collect();
  724. : let in2 = in1.clone();
  725. :
  726. : let mut out1 = vec![0.0; SIZE];
  727. : let mut out2 = out1.clone();
  728. :
  729. : let inputs = vec![in1.as_ptr(), in2.as_ptr()];
  730. : let mut outputs = vec![out1.as_mut_ptr(), out2.as_mut_ptr()];
  731. : let mut buffer = AudioBuffer::new(&inputs, &mut outputs, SIZE);
  732. :
  733. : for (input, output) in buffer.zip() {
  734. : input.into_iter().zip(output.into_iter()).fold(0, |acc,
  735. : (input,
  736. : output)| {
  737. : assert_eq!(*input - acc as f32, 0.0);
  738. : assert_eq!(*output, 0.0);
  739. : acc + 1
  740. : });
  741. : }
  742. : }
  743. :
  744. : /// Test that creating buffers from raw pointers works.
  745. : #[test]
  746. : fn from_raw() {
  747. : let in1: Vec<f32> = (0..SIZE).map(|x| x as f32).collect();
  748. : let in2 = in1.clone();
  749. :
  750. : let mut out1 = vec![0.0; SIZE];
  751. : let mut out2 = out1.clone();
  752. :
  753. : let inputs = vec![in1.as_ptr(), in2.as_ptr()];
  754. : let mut outputs = vec![out1.as_mut_ptr(), out2.as_mut_ptr()];
  755. : let mut buffer =
  756. : unsafe { AudioBuffer::from_raw(2, 2, inputs.as_ptr(), outputs.as_mut_ptr(), SIZE) };
  757. :
  758. : for (input, output) in buffer.zip() {
  759. : input.into_iter().zip(output.into_iter()).fold(0, |acc,
  760. : (input,
  761. : output)| {
  762. : assert_eq!(*input - acc as f32, 0.0);
  763. : assert_eq!(*output, 0.0);
  764. : acc + 1
  765. : });
  766. : }
  767. : }
  768. :}
  769. /*
  770. * Total samples for file : "/build/gcc/src/gcc/libstdc++-v3/libsupc++/del_ops.cc"
  771. *
  772. * 9 8.8e-04
  773. */
  774.  
  775.  
  776. /* operator delete(void*, unsigned long) total: 9 8.8e-04 */
  777. /*
  778. * Total samples for file : "/home/cyrus/.cargo/registry/src/github.com-1ecc6299db9ec823/vst-0.0.1/src/interfaces.rs"
  779. *
  780. * 6 5.9e-04
  781. */
  782.  
  783.  
  784. ://! Function interfaces for VST 2.4 API.
  785. :
  786. :#![doc(hidden)]
  787. :
  788. :use std::{mem, slice};
  789. :
  790. :use std::os::raw::{c_char, c_void};
  791. :
  792. :use buffer::AudioBuffer;
  793. :use api::consts::*;
  794. :use api::{self, AEffect, ChannelProperties};
  795. :use editor::{Rect, KeyCode, Key, KnobMode};
  796. :use host::Host;
  797. :
  798. :/// Deprecated process function.
  799. :pub fn process_deprecated(
  800. : _effect: *mut AEffect,
  801. : _raw_inputs: *const *const f32,
  802. : _raw_outputs: *mut *mut f32,
  803. : _samples: i32,
  804. :) {
  805. :}
  806. :
  807. :/// VST2.4 replacing function.
  808. 3 2.9e-04 :pub fn process_replacing(
  809. /* vst::interfaces::process_replacing total: 6 5.9e-04 */
  810. : effect: *mut AEffect,
  811. : raw_inputs: *const *const f32,
  812. : raw_outputs: *mut *mut f32,
  813. : samples: i32,
  814. :) {
  815. : // Handle to the VST
  816. : let plugin = unsafe { (*effect).get_plugin() };
  817. : let cache = unsafe { (*effect).get_cache() };
  818. : let info = &mut cache.info;
  819. 2 2.0e-04 : let (input_count, output_count) = (info.inputs as usize, info.outputs as usize);
  820. : let mut buffer = unsafe {
  821. : AudioBuffer::from_raw(
  822. : input_count,
  823. : output_count,
  824. : raw_inputs,
  825. : raw_outputs,
  826. : samples as usize,
  827. : )
  828. : };
  829. : plugin.process(&mut buffer);
  830. 1 9.8e-05 :}
  831. :
  832. :/// VST2.4 replacing function with `f64` values.
  833. :pub fn process_replacing_f64(
  834. : effect: *mut AEffect,
  835. : raw_inputs: *const *const f64,
  836. : raw_outputs: *mut *mut f64,
  837. : samples: i32,
  838. :) {
  839. : let plugin = unsafe { (*effect).get_plugin() };
  840. : let cache = unsafe { (*effect).get_cache() };
  841. : let info = &mut cache.info;
  842. : let (input_count, output_count) = (info.inputs as usize, info.outputs as usize);
  843. : let mut buffer = unsafe {
  844. : AudioBuffer::from_raw(
  845. : input_count,
  846. : output_count,
  847. : raw_inputs,
  848. : raw_outputs,
  849. : samples as usize,
  850. : )
  851. : };
  852. : plugin.process_f64(&mut buffer);
  853. :}
  854. :
  855. :/// VST2.4 set parameter function.
  856. :pub fn set_parameter(effect: *mut AEffect, index: i32, value: f32) {
  857. : unsafe { (*effect).get_plugin() }.set_parameter(index, value);
  858. :}
  859. :
  860. :/// VST2.4 get parameter function.
  861. :pub fn get_parameter(effect: *mut AEffect, index: i32) -> f32 {
  862. : unsafe { (*effect).get_plugin() }.get_parameter(index)
  863. :}
  864. :
  865. :/// Copy a string into a destination buffer.
  866. :///
  867. :/// String will be cut at `max` characters.
  868. :fn copy_string(dst: *mut c_void, src: &str, max: usize) -> isize {
  869. : unsafe {
  870. : use std::cmp::min;
  871. : use libc::{c_void, memset, memcpy};
  872. :
  873. : let dst = dst as *mut c_void;
  874. : memset(dst, 0, max);
  875. : memcpy(dst, src.as_ptr() as *const c_void, min(max, src.len()));
  876. : }
  877. :
  878. : 1 // Success
  879. :}
  880. :
  881. :/// VST2.4 dispatch function. This function handles dispatching all opcodes to the VST plugin.
  882. :pub fn dispatch(
  883. : effect: *mut AEffect,
  884. : opcode: i32,
  885. : index: i32,
  886. : value: isize,
  887. : ptr: *mut c_void,
  888. : opt: f32,
  889. :) -> isize {
  890. : use plugin::{CanDo, OpCode};
  891. :
  892. : // Convert passed in opcode to enum
  893. : let opcode = OpCode::from(opcode);
  894. : // Plugin handle
  895. : let plugin = unsafe { (*effect).get_plugin() };
  896. :
  897. : match opcode {
  898. : OpCode::Initialize => plugin.init(),
  899. : OpCode::Shutdown => unsafe {
  900. : (*effect).drop_plugin();
  901. : drop(mem::transmute::<*mut AEffect, Box<AEffect>>(effect));
  902. : },
  903. :
  904. : OpCode::ChangePreset => plugin.change_preset(value as i32),
  905. : OpCode::GetCurrentPresetNum => return plugin.get_preset_num() as isize,
  906. : OpCode::SetCurrentPresetName => plugin.set_preset_name(read_string(ptr)),
  907. : OpCode::GetCurrentPresetName => {
  908. : let num = plugin.get_preset_num();
  909. : return copy_string(ptr, &plugin.get_preset_name(num), MAX_PRESET_NAME_LEN);
  910. : }
  911. :
  912. : OpCode::GetParameterLabel => {
  913. : return copy_string(ptr, &plugin.get_parameter_label(index), MAX_PARAM_STR_LEN)
  914. : }
  915. : OpCode::GetParameterDisplay => {
  916. : return copy_string(ptr, &plugin.get_parameter_text(index), MAX_PARAM_STR_LEN)
  917. : }
  918. : OpCode::GetParameterName => {
  919. : return copy_string(ptr, &plugin.get_parameter_name(index), MAX_PARAM_STR_LEN)
  920. : }
  921. :
  922. : OpCode::SetSampleRate => plugin.set_sample_rate(opt),
  923. : OpCode::SetBlockSize => plugin.set_block_size(value as i64),
  924. : OpCode::StateChanged => {
  925. : if value == 1 {
  926. : plugin.resume();
  927. : } else {
  928. : plugin.suspend();
  929. : }
  930. : }
  931. :
  932. : OpCode::EditorGetRect => {
  933. : if let Some(editor) = plugin.get_editor() {
  934. : let size = editor.size();
  935. : let pos = editor.position();
  936. :
  937. : unsafe {
  938. : // Given a Rect** structure
  939. : // TODO: Investigate whether we are given a valid Rect** pointer already
  940. : *(ptr as *mut *mut c_void) = Box::into_raw(Box::new(Rect {
  941. : left: pos.0 as i16, // x coord of position
  942. : top: pos.1 as i16, // y coord of position
  943. : right: (pos.0 + size.0) as i16, // x coord of pos + x coord of size
  944. : bottom: (pos.1 + size.1) as i16, // y coord of pos + y coord of size
  945. : })) as *mut _; // TODO: free memory
  946. : }
  947. : }
  948. : }
  949. : OpCode::EditorOpen => {
  950. : if let Some(editor) = plugin.get_editor() {
  951. : editor.open(ptr); //ptr is raw window handle, eg HWND* on windows
  952. : }
  953. : }
  954. : OpCode::EditorClose => {
  955. : if let Some(editor) = plugin.get_editor() {
  956. : editor.close();
  957. : }
  958. : }
  959. :
  960. : OpCode::EditorIdle => {
  961. : if let Some(editor) = plugin.get_editor() {
  962. : editor.idle();
  963. : }
  964. : }
  965. :
  966. : OpCode::GetData => {
  967. : let mut chunks = if index == 0 {
  968. : plugin.get_bank_data()
  969. : } else {
  970. : plugin.get_preset_data()
  971. : };
  972. :
  973. : chunks.shrink_to_fit();
  974. : let len = chunks.len() as isize; // eventually we should be using ffi::size_t
  975. :
  976. : unsafe {
  977. : *(ptr as *mut *mut c_void) = chunks.as_ptr() as *mut c_void;
  978. : }
  979. :
  980. : mem::forget(chunks);
  981. : return len;
  982. : }
  983. : OpCode::SetData => {
  984. : let chunks = unsafe { slice::from_raw_parts(ptr as *mut u8, value as usize) };
  985. :
  986. : if index == 0 {
  987. : plugin.load_bank_data(chunks);
  988. : } else {
  989. : plugin.load_preset_data(chunks);
  990. : }
  991. : }
  992. :
  993. : OpCode::ProcessEvents => {
  994. : plugin.process_events(unsafe { &*(ptr as *const api::Events) });
  995. : }
  996. : OpCode::CanBeAutomated => return plugin.can_be_automated(index) as isize,
  997. : OpCode::StringToParameter => {
  998. : return plugin.string_to_parameter(index, read_string(ptr)) as isize
  999. : }
  1000. :
  1001. : OpCode::GetPresetName => {
  1002. : return copy_string(ptr, &plugin.get_preset_name(index), MAX_PRESET_NAME_LEN)
  1003. : }
  1004. :
  1005. : OpCode::GetInputInfo => {
  1006. : if index >= 0 && index < plugin.get_info().inputs {
  1007. : unsafe {
  1008. : let ptr = mem::transmute::<_, *mut ChannelProperties>(ptr);
  1009. : *ptr = plugin.get_input_info(index).into();
  1010. : }
  1011. : }
  1012. : }
  1013. : OpCode::GetOutputInfo => {
  1014. : if index >= 0 && index < plugin.get_info().outputs {
  1015. : unsafe {
  1016. : let ptr = mem::transmute::<_, *mut ChannelProperties>(ptr);
  1017. : *ptr = plugin.get_output_info(index).into();
  1018. : }
  1019. : }
  1020. : }
  1021. : OpCode::GetCategory => {
  1022. : return plugin.get_info().category.into();
  1023. : }
  1024. :
  1025. : OpCode::GetVendorName => {
  1026. : return copy_string(ptr, &plugin.get_info().vendor, MAX_VENDOR_STR_LEN)
  1027. : }
  1028. : OpCode::GetProductName => {
  1029. : return copy_string(ptr, &plugin.get_info().name, MAX_PRODUCT_STR_LEN)
  1030. : }
  1031. : OpCode::GetVendorVersion => return plugin.get_info().version as isize,
  1032. : OpCode::VendorSpecific => return plugin.vendor_specific(index, value, ptr, opt),
  1033. : OpCode::CanDo => {
  1034. : let can_do: CanDo = match read_string(ptr).parse() {
  1035. : Ok(c) => c,
  1036. : Err(e) => {
  1037. : warn!("{}", e);
  1038. : return 0;
  1039. : }
  1040. : };
  1041. : return plugin.can_do(can_do).into();
  1042. : }
  1043. : OpCode::GetTailSize => {
  1044. : if plugin.get_tail_size() == 0 {
  1045. : return 1;
  1046. : } else {
  1047. : return plugin.get_tail_size();
  1048. : }
  1049. : }
  1050. :
  1051. : //OpCode::GetParamInfo => { /*TODO*/ }
  1052. : OpCode::GetApiVersion => return 2400,
  1053. :
  1054. : OpCode::EditorKeyDown => {
  1055. : if let Some(editor) = plugin.get_editor() {
  1056. : editor.key_down(KeyCode {
  1057. : character: index as u8 as char,
  1058. : key: Key::from(value),
  1059. : modifier: unsafe { mem::transmute::<f32, i32>(opt) } as u8,
  1060. : });
  1061. : }
  1062. : }
  1063. : OpCode::EditorKeyUp => {
  1064. : if let Some(editor) = plugin.get_editor() {
  1065. : editor.key_up(KeyCode {
  1066. : character: index as u8 as char,
  1067. : key: Key::from(value),
  1068. : modifier: unsafe { mem::transmute::<f32, i32>(opt) } as u8,
  1069. : });
  1070. : }
  1071. : }
  1072. : OpCode::EditorSetKnobMode => {
  1073. : if let Some(editor) = plugin.get_editor() {
  1074. : editor.set_knob_mode(KnobMode::from(value));
  1075. : }
  1076. : }
  1077. :
  1078. : _ => {
  1079. : warn!("Unimplemented opcode ({:?})", opcode);
  1080. : trace!(
  1081. : "Arguments; index: {}, value: {}, ptr: {:?}, opt: {}",
  1082. : index,
  1083. : value,
  1084. : ptr,
  1085. : opt
  1086. : );
  1087. : }
  1088. : }
  1089. :
  1090. : 0
  1091. :}
  1092. :
  1093. :pub fn host_dispatch(
  1094. : host: &mut Host,
  1095. : effect: *mut AEffect,
  1096. : opcode: i32,
  1097. : index: i32,
  1098. : value: isize,
  1099. : ptr: *mut c_void,
  1100. : opt: f32,
  1101. :) -> isize {
  1102. : use host::OpCode;
  1103. :
  1104. : match OpCode::from(opcode) {
  1105. : OpCode::Version => return 2400,
  1106. : OpCode::Automate => host.automate(index, opt),
  1107. :
  1108. : OpCode::Idle => host.idle(),
  1109. :
  1110. : // ...
  1111. : OpCode::CanDo => {
  1112. : info!("Plugin is asking if host can: {}.", read_string(ptr));
  1113. : }
  1114. :
  1115. : OpCode::GetVendorVersion => return host.get_info().0,
  1116. : OpCode::GetVendorString => return copy_string(ptr, &host.get_info().1, MAX_VENDOR_STR_LEN),
  1117. : OpCode::GetProductString => {
  1118. : return copy_string(ptr, &host.get_info().2, MAX_PRODUCT_STR_LEN)
  1119. : }
  1120. : OpCode::ProcessEvents => {
  1121. : host.process_events(unsafe { &*(ptr as *const api::Events) });
  1122. : }
  1123. :
  1124. : unimplemented => {
  1125. : trace!("VST: Got unimplemented host opcode ({:?})", unimplemented);
  1126. : trace!(
  1127. : "Arguments; effect: {:?}, index: {}, value: {}, ptr: {:?}, opt: {}",
  1128. : effect,
  1129. : index,
  1130. : value,
  1131. : ptr,
  1132. : opt
  1133. : );
  1134. : }
  1135. : }
  1136. : 0
  1137. :}
  1138. :
  1139. :// Read a string from the `ptr` buffer
  1140. :fn read_string(ptr: *mut c_void) -> String {
  1141. : use std::ffi::CStr;
  1142. :
  1143. : String::from_utf8_lossy(unsafe { CStr::from_ptr(ptr as *mut c_char).to_bytes() }).into_owned()
  1144. :}
  1145. /*
  1146. * Total samples for file : "/build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/ostream.tcc"
  1147. *
  1148. * 6 5.9e-04
  1149. */
  1150.  
  1151.  
  1152. /* std::ostream::sentry::sentry(std::ostream&) total: 5 4.9e-04 */
  1153. /* std::ostream::flush() total: 1 9.8e-05 */
  1154. /*
  1155. * Total samples for file : "/build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/streambuf"
  1156. *
  1157. * 4 3.9e-04
  1158. */
  1159.  
  1160.  
  1161. /* std::__cxx11::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >::_M_pbump(char*, char*, long) total: 3 2.9e-04 */
  1162. /*
  1163. * Total samples for file : "/build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/ext/stdio_filebuf.h"
  1164. *
  1165. * 4 3.9e-04
  1166. */
  1167.  
  1168.  
  1169. /* __gnu_cxx::stdio_sync_filebuf<char, std::char_traits<char> >::sync() total: 3 2.9e-04 */
  1170. /* __gnu_cxx::stdio_sync_filebuf<char, std::char_traits<char> >::xsputn(char const*, long) total: 1 9.8e-05 */
  1171. /*
  1172. * Total samples for file : "/build/gcc/src/gcc/libstdc++-v3/libsupc++/eh_catch.cc"
  1173. *
  1174. * 2 2.0e-04
  1175. */
  1176.  
  1177.  
  1178. /* std::uncaught_exception() total: 2 2.0e-04 */
  1179. /*
  1180. * Total samples for file : "/build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/sstream.tcc"
  1181. *
  1182. * 2 2.0e-04
  1183. */
  1184.  
  1185.  
  1186. /* std::__cxx11::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >::_M_sync(char*, unsigned long, unsigned long) total: 2 2.0e-04 */
  1187. /*
  1188. * Total samples for file : "/build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/ostream_insert.h"
  1189. *
  1190. * 2 2.0e-04
  1191. */
  1192.  
  1193.  
  1194. /* std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long) total: 3 2.9e-04 */
  1195. /*
  1196. * Total samples for file : "/home/cyrus/.cargo/registry/src/github.com-1ecc6299db9ec823/vst-0.0.1/src/api.rs"
  1197. *
  1198. * 1 9.8e-05
  1199. */
  1200.  
  1201.  
  1202. ://! Structures and types for interfacing with the VST 2.4 API.
  1203. :
  1204. :use std::os::raw::c_void;
  1205. :
  1206. :use plugin::Plugin;
  1207. :use self::consts::*;
  1208. :
  1209. :/// Constant values
  1210. :#[allow(missing_docs)] // For obvious constants
  1211. :pub mod consts {
  1212. :
  1213. : pub const MAX_PRESET_NAME_LEN: usize = 24;
  1214. : pub const MAX_PARAM_STR_LEN: usize = 32;
  1215. : pub const MAX_LABEL: usize = 64;
  1216. : pub const MAX_SHORT_LABEL: usize = 8;
  1217. : pub const MAX_PRODUCT_STR_LEN: usize = 64;
  1218. : pub const MAX_VENDOR_STR_LEN: usize = 64;
  1219. :
  1220. : /// VST plugins are identified by a magic number. This corresponds to 0x56737450.
  1221. : pub const VST_MAGIC: i32 = ('V' as i32) << 24 | ('s' as i32) << 16 | ('t' as i32) << 8 |
  1222. : ('P' as i32);
  1223. :}
  1224. :
  1225. :/// `VSTPluginMain` function signature.
  1226. :pub type PluginMain = fn(callback: HostCallbackProc) -> *mut AEffect;
  1227. :
  1228. :/// Host callback function passed to plugin.
  1229. :/// Can be used to query host information from plugin side.
  1230. :pub type HostCallbackProc = fn(effect: *mut AEffect,
  1231. : opcode: i32,
  1232. : index: i32,
  1233. : value: isize,
  1234. : ptr: *mut c_void,
  1235. : opt: f32)
  1236. : -> isize;
  1237. :
  1238. :/// Dispatcher function used to process opcodes. Called by host.
  1239. :pub type DispatcherProc = fn(effect: *mut AEffect,
  1240. : opcode: i32,
  1241. : index: i32,
  1242. : value: isize,
  1243. : ptr: *mut c_void,
  1244. : opt: f32)
  1245. : -> isize;
  1246. :
  1247. :/// Process function used to process 32 bit floating point samples. Called by host.
  1248. :pub type ProcessProc = fn(effect: *mut AEffect,
  1249. : inputs: *const *const f32,
  1250. : outputs: *mut *mut f32,
  1251. : sample_frames: i32);
  1252. :
  1253. :/// Process function used to process 64 bit floating point samples. Called by host.
  1254. :pub type ProcessProcF64 = fn(effect: *mut AEffect,
  1255. : inputs: *const *const f64,
  1256. : outputs: *mut *mut f64,
  1257. : sample_frames: i32);
  1258. :
  1259. :/// Callback function used to set parameter values. Called by host.
  1260. :pub type SetParameterProc = fn(effect: *mut AEffect, index: i32, parameter: f32);
  1261. :
  1262. :/// Callback function used to get parameter values. Called by host.
  1263. :pub type GetParameterProc = fn(effect: *mut AEffect, index: i32) -> f32;
  1264. :
  1265. :/// Used with the VST API to pass around plugin information.
  1266. :#[allow(non_snake_case)]
  1267. :#[repr(C)]
  1268. :pub struct AEffect {
  1269. : /// Magic number. Must be `['V', 'S', 'T', 'P']`.
  1270. : pub magic: i32,
  1271. :
  1272. : /// Host to plug-in dispatcher.
  1273. : pub dispatcher: DispatcherProc,
  1274. :
  1275. : /// Accumulating process mode is deprecated in VST 2.4! Use `processReplacing` instead!
  1276. : pub _process: ProcessProc,
  1277. :
  1278. : /// Set value of automatable parameter.
  1279. : pub setParameter: SetParameterProc,
  1280. :
  1281. : /// Get value of automatable parameter.
  1282. : pub getParameter: GetParameterProc,
  1283. :
  1284. : /// Number of programs (Presets).
  1285. : pub numPrograms: i32,
  1286. :
  1287. : /// Number of parameters. All programs are assumed to have this many parameters.
  1288. : pub numParams: i32,
  1289. :
  1290. : /// Number of audio inputs.
  1291. : pub numInputs: i32,
  1292. :
  1293. : /// Number of audio outputs.
  1294. : pub numOutputs: i32,
  1295. :
  1296. : /// Bitmask made of values from api::flags.
  1297. : ///
  1298. : /// ```no_run
  1299. : /// use vst::api::flags;
  1300. : /// let flags = flags::CAN_REPLACING | flags::CAN_DOUBLE_REPLACING;
  1301. : /// // ...
  1302. : /// ```
  1303. : pub flags: i32,
  1304. :
  1305. : /// Reserved for host, must be 0.
  1306. : pub reserved1: isize,
  1307. :
  1308. : /// Reserved for host, must be 0.
  1309. : pub reserved2: isize,
  1310. :
  1311. : /// For algorithms which need input in the first place (Group delay or latency in samples).
  1312. : ///
  1313. : /// This value should be initially in a resume state.
  1314. : pub initialDelay: i32,
  1315. :
  1316. : /// Deprecated unused member.
  1317. : pub _realQualities: i32,
  1318. :
  1319. : /// Deprecated unused member.
  1320. : pub _offQualities: i32,
  1321. :
  1322. : /// Deprecated unused member.
  1323. : pub _ioRatio: f32,
  1324. :
  1325. : /// Void pointer usable by api to store object data.
  1326. : pub object: *mut c_void,
  1327. :
  1328. : /// User defined pointer.
  1329. : pub user: *mut c_void,
  1330. :
  1331. : /// Registered unique identifier (register it at Steinberg 3rd party support Web).
  1332. : /// This is used to identify a plug-in during save+load of preset and project.
  1333. : pub uniqueId: i32,
  1334. :
  1335. : /// Plug-in version (e.g. 1100 for v1.1.0.0).
  1336. : pub version: i32,
  1337. :
  1338. : /// Process audio samples in replacing mode.
  1339. : pub processReplacing: ProcessProc,
  1340. :
  1341. : /// Process double-precision audio samples in replacing mode.
  1342. : pub processReplacingF64: ProcessProcF64,
  1343. :
  1344. : /// Reserved for future use (please zero).
  1345. : pub future: [u8; 56],
  1346. :}
  1347. :
  1348. :impl AEffect {
  1349. : /// Return handle to Plugin object. Only works for plugins created using this library.
  1350. : // Supresses warning about returning a reference to a box
  1351. : #[allow(unknown_lints)]
  1352. : #[allow(borrowed_box)]
  1353. 1 9.8e-05 : pub unsafe fn get_plugin(&mut self) -> &mut Box<Plugin> {
  1354. /* vst::api::AEffect::get_plugin total: 1 9.8e-05 */
  1355. : //FIXME: find a way to do this without resorting to transmuting via a box
  1356. : &mut *(self.object as *mut Box<Plugin>)
  1357. : }
  1358. :
  1359. : /// Drop the Plugin object. Only works for plugins created using this library.
  1360. : pub unsafe fn drop_plugin(&mut self) {
  1361. : drop(Box::from_raw(self.object as *mut Box<Plugin>));
  1362. : drop(Box::from_raw(self.user as *mut super::PluginCache));
  1363. : }
  1364. :
  1365. : pub(crate) unsafe fn get_cache(&mut self) -> &mut super::PluginCache {
  1366. : &mut *(self.user as *mut _)
  1367. : }
  1368. :}
  1369. :
  1370. :/// Information about a channel. Only some hosts use this information.
  1371. :#[repr(C)]
  1372. :pub struct ChannelProperties {
  1373. : /// Channel name.
  1374. : pub name: [u8; MAX_LABEL as usize],
  1375. :
  1376. : /// Flags found in `channel_flags` module.
  1377. : pub flags: i32,
  1378. :
  1379. : /// Type of speaker arrangement this channel is a part of.
  1380. : pub arrangement_type: SpeakerArrangementType,
  1381. :
  1382. : /// Name of channel (recommended: 6 characters + delimiter).
  1383. : pub short_name: [u8; MAX_SHORT_LABEL as usize],
  1384. :
  1385. : /// Reserved for future use.
  1386. : pub future: [u8; 48],
  1387. :}
  1388. :
  1389. :/// Tells the host how the channels are intended to be used in the plugin. Only useful for some
  1390. :/// hosts.
  1391. :#[repr(i32)]
  1392. :#[derive(Clone, Copy)]
  1393. :pub enum SpeakerArrangementType {
  1394. : /// User defined arrangement.
  1395. : Custom = -2,
  1396. : /// Empty arrangement.
  1397. : Empty = -1,
  1398. :
  1399. : /// Mono.
  1400. : Mono = 0,
  1401. :
  1402. : /// L R
  1403. : Stereo,
  1404. : /// Ls Rs
  1405. : StereoSurround,
  1406. : /// Lc Rc
  1407. : StereoCenter,
  1408. : /// Sl Sr
  1409. : StereoSide,
  1410. : /// C Lfe
  1411. : StereoCLfe,
  1412. :
  1413. : /// L R C
  1414. : Cinema30,
  1415. : /// L R S
  1416. : Music30,
  1417. :
  1418. : /// L R C Lfe
  1419. : Cinema31,
  1420. : /// L R Lfe S
  1421. : Music31,
  1422. :
  1423. : /// L R C S (LCRS)
  1424. : Cinema40,
  1425. : /// L R Ls Rs (Quadro)
  1426. : Music40,
  1427. :
  1428. : /// L R C Lfe S (LCRS + Lfe)
  1429. : Cinema41,
  1430. : /// L R Lfe Ls Rs (Quadro + Lfe)
  1431. : Music41,
  1432. :
  1433. : /// L R C Ls Rs
  1434. : Surround50,
  1435. : /// L R C Lfe Ls Rs
  1436. : Surround51,
  1437. :
  1438. : /// L R C Ls Rs Cs
  1439. : Cinema60,
  1440. : /// L R Ls Rs Sl Sr
  1441. : Music60,
  1442. :
  1443. : /// L R C Lfe Ls Rs Cs
  1444. : Cinema61,
  1445. : /// L R Lfe Ls Rs Sl Sr
  1446. : Music61,
  1447. :
  1448. : /// L R C Ls Rs Lc Rc
  1449. : Cinema70,
  1450. : /// L R C Ls Rs Sl Sr
  1451. : Music70,
  1452. :
  1453. : /// L R C Lfe Ls Rs Lc Rc
  1454. : Cinema71,
  1455. : /// L R C Lfe Ls Rs Sl Sr
  1456. : Music71,
  1457. :
  1458. : /// L R C Ls Rs Lc Rc Cs
  1459. : Cinema80,
  1460. : /// L R C Ls Rs Cs Sl Sr
  1461. : Music80,
  1462. :
  1463. : /// L R C Lfe Ls Rs Lc Rc Cs
  1464. : Cinema81,
  1465. : /// L R C Lfe Ls Rs Cs Sl Sr
  1466. : Music81,
  1467. :
  1468. : /// L R C Lfe Ls Rs Tfl Tfc Tfr Trl Trr Lfe2
  1469. : Surround102,
  1470. :}
  1471. :
  1472. :/// Used to specify whether functionality is supported.
  1473. :#[allow(missing_docs)]
  1474. :pub enum Supported {
  1475. : Yes,
  1476. : Maybe,
  1477. : No,
  1478. :}
  1479. :
  1480. :impl Supported {
  1481. : /// Create a `Supported` value from an integer if possible.
  1482. : pub fn from(val: isize) -> Option<Supported> {
  1483. : use self::Supported::*;
  1484. :
  1485. : match val {
  1486. : 1 => Some(Yes),
  1487. : 0 => Some(Maybe),
  1488. : -1 => Some(No),
  1489. : _ => None,
  1490. : }
  1491. : }
  1492. :}
  1493. :
  1494. :impl Into<isize> for Supported {
  1495. : /// Convert to integer ordinal for interop with VST api.
  1496. : fn into(self) -> isize {
  1497. : use self::Supported::*;
  1498. :
  1499. : match self {
  1500. : Yes => 1,
  1501. : Maybe => 0,
  1502. : No => -1,
  1503. : }
  1504. : }
  1505. :}
  1506. :
  1507. :/// Denotes in which thread the host is in.
  1508. :#[repr(i32)]
  1509. :pub enum ProcessLevel {
  1510. : /// Unsupported by host.
  1511. : Unknown = 0,
  1512. :
  1513. : /// GUI thread.
  1514. : User,
  1515. : /// Audio process thread.
  1516. : Realtime,
  1517. : /// Sequence thread (MIDI, etc).
  1518. : Prefetch,
  1519. : /// Offline processing thread (therefore GUI/user thread).
  1520. : Offline,
  1521. :}
  1522. :
  1523. :/// Language that the host is using.
  1524. :#[repr(i32)]
  1525. :#[allow(missing_docs)]
  1526. :pub enum HostLanguage {
  1527. : English = 1,
  1528. : German,
  1529. : French,
  1530. : Italian,
  1531. : Spanish,
  1532. : Japanese,
  1533. :}
  1534. :
  1535. :/// The file operation to perform.
  1536. :#[repr(i32)]
  1537. :pub enum FileSelectCommand {
  1538. : /// Load a file.
  1539. : Load = 0,
  1540. : /// Save a file.
  1541. : Save,
  1542. : /// Load multiple files simultaneously.
  1543. : LoadMultipleFiles,
  1544. : /// Choose a directory.
  1545. : SelectDirectory,
  1546. :}
  1547. :
  1548. :// TODO: investigate removing this.
  1549. :/// Format to select files.
  1550. :pub enum FileSelectType {
  1551. : /// Regular file selector.
  1552. : Regular,
  1553. :}
  1554. :
  1555. :/// File type descriptor.
  1556. :#[repr(C)]
  1557. :pub struct FileType {
  1558. : /// Display name of file type.
  1559. : pub name: [u8; 128],
  1560. :
  1561. : /// OS X file type.
  1562. : pub osx_type: [u8; 8],
  1563. : /// Windows file type.
  1564. : pub win_type: [u8; 8],
  1565. : /// Unix file type.
  1566. : pub nix_type: [u8; 8],
  1567. :
  1568. : /// MIME type.
  1569. : pub mime_type_1: [u8; 128],
  1570. : /// Additional MIME type.
  1571. : pub mime_type_2: [u8; 128],
  1572. :}
  1573. :
  1574. :/// File selector descriptor used in `host::OpCode::OpenFileSelector`.
  1575. :#[repr(C)]
  1576. :pub struct FileSelect {
  1577. : /// The type of file selection to perform.
  1578. : pub command: FileSelectCommand,
  1579. : /// The file selector to open.
  1580. : pub select_type: FileSelectType,
  1581. : /// Unknown. 0 = no creator.
  1582. : pub mac_creator: i32,
  1583. : /// Number of file types.
  1584. : pub num_types: i32,
  1585. : /// List of file types to show.
  1586. : pub file_types: *mut FileType,
  1587. :
  1588. : /// File selector's title.
  1589. : pub title: [u8; 1024],
  1590. : /// Initial path.
  1591. : pub initial_path: *mut u8,
  1592. : /// Used when operation returns a single path.
  1593. : pub return_path: *mut u8,
  1594. : /// Size of the path buffer in bytes.
  1595. : pub size_return_path: i32,
  1596. :
  1597. : /// Used when operation returns multiple paths.
  1598. : pub return_multiple_paths: *mut *mut u8,
  1599. : /// Number of paths returned.
  1600. : pub num_paths: i32,
  1601. :
  1602. : /// Reserved by host.
  1603. : pub reserved: isize,
  1604. : /// Reserved for future use.
  1605. : pub future: [u8; 116],
  1606. :}
  1607. :
  1608. :/// A struct which contains events.
  1609. :#[repr(C)]
  1610. :pub struct Events {
  1611. : /// Number of events.
  1612. : pub num_events: i32,
  1613. :
  1614. : /// Reserved for future use. Should be 0.
  1615. : pub _reserved: isize,
  1616. :
  1617. : /// Variable-length array of pointers to `api::Event` objects.
  1618. : ///
  1619. : /// The VST standard specifies a variable length array of initial size 2. If there are more
  1620. : /// than 2 elements a larger array must be stored in this structure.
  1621. : pub events: [*mut Event; 2],
  1622. :}
  1623. :
  1624. :impl Events {
  1625. : #[inline]
  1626. : pub(crate) fn events_raw(&self) -> &[*const Event] {
  1627. : use std::slice;
  1628. : unsafe {
  1629. : slice::from_raw_parts(
  1630. : &self.events[0] as *const *mut _ as *const *const _,
  1631. : self.num_events as usize,
  1632. : )
  1633. : }
  1634. : }
  1635. :
  1636. : #[inline]
  1637. : pub(crate) fn events_raw_mut(&mut self) -> &mut [*const SysExEvent] {
  1638. : use std::slice;
  1639. : unsafe {
  1640. : slice::from_raw_parts_mut(
  1641. : &mut self.events[0] as *mut *mut _ as *mut *const _,
  1642. : self.num_events as usize,
  1643. : )
  1644. : }
  1645. : }
  1646. :
  1647. : /// Use this in your impl of process_events() to process the incoming midi events.
  1648. : ///
  1649. : /// # Example
  1650. : /// ```no_run
  1651. : /// # use vst::plugin::{Info, Plugin, HostCallback};
  1652. : /// # use vst::buffer::{AudioBuffer, SendEventBuffer};
  1653. : /// # use vst::host::Host;
  1654. : /// # use vst::api;
  1655. : /// # use vst::event::{Event, MidiEvent};
  1656. : /// # struct ExamplePlugin { host: HostCallback, send_buf: SendEventBuffer }
  1657. : /// # impl Plugin for ExamplePlugin {
  1658. : /// # fn get_info(&self) -> Info { Default::default() }
  1659. : /// #
  1660. : /// fn process_events(&mut self, events: &api::Events) {
  1661. : /// for e in events.events() {
  1662. : /// match e {
  1663. : /// Event::Midi(MidiEvent { data, .. }) => {
  1664. : /// // ...
  1665. : /// }
  1666. : /// _ => ()
  1667. : /// }
  1668. : /// }
  1669. : /// }
  1670. : /// # }
  1671. : /// ```
  1672. : #[inline]
  1673. : pub fn events(&self) -> EventIterator {
  1674. : EventIterator {
  1675. : events: self.events_raw(),
  1676. : index: 0,
  1677. : }
  1678. : }
  1679. :}
  1680. :
  1681. :/// An iterator over events, returned by `api::Events::events`
  1682. :pub struct EventIterator<'a> {
  1683. : events: &'a [*const Event],
  1684. : index: usize,
  1685. :}
  1686. :
  1687. :impl<'a> Iterator for EventIterator<'a> {
  1688. : type Item = ::event::Event<'a>;
  1689. :
  1690. : fn next(&mut self) -> Option<Self::Item> {
  1691. : let index = self.index;
  1692. : if index < self.events.len() {
  1693. : self.index += 1;
  1694. : Some(::event::Event::from(unsafe { *self.events[index] }))
  1695. : } else {
  1696. : None
  1697. : }
  1698. : }
  1699. :}
  1700. :
  1701. :/// The type of event that has occured. See `api::Event.event_type`.
  1702. :#[repr(i32)]
  1703. :#[derive(Copy, Clone, Debug)]
  1704. :pub enum EventType {
  1705. : /// Midi event. See `api::MidiEvent`.
  1706. : Midi = 1,
  1707. :
  1708. : /// Deprecated.
  1709. : _Audio,
  1710. : /// Deprecated.
  1711. : _Video,
  1712. : /// Deprecated.
  1713. : _Parameter,
  1714. : /// Deprecated.
  1715. : _Trigger,
  1716. :
  1717. : /// System exclusive event. See `api::SysExEvent`.
  1718. : SysEx,
  1719. :}
  1720. :
  1721. :/// A VST event intended to be casted to a corresponding type.
  1722. :///
  1723. :/// The event types are not all guaranteed to be the same size,
  1724. :/// so casting between them can be done
  1725. :/// via `mem::transmute()` while leveraging pointers, e.g.
  1726. :///
  1727. :/// ```
  1728. :/// # use vst::api::{Event, EventType, MidiEvent, SysExEvent};
  1729. :/// # let mut event: *mut Event = &mut unsafe { std::mem::zeroed() };
  1730. :/// // let event: *const Event = ...;
  1731. :/// let midi_event: &MidiEvent = unsafe { std::mem::transmute(event) };
  1732. :/// ```
  1733. :#[repr(C)]
  1734. :#[derive(Copy, Clone)]
  1735. :pub struct Event {
  1736. : /// The type of event. This lets you know which event this object should be casted to.
  1737. : ///
  1738. : /// # Example
  1739. : ///
  1740. : /// ```
  1741. : /// # use vst::api::{Event, EventType, MidiEvent, SysExEvent};
  1742. : /// #
  1743. : /// # // Valid for test
  1744. : /// # let mut event: *mut Event = &mut unsafe { std::mem::zeroed() };
  1745. : /// #
  1746. : /// // let mut event: *mut Event = ...
  1747. : /// match unsafe { (*event).event_type } {
  1748. : /// EventType::Midi => {
  1749. : /// let midi_event: &MidiEvent = unsafe {
  1750. : /// std::mem::transmute(event)
  1751. : /// };
  1752. : ///
  1753. : /// // ...
  1754. : /// }
  1755. : /// EventType::SysEx => {
  1756. : /// let sys_event: &SysExEvent = unsafe {
  1757. : /// std::mem::transmute(event)
  1758. : /// };
  1759. : ///
  1760. : /// // ...
  1761. : /// }
  1762. : /// // ...
  1763. : /// # _ => {}
  1764. : /// }
  1765. : /// ```
  1766. : pub event_type: EventType,
  1767. :
  1768. : /// Size of this structure; `mem::sizeof::<Event>()`.
  1769. : pub byte_size: i32,
  1770. :
  1771. : /// Number of samples into the current processing block that this event occurs on.
  1772. : ///
  1773. : /// E.g. if the block size is 512 and this value is 123, the event will occur on sample
  1774. : /// `samples[123]`.
  1775. : pub delta_frames: i32,
  1776. :
  1777. : /// Generic flags, none defined in VST api yet.
  1778. : pub _flags: i32,
  1779. :
  1780. : /// The `Event` type is cast appropriately, so this acts as reserved space.
  1781. : ///
  1782. : /// The actual size of the data may vary
  1783. : ///as this type is not guaranteed to be the same size as the other event types.
  1784. : pub _reserved: [u8; 16],
  1785. :}
  1786. :
  1787. :/// A midi event.
  1788. :#[repr(C)]
  1789. :pub struct MidiEvent {
  1790. : /// Should be `EventType::Midi`.
  1791. : pub event_type: EventType,
  1792. :
  1793. : /// Size of this structure; `mem::sizeof::<MidiEvent>()`.
  1794. : pub byte_size: i32,
  1795. :
  1796. : /// Number of samples into the current processing block that this event occurs on.
  1797. : ///
  1798. : /// E.g. if the block size is 512 and this value is 123, the event will occur on sample
  1799. : /// `samples[123]`.
  1800. : pub delta_frames: i32,
  1801. :
  1802. : /// See `flags::MidiFlags`.
  1803. : pub flags: i32,
  1804. :
  1805. : /// Length in sample frames of entire note if available, otherwise 0.
  1806. : pub note_length: i32,
  1807. :
  1808. : /// Offset in samples into note from start if available, otherwise 0.
  1809. : pub note_offset: i32,
  1810. :
  1811. : /// 1 to 3 midi bytes. TODO: Doc
  1812. : pub midi_data: [u8; 3],
  1813. :
  1814. : /// Reserved midi byte (0).
  1815. : pub _midi_reserved: u8,
  1816. :
  1817. : /// Detuning between -63 and +64 cents,
  1818. : /// for scales other than 'well-tempered'. e.g. 'microtuning'
  1819. : pub detune: i8,
  1820. :
  1821. : /// Note off velocity between 0 and 127.
  1822. : pub note_off_velocity: u8,
  1823. :
  1824. : /// Reserved for future use. Should be 0.
  1825. : pub _reserved1: u8,
  1826. : /// Reserved for future use. Should be 0.
  1827. : pub _reserved2: u8,
  1828. :}
  1829. :
  1830. :/// A midi system exclusive event.
  1831. :///
  1832. :/// This event only contains raw byte data, and is up to the plugin to interpret it correctly.
  1833. :/// `plugin::CanDo` has a `ReceiveSysExEvent` variant which lets the host query the plugin as to
  1834. :/// whether this event is supported.
  1835. :#[repr(C)]
  1836. :#[derive(Clone)]
  1837. :pub struct SysExEvent {
  1838. : /// Should be `EventType::SysEx`.
  1839. : pub event_type: EventType,
  1840. :
  1841. : /// Size of this structure; `mem::sizeof::<SysExEvent>()`.
  1842. : pub byte_size: i32,
  1843. :
  1844. : /// Number of samples into the current processing block that this event occurs on.
  1845. : ///
  1846. : /// E.g. if the block size is 512 and this value is 123, the event will occur on sample
  1847. : /// `samples[123]`.
  1848. : pub delta_frames: i32,
  1849. :
  1850. : /// Generic flags, none defined in VST api yet.
  1851. : pub _flags: i32,
  1852. :
  1853. : /// Size of payload in bytes.
  1854. : pub data_size: i32,
  1855. :
  1856. : /// Reserved for future use. Should be 0.
  1857. : pub _reserved1: isize,
  1858. :
  1859. : /// Pointer to payload.
  1860. : pub system_data: *mut u8,
  1861. :
  1862. : /// Reserved for future use. Should be 0.
  1863. : pub _reserved2: isize,
  1864. :}
  1865. :
  1866. :/// Bitflags.
  1867. :pub mod flags {
  1868. : bitflags! {
  1869. : /// Flags for VST channels.
  1870. : pub flags Channel: i32 {
  1871. : /// Indicates channel is active. Ignored by host.
  1872. : const ACTIVE = 1,
  1873. : /// Indicates channel is first of stereo pair.
  1874. : const STEREO = 1 << 1,
  1875. : /// Use channel's specified speaker_arrangement instead of stereo flag.
  1876. : const SPEAKER = 1 << 2
  1877. : }
  1878. : }
  1879. :
  1880. : bitflags! {
  1881. : /// Flags for VST plugins.
  1882. : pub flags Plugin: i32 {
  1883. : /// Plugin has an editor.
  1884. : const HAS_EDITOR = 1,
  1885. : /// Plugin can process 32 bit audio. (Mandatory in VST 2.4).
  1886. : const CAN_REPLACING = 1 << 4,
  1887. : /// Plugin preset data is handled in formatless chunks.
  1888. : const PROGRAM_CHUNKS = 1 << 5,
  1889. : /// Plugin is a synth.
  1890. : const IS_SYNTH = 1 << 8,
  1891. : /// Plugin does not produce sound when all input is silence.
  1892. : const NO_SOUND_IN_STOP = 1 << 9,
  1893. : /// Supports 64 bit audio processing.
  1894. : const CAN_DOUBLE_REPLACING = 1 << 12
  1895. : }
  1896. : }
  1897. :
  1898. : bitflags!{
  1899. : /// Cross platform modifier key flags.
  1900. : pub flags ModifierKey: u8 {
  1901. : /// Shift key.
  1902. : const SHIFT = 1,
  1903. : /// Alt key.
  1904. : const ALT = 1 << 1,
  1905. : /// Control on mac.
  1906. : const COMMAND = 1 << 2,
  1907. : /// Command on mac, ctrl on other.
  1908. : const CONTROL = 1 << 3, // Ctrl on PC, Apple on Mac
  1909. : }
  1910. : }
  1911. :
  1912. : bitflags! {
  1913. : /// MIDI event flags.
  1914. : pub flags MidiEvent: i32 {
  1915. : /// This event is played live (not in playback from a sequencer track). This allows the
  1916. : /// plugin to handle these flagged events with higher priority, especially when the
  1917. : /// plugin has a big latency as per `plugin::Info::initial_delay`.
  1918. : const REALTIME_EVENT = 1,
  1919. : }
  1920. : }
  1921. :}
  1922. /*
  1923. * Total samples for file : "/build/gcc/src/gcc/libstdc++-v3/src/c++98/tree.cc"
  1924. *
  1925. * 1 9.8e-05
  1926. */
  1927.  
  1928.  
  1929. /* std::local_Rb_tree_decrement(std::_Rb_tree_node_base*) total: 1 9.8e-05 */
  1930. /*
  1931. * Total samples for file : "/build/gcc/src/gcc/libstdc++-v3/src/c++11/chrono.cc"
  1932. *
  1933. * 1 9.8e-05
  1934. */
  1935.  
  1936.  
  1937. /* std::chrono::_V2::system_clock::now() total: 1 9.8e-05 */
  1938. /*
  1939. * Total samples for file : "/build/gcc/src/gcc/libstdc++-v3/libsupc++/tinfo.h"
  1940. *
  1941. * 1 9.8e-05
  1942. */
  1943.  
  1944.  
  1945. /*
  1946. * Total samples for file : "/build/gcc/src/gcc/libstdc++-v3/libsupc++/del_opv.cc"
  1947. *
  1948. * 1 9.8e-05
  1949. */
  1950.  
  1951.  
  1952. /* operator delete[](void*) total: 1 9.8e-05 */
  1953. /*
  1954. * Total samples for file : "/build/gcc/src/gcc-build/gcc/include/cpuid.h"
  1955. *
  1956. * 1 9.8e-05
  1957. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement