File: organ.cpp

package info (click to toggle)
postal1 2015.git20250526%2Bds-2
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 14,024 kB
  • sloc: cpp: 130,877; ansic: 38,942; python: 874; makefile: 351; sh: 61
file content (179 lines) | stat: -rw-r--r-- 4,983 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
////////////////////////////////////////////////////////////////////////////////
//
// Copyright 2016 RWS Inc, All Rights Reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of version 2 of the GNU General Public License as published by
// the Free Software Foundation
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// Organ.cpp
// 
// History:
//		08/05/97 JRD	Started.  Linked in with SampleMaster.h
//
//		08/05/97	JMI	Now calls PurgeSamples() when done playing with the organ.
//							Converted to rspGetKeyStatusArray().
//
//		08/17/97	JMI	The second time you entered the organ, it would exit 
//							right away.
//							Also, now, when you choose 'Back', it goes back.  It
//							used to merely check for the escape key in order to 
//							exit.  Now it actually pumps the menu input so any normal
//							means of exiting a menu will work for this menu as well.
//							This provides a little better user feedback.
//							Also, took out aborting of sounds on exit.  Seemed to
//							abrupt or something.
//
//		08/21/97	JMI	Changed call to Update() to UpdateSystem().
//
//////////////////////////////////////////////////////////////////////////////
//
// Allows a player to play with his organ
//
//////////////////////////////////////////////////////////////////////////////

#include "RSPiX.h"
#ifdef PATHS_IN_INCLUDES
	#include "WishPiX/ResourceManager/resmgr.h"
#else
	#include "resmgr.h"
#endif
#include "SampleMaster.h"
#include "game.h"
#include "update.h"
#include "organ.h"

#define OR_BANK_KEY		RSP_SK_TAB

// Set by callback or within PlayWithMyOrgan() to quit.
static int16_t	ms_sContinue;

void	PlayWithMyOrgan()
	{
	// only allow certain keys to be active:
	char	acValidKeys[] = "1234567890QWERTYUIOPASDFGHJKLZXCVBNM";
	int16_t	sNumValid = strlen(acValidKeys);
	int16_t sNumSounds = CSoundCatalogue::NumSounds();
	int16_t sNumBanks = (sNumSounds + sNumValid - 1) / sNumValid;

	int16_t sCurBank = 0;
	ms_sContinue = 1;

	U8*	pau8KeyStatus	= rspGetKeyStatusArray();
	RInputEvent	ie;

	// Clear status array.
	memset(pau8KeyStatus, 0, 128);

	// Let's play some noise!
	while (ms_sContinue)
		{
		int16_t i;

		UpdateSystem();

		for (i=0;i<sNumValid;i++)
			{
			if ( pau8KeyStatus[acValidKeys[i]] )
				{
				// he just pressed this key - play the note:
				// Play sample CSoundCatalogue::ms_ppcNameList[
				// i + sNumValid * sCurBank if this isn't bigger
				// than sNumSounds
				int16_t sCurSample = (sNumValid * sCurBank + i) % sNumSounds;
				if (sCurSample < sNumSounds)
					{
					// Play the sample
					PlaySample(
						*CSoundCatalogue::ms_ppsmNameList[sCurSample],
						SampleMaster::Unspecified,
						255);	// initial volume
					}

				// Clear key.
				pau8KeyStatus[acValidKeys[i]]	= 0;
				}
			}

		if (pau8KeyStatus[OR_BANK_KEY]) // switch banks:
			{
			sCurBank++;
			if (sCurBank > sNumBanks)
				{
				sCurBank = 0;
				}

			// Clear key.
			pau8KeyStatus[OR_BANK_KEY]	= 0;
			}

		
		// Get the next input event, if any.
		ie.type	= RInputEvent::None;
		rspGetNextInputEvent(&ie);

		// Process menu input (cancel or choice keys).
		DoMenuInput(&ie, 1);
		// Do menu output (probably none most of the time in this case).
		// ....maybe not necessary since there's
//		DoMenuOutput(g_pimScreenBuf);

		// Draw newest state of menu....maybe not necessary since there's
		// only one option.
//		rspUpdateDisplay();

		if (rspGetQuitStatus() )
			{
			ms_sContinue = 0;
			}
		}

	// End playing samples.
//	AbortAllSamples();

	// Loop until done (if not they won't purge).
//	while (IsSamplePlaying() == true)
		{
//		Update();
		}

	// Purge all samples so we increase memory overhead.
	PurgeSamples();

	rspClearAllInputEvents();
	}

//////////////////////////////////////////////////////////////////////////////
// Choice callback from menu.
//////////////////////////////////////////////////////////////////////////////
extern bool Organ_MenuChoice(	// Returns true to accept choice, false to deny.
	Menu*	/*pmenuCurrent*/,		// Current menu.
	int16_t	sMenuItem)				// Item chosen.
	{
	if (sMenuItem >= 0)
		{
		ms_sContinue	= FALSE;
		}

	// Audible Feedback.
	if (sMenuItem == -1)
		PlaySample(g_smidMenuItemChange, SampleMaster::UserFeedBack);
	else
		PlaySample(g_smidMenuItemSelect, SampleMaster::UserFeedBack);

	// I'm sure that choice'll be fine.
	return true;
	}

//////////////////////////////////////////////////////////////////////////////
// EOF
//////////////////////////////////////////////////////////////////////////////