Advertisement
Guest User

RetroCade Lite 1.1

a guest
Feb 1st, 2013
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.27 KB | None | 0 0
  1.  
  2. /*
  3. Gadget Factory
  4. RetroCade Lite Synthesizer
  5. This example will let you play the YM2149 and SID audio chip integrated into the ZPUino Soft Processor using a MIDI instrument such as a keyboard or guitar.
  6. To learn more about this example visit its home page at the Papilio RetroCade Wiki:
  7. http://retrocade.gadgetfactory.net
  8.  
  9. To learn more about the Papilio and Gadget Factory products visit:
  10. http://www.GadgetFactory.net
  11.  
  12. Hardware:
  13. * Connect a RetroCade MegaWing
  14.  
  15. *******IMPORTANT********************
  16. Be sure to load the ZPUino "RetroCade" variant to the Papilio's SPI Flash before loading this sketch.
  17.  
  18. created 2012
  19. by Jack Gassett
  20. http://www.gadgetfactory.net
  21.  
  22. License: GPL
  23.  
  24. ChangeLog:
  25. 1/8/2013 Version 1.01L
  26. -RetroCade Lite for the Papilio One 500K
  27. -No SD Card
  28. -No ModPlayer
  29. -No YM Player
  30.  
  31. 11/23/2012 Version 1.01
  32. -RetroCade Sketch
  33. -YM Player Volume Control
  34.  
  35. 11/23/2012 Version 1.0
  36. -RetroCade Sketch
  37. -SID Volume CC added.
  38. -Crawling Space Invaders added to the Welcome LCD screen.
  39. -Added ability to browse and play YMD and MOD files from the LCD screen.
  40. -Ring Mod and Sync CC's added.
  41. -Added YM2149 Noise Frequency.
  42. -SID V1 Instrument select from LCD.
  43. -SID Pitch Control
  44. -HiHat and Kick split keyboard from mod files on MIDI channel 7
  45.  
  46. 11/1/2012 Version .3
  47. -FlowStone Dashboard
  48. -Changed from SynthMaker to FlowStone
  49. -Added the ability to control the RetroCade without a MIDI output, can control over a Com Port instead.
  50. -Generated an EXE version of the Dashboard. VST will be generated when FlowStone 3.0 is released in November.
  51. -Zoom Controls added to Dashboard
  52. -Pressing Up Arrow toggles full screen.
  53. -While in full screen pressing Left Arrow fills the screen.
  54. -Pressing Down Arrow returns to normal size.
  55. -RetroCade Sketch
  56. -Control the RetroCade from a COM port or MIDI In
  57. -Play YMdat and Mod files from SD card or SmallFS filesystem.
  58. -Place a file name track[1-3].mod or track[1-3].ymd onto the SD card to override the files found in smallFS. Must power cycle the board for the files to be found.
  59. -YM files must be converted to ymd files using the process and tools detailed here: (http://audio.gadgetfactory.net/index.php?n=Main.YM2149Flash)
  60. -Mod files play out of RamFS filesystem which is located entirely in the 8MB SDRAM.
  61. -Merged RetroCade Bit File: Shortcut to load RetroCade-.01d-zpuino-1.0-PapilioPro-S6LX9-RetroCade-1.04.bit with the Papilio Loader
  62. -Changes from RetroCade Sketch are merged into this bit file.
  63. -Smallfs version of MOD and YM files are merged into this bit file.
  64.  
  65. 10/8/2012 Version .2
  66. -SynthMaker Dashboard
  67. -Added Midi In and Midi Out Selectors to the front panel.
  68. -Added SID Volume
  69. -Fixed CC#'s for all Presets
  70. -Renamed Presets from Hoppa to User
  71.  
  72. 9/26/2012 Version .1
  73. -ZPUino IDE: Shortcut to open RetroCade Sketch with the ZPUino IDE.
  74. -Merged RetroCade Bit File: Shortcut to load RetroCade-.01b-zpuino-1.0-PapilioPro-S6LX9-RetroCade-1.04.bit with the Papilio Loader
  75. -MOD files, YM2149, SID chips play on both left and right channel now.
  76. -Code runs from SDRAM providing 8MB of code space!
  77. -RetroCade Sketch is merged into this bit file.
  78. -Smallfs version of MOD and YM files are merged into this bit file.
  79. -Papilio Loader
  80. -SynthMaker Dashboard: The dashboard requires that Synthmaker be installed. MIDI selections are not moved to the main page yet.
  81.  
  82. */
  83.  
  84. HardwareSerial Serial1(11); //This is to define Serial1 for the ZPUino.
  85.  
  86. #include "RetroCade.h"
  87. //#include "SID.h"
  88. //#include "YM2149.h"
  89. #include "MIDI.h" //Be sure to change MIDI.h to user Serial1 instead of Serial
  90. #include "SmallFS.h"
  91. #include <LiquidCrystal.h>
  92. #include <SD.h>
  93.  
  94. byte lastpitch[8];
  95. //File root;
  96.  
  97. #undef DO_CHECKS
  98. #define DEBUG
  99.  
  100. //Instantiate the objects we will be using.
  101. RETROCADE retrocade;
  102. //YM2149 ym2149;
  103. //SID sid;
  104.  
  105. void setup(){
  106. Serial.begin(115200);
  107. Serial1.begin(31250);
  108.  
  109. //Setup pins for RetroCade MegaWing
  110. retrocade.setupMegaWing();
  111.  
  112. ///Give some volume
  113. retrocade.ym2149.V1.setVolume(11);
  114. retrocade.ym2149.V2.setVolume(11);
  115. retrocade.ym2149.V3.setVolume(11);
  116. retrocade.sid.setVolume(15);
  117.  
  118. //Select an instrument for each SID Voice.
  119. retrocade.sid.V1.setInstrument("Calliope",0,0,15,0,0,0,0,1,0); //Calliope
  120. retrocade.sid.V2.setInstrument("Accordian",12,0,12,0,0,0,1,0,0); //Accordian
  121. retrocade.sid.V3.setInstrument("Harpsicord",0,9,0,0,0,1,0,0,512); //Harpsicord
  122.  
  123. // Initiate MIDI communications, listen to all channels
  124. MIDI.begin(MIDI_CHANNEL_OMNI);
  125.  
  126. // Connect the HandleNoteOn function to the library, so it is called upon reception of a NoteOn.
  127. MIDI.setHandleNoteOn(HandleNoteOn); // Put only the name of the function
  128. MIDI.setHandleControlChange(HandleControlChange); // Put only the name of the function
  129. MIDI.setHandleNoteOff(HandleNoteOff); // Put only the name of the function
  130. // MIDI.setHandleProgramChange(HandleProgramChange); // Put only the name of the function
  131. MIDI.setHandlePitchBend(HandlePitchBend); // Put only the name of the function
  132.  
  133. //retrocade.modplayer.setup();
  134. //retrocade.ymplayer.setup(&retrocade.ym2149);
  135.  
  136. }
  137.  
  138.  
  139. void _zpu_interrupt()
  140. {
  141. //Serial.println("in zpu interupt");
  142. //retrocade.setTimeout();
  143. }
  144.  
  145. void HandleControlChange(byte channel, byte number, byte value) {
  146.  
  147. #ifdef DEBUG
  148. Serial.print("Change Control Channel: ");
  149. Serial.println(channel);
  150. Serial.print("Change Control Number: ");
  151. Serial.println(number);
  152. Serial.print("Change Control Value: ");
  153. Serial.println(value);
  154. #endif
  155.  
  156. //Define which voice responds to each channel
  157. switch (channel) {
  158. case 1:
  159. retrocade.sid.V1.handleCC(number, value);
  160. break;
  161. case 2:
  162. retrocade.sid.V2.handleCC(number, value);
  163. break;
  164. case 3:
  165. retrocade.sid.V3.handleCC(number, value);
  166. break;
  167. case 4:
  168. retrocade.ym2149.V1.handleCC(number, value);
  169. break;
  170. case 5:
  171. retrocade.ym2149.V2.handleCC(number, value);
  172. break;
  173. case 6:
  174. retrocade.ym2149.V3.handleCC(number, value);
  175. break;
  176. default:
  177. //return;
  178. break;
  179. }
  180.  
  181. // These are active no matter which channel is selected.
  182. switch (number) {
  183. case 9:
  184. if (value == 127)
  185. //retrocade.modplayer.loadFile("track1.mod");
  186. //retrocade.modplayer.play(value);
  187. break;
  188. case 10:
  189. if (value == 127)
  190. //retrocade.ymplayer.loadFile("track1.ymd");
  191. //retrocade.ymplayer.play(value);
  192. break;
  193. case 11:
  194. if (value == 127)
  195. //retrocade.modplayer.loadFile("track2.mod");
  196. //retrocade.modplayer.play(value);
  197. break;
  198. case 12:
  199. if (value == 127)
  200. //retrocade.ymplayer.loadFile("track2.ymd");
  201. //retrocade.ymplayer.play(value);
  202. break;
  203. case 13:
  204. if (value == 127)
  205. //retrocade.modplayer.loadFile("track3.mod");
  206. //retrocade.modplayer.play(value);
  207. break;
  208. case 14:
  209. if (value == 127)
  210. //retrocade.ymplayer.loadFile("track3.ymd");
  211. //retrocade.ymplayer.play(value);
  212. break;
  213. case 84:
  214. //retrocade.modplayer.volume(value <<1);
  215. break;
  216. case 86:
  217. retrocade.sid.setVolume(value/8);
  218. break;
  219. case 117:
  220. //retrocade.modplayer.play(!value);
  221. //retrocade.ymplayer.play(!value);
  222. break;
  223. default:
  224. return;
  225. break;
  226. }
  227.  
  228. }
  229.  
  230. void HandlePitchBend(byte channel, int bend) {
  231. #ifdef DEBUG
  232. Serial.print("Pitch Bend Received: ");
  233. Serial.println(channel);
  234. Serial.println(bend);
  235. #endif
  236. byte activeChannel = retrocade.getActiveChannel();
  237. if ( activeChannel != 0 )
  238. channel = activeChannel;
  239. int ymBend = bend/10;
  240. switch (channel){
  241. case 1:
  242. if (retrocade.sid.V1.getCurrentFreq() + bend > 388)
  243. retrocade.sid.V1.setFreq(retrocade.sid.V1.getCurrentFreq()+bend);
  244. break;
  245. case 2:
  246. if (retrocade.sid.V2.getCurrentFreq() + bend > 388)
  247. retrocade.sid.V2.setFreq(retrocade.sid.V2.getCurrentFreq()+bend);
  248. break;
  249. case 3:
  250. if (retrocade.sid.V3.getCurrentFreq() + bend > 388)
  251. retrocade.sid.V3.setFreq(retrocade.sid.V3.getCurrentFreq()+bend);
  252. break;
  253. case 4:
  254. if (retrocade.ym2149.V1.getCurrentFreq() - ymBend > 100)
  255. retrocade.ym2149.V1.setFreq(retrocade.ym2149.V1.getCurrentFreq()-ymBend);
  256. break;
  257. case 5:
  258. if (retrocade.ym2149.V2.getCurrentFreq() - ymBend > 100)
  259. retrocade.ym2149.V2.setFreq(retrocade.ym2149.V2.getCurrentFreq()-ymBend);
  260. break;
  261. case 6:
  262. if (retrocade.ym2149.V3.getCurrentFreq() - ymBend > 100)
  263. retrocade.ym2149.V3.setFreq(retrocade.ym2149.V3.getCurrentFreq()-ymBend);
  264. break;
  265. default:
  266. return;
  267. break;
  268. }
  269. }
  270. void HandleNoteOn(byte channel, byte pitch, byte velocity) {
  271. #ifdef DEBUG
  272. Serial.print("Note Received: ");
  273. Serial.println(pitch);
  274. Serial.print("Channel Received: ");
  275. Serial.println(channel);
  276. #endif
  277. lastpitch[channel-1]=pitch;
  278. byte activeChannel = retrocade.getActiveChannel();
  279. if ( activeChannel != 0 )
  280. channel = activeChannel;
  281. switch (channel){
  282. case 1:
  283. retrocade.sid.V1.setNote(pitch, 1);
  284. break;
  285. case 2:
  286. retrocade.sid.V2.setNote(pitch, 1);
  287. break;
  288. case 3:
  289. retrocade.sid.V3.setNote(pitch, 1);
  290. break;
  291. case 4:
  292. retrocade.ym2149.V1.setNote(pitch, 1);
  293. break;
  294. case 5:
  295. retrocade.ym2149.V2.setNote(pitch, 1);
  296. break;
  297. case 6:
  298. retrocade.ym2149.V3.setNote(pitch, 1);
  299. break;
  300. case 7:
  301. if (pitch > 60) {
  302. //retrocade.modplayer.loadFile("hihat.mod");
  303. //retrocade.modplayer.play(true);
  304. }
  305. else {
  306. //retrocade.modplayer.loadFile("kick.mod");
  307. //retrocade.modplayer.play(true);
  308. }
  309. break;
  310. default:
  311. return;
  312. break;
  313. }
  314. }
  315.  
  316. void HandleNoteOff(byte channel, byte pitch, byte velocity) {
  317. #ifdef DEBUG
  318. Serial.println("In NoteOff");
  319. Serial.println(pitch);
  320. #endif
  321. byte activeChannel = retrocade.getActiveChannel();
  322. if ( activeChannel != 0 )
  323. channel = activeChannel;
  324. if (lastpitch[channel-1]!=pitch) { return; }
  325. switch(channel){
  326. case 1:
  327. retrocade.sid.V1.setNote(pitch, 0);
  328. break;
  329. case 2:
  330. retrocade.sid.V2.setNote(pitch, 0);
  331. break;
  332. case 3:
  333. retrocade.sid.V3.setNote(pitch, 0);
  334. break;
  335. case 4:
  336. retrocade.ym2149.V1.setNote(128, 1);
  337. break;
  338. case 5:
  339. retrocade.ym2149.V2.setNote(128, 1);
  340. break;
  341. case 6:
  342. retrocade.ym2149.V3.setNote(128, 1);
  343. break;
  344. case 7:
  345. // retrocade.modplayer.play(false);
  346. break;
  347. default:
  348. return;
  349. break;
  350. }
  351. }
  352.  
  353.  
  354. void loop(){
  355. // Call MIDI.read the fastest you can for real-time performance.
  356. MIDI.read(&Serial);
  357. MIDI.read(&Serial1);
  358. retrocade.spaceInvadersLCD();
  359. retrocade.handleJoystick();
  360. retrocade.setTimeout();
  361. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement