organ.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. // Organ.cpp
  19. //
  20. // History:
  21. // 08/05/97 JRD Started. Linked in with SampleMaster.h
  22. //
  23. // 08/05/97 JMI Now calls PurgeSamples() when done playing with the organ.
  24. // Converted to rspGetKeyStatusArray().
  25. //
  26. // 08/17/97 JMI The second time you entered the organ, it would exit
  27. // right away.
  28. // Also, now, when you choose 'Back', it goes back. It
  29. // used to merely check for the escape key in order to
  30. // exit. Now it actually pumps the menu input so any normal
  31. // means of exiting a menu will work for this menu as well.
  32. // This provides a little better user feedback.
  33. // Also, took out aborting of sounds on exit. Seemed to
  34. // abrupt or something.
  35. //
  36. // 08/21/97 JMI Changed call to Update() to UpdateSystem().
  37. //
  38. //////////////////////////////////////////////////////////////////////////////
  39. //
  40. // Allows a player to play with his organ
  41. //
  42. //////////////////////////////////////////////////////////////////////////////
  43. #include "RSPiX.h"
  44. #ifdef PATHS_IN_INCLUDES
  45. #include "WishPiX/ResourceManager/resmgr.h"
  46. #else
  47. #include "resmgr.h"
  48. #endif
  49. #include "SampleMaster.h"
  50. #include "game.h"
  51. #include "update.h"
  52. #include "organ.h"
  53. #define OR_BANK_KEY RSP_SK_TAB
  54. // Set by callback or within PlayWithMyOrgan() to quit.
  55. static short ms_sContinue;
  56. void PlayWithMyOrgan()
  57. {
  58. // only allow certain keys to be active:
  59. char acValidKeys[] = "1234567890QWERTYUIOPASDFGHJKLZXCVBNM";
  60. short sNumValid = strlen(acValidKeys);
  61. short sNumSounds = CSoundCatalogue::NumSounds();
  62. short sNumBanks = (sNumSounds + sNumValid - 1) / sNumValid;
  63. short sCurBank = 0;
  64. ms_sContinue = 1;
  65. U8* pau8KeyStatus = rspGetKeyStatusArray();
  66. RInputEvent ie;
  67. // Clear status array.
  68. memset(pau8KeyStatus, 0, 128);
  69. // Let's play some noise!
  70. while (ms_sContinue)
  71. {
  72. short i;
  73. UpdateSystem();
  74. for (i=0;i<sNumValid;i++)
  75. {
  76. if ( pau8KeyStatus[acValidKeys[i]] )
  77. {
  78. // he just pressed this key - play the note:
  79. // Play sample CSoundCatalogue::ms_ppcNameList[
  80. // i + sNumValid * sCurBank if this isn't bigger
  81. // than sNumSounds
  82. short sCurSample = (sNumValid * sCurBank + i) % sNumSounds;
  83. if (sCurSample < sNumSounds)
  84. {
  85. // Play the sample
  86. PlaySample(
  87. *CSoundCatalogue::ms_ppsmNameList[sCurSample],
  88. SampleMaster::Unspecified,
  89. 255); // initial volume
  90. }
  91. // Clear key.
  92. pau8KeyStatus[acValidKeys[i]] = 0;
  93. }
  94. }
  95. if (pau8KeyStatus[OR_BANK_KEY]) // switch banks:
  96. {
  97. sCurBank++;
  98. if (sCurBank > sNumBanks)
  99. {
  100. sCurBank = 0;
  101. }
  102. // Clear key.
  103. pau8KeyStatus[OR_BANK_KEY] = 0;
  104. }
  105. // Get the next input event, if any.
  106. ie.type = RInputEvent::None;
  107. rspGetNextInputEvent(&ie);
  108. // Process menu input (cancel or choice keys).
  109. DoMenuInput(&ie, 1);
  110. // Do menu output (probably none most of the time in this case).
  111. // ....maybe not necessary since there's
  112. // DoMenuOutput(g_pimScreenBuf);
  113. // Draw newest state of menu....maybe not necessary since there's
  114. // only one option.
  115. // rspUpdateDisplay();
  116. if (rspGetQuitStatus() )
  117. {
  118. ms_sContinue = 0;
  119. }
  120. }
  121. // End playing samples.
  122. // AbortAllSamples();
  123. // Loop until done (if not they won't purge).
  124. // while (IsSamplePlaying() == true)
  125. {
  126. // Update();
  127. }
  128. // Purge all samples so we increase memory overhead.
  129. PurgeSamples();
  130. rspClearAllInputEvents();
  131. }
  132. //////////////////////////////////////////////////////////////////////////////
  133. // Choice callback from menu.
  134. //////////////////////////////////////////////////////////////////////////////
  135. extern bool Organ_MenuChoice( // Returns true to accept choice, false to deny.
  136. Menu* /*pmenuCurrent*/, // Current menu.
  137. short sMenuItem) // Item chosen.
  138. {
  139. if (sMenuItem >= 0)
  140. {
  141. ms_sContinue = FALSE;
  142. }
  143. // Audible Feedback.
  144. if (sMenuItem == -1)
  145. PlaySample(g_smidMenuItemChange, SampleMaster::UserFeedBack);
  146. else
  147. PlaySample(g_smidMenuItemSelect, SampleMaster::UserFeedBack);
  148. // I'm sure that choice'll be fine.
  149. return true;
  150. }
  151. //////////////////////////////////////////////////////////////////////////////
  152. // EOF
  153. //////////////////////////////////////////////////////////////////////////////