Files
oboe/osx/tools/soundtool.cpp
Celtic Minstrel 7cd4a618b4 - Got rid of the prefix header in favour of directly including it in every file that needs it (though some files still need the include yet apparently work fine; perhaps a clean build would catch that)
- Replaced all occurrences of FillCRect with the new tileImage, to get away from 'ppat' resources.
- Fixed a minor error in the character editor where part of a text string was off the window.
- With the prefix header gone, libticpp.dylib has been removed; TinyXML++ is now compiled right into the program.
- The scenario editor splash screen is now loaded from a file.
- The pc editor title has its transparency problem fixed.
- Added an overload of tileImage that takes a RgnHandle instead of a Rect in order to replace the single occurrence of FillCRgn.
- Removed an unused function in boe.graphics.cpp
- Changed loading of patterns. Instead of loading each pattern individually from a resource, a single file containing all of them is loading. The arrays that formerly contained the actual patterns now contain the source rects of the patterns.
- Fixed the cursor hotspots (the coordinates were reversed)
- Removed the useless flip_pict that was written when I didn't know what I was doing.
- Fixed error in tileImage in which vrep and hrep were switched.
- Added code to tileImage to ensure that the pattern will line up with anything already onscreen, regardless of the rect to fill.
- Two images were altered: pcedtitle.png to fix the transparenct problem, and pixpats.png to add one pattern that had been missed (and also rearrange the smaller patterns a little)

git-svn-id: http://openexile.googlecode.com/svn/trunk@91 4ebdad44-0ea0-11de-aab3-ff745001d230
2009-06-10 04:01:15 +00:00

203 lines
4.8 KiB
C++

/*
* soundtool.cpp
* BoE
*
* Created by Celtic Minstrel on 16/04/09.
*
*/
#include <Carbon/Carbon.h>
#include "soundtool.h"
Handle sound_handles[NUM_SOUNDS];
bool play_sounds = true;
short last_played = 10000;
bool always_asynch[100] = {
false,false,false,false,false,
false,true,false,false,false,
false,false,false,false,false, // 10
false,false,false,false,false,
false,false,false,false,true, // 20
true,false,false,false,false,
false,false,false,false,true, // 30
false,false,true,false,true,
false,true,true,true,true, // 40
true,true,true,true,true,
true,false,false,false,false, // 50
true,false,false,false,false,
false,true,false,false,false, // 60
false,false,false,false,false,
false,false,false,false,false, // 70
false,true,true,true,true,
true,true,true,true,false, // 80
true,false,false,false,false,
false,true,false,false,false, // 90
false,false,false,false,false
};
bool load_when_play[100] = {
0,0,1,1,1,1,0,1,1,1,
0,0,0,1,0,1,1,1,1,1,
1,1,1,1,1,1,1,0,1,1,
1,1,1,1,0,1,1,0,1,1,
1,1,1,1,1,1,1,0,0,0,
0,1,1,1,1,0,1,1,1,1,
1,0,1,1,1,1,1,1,1,0,
0,0,0,0,0,0,1,1,1,1,
1,1,1,1,1,0,0,0,0,0,
1,1,1,1,1,1,1,1,1,0
};
short sound_delay[100] = {
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,25,25,0,0,0,0,
0,0,0,0,8,0,0,8,0,0,
0,0,0,10,20,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,13,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0
};
//Allocate SndChannelPtr chan[4] as a global variable.
//Allocate char numchannel = 3; (This gives 4 channels, = 2 gives 3 etc...
//Allocate char channel; This is just used as a counter so each sound is played by the next
//channel in line. You can have up to 4 sounds playing at once.
SndChannelPtr chan[4];
char numchannel = 3;
char channel;
short snd_played[4] = {-1,-1,-1,-1};
bool sound_going(short which_s) {
short i;
for (i = 0; i < 4; i++)
if (snd_played[i] == which_s)
return true;
return false;
}
pascal void snd_channel_callback(SndChannelPtr theChannel,SndCommand* theCommand) {
long theA5;
short channel = -1,i,which_sound;
#ifndef EXILE_BIG_GUNS
theA5 = SetA5(theCommand->param2);
#endif
for (i = 0; i < 4; i++)
if (chan[i] == theChannel)
channel = i;
which_sound = snd_played[channel];
snd_played[channel] = -1;
//if (in_startup_mode == false)
// print_num(0,snd_played[channel],channel);
if ((sound_going(which_sound) == false) && (load_when_play[which_sound] == true)) {
HUnlock(sound_handles[which_sound]);
//if (in_startup_mode == false)
// print_num(99,snd_played[channel],channel);
}
#ifndef EXILE_BIG_GUNS
theA5 = SetA5(theA5);
#endif
}
void init_snd_tool(){
short i,t;
SndCallBackUPP callback;
for (i = 0; i < NUM_SOUNDS; i++) {
if (!load_when_play[i]) {
sound_handles[i] = GetResource('snd ', 20000 + i);
}
}
callback = NewSndCallBackUPP(snd_channel_callback);
for(t=0;t<4;t++){ // setup 4 sound channels
SndNewChannel(&chan[t], sampledSynth, initMono + initNoDrop, callback);
chan[t]->qLength = 128;
}
}
void play_sound(short which, short how_many_times){ // if < 0, play asynch
if (!play_sounds) return;
Handle sndhandle;
unsigned long dummy;
OSErr err;
SndCommand theCommand;
if (abs(which) > NUM_SOUNDS) {
//char msg[50];
/*s*/printf(/*msg,*/"Error: Sound #%i does not exist.\n",abs(which));
//give_error(msg,"",0);
return;
}
channel++;
if (channel > numchannel) channel = 0;
if (!sound_going(abs(which)) && load_when_play[abs(which)])
sndhandle = GetResource('snd ',20000 + abs(which));
else sndhandle = sound_handles[abs(which)];
if (which > 0)
if (always_asynch[which])
which *= -1;
if (sndhandle != NULL)
{
HLock(sndhandle);
if (which < 0) err = SndPlay(chan[channel],(SndListHandle) sndhandle,true); // Normal SndPlay
else {
err = SndPlay(chan[channel],(SndListHandle) sndhandle,false);
}
if (err != 0) {
printf("Sound error.\n");
//add_string_to_buf("Sound Error. Error codes:");
//print_nums(channel,which,err);
//add_string_to_buf("Your system could not play a sound.");
//add_string_to_buf("Make sure editor isn't running.");
//add_string_to_buf("Turn off sounds if necessary.");
}
HUnlock(sndhandle);
snd_played[channel] = abs(which);
theCommand.cmd = callBackCmd;
theCommand.param1 = 0;
#ifndef EXILE_BIG_GUNS
theCommand.param2 = SetCurrentA5();
#endif
#ifdef EXILE_BIG_GUNS
theCommand.param2 = 0;
#endif
SndDoCommand(chan[channel],&theCommand,true);
}
else SysBeep(20);
if (which < 0)
Delay(sound_delay[-1 * which],&dummy);
if(how_many_times > 1)
play_sound(which, how_many_times - 1);
}
void one_sound(short which){
if (which == last_played)
return;
play_sound(which);
last_played = which;
}
void clear_sound_memory(){
last_played = 100;
}
void flip_sound()
{
play_sounds = (play_sounds == true) ? false : true;
}