Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "shared.h"
- using namespace pfc;
- DECLARE_COMPONENT_VERSION("DSP chain [de]serializer", "1.0",
- stringcvt::string_utf8_from_os(L"© 2011 Yegor Petrov (entrase@ya.ru)"));
- VALIDATE_COMPONENT_FILENAME("foo_chain_impexp.dll");
- static const GUID g_group =
- { 0x211522be, 0xa20, 0x4f98,
- { 0xba, 0x9c, 0x5c, 0x18, 0x42, 0x20, 0x25, 0xee } };
- static mainmenu_group_popup_factory g_mainmenu_group(
- g_group, mainmenu_groups::playback_etc,
- mainmenu_commands::sort_priority_dontcare, "DSP chain serializer");
- class dsp_serializer_cmds : public mainmenu_commands {
- public:
- void execute(t_uint32 p_index, service_ptr_t<service_base> p_callback)
- {
- string8 filename = "";
- if (!uGetOpenFileName(core_api::get_main_window(),
- "DSP chain presets (*.fbcp)|*.fbcp", 0,
- "fbcp", "", "", filename, p_index != 0))
- {
- return;
- }
- using namespace foobar2000_io;
- abort_callback_dummy cb;
- service_ptr_t<file> fbcp;
- if (p_index == 0) // Load
- {
- if (!filesystem::g_exists(filename, cb))
- {
- popup_message::g_complain("File does not exist.");
- return;
- }
- filesystem::g_open_read(fbcp, filename, cb);
- if (fbcp->get_size(cb) < 8) // Can't be (header + size prefix)
- {
- popup_message::g_complain("Not a Foobar2000 DSP chain preset.");
- return;
- }
- t_int32 hdr = 0;
- fbcp->read_bendian_t(hdr, cb);
- if (hdr != 'FBCP') // Someone is cheating
- {
- popup_message::g_complain("Not a Foobar2000 DSP chain preset.");
- return;
- }
- dsp_chain_config_impl chain;
- chain.contents_from_stream(fbcp.get_ptr(), cb);
- static_api_ptr_t<dsp_config_manager>()->set_core_settings(chain);
- }
- else // Save
- {
- filesystem::g_open_write_new(fbcp, filename, cb);
- fbcp->write_bendian_t('FBCP', cb);
- dsp_chain_config_impl chain;
- static_api_ptr_t<dsp_config_manager>()->get_core_settings(chain);
- chain.contents_to_stream(fbcp.get_ptr(), cb);
- }
- }
- t_uint32 get_command_count() { return 2; }
- GUID get_parent() { return g_group; }
- GUID get_command(t_uint32 p_index) {
- static const GUID guid_load =
- { 0x7bfce41, 0x4baa, 0x406a,
- { 0x9d, 0x81, 0x7d, 0x9e, 0xab, 0x7, 0x5c, 0x77 } };
- static const GUID guid_save =
- { 0x8778d00, 0xc497, 0x4f67,
- { 0xb5, 0xac, 0xb, 0x4c, 0xcc, 0x56, 0xd8, 0x16 } };
- return p_index == 0 ? guid_load : guid_save;
- }
- void get_name(t_uint32 p_index, pfc::string_base & p_out) {
- p_out = p_index == 0 ? "Load" : "Save";
- }
- bool get_description(t_uint32 p_index, string_base & p_out) {
- p_out = p_index == 0 ?
- "Loads a DSP chain configuration file." :
- "Writes current DSP chain configuration to a file.";
- return true;
- }
- bool get_display(t_uint32 p_index, string_base & p_txt, t_uint32 & p_flags)
- {
- p_flags |= mainmenu_commands::flag_defaulthidden;
- p_txt = p_index == 0 ? "Load..." : "Save as...";
- return true;
- }
- };
- static mainmenu_commands_factory_t<dsp_serializer_cmds> _dsp_serializer_cmds_;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement