//
//  SoundRef.h
//  Meteor
//
//  Created by Cesar Parent on 09/09/2015.
//  Copyright © 2015 Cesar Parent. All rights reserved.
//

#ifndef SoundRef_h
#define SoundRef_h

#include "../defines.h"
#include "../CPFoundation.h"
#include "../sdl_includes.h"

NS_BEGIN

class SoundRef : public CPObject {
    
public:
    
    SoundRef(const std::string& filename) {
        sound = Mix_LoadWAV(filename.c_str());
        if(sound == nullptr) {
            throw std::runtime_error(filename +
                                     std::string(": Error opening sound file ") +
                                     Mix_GetError());
        }
    }
    
    virtual ~SoundRef() {
        Mix_FreeChunk(sound);
    }
    
    
    Mix_Chunk* sound;
};

class MusicRef : public CPObject {
public:
    
    MusicRef(const std::string& filename) {
        music = Mix_LoadMUS(filename.c_str());
        if(music == nullptr) {
            throw std::runtime_error(filename +
                                     std::string(": Error opening music file ") +
                                     Mix_GetError());
        }
    }
    
    virtual ~MusicRef() {
        
    }
    
    Mix_Music* music;
};


NS_END


#endif /* SoundRef_h */
