SDLMixerPlugin done...
[potpourri.git] / src / SDLMixerPlugin / SDLMixerPlugin.cpp
blob9ff37a69428660a59241460f1eac48d87215f69f
1 // Copyright 2008 Brian Caine
3 // This file is part of Potpourri.
5 // Potpourri is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Potpourri is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTIBILITY of FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Potpourri. If not, see <http://www.gnu.org/licenses/>.
19 // NOTES:
20 // machinery..blahblahblah
22 #include "SDLMixerPlugin.h"
23 #include "../../include/plugins/audio/AudioSample.h"
24 #include <stdexcept>
26 using namespace fragrant;
28 AudioSample* makeAudioSample(std::string path, MediaLoader& loader)
30 std::string data;
32 try
34 data = loader.loadMedia(path);
37 catch (std::runtime_error& e)
39 std::cerr << "make_image(): Error loading image\n\t"
40 << e.what() << std::endl;
41 return 0;
44 SDL_RWops* const_mem_sauce = SDL_RWFromConstMem(
45 (const void*)data.c_str(), data.size());
46 Mix_Chunk* chunk = Mix_LoadWAV_RW(const_mem_sauce, 1);
48 SDLMixerSample* sample = new SDLMixerSample(chunk);
50 return dynamic_cast<AudioSample*>(sample);
53 AudioDevice* makeDevice()
55 return dynamic_cast<AudioDevice*>(new SDLMixerDevice);
58 PluginData queryPlugin()
60 PluginData data;
62 data.name = "SDL_mixer Audio Plugin";
63 data.type = PT_Audio;
64 data.version = "1.0";
65 data.authors.push_back("Brian Caine");
67 return data;
70 Variant* loadPluginPayload()
72 Variant* payload = new Variant;
74 Audio results;
75 results.device_function = makeDevice;
76 results.sample_function = makeAudioSample;
78 *payload = results;
80 return payload;