Extra "ports" of juce-based plugins using the distrho build system
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
5.6KB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  5. <head>
  6. <title>protoplug: Example midi-chordify.lua</title>
  7. <link rel="stylesheet" href="../ldoc.css" type="text/css" />
  8. </head>
  9. <body>
  10. <div id="container">
  11. <div id="product">
  12. <div id="product_logo"></div>
  13. <div id="product_name"><big><b></b></big></div>
  14. <div id="product_description"></div>
  15. </div> <!-- id="product" -->
  16. <div id="main">
  17. <!-- Menu -->
  18. <div id="navigation">
  19. <a href="http://osar.fr">
  20. <div class=osarlogo> </div>
  21. </a>
  22. <br/>
  23. <a href="http://osar.fr/protoplug">
  24. <h1>protoplug</h1>
  25. </a>
  26. <span class="proto_subtitle">Lua API reference</span>
  27. <ul>
  28. <li><a href="../index.html">Index</a></li>
  29. </ul>
  30. <h2>Examples</h2>
  31. <ul class="$(kind=='Topics' and '' or 'nowrap'">
  32. <li><a href="../examples/classic-filter.lua.html">classic-filter.lua</a></li>
  33. <li><a href="../examples/sine-organ.lua.html">sine-organ.lua</a></li>
  34. <li><strong>midi-chordify.lua</strong></li>
  35. <li><a href="../examples/sinemouse-demo.lua.html">sinemouse-demo.lua</a></li>
  36. <li><a href="../examples/soundfile-test.lua.html">soundfile-test.lua</a></li>
  37. </ul>
  38. <h2>Modules</h2>
  39. <ul class="$(kind=='Topics' and '' or 'nowrap'">
  40. <li><a href="../modules/plugin.html">plugin</a></li>
  41. <li><a href="../modules/script.html">script</a></li>
  42. <li><a href="../modules/midi.html">midi</a></li>
  43. <li><a href="../modules/gui.html">gui</a></li>
  44. <li><a href="../modules/polyGen.html">polyGen</a></li>
  45. <li><a href="../modules/stereoFx.html">stereoFx</a></li>
  46. </ul>
  47. <h2>Classes</h2>
  48. <ul class="$(kind=='Topics' and '' or 'nowrap'">
  49. <li><a href="../classes/juce.AffineTransform.html">juce.AffineTransform</a></li>
  50. <li><a href="../classes/juce.AudioFormatReader.html">juce.AudioFormatReader</a></li>
  51. <li><a href="../classes/juce.Colour.html">juce.Colour</a></li>
  52. <li><a href="../classes/juce.ColourGradient.html">juce.ColourGradient</a></li>
  53. <li><a href="../classes/juce.Component.html">juce.Component</a></li>
  54. <li><a href="../classes/juce.FillType.html">juce.FillType</a></li>
  55. <li><a href="../classes/juce.Font.html">juce.Font</a></li>
  56. <li><a href="../classes/juce.Graphics.html">juce.Graphics</a></li>
  57. <li><a href="../classes/juce.Image.html">juce.Image</a></li>
  58. <li><a href="../classes/juce.Justification.html">juce.Justification</a></li>
  59. <li><a href="../classes/juce.LagrangeInterpolator.html">juce.LagrangeInterpolator</a></li>
  60. <li><a href="../classes/juce.Line.html">juce.Line</a></li>
  61. <li><a href="../classes/juce.Path.html">juce.Path</a></li>
  62. <li><a href="../classes/juce.Point.html">juce.Point</a></li>
  63. <li><a href="../classes/juce.RectanglePlacement.html">juce.RectanglePlacement</a></li>
  64. <li><a href="../classes/juce.Rectangle_float.html">juce.Rectangle_float</a></li>
  65. <li><a href="../classes/juce.Rectangle_int.html">juce.Rectangle_int</a></li>
  66. </ul>
  67. </div>
  68. <div id="content">
  69. <pre>
  70. <span class="comment">--[[
  71. name: midi chordify
  72. description: MIDI processor VST/AU. Notes go in, chords come out.
  73. author: osar.fr
  74. --]]</span>
  75. <span class="global">require</span> <span class="string">"include/protoplug"</span>
  76. <span class="comment">-- what kind of chord ?
  77. </span><span class="keyword">local</span> chordStructure = {<span class="number">0</span>, <span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>, <span class="number">11</span>}
  78. <span class="keyword">local</span> blockEvents = {}
  79. <span class="keyword">function</span> plugin.processBlock(samples, smax, midiBuf)
  80. blockEvents = {}
  81. <span class="comment">-- analyse midi buffer and prepare a chord for each note
  82. </span> <span class="keyword">for</span> ev <span class="keyword">in</span> midiBuf:eachEvent() <span class="keyword">do</span>
  83. <span class="keyword">if</span> ev:isNoteOn() <span class="keyword">then</span>
  84. chordOn(ev)
  85. <span class="keyword">elseif</span> ev:isNoteOff() <span class="keyword">then</span>
  86. chordOff(ev)
  87. <span class="keyword">end</span>
  88. <span class="keyword">end</span>
  89. <span class="comment">-- fill midi buffer with prepared notes
  90. </span> midiBuf:clear()
  91. <span class="keyword">if</span> #blockEvents&gt;<span class="number">0</span> <span class="keyword">then</span>
  92. <span class="keyword">for</span> _,e <span class="keyword">in</span> <span class="global">ipairs</span>(blockEvents) <span class="keyword">do</span>
  93. midiBuf:addEvent(e)
  94. <span class="keyword">end</span>
  95. <span class="keyword">end</span>
  96. <span class="keyword">end</span>
  97. <span class="keyword">function</span> chordOn(root)
  98. <span class="keyword">for</span> _, offset <span class="keyword">in</span> <span class="global">ipairs</span>(chordStructure) <span class="keyword">do</span>
  99. <span class="keyword">local</span> newEv = midi.Event.noteOn(
  100. root:getChannel(),
  101. root:getNote()+offset,
  102. root:getVel())
  103. <span class="global">table</span>.insert(blockEvents, newEv)
  104. <span class="keyword">end</span>
  105. <span class="keyword">end</span>
  106. <span class="keyword">function</span> chordOff(root)
  107. <span class="keyword">for</span> _, offset <span class="keyword">in</span> <span class="global">ipairs</span>(chordStructure) <span class="keyword">do</span>
  108. <span class="keyword">local</span> newEv = midi.Event.noteOff(
  109. root:getChannel(),
  110. root:getNote()+offset)
  111. <span class="global">table</span>.insert(blockEvents, newEv)
  112. <span class="keyword">end</span>
  113. <span class="keyword">end</span></pre>
  114. </div> <!-- id="content" -->
  115. </div> <!-- id="main" -->
  116. <div id="about">
  117. <i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.2</a></i>
  118. </div> <!-- id="about" -->
  119. </div> <!-- id="container" -->
  120. </body>
  121. </html>