Exemplo n.º 1
0
void parseInput(char s[])
{
	if( (s[0] <= '7') && ( s[0] >= '1') ) // 7 tunes
	{
		startTune(s[0]);
	}
	else
	{
		// parse first character	
		switch (s[0])
		{
			case '+':
				volumeUp();
				break;
			case '-':
				volumeDown();
				break;
			case 's':
				if( (s[1] == 't') && (s[2] == 'o') && (s[3] == 'p'))
				stopTune();
				break;				
			case 'd':
				if( (s[1] == 'e') && (s[2] == 'm') && (s[3] == 'o') && (s[4] == '?') )
				sendFString(TALKING_TO);
				sendFString(WHO_DEMO);
				break;
			default:
				sendFString(BAD_COMMAND1);
				sendChar(s[0]);
				sendFString(BAD_COMMAND2);

				break;
			
		}
	s[0] = '\0';
	}
}
Exemplo n.º 2
0
int main(int argc, char *argv[]) try
{
   setPath(argv[0]);
   
   bool shaders = true;
   
   // load tune if argument is given
   for (int i=1; i<argc; ++i)
   {
      const std::string arg = argv[i];
      if (arg == "--no-shaders")
         shaders = false;
      else
         loadTune(arg);
   }

   class InitAndQuit
   {
      public:
         InitAndQuit(bool shadersOn)
         {
            if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) != 0)
            {
               std::ostringstream error;
               error << "Failed on SDL_Init: " << SDL_GetError() << "\n";
               throw std::runtime_error(error.str());
            }
            graphics::setupGraphics(shadersOn);
            SDL_WM_SetCaption("Sousaphone Hero", "Sousaphone Hero");
            if(Mix_OpenAudio(AUDIO_RATE, AUDIO_FORMAT, AUDIO_CHANNELS, AUDIO_BUFFERS) != 0)
            {
               SDL_Quit();
               std::ostringstream error;
               error << "Failed on Mix_OpenAudio: " << Mix_GetError() << "\n";
               throw std::runtime_error(error.str());
            }

            std::srand(time(NULL));

            Mix_ChannelFinished(doChangedNotes); // set callback function

            startTiming();
         }

         ~InitAndQuit()
         {
            graphics::cleanupGraphics();
            Mix_CloseAudio();
            SDL_Quit();
         }
   } iandq(shaders);

   // load all the notes (to load them)
   getNoteA(); getNoteB(); getNoteC(); getNoteD(); getNoteE(); getNoteF(); getNoteG();

   const bool demoMode = false;

   double lastNoteFraction = 0;

   int channel = -1;

   bool tuneStarted = false;

   try
   {
      while(1)
      {
         const double currentNoteFraction = noteFraction();
         if (currentNoteFraction < lastNoteFraction) // i.e. we have wrapped round a note
         {
            incrementTune();
            if (demoMode)
            {
               const char current = getCurrentNote();
               if (current != NO_NOTE_CHARACTER)
               {
                  if (channel != -1)
                     Mix_HaltChannel(channel);

                  channel = Mix_PlayChannelTimed(-1, getNote(current).get(), -1, NOTE_DURATION);
               }
            }
         }
         lastNoteFraction = currentNoteFraction;

         if ((getTimeSinceStart() > graphics::ZOOM_OUT_LENGTH*1000.0) && !tuneStarted)
         {
            startTune();
            tuneStarted = true;
         }

         //SDL_Delay(100);

         doIOLoop();
         playAppropriateNote();
         graphics::draw(currentNoteFraction);
         graphics::updateScreen();
         score::doEveryLoop();
      }
   }
   catch(QuitSignal&)
   {} // do nothing

   return 0;
} catch (std::exception& error)
{
   std::cout << error.what();
   return 1;
}