Commit 229c02d8 authored by daFischer's avatar daFischer

first

parent d031cac2
# This code depends on make tool being used
DEPFILES=$(wildcard $(addsuffix .d, ${OBJECTFILES}))
ifneq (${DEPFILES},)
include ${DEPFILES}
endif
/*
* File: Audio.cpp
* Author: user
*
* Created on April 30, 2014, 3:39 PM
*/
#include "Audio.h"
Audio::Audio(const char* path) {
//settings
audio_rate = 22050;
audio_format = AUDIO_S16SYS;
audio_channels = 2;
audio_buffers = 4096;
musicPlaying=0;
failed=false;
finished=true;//TODO: false
//Initialize SDL_mixer with settings as above
if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) != 0)
{
printf("Unable to initialize audio: %s\n", Mix_GetError());
failed=true;
return;
}
/*
//Load audio file
string extension[6] = {".mp3", ".MP3", ".mp2", ".MP2", ".ogg"};//.wav don't work
string filename;
for(int i=0;i<sizeof(extension);i++)
{
filename=path+extension[i];
music = Mix_LoadMUS(filename.c_str());
if(music == NULL)
{
printf("No %s file loaded: %s\n", extension[i].c_str(), Mix_GetError());
}
else
break;
}
if(music == NULL)
{
printf("Unable to load audio file.\n");
failed=true;
return;
}
*/
}
void Audio::play(){
//Play the audio file
/*if(Mix_PlayMusic(music, 0) == -1)
{
printf("Unable to play audio file: %s\n", Mix_GetError());
return;
}*/
//The music is playing!
musicPlaying = 1;
startTime=0;
/*printf("Setting time\n");
if(setPosition(30)==0)
printf("Unable to set Position\n");*/
//Make sure that the finished() function is called when the music stops playing
Mix_HookMusicFinished(audioFinished);
}
Audio::~Audio() {
//Release the memory allocated to our music
Mix_HaltMusic();
Mix_FreeMusic(music);
//Need to make sure that SDL_mixer and SDL have a chance to clean up
Mix_CloseAudio();
}
static void audioFinished()
{
printf("Finished the Audio\n");
}
/*void Audio::finished()
{
//Music is done!
printf("Finished the Audio2\n");
musicPlaying = 0;
}*/
int Audio::getTime()
{
//might help: http://stackoverflow.com/questions/10110905/simple-wave-generator-with-sdl-in-c
currentTime=SDL_GetTicks();
if(startTime==0)
startTime=currentTime;
//currentTime-=startTime;
//printf("%d\n",currentTime);
return currentTime;
}
int Audio::setPosition(double pos)
{
return Mix_SetMusicPosition(pos);
}
double Audio::getDuration()
{
//not possible with sdl, try openAL?
return 0.0;
}
/*
* File: Audio.h
* Author: user
*
* Created on April 30, 2014, 3:39 PM
*/
#ifndef AUDIO_H
#define AUDIO_H
#include <stdio.h>
#include <time.h>
#include <string>
#include <SDL/SDL.h>
#include <SDL/SDL_mixer.h>
using namespace std;
static void audioFinished();
class Audio {
public:
Audio(const char*);
void play();
virtual ~Audio();
//void finished();
int getTime();
int setPosition(double pos);
double getDuration();
bool failed;
bool finished;
private:
int audio_rate; //Frequency of audio playback
Uint16 audio_format; //Format of the audio we're playing
int audio_channels; //2 channels = stereo
int audio_buffers; //Size of the audio buffers in memory
int musicPlaying;
Mix_Music *music; //Pointer to our music, in memory
int startTime;
int currentTime;
};
#endif /* AUDIO_H */
/*
* File: ColorConverter.cpp
* Author: user
*
* Created on June 4, 2014, 3:55 PM
*/
#include "ColorConverter.h"
ColorConverter::ColorConverter() {
}
int ColorConverter::decodeColor(unsigned char* bytes, int byteNum, SDL_PixelFormat* format){
if(byteNum>=4)
{
printf("Tried to decode wrong color format");
return 0x000000;
}
int red=0;
for(int i=0;i<byteNum;i++)
{
red <<= 8;
red+=bytes[byteNum-1-i];
}
int green=red;
int blue=red;
int color;
if(byteNum==2)
{
red >>= 0;
red = (red & 0x1f)*8;//1111 1000 0000 0000
green >>= 5;
green = (green & 0x1f)*8;//0000 0111 1100 0000
blue >>= 10;
blue = (blue & 0x3f)*4;//0000 0000 0011 1111
color=SDL_MapRGB(format, (Uint8) red, (Uint8) green, (Uint8) blue);
//printf("color: %d.%d.%d => %d\n",red,green,blue,color);
//1111 1100 0010 0000
//
}
else//byteNum==1
{
color= (int)(colors[bytes[0]][0]);
}
return color;
}
int ColorConverter::decodeColor8(int num){
int color= (int)(colors[num][0]);
return color;
}
void ColorConverter::getAnnotationColor(int colorValue, char* red, char* green, char* blue, char* alpha){
*red = colors[colorValue][0];
*green = colors[colorValue][1];
*blue = colors[colorValue][2];
*alpha = colors[colorValue][3];
}
/*
* File: ColorConverter.h
* Author: user
*
* Created on June 4, 2014, 3:55 PM
*/
#ifndef COLORCONVERTER_H
#define COLORCONVERTER_H
#include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
class ColorConverter {
public:
ColorConverter();
void getAnnotationColor(int colorValue, char* redRef, char* greenRef, char* blueRef, char* alphaRef);
int decodeColor(unsigned char* bytes, int byteNum, SDL_PixelFormat* format);
int decodeColor8(int num);
private:
char colors[256][4]/* = {{255, 255, 255, 255}, // white
{255, 255, 255, 192},
{255, 255, 255, 128},
{255, 255, 255, 64},
{64, 64, 64, 255},
// darkGray
{64, 64, 64, 192},
{64, 64, 64, 128},
{64, 64, 64, 64},
{128, 128, 128, 255},
// gray
{128, 128, 128, 192},
{128, 128, 128, 128},
{128, 128, 128, 64},
{192, 192, 192, 255},
// lightGray
{192, 192, 192, 192},
{192, 192, 192, 128},
{192, 192, 192, 64},
{0, 0, 0, 255},
// black
{0, 0, 0, 192},
{0, 0, 0, 128},
{0, 0, 0, 64},
{255, 200, 0, 255},
// orange
{255, 200, 0, 192},
{255, 200, 0, 128},
{255, 200, 0, 64},
{255, 175, 175, 255},
// pink
{255, 175, 175, 192},
{255, 175, 175, 128},
{255, 175, 175, 64},
{0, 0, 255, 255},
// blue
{0, 0, 255, 192},
{0, 0, 255, 128},
{0, 0, 255, 64},
{255, 0, 0, 255},
// red
{255, 0, 0, 192},
{255, 0, 0, 128},
{255, 0, 0, 64},
{0, 255, 0, 255},
// green
{0, 255, 0, 192},
{0, 255, 0, 128},
{0, 255, 0, 64},
{255, 0, 255, 255},
// magenta
{255, 0, 255, 192},
{255, 0, 255, 128},
{255, 0, 255, 64},
{255, 255, 0, 255},
// yellow
{255, 255, 0, 192},
{255, 255, 0, 128},
{255, 255, 0, 64},
{0, 255, 255, 255},
// cyan
{0, 255, 255, 192},
{0, 255, 255, 128},
{0, 255, 255, 64},
{0, 0, 153, 255},
// dark blue
{0, 0, 153, 192},
{0, 0, 153, 128},
{0, 0, 153, 64},
{102, 102, 255, 255},
// light blue
{102, 102, 255, 192},
{102, 102, 255, 128},
{102, 102, 255, 64},
{204, 204, 255, 255},
// very light blue
{204, 204, 255, 192},
{204, 204, 255, 128},
{204, 204, 255, 64},
{255, 102, 102, 255},
// light red
{255, 102, 102, 192},
{255, 102, 102, 128},
{255, 102, 102, 64},
{255, 204, 204, 255},
// very light red
{255, 204, 204, 192},
{255, 204, 204, 128},
{255, 204, 204, 64},
{0, 102, 0, 255},
// dark green
{0, 102, 0, 192},
{0, 102, 0, 128},
{0, 102, 0, 64},
{102, 255, 102, 255},
// light green
{102, 255, 102, 192},
{102, 255, 102, 128},
{102, 255, 102, 64},
{204, 255, 204, 255},
// very light green
{204, 255, 204, 192},
{204, 255, 204, 128},
{204, 255, 204, 64},
{102, 0, 102, 255},
// dark rose
{102, 0, 102, 192},
{102, 0, 102, 128},
{102, 0, 102, 64},
{255, 0, 255, 255},
// rose
{255, 0, 255, 192},
{255, 0, 255, 128},
{255, 0, 255, 64},
{255, 102, 255, 255},
// light rose
{255, 102, 255, 192},
{255, 102, 255, 128},
{255, 102, 255, 64},
{255, 204, 255, 255},
// very light rose
{255, 204, 255, 192},
{255, 204, 255, 128},
{255, 204, 255, 64},
{102, 102, 0, 255},
// dark yellow
{102, 102, 0, 192},
{102, 102, 0, 128},
{102, 102, 0, 64},
{255, 255, 102, 255},
// light yellow
{255, 255, 102, 192},
{255, 255, 102, 128},
{255, 255, 102, 64},
{255, 255, 204, 255},
// very light yellow
{255, 255, 204, 192},
{255, 255, 204, 128},
{255, 255, 204, 64},
{0, 0, 102, 255},
// dark turquoise
{0, 0, 102, 192},
{0, 0, 102, 128},
{0, 0, 102, 64},
{102, 255, 255, 255},
// light turquoise
{102, 255, 255, 192},
{102, 255, 255, 128},
{102, 255, 255, 64},
{204, 255, 255, 255},
// very light turquoise
{204, 255, 255, 192},
{204, 255, 255, 128},
{204, 255, 255, 64},
{153, 0, 255, 255},
// violet
{153, 0, 255, 192},
{153, 0, 255, 128},
{153, 0, 255, 64},
{102, 0, 153, 255},
// dark violet
{102, 0, 153, 192},
{102, 0, 153, 128},
{102, 0, 153, 64},
{153, 102, 255, 255},
// blueish light violet
{153, 102, 255, 192},
{153, 102, 255, 128},
{153, 102, 255, 64},
{204, 102, 255, 255},
// redish light violet
{204, 102, 255, 192},
{204, 102, 255, 128},
{204, 102, 255, 64},
{204, 102, 0, 255},
// light brown
{204, 102, 0, 192},
{204, 102, 0, 128},
{204, 102, 0, 64},
{255, 102, 51, 255},
// dark orange
{255, 102, 51, 192},
{255, 102, 51, 128},
{255, 102, 51, 64},
{255, 204, 153, 255},
// light orange
{255, 204, 153, 192},
{255, 204, 153, 128},
{255, 204, 153, 64},
{255, 215, 0, 255},
// gold
{255, 215, 0, 192},
{255, 215, 0, 128},
{255, 215, 0, 64},
{240, 230, 140, 255},
// khaki
{240, 230, 140, 192},
{240, 230, 140, 128},
{240, 230, 140, 64},
{218, 165, 32, 255},
// goldenrod
{218, 165, 32, 192},
{218, 165, 32, 128},
{218, 165, 32, 64},
{245, 245, 220, 255},
// beige
{245, 245, 220, 192},
{245, 245, 220, 128},
{245, 245, 220, 64},
{255, 228, 181, 255},
// moccasin
{255, 228, 181, 192},
{255, 228, 181, 128},
{255, 228, 181, 64},
{255, 99, 71, 255},
// tomato
{255, 99, 71, 192},
{255, 99, 71, 128},
{255, 99, 71, 64},
{255, 140, 0, 255},
// darkorange
{255, 140, 0, 192},
{255, 140, 0, 128},
{255, 140, 0, 64},
{220, 20, 60, 255},
// crimson
{220, 20, 60, 192},
{220, 20, 60, 128},
{220, 20, 60, 64},
{70, 130, 180, 255},
// steelblue
{70, 130, 180, 192},
{70, 130, 180, 128},
{70, 130, 180, 64},
{65, 105, 225, 255},
// royalblue
{65, 105, 225, 192},
{65, 105, 225, 128},
{65, 105, 225, 64},
{123, 104, 238, 255},
// medslateblue
{123, 104, 238, 192},
{123, 104, 238, 128},
{123, 104, 238, 64},
{127, 255, 212, 255},
// aquamarine
{127, 255, 212, 192},
{127, 255, 212, 128},
{127, 255, 212, 64},
{0, 255, 127, 255},
// springgreen
{0, 255, 127, 192},
{0, 255, 127, 128},
{0, 255, 127, 64},
{150, 205, 50, 255},
// yellowgreen
{150, 205, 50, 192},
{150, 205, 50, 128},
{150, 205, 50, 64},
{216, 191, 216, 255},
// thistle
{216, 191, 216, 192},
{216, 191, 216, 128},
{216, 191, 216, 64},
{245, 222, 179, 255},
// wheat
{245, 222, 179, 192},
{245, 222, 179, 128},
{245, 222, 179, 64},
{160, 82, 45, 255},
// siena
{160, 82, 45, 192},
{160, 82, 45, 128},
{160, 82, 45, 64},
{233, 150, 122, 255},
// darksalmon
{233, 150, 122, 192},
{233, 150, 122, 128},
{233, 150, 122, 64},
{165, 42, 42, 255},
// brown
{165, 42, 42, 192},
{165, 42, 42, 128},
{165, 42, 42, 64},
{210, 105, 30, 255},
// chocolate
{210, 105, 30, 192},
{210, 105, 30, 128},
{210, 105, 30, 64},
{244, 164, 96, 255},
// sandybrown
{244, 164, 96, 192},
{244, 164, 96, 128},
{244, 164, 96, 64},
{255, 20, 147, 255},
// deeppink
{255, 20, 147, 192},
{255, 20, 147, 128},
{255, 20, 147, 64},
{255, 105, 180, 255},
// hotpink
{255, 105, 180, 192},
{255, 105, 180, 128},
{255, 105, 180, 64},
{221, 160, 221, 255},
// plum
{221, 160, 221, 192},
{221, 160, 221, 128},
{221, 160, 221, 64},
{186, 85, 211, 255},
// medorchid
{186, 85, 211, 192},
{186, 85, 211, 128},
{186, 85, 211, 64},
{112, 128, 144, 255},
// slategray
{112, 128, 144, 192},
{112, 128, 144, 128},
{112, 128, 144, 64}}*/;
};
#endif /* COLORCONVERTER_H */
/*
* File: Constants.cpp
* Author: user
*
* Created on May 5, 2014, 5:39 PM