Advertisement
Guest User

Untitled

a guest
Feb 20th, 2011
477
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.97 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "shared.h"
  3.  
  4. using namespace pfc;
  5.  
  6. DECLARE_COMPONENT_VERSION("DSP chain [de]serializer", "1.0",
  7. stringcvt::string_utf8_from_os(L"© 2011 Yegor Petrov (entrase@ya.ru)"));
  8. VALIDATE_COMPONENT_FILENAME("foo_chain_impexp.dll");
  9.  
  10. static const GUID g_group =
  11.     { 0x211522be, 0xa20, 0x4f98,
  12.     { 0xba, 0x9c, 0x5c, 0x18, 0x42, 0x20, 0x25, 0xee } };
  13.  
  14. static mainmenu_group_popup_factory g_mainmenu_group(
  15.     g_group, mainmenu_groups::playback_etc,
  16.     mainmenu_commands::sort_priority_dontcare, "DSP chain serializer");
  17.  
  18. class dsp_serializer_cmds : public mainmenu_commands {
  19.  
  20. public:
  21.     void execute(t_uint32 p_index, service_ptr_t<service_base> p_callback)
  22.     {
  23.         string8 filename = "";
  24.         if (!uGetOpenFileName(core_api::get_main_window(),
  25.                 "DSP chain presets (*.fbcp)|*.fbcp", 0,
  26.                 "fbcp", "", "", filename, p_index != 0))
  27.         {
  28.             return;
  29.         }
  30.        
  31.         using namespace foobar2000_io;
  32.         abort_callback_dummy cb;
  33.         service_ptr_t<file> fbcp;
  34.        
  35.         if (p_index == 0) // Load
  36.         {
  37.             if (!filesystem::g_exists(filename, cb))
  38.             {
  39.                 popup_message::g_complain("File does not exist.");
  40.                 return;
  41.             }
  42.             filesystem::g_open_read(fbcp, filename, cb);
  43.             if (fbcp->get_size(cb) < 8) // Can't be (header + size prefix)
  44.             {
  45.                 popup_message::g_complain("Not a Foobar2000 DSP chain preset.");
  46.                 return;
  47.             }
  48.             t_int32 hdr = 0;
  49.             fbcp->read_bendian_t(hdr, cb);
  50.             if (hdr != 'FBCP') // Someone is cheating
  51.             {
  52.                 popup_message::g_complain("Not a Foobar2000 DSP chain preset.");
  53.                 return;
  54.             }
  55.             dsp_chain_config_impl chain;
  56.             chain.contents_from_stream(fbcp.get_ptr(), cb);
  57.             static_api_ptr_t<dsp_config_manager>()->set_core_settings(chain);
  58.         }
  59.         else // Save
  60.         {
  61.             filesystem::g_open_write_new(fbcp, filename, cb);
  62.             fbcp->write_bendian_t('FBCP', cb);
  63.             dsp_chain_config_impl chain;
  64.             static_api_ptr_t<dsp_config_manager>()->get_core_settings(chain);
  65.             chain.contents_to_stream(fbcp.get_ptr(), cb);
  66.         }
  67.     }
  68.  
  69.     t_uint32 get_command_count() { return 2; }
  70.    
  71.     GUID get_parent() { return g_group; }
  72.  
  73.     GUID get_command(t_uint32 p_index) {
  74.         static const GUID guid_load =
  75.             { 0x7bfce41, 0x4baa, 0x406a,
  76.             { 0x9d, 0x81, 0x7d, 0x9e, 0xab, 0x7, 0x5c, 0x77 } };
  77.         static const GUID guid_save =
  78.             { 0x8778d00, 0xc497, 0x4f67,
  79.             { 0xb5, 0xac, 0xb, 0x4c, 0xcc, 0x56, 0xd8, 0x16 } };
  80.         return p_index == 0 ? guid_load : guid_save;
  81.     }
  82.  
  83.     void get_name(t_uint32 p_index, pfc::string_base & p_out) {
  84.         p_out = p_index == 0 ? "Load" : "Save";
  85.     }
  86.  
  87.     bool get_description(t_uint32 p_index, string_base & p_out) {
  88.         p_out = p_index == 0 ?
  89.             "Loads a DSP chain configuration file." :
  90.             "Writes current DSP chain configuration to a file.";
  91.         return true;
  92.     }
  93.    
  94.     bool get_display(t_uint32 p_index, string_base & p_txt, t_uint32 & p_flags)
  95.     {
  96.         p_flags |= mainmenu_commands::flag_defaulthidden;
  97.         p_txt = p_index == 0 ? "Load..." : "Save as...";
  98.         return true;
  99.     }
  100. };
  101.  
  102. static mainmenu_commands_factory_t<dsp_serializer_cmds> _dsp_serializer_cmds_;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement