From 024e8b9707968c597d7244059675df84dd6dba06 Mon Sep 17 00:00:00 2001 From: kode54 Date: Sat, 9 Jan 2010 04:14:00 +0000 Subject: [PATCH] Fixed vio2sf interpolation setting, imported foobar2000 0.9 SDK, imported missing files from foobar2000 0.8.3 SDK --- tools/vio2sf/foo_input_vio2sf.sln | 56 +- tools/vio2sf/foo_input_vio2sf.vcproj | 20 +- tools/vio2sf/src/foobar/SDK-test.sln | 73 + .../foobar/foobar2000/SDK/abort_callback.cpp | 17 + .../foobar/foobar2000/SDK/abort_callback.h | 76 + .../src/foobar/foobar2000/SDK/advconfig.h | 266 +++ .../src/foobar/foobar2000/SDK/album_art.cpp | 17 + .../src/foobar/foobar2000/SDK/album_art.h | 222 ++ .../foobar2000/SDK/app_close_blocker.cpp | 12 + .../foobar/foobar2000/SDK/app_close_blocker.h | 45 + .../src/foobar/foobar2000/SDK/audio_chunk.cpp | 335 +++ .../src/foobar/foobar2000/SDK/audio_chunk.h | 342 ++++ .../SDK/audio_chunk_channel_config.cpp | 131 ++ .../foobar2000/SDK/audio_postprocessor.h | 25 + .../src/foobar/foobar2000/SDK/autoplaylist.h | 106 + .../src/foobar/foobar2000/SDK/cfg_var.cpp | 57 + .../src/foobar/foobar2000/SDK/cfg_var.h | 235 +++ .../src/foobar/foobar2000/SDK/chapterizer.cpp | 24 + .../src/foobar/foobar2000/SDK/chapterizer.h | 72 + .../src/foobar/foobar2000/SDK/commandline.cpp | 24 + .../src/foobar/foobar2000/SDK/commandline.h | 41 + .../foobar2000/SDK/completion_notify.cpp | 25 + .../foobar/foobar2000/SDK/completion_notify.h | 89 + .../src/foobar/foobar2000/SDK/component.h | 44 + .../foobar/foobar2000/SDK/component_client.h | 6 + .../foobar/foobar2000/SDK/components_menu.h | 7 + .../foobar/foobar2000/SDK/componentversion.h | 56 + .../foobar2000/SDK/config_io_callback.h | 15 + .../foobar/foobar2000/SDK/config_object.cpp | 206 ++ .../src/foobar/foobar2000/SDK/config_object.h | 85 + .../foobar2000/SDK/config_object_impl.h | 174 ++ .../src/foobar/foobar2000/SDK/console.cpp | 50 + .../src/foobar/foobar2000/SDK/console.h | 31 + .../src/foobar/foobar2000/SDK/contextmenu.h | 242 +++ .../foobar2000/SDK/contextmenu_manager.h | 109 + .../src/foobar/foobar2000/SDK/core_api.h | 33 + .../src/foobar/foobar2000/SDK/coreversion.h | 36 + .../vio2sf/src/foobar/foobar2000/SDK/dsp.cpp | 395 ++++ tools/vio2sf/src/foobar/foobar2000/SDK/dsp.h | 482 +++++ .../src/foobar/foobar2000/SDK/dsp_manager.cpp | 188 ++ .../src/foobar/foobar2000/SDK/dsp_manager.h | 81 + .../src/foobar/foobar2000/SDK/event_logger.h | 19 + .../src/foobar/foobar2000/SDK/file_info.cpp | 451 ++++ .../src/foobar/foobar2000/SDK/file_info.h | 230 +++ .../foobar/foobar2000/SDK/file_info_impl.cpp | 243 +++ .../foobar/foobar2000/SDK/file_info_impl.h | 144 ++ .../foobar/foobar2000/SDK/file_info_merge.cpp | 130 ++ .../SDK/file_operation_callback.cpp | 144 ++ .../foobar2000/SDK/file_operation_callback.h | 66 + .../src/foobar/foobar2000/SDK/filesystem.cpp | 863 ++++++++ .../src/foobar/foobar2000/SDK/filesystem.h | 598 ++++++ .../foobar2000/SDK/filesystem_helper.cpp | 106 + .../foobar/foobar2000/SDK/filesystem_helper.h | 579 ++++++ .../src/foobar/foobar2000/SDK/foobar2000.h | 95 + .../foobar2000/SDK/foobar2000_SDK.vcproj | 1810 +++++++++++++++++ .../src/foobar/foobar2000/SDK/genrand.h | 13 + .../src/foobar/foobar2000/SDK/guids.cpp | 1115 ++++++++++ .../src/foobar/foobar2000/SDK/hasher_md5.cpp | 22 + .../src/foobar/foobar2000/SDK/hasher_md5.h | 73 + .../src/foobar/foobar2000/SDK/icon_remap.h | 26 + .../foobar2000/SDK/info_lookup_handler.h | 24 + .../src/foobar/foobar2000/SDK/initquit.h | 13 + .../src/foobar/foobar2000/SDK/input.cpp | 248 +++ .../vio2sf/src/foobar/foobar2000/SDK/input.h | 189 ++ .../foobar/foobar2000/SDK/input_file_type.cpp | 65 + .../foobar/foobar2000/SDK/input_file_type.h | 94 + .../src/foobar/foobar2000/SDK/input_impl.h | 314 +++ .../foobar/foobar2000/SDK/library_manager.h | 181 ++ .../foobar/foobar2000/SDK/link_resolver.cpp | 17 + .../src/foobar/foobar2000/SDK/link_resolver.h | 33 + .../foobar2000/SDK/main_thread_callback.h | 20 + .../src/foobar/foobar2000/SDK/mainmenu.cpp | 34 + .../foobar2000/SDK/mem_block_container.cpp | 12 + .../foobar2000/SDK/mem_block_container.h | 68 + tools/vio2sf/src/foobar/foobar2000/SDK/menu.h | 128 ++ .../foobar/foobar2000/SDK/menu_helpers.cpp | 326 +++ .../src/foobar/foobar2000/SDK/menu_helpers.h | 182 ++ .../src/foobar/foobar2000/SDK/menu_item.cpp | 40 + .../foobar/foobar2000/SDK/menu_manager.cpp | 401 ++++ .../src/foobar/foobar2000/SDK/message_loop.h | 80 + .../src/foobar/foobar2000/SDK/metadb.cpp | 76 + .../vio2sf/src/foobar/foobar2000/SDK/metadb.h | 312 +++ .../foobar/foobar2000/SDK/metadb_handle.cpp | 48 + .../src/foobar/foobar2000/SDK/metadb_handle.h | 207 ++ .../foobar2000/SDK/metadb_handle_list.cpp | 386 ++++ .../foobar/foobar2000/SDK/modeless_dialog.h | 17 + .../foobar/foobar2000/SDK/ole_interaction.h | 149 ++ .../foobar/foobar2000/SDK/packet_decoder.cpp | 14 + .../foobar/foobar2000/SDK/packet_decoder.h | 113 + .../src/foobar/foobar2000/SDK/play_callback.h | 149 ++ .../foobar2000/SDK/playable_location.cpp | 23 + .../foobar/foobar2000/SDK/playable_location.h | 90 + .../foobar2000/SDK/playback_control.cpp | 13 + .../foobar/foobar2000/SDK/playback_control.h | 135 ++ .../src/foobar/foobar2000/SDK/playlist.cpp | 861 ++++++++ .../src/foobar/foobar2000/SDK/playlist.h | 873 ++++++++ .../foobar/foobar2000/SDK/playlist_loader.cpp | 270 +++ .../foobar/foobar2000/SDK/playlist_loader.h | 151 ++ .../foobar/foobar2000/SDK/popup_message.cpp | 6 + .../src/foobar/foobar2000/SDK/popup_message.h | 42 + .../foobar2000/SDK/preferences_page.cpp | 10 + .../foobar/foobar2000/SDK/preferences_page.h | 84 + .../src/foobar/foobar2000/SDK/replaygain.cpp | 223 ++ .../src/foobar/foobar2000/SDK/replaygain.h | 56 + .../foobar/foobar2000/SDK/replaygain_info.cpp | 136 ++ .../foobar2000/SDK/replaygain_scanner.h | 37 + .../src/foobar/foobar2000/SDK/resampler.h | 25 + .../src/foobar/foobar2000/SDK/search_tools.h | 68 + .../src/foobar/foobar2000/SDK/service.cpp | 59 + .../src/foobar/foobar2000/SDK/service.h | 605 ++++++ .../src/foobar/foobar2000/SDK/service_impl.h | 37 + .../foobar/foobar2000/SDK/shortcut_actions.h | 1 + .../src/foobar/foobar2000/SDK/stdafx.cpp | 2 + .../foobar/foobar2000/SDK/tag_processor.cpp | 170 ++ .../src/foobar/foobar2000/SDK/tag_processor.h | 99 + .../foobar2000/SDK/tag_processor_id3v2.cpp | 97 + .../foobar2000/SDK/threaded_process.cpp | 36 + .../foobar/foobar2000/SDK/threaded_process.h | 62 + .../src/foobar/foobar2000/SDK/titleformat.cpp | 190 ++ .../src/foobar/foobar2000/SDK/titleformat.h | 227 +++ .../foobar/foobar2000/SDK/track_property.h | 45 + tools/vio2sf/src/foobar/foobar2000/SDK/ui.cpp | 35 + tools/vio2sf/src/foobar/foobar2000/SDK/ui.h | 190 ++ .../vio2sf/src/foobar/foobar2000/SDK/unpack.h | 22 + tools/vio2sf/src/foobar/foobar2000/SDK/vis.h | 78 + .../component_client.cpp | 132 ++ .../foobar2000_component_client.vcproj | 334 +++ .../src/foobar/foobar2000/helpers/COM_utils.h | 7 + .../foobar/foobar2000/helpers/CallForwarder.h | 32 + .../foobar2000/helpers/IDataObjectUtils.cpp | 183 ++ .../foobar2000/helpers/IDataObjectUtils.h | 183 ++ .../src/foobar/foobar2000/helpers/StdAfx.cpp | 6 + .../src/foobar/foobar2000/helpers/StdAfx.h | 22 + .../foobar/foobar2000/helpers/ThreadUtils.h | 135 ++ .../foobar/foobar2000/helpers/VisUtils.cpp | 36 + .../src/foobar/foobar2000/helpers/VisUtils.h | 8 + .../foobar2000/helpers/album_art_helpers.h | 109 + .../foobar2000/helpers/bitreader_helper.h | 122 ++ .../foobar/foobar2000/helpers/cfg_guidlist.h | 29 + .../foobar/foobar2000/helpers/clipboard.cpp | 37 + .../src/foobar/foobar2000/helpers/clipboard.h | 40 + .../helpers/create_directory_helper.cpp | 122 ++ .../helpers/create_directory_helper.h | 10 + .../foobar/foobar2000/helpers/cue_creator.cpp | 171 ++ .../foobar/foobar2000/helpers/cue_creator.h | 17 + .../foobar/foobar2000/helpers/cue_parser.cpp | 764 +++++++ .../foobar/foobar2000/helpers/cue_parser.h | 445 ++++ .../helpers/cue_parser_embedding.cpp | 358 ++++ .../helpers/cuesheet_index_list.cpp | 139 ++ .../foobar2000/helpers/cuesheet_index_list.h | 31 + .../helpers/dialog_resize_helper.cpp | 160 ++ .../foobar2000/helpers/dialog_resize_helper.h | 48 + .../foobar2000/helpers/dropdown_helper.cpp | 153 ++ .../foobar2000/helpers/dropdown_helper.h | 32 + .../helpers/dynamic_bitrate_helper.cpp | 74 + .../helpers/dynamic_bitrate_helper.h | 15 + .../foobar/foobar2000/helpers/file_cached.h | 116 ++ .../helpers/file_info_const_impl.cpp | 269 +++ .../foobar2000/helpers/file_info_const_impl.h | 78 + .../helpers/file_info_update_helper.cpp | 101 + .../helpers/file_info_update_helper.h | 29 + .../foobar2000/helpers/file_list_helper.cpp | 70 + .../foobar2000/helpers/file_list_helper.h | 30 + .../foobar2000/helpers/file_move_helper.cpp | 278 +++ .../foobar2000/helpers/file_move_helper.h | 60 + .../foobar2000/helpers/file_win32_wrapper.h | 183 ++ .../helpers/file_wrapper_simple.cpp | 75 + .../foobar2000/helpers/file_wrapper_simple.h | 21 + .../foobar2000/helpers/filetimetools.cpp | 84 + .../foobar/foobar2000/helpers/filetimetools.h | 14 + .../helpers/foobar2000_sdk_helpers.vcproj | 909 +++++++++ .../src/foobar/foobar2000/helpers/helpers.h | 45 + .../helpers/icon_remapping_wildcard.h | 13 + .../foobar2000/helpers/input_helpers.cpp | 405 ++++ .../foobar/foobar2000/helpers/input_helpers.h | 97 + .../foobar2000/helpers/listview_helper.cpp | 168 ++ .../foobar2000/helpers/listview_helper.h | 40 + .../foobar2000/helpers/meta_table_builder.h | 74 + .../foobar2000/helpers/metadb_io_hintlist.cpp | 39 + .../foobar2000/helpers/metadb_io_hintlist.h | 50 + .../foobar/foobar2000/helpers/mp3_utils.cpp | 261 +++ .../src/foobar/foobar2000/helpers/mp3_utils.h | 68 + .../playlist_position_reference_tracker.h | 73 + .../helpers/preload_info_helper.cpp | 29 + .../foobar2000/helpers/preload_info_helper.h | 6 + .../foobar2000/helpers/seekabilizer.cpp | 218 ++ .../foobar/foobar2000/helpers/seekabilizer.h | 36 + .../helpers/stream_buffer_helper.cpp | 79 + .../foobar2000/helpers/stream_buffer_helper.h | 26 + .../foobar/foobar2000/helpers/string_filter.h | 24 + .../foobar2000/helpers/text_file_loader.cpp | 100 + .../foobar2000/helpers/text_file_loader.h | 9 + .../foobar/foobar2000/helpers/wildcard.cpp | 44 + .../src/foobar/foobar2000/helpers/wildcard.h | 13 + .../foobar2000/helpers/win32_dialog.cpp | 288 +++ .../foobar/foobar2000/helpers/win32_dialog.h | 121 ++ .../foobar/foobar2000/helpers/win32_misc.cpp | 70 + .../foobar/foobar2000/helpers/win32_misc.h | 399 ++++ .../helpers/window_placement_helper.cpp | 206 ++ .../helpers/window_placement_helper.h | 34 + .../src/foobar/foobar2000/shared/audio_math.h | 78 + .../foobar/foobar2000/shared/filedialogs.h | 7 + .../src/foobar/foobar2000/shared/shared.h | 788 +++++++ .../src/foobar/foobar2000/shared/shared.lib | Bin 0 -> 34822 bytes .../src/foobar/foobar2000/shared/win32_misc.h | 252 +++ tools/vio2sf/src/foobar/pfc/alloc.h | 422 ++++ tools/vio2sf/src/foobar/pfc/array.h | 239 +++ tools/vio2sf/src/foobar/pfc/avltree.h | 537 +++++ tools/vio2sf/src/foobar/pfc/binary_search.h | 81 + tools/vio2sf/src/foobar/pfc/bit_array.h | 59 + tools/vio2sf/src/foobar/pfc/bit_array_impl.h | 222 ++ tools/vio2sf/src/foobar/pfc/bsearch.cpp | 19 + tools/vio2sf/src/foobar/pfc/bsearch.h | 87 + tools/vio2sf/src/foobar/pfc/bsearch_inline.h | 48 + .../vio2sf/src/foobar/pfc/byte_order_helper.h | 232 +++ tools/vio2sf/src/foobar/pfc/chain_list_v2.h | 264 +++ tools/vio2sf/src/foobar/pfc/com_ptr_t.h | 82 + tools/vio2sf/src/foobar/pfc/guid.cpp | 144 ++ tools/vio2sf/src/foobar/pfc/guid.h | 47 + .../vio2sf/src/foobar/pfc/instance_tracker.h | 49 + tools/vio2sf/src/foobar/pfc/int_types.h | 120 ++ tools/vio2sf/src/foobar/pfc/iterators.h | 113 + tools/vio2sf/src/foobar/pfc/license.txt | 10 + tools/vio2sf/src/foobar/pfc/list.h | 591 ++++++ tools/vio2sf/src/foobar/pfc/map.h | 235 +++ tools/vio2sf/src/foobar/pfc/mem_block_mgr.h | 71 + tools/vio2sf/src/foobar/pfc/order_helper.h | 83 + tools/vio2sf/src/foobar/pfc/other.cpp | 137 ++ tools/vio2sf/src/foobar/pfc/other.h | 207 ++ tools/vio2sf/src/foobar/pfc/pathUtils.cpp | 164 ++ tools/vio2sf/src/foobar/pfc/pathUtils.h | 29 + tools/vio2sf/src/foobar/pfc/pfc.h | 166 ++ tools/vio2sf/src/foobar/pfc/pfc.vcproj | 802 ++++++++ tools/vio2sf/src/foobar/pfc/primitives.h | 783 +++++++ tools/vio2sf/src/foobar/pfc/printf.cpp | 117 ++ tools/vio2sf/src/foobar/pfc/profiler.cpp | 34 + tools/vio2sf/src/foobar/pfc/profiler.h | 100 + tools/vio2sf/src/foobar/pfc/ptr_list.h | 45 + tools/vio2sf/src/foobar/pfc/rcptr.h | 250 +++ tools/vio2sf/src/foobar/pfc/ref_counter.h | 122 ++ tools/vio2sf/src/foobar/pfc/selftest.cpp | 29 + tools/vio2sf/src/foobar/pfc/sort.cpp | 263 +++ tools/vio2sf/src/foobar/pfc/sort.h | 181 ++ tools/vio2sf/src/foobar/pfc/stdafx.cpp | 2 + tools/vio2sf/src/foobar/pfc/string.cpp | 850 ++++++++ tools/vio2sf/src/foobar/pfc/string.h | 854 ++++++++ tools/vio2sf/src/foobar/pfc/string8_impl.h | 123 ++ tools/vio2sf/src/foobar/pfc/stringNew.cpp | 82 + tools/vio2sf/src/foobar/pfc/stringNew.h | 220 ++ tools/vio2sf/src/foobar/pfc/string_conv.cpp | 216 ++ tools/vio2sf/src/foobar/pfc/string_conv.h | 410 ++++ tools/vio2sf/src/foobar/pfc/string_list.h | 58 + tools/vio2sf/src/foobar/pfc/threads.cpp | 23 + tools/vio2sf/src/foobar/pfc/threads.h | 57 + tools/vio2sf/src/foobar/pfc/traits.h | 81 + tools/vio2sf/src/foobar/pfc/utf8.cpp | 323 +++ tools/vio2sf/src/foobar/sdk-license.txt | 14 + tools/vio2sf/src/foobar/sdk-readme.css | 1 + tools/vio2sf/src/foobar/sdk-readme.html | 372 ++++ .../foobar2000_component_client.dsp | 92 + tools/vio2sf/src/foobar8/pfc/ptr_list.h | 201 ++ tools/vio2sf/src/xsfc/foo_input_xsf.cpp | 13 + tools/vio2sf/src/xsfc/foo_input_xsf8.cpp | 6 + tools/vio2sf/src/xsfc/foo_input_xsfcfg.cpp | 9 + tools/vio2sf/src/xsfc/foo_input_xsfcfg8.cpp | 12 + tools/vio2sf/src/xsfc/in_xsfcfg.cpp | 4 - tools/vio2sf/src/xsfc/xsfc.cpp | 19 + tools/vio2sf/src/xsfc/xsfc.h | 2 + tools/vio2sf/src/xsfc/xsfcfg.cpp | 4 + tools/vio2sf/src/xsfc/xsfui.rc | 25 +- 270 files changed, 41936 insertions(+), 27 deletions(-) create mode 100644 tools/vio2sf/src/foobar/SDK-test.sln create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/abort_callback.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/abort_callback.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/advconfig.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/album_art.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/album_art.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/app_close_blocker.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/app_close_blocker.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/audio_chunk.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/audio_chunk.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/audio_chunk_channel_config.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/audio_postprocessor.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/autoplaylist.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/cfg_var.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/cfg_var.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/chapterizer.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/chapterizer.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/commandline.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/commandline.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/completion_notify.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/completion_notify.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/component.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/component_client.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/components_menu.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/componentversion.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/config_io_callback.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/config_object.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/config_object.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/config_object_impl.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/console.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/console.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/contextmenu.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/contextmenu_manager.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/core_api.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/coreversion.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/dsp.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/dsp.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/dsp_manager.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/dsp_manager.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/event_logger.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/file_info.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/file_info.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/file_info_impl.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/file_info_impl.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/file_info_merge.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/file_operation_callback.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/file_operation_callback.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/filesystem.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/filesystem.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/filesystem_helper.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/filesystem_helper.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/foobar2000.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/foobar2000_SDK.vcproj create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/genrand.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/guids.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/hasher_md5.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/hasher_md5.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/icon_remap.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/info_lookup_handler.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/initquit.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/input.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/input.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/input_file_type.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/input_file_type.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/input_impl.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/library_manager.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/link_resolver.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/link_resolver.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/main_thread_callback.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/mainmenu.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/mem_block_container.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/mem_block_container.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/menu.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/menu_helpers.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/menu_helpers.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/menu_item.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/menu_manager.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/message_loop.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/metadb.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/metadb.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/metadb_handle.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/metadb_handle.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/metadb_handle_list.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/modeless_dialog.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/ole_interaction.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/packet_decoder.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/packet_decoder.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/play_callback.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/playable_location.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/playable_location.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/playback_control.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/playback_control.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/playlist.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/playlist.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/playlist_loader.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/playlist_loader.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/popup_message.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/popup_message.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/preferences_page.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/preferences_page.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/replaygain.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/replaygain.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/replaygain_info.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/replaygain_scanner.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/resampler.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/search_tools.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/service.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/service.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/service_impl.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/shortcut_actions.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/stdafx.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/tag_processor.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/tag_processor.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/tag_processor_id3v2.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/threaded_process.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/threaded_process.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/titleformat.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/titleformat.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/track_property.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/ui.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/ui.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/unpack.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/SDK/vis.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/foobar2000_component_client/component_client.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/foobar2000_component_client/foobar2000_component_client.vcproj create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/COM_utils.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/CallForwarder.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/IDataObjectUtils.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/IDataObjectUtils.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/StdAfx.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/StdAfx.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/ThreadUtils.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/VisUtils.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/VisUtils.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/album_art_helpers.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/bitreader_helper.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/cfg_guidlist.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/clipboard.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/clipboard.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/create_directory_helper.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/create_directory_helper.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/cue_creator.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/cue_creator.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/cue_parser.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/cue_parser.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/cue_parser_embedding.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/cuesheet_index_list.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/cuesheet_index_list.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/dialog_resize_helper.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/dialog_resize_helper.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/dropdown_helper.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/dropdown_helper.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/dynamic_bitrate_helper.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/dynamic_bitrate_helper.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/file_cached.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/file_info_const_impl.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/file_info_const_impl.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/file_info_update_helper.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/file_info_update_helper.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/file_list_helper.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/file_list_helper.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/file_move_helper.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/file_move_helper.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/file_win32_wrapper.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/file_wrapper_simple.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/file_wrapper_simple.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/filetimetools.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/filetimetools.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/foobar2000_sdk_helpers.vcproj create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/helpers.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/icon_remapping_wildcard.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/input_helpers.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/input_helpers.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/listview_helper.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/listview_helper.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/meta_table_builder.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/metadb_io_hintlist.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/metadb_io_hintlist.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/mp3_utils.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/mp3_utils.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/playlist_position_reference_tracker.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/preload_info_helper.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/preload_info_helper.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/seekabilizer.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/seekabilizer.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/stream_buffer_helper.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/stream_buffer_helper.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/string_filter.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/text_file_loader.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/text_file_loader.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/wildcard.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/wildcard.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/win32_dialog.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/win32_dialog.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/win32_misc.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/win32_misc.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/window_placement_helper.cpp create mode 100644 tools/vio2sf/src/foobar/foobar2000/helpers/window_placement_helper.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/shared/audio_math.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/shared/filedialogs.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/shared/shared.h create mode 100644 tools/vio2sf/src/foobar/foobar2000/shared/shared.lib create mode 100644 tools/vio2sf/src/foobar/foobar2000/shared/win32_misc.h create mode 100644 tools/vio2sf/src/foobar/pfc/alloc.h create mode 100644 tools/vio2sf/src/foobar/pfc/array.h create mode 100644 tools/vio2sf/src/foobar/pfc/avltree.h create mode 100644 tools/vio2sf/src/foobar/pfc/binary_search.h create mode 100644 tools/vio2sf/src/foobar/pfc/bit_array.h create mode 100644 tools/vio2sf/src/foobar/pfc/bit_array_impl.h create mode 100644 tools/vio2sf/src/foobar/pfc/bsearch.cpp create mode 100644 tools/vio2sf/src/foobar/pfc/bsearch.h create mode 100644 tools/vio2sf/src/foobar/pfc/bsearch_inline.h create mode 100644 tools/vio2sf/src/foobar/pfc/byte_order_helper.h create mode 100644 tools/vio2sf/src/foobar/pfc/chain_list_v2.h create mode 100644 tools/vio2sf/src/foobar/pfc/com_ptr_t.h create mode 100644 tools/vio2sf/src/foobar/pfc/guid.cpp create mode 100644 tools/vio2sf/src/foobar/pfc/guid.h create mode 100644 tools/vio2sf/src/foobar/pfc/instance_tracker.h create mode 100644 tools/vio2sf/src/foobar/pfc/int_types.h create mode 100644 tools/vio2sf/src/foobar/pfc/iterators.h create mode 100644 tools/vio2sf/src/foobar/pfc/license.txt create mode 100644 tools/vio2sf/src/foobar/pfc/list.h create mode 100644 tools/vio2sf/src/foobar/pfc/map.h create mode 100644 tools/vio2sf/src/foobar/pfc/mem_block_mgr.h create mode 100644 tools/vio2sf/src/foobar/pfc/order_helper.h create mode 100644 tools/vio2sf/src/foobar/pfc/other.cpp create mode 100644 tools/vio2sf/src/foobar/pfc/other.h create mode 100644 tools/vio2sf/src/foobar/pfc/pathUtils.cpp create mode 100644 tools/vio2sf/src/foobar/pfc/pathUtils.h create mode 100644 tools/vio2sf/src/foobar/pfc/pfc.h create mode 100644 tools/vio2sf/src/foobar/pfc/pfc.vcproj create mode 100644 tools/vio2sf/src/foobar/pfc/primitives.h create mode 100644 tools/vio2sf/src/foobar/pfc/printf.cpp create mode 100644 tools/vio2sf/src/foobar/pfc/profiler.cpp create mode 100644 tools/vio2sf/src/foobar/pfc/profiler.h create mode 100644 tools/vio2sf/src/foobar/pfc/ptr_list.h create mode 100644 tools/vio2sf/src/foobar/pfc/rcptr.h create mode 100644 tools/vio2sf/src/foobar/pfc/ref_counter.h create mode 100644 tools/vio2sf/src/foobar/pfc/selftest.cpp create mode 100644 tools/vio2sf/src/foobar/pfc/sort.cpp create mode 100644 tools/vio2sf/src/foobar/pfc/sort.h create mode 100644 tools/vio2sf/src/foobar/pfc/stdafx.cpp create mode 100644 tools/vio2sf/src/foobar/pfc/string.cpp create mode 100644 tools/vio2sf/src/foobar/pfc/string.h create mode 100644 tools/vio2sf/src/foobar/pfc/string8_impl.h create mode 100644 tools/vio2sf/src/foobar/pfc/stringNew.cpp create mode 100644 tools/vio2sf/src/foobar/pfc/stringNew.h create mode 100644 tools/vio2sf/src/foobar/pfc/string_conv.cpp create mode 100644 tools/vio2sf/src/foobar/pfc/string_conv.h create mode 100644 tools/vio2sf/src/foobar/pfc/string_list.h create mode 100644 tools/vio2sf/src/foobar/pfc/threads.cpp create mode 100644 tools/vio2sf/src/foobar/pfc/threads.h create mode 100644 tools/vio2sf/src/foobar/pfc/traits.h create mode 100644 tools/vio2sf/src/foobar/pfc/utf8.cpp create mode 100644 tools/vio2sf/src/foobar/sdk-license.txt create mode 100644 tools/vio2sf/src/foobar/sdk-readme.css create mode 100644 tools/vio2sf/src/foobar/sdk-readme.html create mode 100644 tools/vio2sf/src/foobar8/foobar2000/foobar2000_component_client/foobar2000_component_client.dsp create mode 100644 tools/vio2sf/src/foobar8/pfc/ptr_list.h diff --git a/tools/vio2sf/foo_input_vio2sf.sln b/tools/vio2sf/foo_input_vio2sf.sln index cbcdcc6a5..301c0863f 100644 --- a/tools/vio2sf/foo_input_vio2sf.sln +++ b/tools/vio2sf/foo_input_vio2sf.sln @@ -1,18 +1,70 @@  -Microsoft Visual Studio Solution File, Format Version 9.00 -# Visual C++ Express 2005 +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "foo_input_vio2sf", "foo_input_vio2sf.vcproj", "{22752D82-8F89-4F87-B07E-D254D7BF675A}" + ProjectSection(ProjectDependencies) = postProject + {E8091321-D79D-4575-86EF-064EA1A4A20D} = {E8091321-D79D-4575-86EF-064EA1A4A20D} + {EE47764E-A202-4F85-A767-ABDAB4AFF35F} = {EE47764E-A202-4F85-A767-ABDAB4AFF35F} + {71AD2674-065B-48F5-B8B0-E1F9D3892081} = {71AD2674-065B-48F5-B8B0-E1F9D3892081} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pfc", "src\foobar\pfc\pfc.vcproj", "{EBFFFB4E-261D-44D3-B89C-957B31A0BF9C}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "foobar2000_component_client", "src\foobar\foobar2000\foobar2000_component_client\foobar2000_component_client.vcproj", "{71AD2674-065B-48F5-B8B0-E1F9D3892081}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "foobar2000_sdk_helpers", "src\foobar\foobar2000\helpers\foobar2000_sdk_helpers.vcproj", "{EE47764E-A202-4F85-A767-ABDAB4AFF35F}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "foobar2000_SDK", "src\foobar\foobar2000\SDK\foobar2000_SDK.vcproj", "{E8091321-D79D-4575-86EF-064EA1A4A20D}" + ProjectSection(ProjectDependencies) = postProject + {EBFFFB4E-261D-44D3-B89C-957B31A0BF9C} = {EBFFFB4E-261D-44D3-B89C-957B31A0BF9C} + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 Release|Win32 = Release|Win32 + Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {22752D82-8F89-4F87-B07E-D254D7BF675A}.Debug|Win32.ActiveCfg = Debug|Win32 {22752D82-8F89-4F87-B07E-D254D7BF675A}.Debug|Win32.Build.0 = Debug|Win32 + {22752D82-8F89-4F87-B07E-D254D7BF675A}.Debug|x64.ActiveCfg = Debug|Win32 {22752D82-8F89-4F87-B07E-D254D7BF675A}.Release|Win32.ActiveCfg = Release|Win32 {22752D82-8F89-4F87-B07E-D254D7BF675A}.Release|Win32.Build.0 = Release|Win32 + {22752D82-8F89-4F87-B07E-D254D7BF675A}.Release|x64.ActiveCfg = Release|Win32 + {EBFFFB4E-261D-44D3-B89C-957B31A0BF9C}.Debug|Win32.ActiveCfg = Debug|Win32 + {EBFFFB4E-261D-44D3-B89C-957B31A0BF9C}.Debug|Win32.Build.0 = Debug|Win32 + {EBFFFB4E-261D-44D3-B89C-957B31A0BF9C}.Debug|x64.ActiveCfg = Debug|x64 + {EBFFFB4E-261D-44D3-B89C-957B31A0BF9C}.Debug|x64.Build.0 = Debug|x64 + {EBFFFB4E-261D-44D3-B89C-957B31A0BF9C}.Release|Win32.ActiveCfg = Release|Win32 + {EBFFFB4E-261D-44D3-B89C-957B31A0BF9C}.Release|Win32.Build.0 = Release|Win32 + {EBFFFB4E-261D-44D3-B89C-957B31A0BF9C}.Release|x64.ActiveCfg = Release|x64 + {EBFFFB4E-261D-44D3-B89C-957B31A0BF9C}.Release|x64.Build.0 = Release|x64 + {71AD2674-065B-48F5-B8B0-E1F9D3892081}.Debug|Win32.ActiveCfg = Debug|Win32 + {71AD2674-065B-48F5-B8B0-E1F9D3892081}.Debug|Win32.Build.0 = Debug|Win32 + {71AD2674-065B-48F5-B8B0-E1F9D3892081}.Debug|x64.ActiveCfg = Debug|x64 + {71AD2674-065B-48F5-B8B0-E1F9D3892081}.Debug|x64.Build.0 = Debug|x64 + {71AD2674-065B-48F5-B8B0-E1F9D3892081}.Release|Win32.ActiveCfg = Release|Win32 + {71AD2674-065B-48F5-B8B0-E1F9D3892081}.Release|Win32.Build.0 = Release|Win32 + {71AD2674-065B-48F5-B8B0-E1F9D3892081}.Release|x64.ActiveCfg = Release|x64 + {71AD2674-065B-48F5-B8B0-E1F9D3892081}.Release|x64.Build.0 = Release|x64 + {EE47764E-A202-4F85-A767-ABDAB4AFF35F}.Debug|Win32.ActiveCfg = Debug|Win32 + {EE47764E-A202-4F85-A767-ABDAB4AFF35F}.Debug|Win32.Build.0 = Debug|Win32 + {EE47764E-A202-4F85-A767-ABDAB4AFF35F}.Debug|x64.ActiveCfg = Debug|x64 + {EE47764E-A202-4F85-A767-ABDAB4AFF35F}.Debug|x64.Build.0 = Debug|x64 + {EE47764E-A202-4F85-A767-ABDAB4AFF35F}.Release|Win32.ActiveCfg = Release|Win32 + {EE47764E-A202-4F85-A767-ABDAB4AFF35F}.Release|Win32.Build.0 = Release|Win32 + {EE47764E-A202-4F85-A767-ABDAB4AFF35F}.Release|x64.ActiveCfg = Release|x64 + {EE47764E-A202-4F85-A767-ABDAB4AFF35F}.Release|x64.Build.0 = Release|x64 + {E8091321-D79D-4575-86EF-064EA1A4A20D}.Debug|Win32.ActiveCfg = Debug|Win32 + {E8091321-D79D-4575-86EF-064EA1A4A20D}.Debug|Win32.Build.0 = Debug|Win32 + {E8091321-D79D-4575-86EF-064EA1A4A20D}.Debug|x64.ActiveCfg = Debug|x64 + {E8091321-D79D-4575-86EF-064EA1A4A20D}.Debug|x64.Build.0 = Debug|x64 + {E8091321-D79D-4575-86EF-064EA1A4A20D}.Release|Win32.ActiveCfg = Release|Win32 + {E8091321-D79D-4575-86EF-064EA1A4A20D}.Release|Win32.Build.0 = Release|Win32 + {E8091321-D79D-4575-86EF-064EA1A4A20D}.Release|x64.ActiveCfg = Release|x64 + {E8091321-D79D-4575-86EF-064EA1A4A20D}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/tools/vio2sf/foo_input_vio2sf.vcproj b/tools/vio2sf/foo_input_vio2sf.vcproj index 49ebbc231..a3a712e2c 100644 --- a/tools/vio2sf/foo_input_vio2sf.vcproj +++ b/tools/vio2sf/foo_input_vio2sf.vcproj @@ -1,11 +1,12 @@ - @@ -118,9 +118,11 @@ - diff --git a/tools/vio2sf/src/foobar/SDK-test.sln b/tools/vio2sf/src/foobar/SDK-test.sln new file mode 100644 index 000000000..5d8e7a4a3 --- /dev/null +++ b/tools/vio2sf/src/foobar/SDK-test.sln @@ -0,0 +1,73 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "foobar2000_SDK", "foobar2000\SDK\foobar2000_SDK.vcproj", "{E8091321-D79D-4575-86EF-064EA1A4A20D}" + ProjectSection(ProjectDependencies) = postProject + {EBFFFB4E-261D-44D3-B89C-957B31A0BF9C} = {EBFFFB4E-261D-44D3-B89C-957B31A0BF9C} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "foobar2000_ATL_helpers", "foobar2000\ATLHelpers\foobar2000_ATL_helpers.vcproj", "{622E8B19-8109-4717-BD4D-9657AA78363E}" + ProjectSection(ProjectDependencies) = postProject + {E8091321-D79D-4575-86EF-064EA1A4A20D} = {E8091321-D79D-4575-86EF-064EA1A4A20D} + {EE47764E-A202-4F85-A767-ABDAB4AFF35F} = {EE47764E-A202-4F85-A767-ABDAB4AFF35F} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "foobar2000_component_client", "foobar2000\foobar2000_component_client\foobar2000_component_client.vcproj", "{71AD2674-065B-48F5-B8B0-E1F9D3892081}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "foobar2000_sdk_helpers", "foobar2000\helpers\foobar2000_sdk_helpers.vcproj", "{EE47764E-A202-4F85-A767-ABDAB4AFF35F}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pfc", "pfc\pfc.vcproj", "{EBFFFB4E-261D-44D3-B89C-957B31A0BF9C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E8091321-D79D-4575-86EF-064EA1A4A20D}.Debug|Win32.ActiveCfg = Debug|Win32 + {E8091321-D79D-4575-86EF-064EA1A4A20D}.Debug|Win32.Build.0 = Debug|Win32 + {E8091321-D79D-4575-86EF-064EA1A4A20D}.Debug|x64.ActiveCfg = Debug|x64 + {E8091321-D79D-4575-86EF-064EA1A4A20D}.Debug|x64.Build.0 = Debug|x64 + {E8091321-D79D-4575-86EF-064EA1A4A20D}.Release|Win32.ActiveCfg = Release|Win32 + {E8091321-D79D-4575-86EF-064EA1A4A20D}.Release|Win32.Build.0 = Release|Win32 + {E8091321-D79D-4575-86EF-064EA1A4A20D}.Release|x64.ActiveCfg = Release|x64 + {E8091321-D79D-4575-86EF-064EA1A4A20D}.Release|x64.Build.0 = Release|x64 + {622E8B19-8109-4717-BD4D-9657AA78363E}.Debug|Win32.ActiveCfg = Debug|Win32 + {622E8B19-8109-4717-BD4D-9657AA78363E}.Debug|Win32.Build.0 = Debug|Win32 + {622E8B19-8109-4717-BD4D-9657AA78363E}.Debug|x64.ActiveCfg = Debug|x64 + {622E8B19-8109-4717-BD4D-9657AA78363E}.Debug|x64.Build.0 = Debug|x64 + {622E8B19-8109-4717-BD4D-9657AA78363E}.Release|Win32.ActiveCfg = Release|Win32 + {622E8B19-8109-4717-BD4D-9657AA78363E}.Release|Win32.Build.0 = Release|Win32 + {622E8B19-8109-4717-BD4D-9657AA78363E}.Release|x64.ActiveCfg = Release|x64 + {622E8B19-8109-4717-BD4D-9657AA78363E}.Release|x64.Build.0 = Release|x64 + {71AD2674-065B-48F5-B8B0-E1F9D3892081}.Debug|Win32.ActiveCfg = Debug|Win32 + {71AD2674-065B-48F5-B8B0-E1F9D3892081}.Debug|Win32.Build.0 = Debug|Win32 + {71AD2674-065B-48F5-B8B0-E1F9D3892081}.Debug|x64.ActiveCfg = Debug|x64 + {71AD2674-065B-48F5-B8B0-E1F9D3892081}.Debug|x64.Build.0 = Debug|x64 + {71AD2674-065B-48F5-B8B0-E1F9D3892081}.Release|Win32.ActiveCfg = Release|Win32 + {71AD2674-065B-48F5-B8B0-E1F9D3892081}.Release|Win32.Build.0 = Release|Win32 + {71AD2674-065B-48F5-B8B0-E1F9D3892081}.Release|x64.ActiveCfg = Release|x64 + {71AD2674-065B-48F5-B8B0-E1F9D3892081}.Release|x64.Build.0 = Release|x64 + {EE47764E-A202-4F85-A767-ABDAB4AFF35F}.Debug|Win32.ActiveCfg = Debug|Win32 + {EE47764E-A202-4F85-A767-ABDAB4AFF35F}.Debug|Win32.Build.0 = Debug|Win32 + {EE47764E-A202-4F85-A767-ABDAB4AFF35F}.Debug|x64.ActiveCfg = Debug|x64 + {EE47764E-A202-4F85-A767-ABDAB4AFF35F}.Debug|x64.Build.0 = Debug|x64 + {EE47764E-A202-4F85-A767-ABDAB4AFF35F}.Release|Win32.ActiveCfg = Release|Win32 + {EE47764E-A202-4F85-A767-ABDAB4AFF35F}.Release|Win32.Build.0 = Release|Win32 + {EE47764E-A202-4F85-A767-ABDAB4AFF35F}.Release|x64.ActiveCfg = Release|x64 + {EE47764E-A202-4F85-A767-ABDAB4AFF35F}.Release|x64.Build.0 = Release|x64 + {EBFFFB4E-261D-44D3-B89C-957B31A0BF9C}.Debug|Win32.ActiveCfg = Debug|Win32 + {EBFFFB4E-261D-44D3-B89C-957B31A0BF9C}.Debug|Win32.Build.0 = Debug|Win32 + {EBFFFB4E-261D-44D3-B89C-957B31A0BF9C}.Debug|x64.ActiveCfg = Debug|x64 + {EBFFFB4E-261D-44D3-B89C-957B31A0BF9C}.Debug|x64.Build.0 = Debug|x64 + {EBFFFB4E-261D-44D3-B89C-957B31A0BF9C}.Release|Win32.ActiveCfg = Release|Win32 + {EBFFFB4E-261D-44D3-B89C-957B31A0BF9C}.Release|Win32.Build.0 = Release|Win32 + {EBFFFB4E-261D-44D3-B89C-957B31A0BF9C}.Release|x64.ActiveCfg = Release|x64 + {EBFFFB4E-261D-44D3-B89C-957B31A0BF9C}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/abort_callback.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/abort_callback.cpp new file mode 100644 index 000000000..affc69ff2 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/abort_callback.cpp @@ -0,0 +1,17 @@ +#include "foobar2000.h" + +void abort_callback::check() const { + if (is_aborting()) throw exception_aborted(); +} + +void abort_callback::sleep(double p_timeout_seconds) const { + if (!sleep_ex(p_timeout_seconds)) throw exception_aborted(); +} + +bool abort_callback::sleep_ex(double p_timeout_seconds) const { +#ifdef _WIN32 + return !win32_event::g_wait_for(get_abort_event(),p_timeout_seconds); +#else +#error PORTME +#endif +} \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/abort_callback.h b/tools/vio2sf/src/foobar/foobar2000/SDK/abort_callback.h new file mode 100644 index 000000000..97ed3afea --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/abort_callback.h @@ -0,0 +1,76 @@ +#ifndef _foobar2000_sdk_abort_callback_h_ +#define _foobar2000_sdk_abort_callback_h_ + +namespace foobar2000_io { + +PFC_DECLARE_EXCEPTION(exception_aborted,pfc::exception,"User abort"); + +#ifdef _WIN32 +typedef HANDLE abort_callback_event; +#else +#error PORTME +#endif + +//! This class is used to signal underlying worker code whether user has decided to abort a potentially time-consuming operation. It is commonly required by all file related operations. Code that receives an abort_callback object should periodically check it and abort any operations being performed if it is signaled, typically throwing exception_aborted. \n +//! See abort_callback_impl for an implementation. +class NOVTABLE abort_callback +{ +public: + //! Returns whether user has requested the operation to be aborted. + virtual bool is_aborting() const = 0; + + //! Retrieves event object that can be used with some OS calls. The even object becomes signaled when abort is triggered. On win32, this is equivalent to win32 event handle (see: CreateEvent). \n + //! You must not close this handle or call any methods that change this handle's state (SetEvent() or ResetEvent()), you can only wait for it. + virtual abort_callback_event get_abort_event() const = 0; + + //! Checks if user has requested the operation to be aborted, and throws exception_aborted if so. + void check() const; + + //! For compatibility with old code. Do not call. + inline void check_e() const {check();} + + + //! Sleeps p_timeout_seconds or less when aborted, throws exception_aborted on abort. + void sleep(double p_timeout_seconds) const; + //! Sleeps p_timeout_seconds or less when aborted, returns true when execution should continue, false when not. + bool sleep_ex(double p_timeout_seconds) const; +protected: + abort_callback() {} + ~abort_callback() {} +}; + + + +//! Implementation of abort_callback interface. +class abort_callback_impl : public abort_callback { +public: + abort_callback_impl() : m_aborting(false) { + m_event.create(true,false); + } + inline void abort() {set_state(true);} + inline void reset() {set_state(false);} + + void set_state(bool p_state) {m_aborting = p_state; m_event.set_state(p_state);} + + bool is_aborting() const {return m_aborting;} + + abort_callback_event get_abort_event() const {return m_event.get();} + +private: + abort_callback_impl(const abort_callback_impl &) {throw pfc::exception_not_implemented();} + const abort_callback_impl & operator=(const abort_callback_impl&) {throw pfc::exception_not_implemented();} + + volatile bool m_aborting; +#ifdef WIN32 + win32_event m_event; +#endif +}; + +//! Dummy abort_callback that never gets aborted. To be possibly optimized in the future. +typedef abort_callback_impl abort_callback_dummy; + +} + +using namespace foobar2000_io; + +#endif //_foobar2000_sdk_abort_callback_h_ diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/advconfig.h b/tools/vio2sf/src/foobar/foobar2000/SDK/advconfig.h new file mode 100644 index 000000000..3b2198953 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/advconfig.h @@ -0,0 +1,266 @@ +//! Entrypoint class for adding items to Advanced Preferences page. \n +//! Implementations must derive from one of subclasses: advconfig_branch, advconfig_entry_checkbox, advconfig_entry_string. \n +//! Implementations are typically registered using static service_factory_single_t, or using provided helper classes in case of standard implementations declared in this header. +class NOVTABLE advconfig_entry : public service_base { +public: + virtual void get_name(pfc::string_base & p_out) = 0; + virtual GUID get_guid() = 0; + virtual GUID get_parent() = 0; + virtual void reset() = 0; + virtual double get_sort_priority() = 0; + + static bool g_find(service_ptr_t& out, const GUID & id) { + service_enum_t e; service_ptr_t ptr; while(e.next(ptr)) { if (ptr->get_guid() == id) {out = ptr; return true;} } return false; + } + + static const GUID guid_root; + static const GUID guid_branch_tagging,guid_branch_decoding,guid_branch_tools,guid_branch_playback,guid_branch_display; + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(advconfig_entry); +}; + +//! Creates a new branch in Advanced Preferences. \n +//! Implementation: see advconfig_branch_impl / advconfig_branch_factory. +class NOVTABLE advconfig_branch : public advconfig_entry { +public: + FB2K_MAKE_SERVICE_INTERFACE(advconfig_branch,advconfig_entry); +}; + +//! Creates a checkbox/radiocheckbox entry in Advanced Preferences. \n +//! The difference between checkboxes and radiocheckboxes is different icon (obviously) and that checking a radiocheckbox unchecks all other radiocheckboxes in the same branch. \n +//! Implementation: see advconfig_entry_checkbox_impl / advconfig_checkbox_factory_t. +class NOVTABLE advconfig_entry_checkbox : public advconfig_entry { +public: + virtual bool get_state() = 0; + virtual void set_state(bool p_state) = 0; + virtual bool is_radio() = 0; + + FB2K_MAKE_SERVICE_INTERFACE(advconfig_entry_checkbox,advconfig_entry); +}; + +//! Creates a string/integer editbox entry in Advanced Preferences.\n +//! Implementation: see advconfig_entry_string_impl / advconfig_string_factory. +class NOVTABLE advconfig_entry_string : public advconfig_entry { +public: + virtual void get_state(pfc::string_base & p_out) = 0; + virtual void set_state(const char * p_string,t_size p_length = infinite) = 0; + virtual t_uint32 get_flags() = 0; + + enum { + flag_is_integer = 1 << 0, + flag_is_signed = 1 << 1, + }; + + FB2K_MAKE_SERVICE_INTERFACE(advconfig_entry_string,advconfig_entry); +}; + + +//! Standard implementation of advconfig_branch. \n +//! Usage: no need to use this class directly - use advconfig_branch_factory instead. +class advconfig_branch_impl : public advconfig_branch { +public: + advconfig_branch_impl(const char * p_name,const GUID & p_guid,const GUID & p_parent,double p_priority) : m_name(p_name), m_guid(p_guid), m_parent(p_parent), m_priority(p_priority) {} + void get_name(pfc::string_base & p_out) {p_out = m_name;} + GUID get_guid() {return m_guid;} + GUID get_parent() {return m_parent;} + void reset() {} + double get_sort_priority() {return m_priority;} +private: + pfc::string8 m_name; + GUID m_guid,m_parent; + const double m_priority; +}; + +//! Standard implementation of advconfig_entry_checkbox. \n +//! p_is_radio parameter controls whether we're implementing a checkbox or a radiocheckbox (see advconfig_entry_checkbox description for more details). +template +class advconfig_entry_checkbox_impl : public advconfig_entry_checkbox { +public: + advconfig_entry_checkbox_impl(const char * p_name,const GUID & p_guid,const GUID & p_parent,double p_priority,bool p_initialstate) + : m_name(p_name), m_initialstate(p_initialstate), m_state(p_guid,p_initialstate), m_parent(p_parent), m_priority(p_priority) {} + + void get_name(pfc::string_base & p_out) {p_out = m_name;} + GUID get_guid() {return m_state.get_guid();} + GUID get_parent() {return m_parent;} + void reset() {m_state = m_initialstate;} + bool get_state() {return m_state;} + void set_state(bool p_state) {m_state = p_state;} + bool is_radio() {return p_is_radio;} + double get_sort_priority() {return m_priority;} + bool get_state_() const {return m_state;} +private: + pfc::string8 m_name; + const bool m_initialstate; + cfg_bool m_state; + GUID m_parent; + const double m_priority; +}; + +//! Service factory helper around standard advconfig_branch implementation. Use this class to register your own Advanced Preferences branches. \n +//! Usage: static advconfig_branch_factory mybranch(name, branchID, parentBranchID, priority); +class advconfig_branch_factory : public service_factory_single_t { +public: + advconfig_branch_factory(const char * p_name,const GUID & p_guid,const GUID & p_parent,double p_priority) + : service_factory_single_t(p_name,p_guid,p_parent,p_priority) {} +}; + +//! Service factory helper around standard advconfig_entry_checkbox implementation. Use this class to register your own Advanced Preferences checkbox/radiocheckbox entries. \n +//! Usage: static advconfig_entry_checkbox mybox(name, itemID, parentID, priority, initialstate); +template +class advconfig_checkbox_factory_t : public service_factory_single_t > { +public: + advconfig_checkbox_factory_t(const char * p_name,const GUID & p_guid,const GUID & p_parent,double p_priority,bool p_initialstate) + : service_factory_single_t >(p_name,p_guid,p_parent,p_priority,p_initialstate) {} + + bool get() const {return get_static_instance().get_state_();} + void set(bool val) {get_static_instance().set_state(val);} + operator bool() const {return get();} + bool operator=(bool val) {set(val); return val;} +}; + +//! Service factory helper around standard advconfig_entry_checkbox implementation, specialized for checkboxes (rather than radiocheckboxes). See advconfig_checkbox_factory_t<> for more details. +typedef advconfig_checkbox_factory_t advconfig_checkbox_factory; +//! Service factory helper around standard advconfig_entry_checkbox implementation, specialized for radiocheckboxes (rather than standard checkboxes). See advconfig_checkbox_factory_t<> for more details. +typedef advconfig_checkbox_factory_t advconfig_radio_factory; + + +//! Standard advconfig_entry_string implementation. Use advconfig_string_factory to register your own string entries in Advanced Preferences instead of using this class directly. +class advconfig_entry_string_impl : public advconfig_entry_string { +public: + advconfig_entry_string_impl(const char * p_name,const GUID & p_guid,const GUID & p_parent,double p_priority,const char * p_initialstate) + : m_name(p_name), m_parent(p_parent), m_priority(p_priority), m_initialstate(p_initialstate), m_state(p_guid,p_initialstate) {} + void get_name(pfc::string_base & p_out) {p_out = m_name;} + GUID get_guid() {return m_state.get_guid();} + GUID get_parent() {return m_parent;} + void reset() {core_api::ensure_main_thread();m_state = m_initialstate;} + double get_sort_priority() {return m_priority;} + void get_state(pfc::string_base & p_out) {core_api::ensure_main_thread();p_out = m_state;} + void set_state(const char * p_string,t_size p_length = infinite) {core_api::ensure_main_thread();m_state.set_string(p_string,p_length);} + t_uint32 get_flags() {return 0;} +private: + const pfc::string8 m_initialstate, m_name; + cfg_string m_state; + const double m_priority; + const GUID m_parent; +}; + +//! Service factory helper around standard advconfig_entry_string implementation. Use this class to register your own string entries in Advanced Preferences. \n +//! Usage: static advconfig_string_factory mystring(name, itemID, branchID, priority, initialValue); +class advconfig_string_factory : public service_factory_single_t { +public: + advconfig_string_factory(const char * p_name,const GUID & p_guid,const GUID & p_parent,double p_priority,const char * p_initialstate) + : service_factory_single_t(p_name,p_guid,p_parent,p_priority,p_initialstate) {} + + void get(pfc::string_base & out) {get_static_instance().get_state(out);} + void set(const char * in) {get_static_instance().set_state(in);} +}; + + +//! Special advconfig_entry_string implementation - implements integer entries. Use advconfig_integer_factory to register your own integer entries in Advanced Preferences instead of using this class directly. +class advconfig_entry_integer_impl : public advconfig_entry_string { +public: + advconfig_entry_integer_impl(const char * p_name,const GUID & p_guid,const GUID & p_parent,double p_priority,t_uint64 p_initialstate,t_uint64 p_min,t_uint64 p_max) + : m_name(p_name), m_parent(p_parent), m_priority(p_priority), m_initval(p_initialstate), m_min(p_min), m_max(p_max), m_state(p_guid,p_initialstate) {} + void get_name(pfc::string_base & p_out) {p_out = m_name;} + GUID get_guid() {return m_state.get_guid();} + GUID get_parent() {return m_parent;} + void reset() {m_state = m_initval;} + double get_sort_priority() {return m_priority;} + void get_state(pfc::string_base & p_out) {p_out = pfc::format_uint(m_state.get_value());} + void set_state(const char * p_string,t_size p_length) {set_state_int(pfc::atoui64_ex(p_string,p_length));} + t_uint32 get_flags() {return advconfig_entry_string::flag_is_integer;} + + t_uint64 get_state_int() const {return m_state;} + void set_state_int(t_uint64 val) {m_state = pfc::clip_t(val,m_min,m_max);} +private: + cfg_int_t m_state; + const double m_priority; + const t_uint64 m_initval, m_min, m_max; + const GUID m_parent; + const pfc::string8 m_name; +}; + +//! Service factory helper around integer-specialized advconfig_entry_string implementation. Use this class to register your own integer entries in Advanced Preferences. \n +//! Usage: static advconfig_integer_factory myint(name, itemID, parentID, priority, initialValue, minValue, maxValue); +class advconfig_integer_factory : public service_factory_single_t { +public: + advconfig_integer_factory(const char * p_name,const GUID & p_guid,const GUID & p_parent,double p_priority,t_uint64 p_initialstate,t_uint64 p_min,t_uint64 p_max) + : service_factory_single_t(p_name,p_guid,p_parent,p_priority,p_initialstate,p_min,p_max) {} + + t_uint64 get() const {return get_static_instance().get_state_int();} + void set(t_uint64 val) {get_static_instance().set_state_int(val);} + + operator t_uint64() const {return get();} + t_uint64 operator=(t_uint64 val) {set(val); return val;} +}; + + +//! Not currently used, reserved for future use. +class NOVTABLE advconfig_entry_enum : public advconfig_entry { +public: + virtual t_size get_value_count() = 0; + virtual void enum_value(pfc::string_base & p_out,t_size p_index) = 0; + virtual t_size get_state() = 0; + virtual void set_state(t_size p_value) = 0; + + FB2K_MAKE_SERVICE_INTERFACE(advconfig_entry_enum,advconfig_entry); +}; + + + + +//! Special version if advconfig_entry_string_impl that allows the value to be retrieved from worker threads. +class advconfig_entry_string_impl_MT : public advconfig_entry_string { +public: + advconfig_entry_string_impl_MT(const char * p_name,const GUID & p_guid,const GUID & p_parent,double p_priority,const char * p_initialstate) + : m_name(p_name), m_parent(p_parent), m_priority(p_priority), m_initialstate(p_initialstate), m_state(p_guid,p_initialstate) {} + void get_name(pfc::string_base & p_out) {p_out = m_name;} + GUID get_guid() {return m_state.get_guid();} + GUID get_parent() {return m_parent;} + void reset() { + insync(m_sync); + m_state = m_initialstate; + } + double get_sort_priority() {return m_priority;} + void get_state(pfc::string_base & p_out) { + insync(m_sync); + p_out = m_state; + } + void set_state(const char * p_string,t_size p_length = infinite) { + insync(m_sync); + m_state.set_string(p_string,p_length); + } + t_uint32 get_flags() {return 0;} +private: + const pfc::string8 m_initialstate, m_name; + cfg_string m_state; + critical_section m_sync; + const double m_priority; + const GUID m_parent; +}; + +//! Special version if advconfig_string_factory that allows the value to be retrieved from worker threads. +class advconfig_string_factory_MT : public service_factory_single_t { +public: + advconfig_string_factory_MT(const char * p_name,const GUID & p_guid,const GUID & p_parent,double p_priority,const char * p_initialstate) + : service_factory_single_t(p_name,p_guid,p_parent,p_priority,p_initialstate) {} + + void get(pfc::string_base & out) {get_static_instance().get_state(out);} + void set(const char * in) {get_static_instance().set_state(in);} +}; + + + + +/* + Advanced Preferences variable declaration examples + + static advconfig_string_factory mystring("name goes here",myguid,parentguid,0,"asdf"); + to retrieve state: pfc::string8 val; mystring.get(val); + + static advconfig_checkbox_factory mycheckbox("name goes here",myguid,parentguid,0,false); + to retrieve state: mycheckbox.get(); + + static advconfig_integer_factory myint("name goes here",myguid,parentguid,0,initialValue,minimumValue,maximumValue); + to retrieve state: myint.get(); +*/ diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/album_art.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/album_art.cpp new file mode 100644 index 000000000..1fea648a0 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/album_art.cpp @@ -0,0 +1,17 @@ +#include "foobar2000.h" + +bool album_art_editor::g_get_interface(service_ptr_t & out,const char * path) { + service_enum_t e; ptr ptr; + pfc::string_extension ext(path); + while(e.next(ptr)) { + if (ptr->is_our_path(path,ext)) { + out = ptr; return true; + } + } + return false; +} + +bool album_art_editor::g_is_supported_path(const char * path) { + ptr ptr; + return g_get_interface(ptr,path); +} \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/album_art.h b/tools/vio2sf/src/foobar/foobar2000/SDK/album_art.h new file mode 100644 index 000000000..6f16d9090 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/album_art.h @@ -0,0 +1,222 @@ +//new in 0.9.5 + +//! Common class for handling picture data. \n +//! Type of contained picture data is unknown and to be determined according to memory block contents by code parsing/rendering the picture. Commonly encountered types are: BMP, PNG, JPEG and GIF. \n +//! Implementation: use album_art_data_impl. +class NOVTABLE album_art_data : public service_base { +public: + //! Retrieves a pointer to a memory block containing the picture. + virtual const void * get_ptr() const = 0; + //! Retrieves size of the memory block containing the picture. + virtual t_size get_size() const = 0; + + //! Determine whether two album_art_data objects store the same picture data. + static bool equals(album_art_data const & v1, album_art_data const & v2) { + const t_size s = v1.get_size(); + if (s != v2.get_size()) return false; + return memcmp(v1.get_ptr(), v2.get_ptr(),s) == 0; + } + bool operator==(const album_art_data & other) const {return equals(*this,other);} + bool operator!=(const album_art_data & other) const {return !equals(*this,other);} + + FB2K_MAKE_SERVICE_INTERFACE(album_art_data,service_base); +}; + +typedef service_ptr_t album_art_data_ptr; + +//! Implements album_art_data. +class album_art_data_impl : public album_art_data { +public: + const void * get_ptr() const {return m_content.get_ptr();} + t_size get_size() const {return m_content.get_size();} + + void * get_ptr() {return m_content.get_ptr();} + void set_size(t_size p_size) {m_content.set_size(p_size);} + + //! Reads picture data from the specified stream object. + void from_stream(stream_reader * p_stream,t_size p_bytes,abort_callback & p_abort) { + set_size(p_bytes); p_stream->read_object(get_ptr(),p_bytes,p_abort); + } + + //! Creates an album_art_data object from picture data contained in a memory buffer. + static album_art_data_ptr g_create(const void * p_buffer,t_size p_bytes) { + service_ptr_t instance = new service_impl_t(); + instance->set_size(p_bytes); + memcpy(instance->get_ptr(),p_buffer,p_bytes); + return instance; + } + //! Creates an album_art_data object from picture data contained in a stream. + static album_art_data_ptr g_create(stream_reader * p_stream,t_size p_bytes,abort_callback & p_abort) { + service_ptr_t instance = new service_impl_t(); + instance->from_stream(p_stream,p_bytes,p_abort); + return instance; + } + +private: + pfc::array_t m_content; +}; + +//! Namespace containing identifiers of album art types. +namespace album_art_ids { + //! Front cover. + static const GUID cover_front = { 0xf1e66f4e, 0xfe09, 0x4b94, { 0x91, 0xa3, 0x67, 0xc2, 0x3e, 0xd1, 0x44, 0x5e } }; + //! Back cover. + static const GUID cover_back = { 0xcb552d19, 0x86d5, 0x434c, { 0xac, 0x77, 0xbb, 0x24, 0xed, 0x56, 0x7e, 0xe4 } }; + //! Picture of a disc or other storage media. + static const GUID disc = { 0x3dba9f36, 0xf928, 0x4fa4, { 0x87, 0x9c, 0xd3, 0x40, 0x47, 0x59, 0x58, 0x7e } }; + //! Album-specific icon (NOT a file type icon). + static const GUID icon = { 0x74cdf5b4, 0x7053, 0x4b3d, { 0x9a, 0x3c, 0x54, 0x69, 0xf5, 0x82, 0x6e, 0xec } }; +}; + +PFC_DECLARE_EXCEPTION(exception_album_art_not_found,exception_io_not_found,"Album Art Not Found"); +PFC_DECLARE_EXCEPTION(exception_album_art_unsupported_entry,exception_io_data,"Unsupported Album Art Entry"); + +//! Class encapsulating access to album art stored in a media file. Use album_art_extractor class obtain album_art_extractor_instance referring to specified media file. +class NOVTABLE album_art_extractor_instance : public service_base { +public: + //! Throws exception_album_art_not_found when the requested album art entry could not be found in the referenced media file. + virtual album_art_data_ptr query(const GUID & p_what,abort_callback & p_abort) = 0; + + FB2K_MAKE_SERVICE_INTERFACE(album_art_extractor_instance,service_base); +}; + +//! Class encapsulating access to album art stored in a media file. Use album_art_editor class to obtain album_art_editor_instance referring to specified media file. +class NOVTABLE album_art_editor_instance : public album_art_extractor_instance { +public: + //! Throws exception_album_art_unsupported_entry when the file format we're dealing with does not support specific entry. + virtual void set(const GUID & p_what,album_art_data_ptr p_data,abort_callback & p_abort) = 0; + + //! Removes the requested entry. Fails silently when the entry doesn't exist. + virtual void remove(const GUID & p_what) = 0; + + //! Finalizes file tag update operation. + virtual void commit(abort_callback & p_abort) = 0; + + + FB2K_MAKE_SERVICE_INTERFACE(album_art_editor_instance,album_art_extractor_instance); +}; + +typedef service_ptr_t album_art_extractor_instance_ptr; +typedef service_ptr_t album_art_editor_instance_ptr; + +//! Entrypoint class for accessing album art extraction functionality. Register your own implementation to allow album art extraction from your media file format. \n +//! If you want to extract album art from a media file, it's recommended that you use album_art_manager API instead of calling album_art_extractor directly. +class NOVTABLE album_art_extractor : public service_base { +public: + //! Returns whether the specified file is one of formats supported by our album_art_extractor implementation. + //! @param p_path Path to file being queried. + //! @param p_extension Extension of file being queried (also present in p_path parameter) - provided as a separate parameter for performance reasons. + virtual bool is_our_path(const char * p_path,const char * p_extension) = 0; + + //! Instantiates album_art_extractor_instance providing access to album art stored in a specified media file. \n + //! Throws one of I/O exceptions on failure; exception_album_art_not_found when the file has no album art record at all. + //! @param p_filehint Optional; specifies a file interface to use for accessing the specified file; can be null - in that case, the implementation will open and close the file internally. + virtual album_art_extractor_instance_ptr open(file_ptr p_filehint,const char * p_path,abort_callback & p_abort) = 0; + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(album_art_extractor); +}; + +//! Entrypoint class for accessing album art editing functionality. Register your own implementation to allow album art editing on your media file format. +class NOVTABLE album_art_editor : public service_base { +public: + //! Returns whether the specified file is one of formats supported by our album_art_editor implementation. + //! @param p_path Path to file being queried. + //! @param p_extension Extension of file being queried (also present in p_path parameter) - provided as a separate parameter for performance reasons. + virtual bool is_our_path(const char * p_path,const char * p_extension) = 0; + + //! Instantiates album_art_editor_instance providing access to album art stored in a specified media file. \n + //! @param p_filehint Optional; specifies a file interface to use for accessing the specified file; can be null - in that case, the implementation will open and close the file internally. + virtual album_art_editor_instance_ptr open(file_ptr p_filehint,const char * p_path,abort_callback & p_abort) = 0; + + //! Helper; attempts to retrieve an album_art_editor service pointer that supports the specified file. + //! @returns True on success, false on failure (no registered album_art_editor supports this file type). + static bool g_get_interface(service_ptr_t & out,const char * path); + //! Helper; returns whether one of registered album_art_editor implementations is capable of opening the specified file. + static bool g_is_supported_path(const char * path); + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(album_art_editor); +}; + +//! Primary API for interfacing with foobar2000 core's album art extraction functionality. \n +//! Use static_api_ptr_t()->instantiate() to obtain a pointer to album_art_manager_instance. \n +//! The main difference between using album_art_manager_instance and calling album_art_extractor methods directly is that +//! album_art_manager_instance will fall back to returning pictures found in the folder containing the specified media file +//! in case requested album art entries can't be extracted from the media file itself. +class NOVTABLE album_art_manager_instance : public service_base { +public: + //! @returns True when the newly requested file has different album art than the old one, false when album art we're referencing is the same as before. + virtual bool open(const char * p_file,abort_callback & p_abort) = 0; + //! Resets internal data. + virtual void close() = 0; + + //! Queries album art data for currently open media file. Throws exception_album_art_not_found when the requested album art entry isn't present. + virtual album_art_data_ptr query(const GUID & p_what,abort_callback & p_abort) = 0; + + //! Queries for stub image to display when there's no album art to show. \n + //! May fail with exception_album_art_not_found as well when we have no stub image configured. + virtual album_art_data_ptr query_stub_image(abort_callback & p_abort) = 0; + + FB2K_MAKE_SERVICE_INTERFACE(album_art_manager_instance,service_base); +}; + +typedef service_ptr_t album_art_manager_instance_ptr; + +//! Entrypoint API for accessing album art loading functionality provided by foobar2000 core. Usage: static_api_ptr_t. \n +//! This API was introduced in 0.9.5. +class NOVTABLE album_art_manager : public service_base { +public: + virtual album_art_manager_instance_ptr instantiate() = 0; + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(album_art_manager); +}; + + +//! Helper - simple implementation of album_art_extractor_instance. +class album_art_extractor_instance_simple : public album_art_extractor_instance { +public: + void set(const GUID & p_what,album_art_data_ptr p_content) {m_content.set(p_what,p_content);} + bool have_item(const GUID & p_what) {return m_content.have_item(p_what);} + album_art_data_ptr query(const GUID & p_what,abort_callback & p_abort) { + album_art_data_ptr temp; + if (!m_content.query(p_what,temp)) throw exception_album_art_not_found(); + return temp; + } + bool is_empty() const {return m_content.get_count() == 0;} +private: + pfc::map_t m_content; +}; + +//! Helper API for extracting album art from APEv2 tags - introduced in 0.9.5. +class NOVTABLE tag_processor_album_art_utils : public service_base { +public: + + //! Throws one of I/O exceptions on failure; exception_album_art_not_found when the file has no album art record at all. + virtual album_art_extractor_instance_ptr open(file_ptr p_file,abort_callback & p_abort) = 0; + + //! Currently not implemented. Reserved for future use. + virtual album_art_editor_instance_ptr edit(file_ptr p_file,abort_callback & p_abort) = 0; + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(tag_processor_album_art_utils) +}; + +//! Helper implementation of album_art_extractor - reads album art from arbitrary file formats that comply with APEv2 tagging specification. +class album_art_extractor_impl_stdtags : public album_art_extractor { +public: + //! @param exts Semicolon-separated list of file format extensions to support. + album_art_extractor_impl_stdtags(const char * exts) { + pfc::splitStringSimple_toList(m_extensions,";",exts); + } + + bool is_our_path(const char * p_path,const char * p_extension) { + return m_extensions.have_item(p_extension); + } + + album_art_extractor_instance_ptr open(file_ptr p_filehint,const char * p_path,abort_callback & p_abort) { + PFC_ASSERT( is_our_path(p_path, pfc::string_extension(p_path) ) ); + file_ptr l_file ( p_filehint ); + if (l_file.is_empty()) filesystem::g_open_read(l_file, p_path, p_abort); + return static_api_ptr_t()->open( l_file, p_abort ); + } +private: + pfc::avltree_t m_extensions; +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/app_close_blocker.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/app_close_blocker.cpp new file mode 100644 index 000000000..6611e0b56 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/app_close_blocker.cpp @@ -0,0 +1,12 @@ +#include "foobar2000.h" + +bool app_close_blocker::g_query() +{ + service_ptr_t ptr; + service_enum_t e; + while(e.next(ptr)) + { + if (!ptr->query()) return false; + } + return true; +} \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/app_close_blocker.h b/tools/vio2sf/src/foobar/foobar2000/SDK/app_close_blocker.h new file mode 100644 index 000000000..b63659d2f --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/app_close_blocker.h @@ -0,0 +1,45 @@ +//! (DEPRECATED) This service is used to signal whether something is currently preventing main window from being closed and app from being shut down. +class NOVTABLE app_close_blocker : public service_base +{ +public: + //! Checks whether this service is currently preventing main window from being closed and app from being shut down. + virtual bool query() = 0; + + //! Static helper function, checks whether any of registered app_close_blocker services is currently preventing main window from being closed and app from being shut down. + static bool g_query(); + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(app_close_blocker); +}; + +//! An interface encapsulating a task preventing the foobar2000 application from being closed. Instances of this class need to be registered using app_close_blocking_task_manager methods. \n +//! Implementation: it's recommended that you derive from app_close_blocking_task_impl class instead of deriving from app_close_blocking_task directly, it manages registration/unregistration behind-the-scenes. +class NOVTABLE app_close_blocking_task { +public: + virtual void query_task_name(pfc::string_base & out) = 0; + +protected: + app_close_blocking_task() {} + ~app_close_blocking_task() {} + + PFC_CLASS_NOT_COPYABLE_EX(app_close_blocking_task); +}; + +//! Entrypoint class for registering app_close_blocking_task instances. Introduced in 0.9.5.1. \n +//! Usage: static_api_ptr_t(). May fail if user runs pre-0.9.5.1. It's recommended that you use app_close_blocking_task_impl class instead of calling app_close_blocking_task_manager directly. +class NOVTABLE app_close_blocking_task_manager : public service_base { +public: + virtual void register_task(app_close_blocking_task * task) = 0; + virtual void unregister_task(app_close_blocking_task * task) = 0; + + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(app_close_blocking_task_manager); +}; + +//! Helper; implements standard functionality required by app_close_blocking_task implementations - registers/unregisters the task on construction/destruction. +class app_close_blocking_task_impl : public app_close_blocking_task { +public: + app_close_blocking_task_impl() { try { static_api_ptr_t()->register_task(this); } catch(exception_service_not_found) {/*user runs pre-0.9.5.1*/}} + ~app_close_blocking_task_impl() { try { static_api_ptr_t()->unregister_task(this); } catch(exception_service_not_found) {/*user runs pre-0.9.5.1*/}} + + void query_task_name(pfc::string_base & out) { out = ""; } +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/audio_chunk.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/audio_chunk.cpp new file mode 100644 index 000000000..13dc73a46 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/audio_chunk.cpp @@ -0,0 +1,335 @@ +#include "foobar2000.h" + +void audio_chunk::set_data(const audio_sample * src,t_size samples,unsigned nch,unsigned srate,unsigned channel_config) +{ + t_size size = samples * nch; + set_data_size(size); + if (src) + pfc::memcpy_t(get_data(),src,size); + else + pfc::memset_t(get_data(),(audio_sample)0,size); + set_sample_count(samples); + set_channels(nch,channel_config); + set_srate(srate); +} + +static bool check_exclusive(unsigned val, unsigned mask) +{ + return (val&mask)!=0 && (val&mask)!=mask; +} + +namespace { + + template class msvc6_sucks_v2 { public: + inline static void do_fixedpoint_convert(const void * source,unsigned bps,t_size count,audio_sample* buffer) + { + const char * src = (const char *) source; + unsigned bytes = bps>>3; + t_size n; + T max = ((T)1)<<(bps-1); + + T negmask = - max; + + ASSUME(bytes<=sizeof(T)); + + const double div = 1.0 / (double)(1<<(bps-1)); + for(n=0;n(src); + if (b_swap) temp = pfc::byteswap_t(temp); + } + + + + if (!b_signed) temp ^= max; + + if (b_pad) + { + if (temp & max) temp |= negmask; + } + + if (b_pad) + src += bytes; + else + src += sizeof(T); + + + buffer[n] = (audio_sample) ( (double)temp * div ); + } + } + }; + + template class msvc6_sucks { public: + inline static void do_fixedpoint_convert(bool b_swap,bool b_signed,const void * source,unsigned bps,t_size count,audio_sample* buffer) + { + if (sizeof(T)==1) + { + if (b_signed) + { + msvc6_sucks_v2::do_fixedpoint_convert(source,bps,count,buffer); + } + else + { + msvc6_sucks_v2::do_fixedpoint_convert(source,bps,count,buffer); + } + } + else if (b_swap) + { + if (b_signed) + { + msvc6_sucks_v2::do_fixedpoint_convert(source,bps,count,buffer); + } + else + { + msvc6_sucks_v2::do_fixedpoint_convert(source,bps,count,buffer); + } + } + else + { + if (b_signed) + { + msvc6_sucks_v2::do_fixedpoint_convert(source,bps,count,buffer); + } + else + { + msvc6_sucks_v2::do_fixedpoint_convert(source,bps,count,buffer); + } + } + } + }; + + +}; + + +void audio_chunk::set_data_fixedpoint_ex(const void * source,t_size size,unsigned srate,unsigned nch,unsigned bps,unsigned flags,unsigned p_channel_config) +{ + assert( check_exclusive(flags,FLAG_SIGNED|FLAG_UNSIGNED) ); + assert( check_exclusive(flags,FLAG_LITTLE_ENDIAN|FLAG_BIG_ENDIAN) ); + + bool need_swap = !!(flags & FLAG_BIG_ENDIAN); + if (pfc::byte_order_is_big_endian) need_swap = !need_swap; + + t_size count = size / (bps/8); + set_data_size(count); + audio_sample * buffer = get_data(); + bool b_signed = !!(flags & FLAG_SIGNED); + + switch(bps) + { + case 8: + msvc6_sucks::do_fixedpoint_convert(need_swap,b_signed,source,bps,count,buffer); + break; + case 16: + if (!need_swap && b_signed) audio_math::convert_from_int16((const t_int16*)source,count,buffer,1.0); + else msvc6_sucks::do_fixedpoint_convert(need_swap,b_signed,source,bps,count,buffer); + break; + case 24: + msvc6_sucks::do_fixedpoint_convert(need_swap,b_signed,source,bps,count,buffer); + break; + case 32: + if (!need_swap && b_signed) audio_math::convert_from_int32((const t_int32*)source,count,buffer,1.0); + else msvc6_sucks::do_fixedpoint_convert(need_swap,b_signed,source,bps,count,buffer); + break; + default: + //unknown size, cant convert + pfc::memset_t(buffer,(audio_sample)0,count); + break; + } + set_sample_count(count/nch); + set_srate(srate); + set_channels(nch,p_channel_config); +} + +template +static void process_float_multi(audio_sample * p_out,const t_float * p_in,const t_size p_count) +{ + t_size n; + for(n=0;n +static void process_float_multi_swap(audio_sample * p_out,const t_float * p_in,const t_size p_count) +{ + t_size n; + for(n=0;n(ptr),count); + else + process_float_multi(out,reinterpret_cast(ptr),count); + } + else if (bps == 64) + { + if (use_swap) + process_float_multi_swap(out,reinterpret_cast(ptr),count); + else + process_float_multi(out,reinterpret_cast(ptr),count); + } + else throw exception_io_data("invalid bit depth"); + + set_sample_count(count/nch); + set_srate(srate); + set_channels(nch,p_channel_config); +} + +bool audio_chunk::is_valid() const +{ + unsigned nch = get_channels(); + if (nch==0 || nch>256) return false; + if (!g_is_valid_sample_rate(get_srate())) return false; + t_size samples = get_sample_count(); + if (samples==0 || samples >= 0x80000000 / (sizeof(audio_sample) * nch) ) return false; + t_size size = get_data_size(); + if (samples * nch > size) return false; + if (!get_data()) return false; + return true; +} + + +void audio_chunk::pad_with_silence_ex(t_size samples,unsigned hint_nch,unsigned hint_srate) { + if (is_empty()) + { + if (hint_srate && hint_nch) { + return set_data(0,samples,hint_nch,hint_srate); + } else throw exception_io_data(); + } + else + { + if (hint_srate && hint_srate != get_srate()) samples = MulDiv_Size(samples,get_srate(),hint_srate); + if (samples > get_sample_count()) + { + t_size old_size = get_sample_count() * get_channels(); + t_size new_size = samples * get_channels(); + set_data_size(new_size); + pfc::memset_t(get_data() + old_size,(audio_sample)0,new_size - old_size); + set_sample_count(samples); + } + } +} + +void audio_chunk::pad_with_silence(t_size samples) { + if (samples > get_sample_count()) + { + t_size old_size = get_sample_count() * get_channels(); + t_size new_size = pfc::multiply_guarded(samples,get_channels()); + set_data_size(new_size); + pfc::memset_t(get_data() + old_size,(audio_sample)0,new_size - old_size); + set_sample_count(samples); + } +} + +void audio_chunk::insert_silence_fromstart(t_size samples) { + t_size old_size = get_sample_count() * get_channels(); + t_size delta = samples * get_channels(); + t_size new_size = old_size + delta; + set_data_size(new_size); + audio_sample * ptr = get_data(); + pfc::memmove_t(ptr+delta,ptr,old_size); + pfc::memset_t(ptr,(audio_sample)0,delta); + set_sample_count(get_sample_count() + samples); +} + +t_size audio_chunk::skip_first_samples(t_size samples_delta) +{ + t_size samples_old = get_sample_count(); + if (samples_delta >= samples_old) + { + set_sample_count(0); + set_data_size(0); + return samples_old; + } + else + { + t_size samples_new = samples_old - samples_delta; + unsigned nch = get_channels(); + audio_sample * ptr = get_data(); + pfc::memmove_t(ptr,ptr+nch*samples_delta,nch*samples_new); + set_sample_count(samples_new); + set_data_size(nch*samples_new); + return samples_delta; + } +} + +audio_sample audio_chunk::get_peak(audio_sample p_peak) const { + return pfc::max_t(p_peak, get_peak()); +} + +audio_sample audio_chunk::get_peak() const { + return audio_math::calculate_peak(get_data(),get_sample_count() * get_channels()); +} + +void audio_chunk::scale(audio_sample p_value) +{ + audio_sample * ptr = get_data(); + audio_math::scale(ptr,get_sample_count() * get_channels(),ptr,p_value); +} + + +static void render_8bit(const audio_sample * in, t_size inLen, void * out) { + t_int8 * outWalk = reinterpret_cast(out); + for(t_size walk = 0; walk < inLen; ++walk) { + *outWalk++ = (t_int8)pfc::clip_t(audio_math::rint32( in[walk] * 0x80 ), -128, 127); + } +} +static void render_24bit(const audio_sample * in, t_size inLen, void * out) { + t_uint8 * outWalk = reinterpret_cast(out); + for(t_size walk = 0; walk < inLen; ++walk) { + const t_int32 v = pfc::clip_t(audio_math::rint32( in[walk] * 0x800000 ), -128 * 256 * 256, 128 * 256 * 256 - 1); + *(outWalk ++) = (t_uint8) (v & 0xFF); + *(outWalk ++) = (t_uint8) ((v >> 8) & 0xFF); + *(outWalk ++) = (t_uint8) ((v >> 16) & 0xFF); + } +} + +bool audio_chunk::to_raw_data(mem_block_container & out, t_uint32 bps) const { + const t_size samples = get_sample_count(); + const t_size dataLen = pfc::multiply_guarded(samples, (t_size)get_channel_count()); + switch(bps) { + case 8: + out.set_size(dataLen); + render_8bit(get_data(), dataLen, out.get_ptr()); + break; + case 16: + out.set_size(dataLen * 2); + audio_math::convert_to_int16(get_data(), dataLen, reinterpret_cast(out.get_ptr()), 1.0); + break; + case 24: + out.set_size(dataLen * 3); + render_24bit(get_data(), dataLen, out.get_ptr()); + break; + case 32: + pfc::static_assert(); + out.set(get_data(), dataLen * sizeof(audio_sample)); + break; + default: + return false; + } + return true; +} diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/audio_chunk.h b/tools/vio2sf/src/foobar/foobar2000/SDK/audio_chunk.h new file mode 100644 index 000000000..32988a94f --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/audio_chunk.h @@ -0,0 +1,342 @@ +//! Thrown when audio_chunk sample rate or channel mapping changes in mid-stream and the code receiving audio_chunks can't deal with that scenario. +PFC_DECLARE_EXCEPTION(exception_unexpected_audio_format_change, exception_io_data, "Unexpected audio format change" ); + +//! Interface to container of a chunk of audio data. See audio_chunk_impl for an implementation. +class NOVTABLE audio_chunk { +public: + + enum { + sample_rate_min = 1000, sample_rate_max = 1000000 + }; + static bool g_is_valid_sample_rate(t_uint32 p_val) {return p_val >= sample_rate_min && p_val <= sample_rate_max;} + + //! Channel map flag declarations. Note that order of interleaved channel data in the stream is same as order of these flags. + enum + { + channel_front_left = 1<<0, + channel_front_right = 1<<1, + channel_front_center = 1<<2, + channel_lfe = 1<<3, + channel_back_left = 1<<4, + channel_back_right = 1<<5, + channel_front_center_left = 1<<6, + channel_front_center_right = 1<<7, + channel_back_center = 1<<8, + channel_side_left = 1<<9, + channel_side_right = 1<<10, + channel_top_center = 1<<11, + channel_top_front_left = 1<<12, + channel_top_front_center = 1<<13, + channel_top_front_right = 1<<14, + channel_top_back_left = 1<<15, + channel_top_back_center = 1<<16, + channel_top_back_right = 1<<17, + + channel_config_mono = channel_front_center, + channel_config_stereo = channel_front_left | channel_front_right, + channel_config_5point1 = channel_front_left | channel_front_right | channel_back_left | channel_back_right | channel_front_center | channel_lfe, + + defined_channel_count = 18, + }; + + //! Helper function; guesses default channel map for specified channel count. + static unsigned g_guess_channel_config(unsigned count); + +#ifdef _WIN32 + //! Helper function; translates audio_chunk channel map to WAVEFORMATEXTENSIBLE channel map. + static DWORD g_channel_config_to_wfx(unsigned p_config); + //! Helper function; translates WAVEFORMATEXTENSIBLE channel map to audio_chunk channel map. + static unsigned g_channel_config_from_wfx(DWORD p_wfx); +#endif + + //! Extracts flag describing Nth channel from specified map. Usable to figure what specific channel in a stream means. + static unsigned g_extract_channel_flag(unsigned p_config,unsigned p_index); + //! Counts channels specified by channel map. + static unsigned g_count_channels(unsigned p_config); + //! Calculates index of a channel specified by p_flag in a stream where channel map is described by p_config. + static unsigned g_channel_index_from_flag(unsigned p_config,unsigned p_flag); + + + + //! Retrieves audio data buffer pointer (non-const version). Returned pointer is for temporary use only; it is valid until next set_data_size call, or until the object is destroyed. \n + //! Size of returned buffer is equal to get_data_size() return value (in audio_samples). Amount of actual data may be smaller, depending on sample count and channel count. Conditions where sample count * channel count are greater than data size should not be possible. + virtual audio_sample * get_data() = 0; + //! Retrieves audio data buffer pointer (const version). Returned pointer is for temporary use only; it is valid until next set_data_size call, or until the object is destroyed. \n + //! Size of returned buffer is equal to get_data_size() return value (in audio_samples). Amount of actual data may be smaller, depending on sample count and channel count. Conditions where sample count * channel count are greater than data size should not be possible. + virtual const audio_sample * get_data() const = 0; + //! Retrieves size of allocated buffer space, in audio_samples. + virtual t_size get_data_size() const = 0; + //! Resizes audio data buffer to specified size. Throws std::bad_alloc on failure. + virtual void set_data_size(t_size p_new_size) = 0; + + //! Retrieves sample rate of contained audio data. + virtual unsigned get_srate() const = 0; + //! Sets sample rate of contained audio data. + virtual void set_srate(unsigned val) = 0; + //! Retrieves channel count of contained audio data. + virtual unsigned get_channels() const = 0; + //! Helper - for consistency - same as get_channels(). + inline unsigned get_channel_count() const {return get_channels();} + //! Retrieves channel map of contained audio data. Conditions where number of channels specified by channel map don't match get_channels() return value should not be possible. + virtual unsigned get_channel_config() const = 0; + //! Sets channel count / channel map. + virtual void set_channels(unsigned p_count,unsigned p_config) = 0; + + //! Retrieves number of valid samples in the buffer. \n + //! Note that a "sample" means a unit of interleaved PCM data representing states of each channel at given point of time, not a single PCM value. \n + //! For an example, duration of contained audio data is equal to sample count / sample rate, while actual size of contained data is equal to sample count * channel count. + virtual t_size get_sample_count() const = 0; + + //! Sets number of valid samples in the buffer. WARNING: sample count * channel count should never be above allocated buffer size. + virtual void set_sample_count(t_size val) = 0; + + //! Helper, same as get_srate(). + inline unsigned get_sample_rate() const {return get_srate();} + //! Helper, same as set_srate(). + inline void set_sample_rate(unsigned val) {set_srate(val);} + + //! Helper; sets channel count to specified value and uses default channel map for this channel count. + void set_channels(unsigned val) {set_channels(val,g_guess_channel_config(val));} + + + //! Helper; resizes audio data buffer when it's current size is smaller than requested. + inline void grow_data_size(t_size p_requested) {if (p_requested > get_data_size()) set_data_size(p_requested);} + + + //! Retrieves duration of contained audio data, in seconds. + inline double get_duration() const + { + double rv = 0; + t_size srate = get_srate (), samples = get_sample_count(); + if (srate>0 && samples>0) rv = (double)samples/(double)srate; + return rv; + } + + //! Returns whether the chunk is empty (contains no audio data). + inline bool is_empty() const {return get_channels()==0 || get_srate()==0 || get_sample_count()==0;} + + //! Returns whether the chunk contents are valid (for bug check purposes). + bool is_valid() const; + + //! Returns actual amount of audio data contained in the buffer (sample count * channel count). Must not be greater than data size (see get_data_size()). + inline t_size get_data_length() const {return get_sample_count() * get_channels();} + + //! Resets all audio_chunk data. + inline void reset() { + set_sample_count(0); + set_srate(0); + set_channels(0); + set_data_size(0); + } + + //! Helper, sets chunk data to contents of specified buffer, with specified number of channels / sample rate / channel map. + void set_data(const audio_sample * src,t_size samples,unsigned nch,unsigned srate,unsigned channel_config); + + //! Helper, sets chunk data to contents of specified buffer, with specified number of channels / sample rate, using default channel map for specified channel count. + inline void set_data(const audio_sample * src,t_size samples,unsigned nch,unsigned srate) {set_data(src,samples,nch,srate,g_guess_channel_config(nch));} + + //! Helper, sets chunk data to contents of specified buffer, using default win32/wav conventions for signed/unsigned switch. + inline void set_data_fixedpoint(const void * ptr,t_size bytes,unsigned srate,unsigned nch,unsigned bps,unsigned channel_config) { + set_data_fixedpoint_ex(ptr,bytes,srate,nch,bps,(bps==8 ? FLAG_UNSIGNED : FLAG_SIGNED) | flags_autoendian(), channel_config); + } + + inline void set_data_fixedpoint_unsigned(const void * ptr,t_size bytes,unsigned srate,unsigned nch,unsigned bps,unsigned channel_config) { + return set_data_fixedpoint_ex(ptr,bytes,srate,nch,bps,FLAG_UNSIGNED | flags_autoendian(), channel_config); + } + + inline void set_data_fixedpoint_signed(const void * ptr,t_size bytes,unsigned srate,unsigned nch,unsigned bps,unsigned channel_config) { + return set_data_fixedpoint_ex(ptr,bytes,srate,nch,bps,FLAG_SIGNED | flags_autoendian(), channel_config); + } + + enum + { + FLAG_LITTLE_ENDIAN = 1, + FLAG_BIG_ENDIAN = 2, + FLAG_SIGNED = 4, + FLAG_UNSIGNED = 8, + }; + + inline static unsigned flags_autoendian() { + return pfc::byte_order_is_big_endian ? FLAG_BIG_ENDIAN : FLAG_LITTLE_ENDIAN; + } + + void set_data_fixedpoint_ex(const void * ptr,t_size bytes,unsigned p_sample_rate,unsigned p_channels,unsigned p_bits_per_sample,unsigned p_flags,unsigned p_channel_config);//p_flags - see FLAG_* above + + void set_data_floatingpoint_ex(const void * ptr,t_size bytes,unsigned p_sample_rate,unsigned p_channels,unsigned p_bits_per_sample,unsigned p_flags,unsigned p_channel_config);//signed/unsigned flags dont apply + + inline void set_data_32(const float * src,t_size samples,unsigned nch,unsigned srate) {return set_data(src,samples,nch,srate);} + + void pad_with_silence_ex(t_size samples,unsigned hint_nch,unsigned hint_srate); + void pad_with_silence(t_size samples); + void insert_silence_fromstart(t_size samples); + t_size skip_first_samples(t_size samples); + + //! Simple function to get original PCM stream back. Assumes host's endianness, integers are signed - including the 8bit mode; 32bit mode assumed to be float. + //! @returns false when the conversion could not be performed because of unsupported bit depth etc. + bool to_raw_data(class mem_block_container & out, t_uint32 bps) const; + + + //! Helper, calculates peak value of data in the chunk. The optional parameter specifies initial peak value, to simplify calling code. + audio_sample get_peak(audio_sample p_peak) const; + audio_sample get_peak() const; + + //! Helper function; scales entire chunk content by specified value. + void scale(audio_sample p_value); + + //! Helper; copies content of another audio chunk to this chunk. + void copy(const audio_chunk & p_source) { + set_data(p_source.get_data(),p_source.get_sample_count(),p_source.get_channels(),p_source.get_srate(),p_source.get_channel_config()); + } + + const audio_chunk & operator=(const audio_chunk & p_source) { + copy(p_source); + return *this; + } +protected: + audio_chunk() {} + ~audio_chunk() {} +}; + +//! Implementation of audio_chunk. Takes pfc allocator template as template parameter. +template class t_alloc = pfc::alloc_standard> +class audio_chunk_impl_t : public audio_chunk { + typedef audio_chunk_impl_t t_self; + pfc::array_t m_data; + unsigned m_srate,m_nch,m_setup; + t_size m_samples; +public: + audio_chunk_impl_t() : m_srate(0), m_nch(0), m_samples(0), m_setup(0) {} + audio_chunk_impl_t(const audio_sample * src,unsigned samples,unsigned nch,unsigned srate) : m_srate(0), m_nch(0), m_samples(0) + {set_data(src,samples,nch,srate);} + audio_chunk_impl_t(const audio_chunk & p_source) : m_srate(0), m_nch(0), m_samples(0), m_setup(0) {copy(p_source);} + audio_chunk_impl_t(const t_self & p_source) : m_srate(0), m_nch(0), m_samples(0), m_setup(0) {copy(p_source);} + + virtual audio_sample * get_data() {return m_data.get_ptr();} + virtual const audio_sample * get_data() const {return m_data.get_ptr();} + virtual t_size get_data_size() const {return m_data.get_size();} + virtual void set_data_size(t_size new_size) {m_data.set_size(new_size);} + + virtual unsigned get_srate() const {return m_srate;} + virtual void set_srate(unsigned val) {m_srate=val;} + virtual unsigned get_channels() const {return m_nch;} + virtual unsigned get_channel_config() const {return m_setup;} + virtual void set_channels(unsigned val,unsigned setup) {m_nch = val;m_setup = setup;} + void set_channels(unsigned val) {set_channels(val,g_guess_channel_config(val));} + + virtual t_size get_sample_count() const {return m_samples;} + virtual void set_sample_count(t_size val) {m_samples = val;} + + const t_self & operator=(const audio_chunk & p_source) {copy(p_source);return *this;} + const t_self & operator=(const t_self & p_source) {copy(p_source);return *this;} +}; + +typedef audio_chunk_impl_t<> audio_chunk_impl; +typedef audio_chunk_impl_t audio_chunk_impl_temporary; +typedef audio_chunk_impl audio_chunk_i;//for compatibility + +//! Implements const methods of audio_chunk only, referring to an external buffer. For temporary use only (does not maintain own storage), e.g.: somefunc( audio_chunk_temp_impl(mybuffer,....) ); +class audio_chunk_temp_impl : public audio_chunk { +public: + audio_chunk_temp_impl(const audio_sample * p_data,t_size p_samples,t_uint32 p_sample_rate,t_uint32 p_channels,t_uint32 p_channel_config) : + m_data(p_data), m_samples(p_samples), m_sample_rate(p_sample_rate), m_channels(p_channels), m_channel_config(p_channel_config) + { + PFC_ASSERT(is_valid()); + } + + audio_sample * get_data() {throw pfc::exception_not_implemented();} + const audio_sample * get_data() const {return m_data;} + t_size get_data_size() const {return m_samples * m_channels;} + void set_data_size(t_size p_new_size) {throw pfc::exception_not_implemented();} + + unsigned get_srate() const {return m_sample_rate;} + void set_srate(unsigned val) {throw pfc::exception_not_implemented();} + unsigned get_channels() const {return m_channels;} + unsigned get_channel_config() const {return m_channel_config;} + void set_channels(unsigned p_count,unsigned p_config) {throw pfc::exception_not_implemented();} + + t_size get_sample_count() const {return m_samples;} + + void set_sample_count(t_size val) {throw pfc::exception_not_implemented();} + +private: + t_size m_samples; + t_uint32 m_sample_rate,m_channels,m_channel_config; + const audio_sample * m_data; +}; + + + +//! Duration counter class - accumulates duration using sample values, without any kind of rounding error accumulation. +class duration_counter { +public: + duration_counter() : m_offset() { + } + void set(double v) { + m_sampleCounts.remove_all(); + m_offset = v; + } + void reset() { + set(0); + } + + void add(double v) {m_offset += v;} + void subtract(double v) {m_offset -= v;} + + double query() const { + double acc = m_offset; + for(t_map::const_iterator walk = m_sampleCounts.first(); walk.is_valid(); ++walk) { + acc += audio_math::samples_to_time(walk->m_value, walk->m_key); + } + return acc; + } + void add(const audio_chunk & c) { + add(c.get_sample_count(), c.get_sample_rate()); + } + void add(t_uint64 sampleCount, t_uint32 sampleRate) { + PFC_ASSERT( sampleRate > 0 ); + if (sampleRate > 0 && sampleCount > 0) { + m_sampleCounts.find_or_add(sampleRate) += sampleCount; + } + } + void add(const duration_counter & other) { + add(other.m_offset); + for(t_map::const_iterator walk = other.m_sampleCounts.first(); walk.is_valid(); ++walk) { + add(walk->m_value, walk->m_key); + } + } + void subtract(const duration_counter & other) { + subtract(other.m_offset); + for(t_map::const_iterator walk = other.m_sampleCounts.first(); walk.is_valid(); ++walk) { + subtract(walk->m_value, walk->m_key); + } + } + void subtract(t_uint64 sampleCount, t_uint32 sampleRate) { + PFC_ASSERT( sampleRate > 0 ); + if (sampleRate > 0 && sampleCount > 0) { + t_uint64 * val = m_sampleCounts.query_ptr(sampleRate); + if (val == NULL) throw pfc::exception_invalid_params(); + if (*val < sampleCount) throw pfc::exception_invalid_params(); + else if (*val == sampleCount) { + m_sampleCounts.remove(sampleRate); + } else { + *val -= sampleCount; + } + + } + } + void subtract(const audio_chunk & c) { + subtract(c.get_sample_count(), c.get_sample_rate()); + } + template duration_counter & operator+=(const t_source & source) {add(source); return *this;} + template duration_counter & operator-=(const t_source & source) {subtract(source); return *this;} + template duration_counter & operator=(const t_source & source) {reset(); add(source); return *this;} +private: + double m_offset; + typedef pfc::map_t t_map; + t_map m_sampleCounts; +}; + +class audio_chunk_partial_ref : public audio_chunk_temp_impl { +public: + audio_chunk_partial_ref(const audio_chunk & chunk, t_size base, t_size count) : audio_chunk_temp_impl(chunk.get_data() + base * chunk.get_channels(), count, chunk.get_sample_rate(), chunk.get_channels(), chunk.get_channel_config()) {} +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/audio_chunk_channel_config.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/audio_chunk_channel_config.cpp new file mode 100644 index 000000000..16caed4c0 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/audio_chunk_channel_config.cpp @@ -0,0 +1,131 @@ +#include "foobar2000.h" + +#ifdef _WIN32 +#include +#include + +#if 0 +#define SPEAKER_FRONT_LEFT 0x1 +#define SPEAKER_FRONT_RIGHT 0x2 +#define SPEAKER_FRONT_CENTER 0x4 +#define SPEAKER_LOW_FREQUENCY 0x8 +#define SPEAKER_BACK_LEFT 0x10 +#define SPEAKER_BACK_RIGHT 0x20 +#define SPEAKER_FRONT_LEFT_OF_CENTER 0x40 +#define SPEAKER_FRONT_RIGHT_OF_CENTER 0x80 +#define SPEAKER_BACK_CENTER 0x100 +#define SPEAKER_SIDE_LEFT 0x200 +#define SPEAKER_SIDE_RIGHT 0x400 +#define SPEAKER_TOP_CENTER 0x800 +#define SPEAKER_TOP_FRONT_LEFT 0x1000 +#define SPEAKER_TOP_FRONT_CENTER 0x2000 +#define SPEAKER_TOP_FRONT_RIGHT 0x4000 +#define SPEAKER_TOP_BACK_LEFT 0x8000 +#define SPEAKER_TOP_BACK_CENTER 0x10000 +#define SPEAKER_TOP_BACK_RIGHT 0x20000 +#endif + +static struct {DWORD m_wfx; unsigned m_native; } const g_translation_table[] = +{ + {SPEAKER_FRONT_LEFT, audio_chunk::channel_front_left}, + {SPEAKER_FRONT_RIGHT, audio_chunk::channel_front_right}, + {SPEAKER_FRONT_CENTER, audio_chunk::channel_front_center}, + {SPEAKER_LOW_FREQUENCY, audio_chunk::channel_lfe}, + {SPEAKER_BACK_LEFT, audio_chunk::channel_back_left}, + {SPEAKER_BACK_RIGHT, audio_chunk::channel_back_right}, + {SPEAKER_FRONT_LEFT_OF_CENTER, audio_chunk::channel_front_center_left}, + {SPEAKER_FRONT_RIGHT_OF_CENTER, audio_chunk::channel_front_center_right}, + {SPEAKER_BACK_CENTER, audio_chunk::channel_back_center}, + {SPEAKER_SIDE_LEFT, audio_chunk::channel_side_left}, + {SPEAKER_SIDE_RIGHT, audio_chunk::channel_side_right}, + {SPEAKER_TOP_CENTER, audio_chunk::channel_top_center}, + {SPEAKER_TOP_FRONT_LEFT, audio_chunk::channel_top_front_left}, + {SPEAKER_TOP_FRONT_CENTER, audio_chunk::channel_top_front_center}, + {SPEAKER_TOP_FRONT_RIGHT, audio_chunk::channel_top_front_right}, + {SPEAKER_TOP_BACK_LEFT, audio_chunk::channel_top_back_left}, + {SPEAKER_TOP_BACK_CENTER, audio_chunk::channel_top_back_center}, + {SPEAKER_TOP_BACK_RIGHT, audio_chunk::channel_top_back_right}, +}; + + +DWORD audio_chunk::g_channel_config_to_wfx(unsigned p_config) +{ + DWORD ret = 0; + unsigned n; + for(n=0;n= tabsize(g_audio_channel_config_table)) return 0; + return g_audio_channel_config_table[count]; +} + + +unsigned audio_chunk::g_channel_index_from_flag(unsigned p_config,unsigned p_flag) { + unsigned index = 0; + for(unsigned walk = 0; walk < 32; walk++) { + unsigned query = 1 << walk; + if (p_flag & query) return index; + if (p_config & query) index++; + } + return infinite; +} + +unsigned audio_chunk::g_extract_channel_flag(unsigned p_config,unsigned p_index) +{ + unsigned toskip = p_index; + unsigned flag = 1; + while(flag) + { + if (p_config & flag) + { + if (toskip == 0) break; + toskip--; + } + flag <<= 1; + } + return flag; +} + +unsigned audio_chunk::g_count_channels(unsigned p_config) +{ + unsigned ret = 0; + while(p_config) { + ret += (p_config & 1); + p_config >>= 1; + } + return ret; +} diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/audio_postprocessor.h b/tools/vio2sf/src/foobar/foobar2000/SDK/audio_postprocessor.h new file mode 100644 index 000000000..4153d2865 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/audio_postprocessor.h @@ -0,0 +1,25 @@ +//! This class handles conversion of audio data (audio_chunk) to various linear PCM types, with optional dithering. + +class NOVTABLE audio_postprocessor : public service_base +{ +public: + //! Processes one chunk of audio data. + //! @param p_chunk Chunk of audio data to process. + //! @param p_output Receives output linear signed PCM data. + //! @param p_out_bps Desired bit depth of output. + //! @param p_out_bps_physical Desired physical word width of output. Must be either 8, 16, 24 or 32, greater or equal to p_out_bps. This is typically set to same value as p_out_bps. + //! @param p_dither Indicates whether dithering should be used. Note that dithering is CPU-heavy. + //! @param p_prescale Value to scale all audio samples by when converting. Set to 1.0 to do nothing. + + virtual void run(const audio_chunk & p_chunk, + mem_block_container & p_output, + t_uint32 p_out_bps, + t_uint32 p_out_bps_physical, + bool p_dither, + audio_sample p_prescale + ) = 0; + + + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(audio_postprocessor); +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/autoplaylist.h b/tools/vio2sf/src/foobar/foobar2000/SDK/autoplaylist.h new file mode 100644 index 000000000..6417fd375 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/autoplaylist.h @@ -0,0 +1,106 @@ +/* + Autoplaylist APIs + These APIs were introduced in foobar2000 0.9.5, to reduce amount of code required to create your own autoplaylists. Creation of autoplaylists is was also possible before through playlist lock APIs. + In most cases, you'll want to turn regular playlists into autoplaylists using the following code: + static_api_ptr_t()->add_client_simple(querypattern, sortpattern, playlistindex, forceSort ? autoplaylist_flag_sort : 0); + If you require more advanced functionality, such as using your own code to filter which part of user's Media Library should be placed in specific autoplaylist, you must implement autoplaylist_client (to let autoplaylist manager invoke your handlers when needed) / autoplaylist_client_factory (to re-instantiate your autoplaylist_client after a foobar2000 restart cycle). +*/ + +enum { + //! When set, core will keep the autoplaylist sorted and prevent user from reordering it. + autoplaylist_flag_sort = 1 << 0, +}; +//! Main class controlling autoplaylist behaviors. Implemented by autoplaylist client in scenarios where simple query/sort strings are not enough (core provides a standard implementation for simple queries). +class NOVTABLE autoplaylist_client : public service_base { +public: + virtual GUID get_guid() = 0; + //! Called only inside a metadb lock for performance reasons. + virtual void filter(metadb_handle_list_cref data, bool * out) = 0; + //! Return true when you have filled p_orderbuffer with a permutation to apply to p_items, false when you don't support sorting (core's own sort scheme will be applied). + virtual bool sort(metadb_handle_list_cref p_items,t_size * p_orderbuffer) = 0; + //! Retrieves your configuration data to be used later when re-instantiating your autoplaylist_client after a restart. + virtual void get_configuration(stream_writer * p_stream,abort_callback & p_abort) = 0; + + virtual void show_ui(t_size p_source_playlist) = 0; + + //! Helper. + template void get_configuration(t_array & p_out) { + pfc::static_assert(); + typedef pfc::array_t t_temp; t_temp temp; + get_configuration(&stream_writer_buffer_append_ref_t(temp),abort_callback_impl()); + p_out = temp; + } + + + FB2K_MAKE_SERVICE_INTERFACE(autoplaylist_client,service_base) +}; + +typedef service_ptr_t autoplaylist_client_ptr; + +//! Supported from 0.9.5.3 up. +class NOVTABLE autoplaylist_client_v2 : public autoplaylist_client { +public: + //! Sets a completion_notify object that the autoplaylist_client implementation should call when its filtering behaviors have changed so the whole playlist needs to be rebuilt. \n + //! completion_notify::on_completion() status parameter meaning: \n + //! 0.9.5.3 : ignored. \n + //! 0.9.5.4 and newer: set to 1 to indicate that your configuration has changed as well (for an example as a result of user edits) to get a get_configuration() call as well as cause the playlist to be rebuilt; set to zero otherwise - when the configuration hasn't changed but the playlist needs to be rebuilt as a result of some other event. + virtual void set_full_refresh_notify(completion_notify::ptr notify) = 0; + + //! Returns whether the show_ui() method is available / does anything useful with out implementation (not everyone implements show_ui). + virtual bool show_ui_available() = 0; + + //! Returns a human-readable autoplaylist implementer's label to display in playlist's context menu / description / etc. + virtual void get_display_name(pfc::string_base & out) = 0; + + FB2K_MAKE_SERVICE_INTERFACE(autoplaylist_client_v2, autoplaylist_client); +}; + +//! Class needed to re-instantiate autoplaylist_client after a restart. Not directly needed to set up an autoplaylist_client, but without it, your autoplaylist will be lost after a restart. +class NOVTABLE autoplaylist_client_factory : public service_base { +public: + //! Must return same GUID as your autoplaylist_client::get_guid() + virtual GUID get_guid() = 0; + //! Instantiates your autoplaylist_client with specified configuration. + virtual autoplaylist_client_ptr instantiate(stream_reader * p_stream,t_size p_sizehint,abort_callback & p_abort) = 0; + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(autoplaylist_client_factory) +}; + +PFC_DECLARE_EXCEPTION(exception_autoplaylist,pfc::exception,"Autoplaylist error") + +PFC_DECLARE_EXCEPTION(exception_autoplaylist_already_owned,exception_autoplaylist,"This playlist is already an autoplaylist") +PFC_DECLARE_EXCEPTION(exception_autoplaylist_not_owned,exception_autoplaylist,"This playlist is not an autoplaylist") +PFC_DECLARE_EXCEPTION(exception_autoplaylist_lock_failure,exception_autoplaylist,"Playlist could not be locked") + + +//! Primary class for managing autoplaylists. Implemented by core, do not reimplement; instantiate using static_api_ptr_t. +class NOVTABLE autoplaylist_manager : public service_base { +public: + //! Throws exception_autoplaylist or one of its subclasses on failure. + //! @param p_flags See autoplaylist_flag_* constants. + virtual void add_client(autoplaylist_client_ptr p_client,t_size p_playlist,t_uint32 p_flags) = 0; + virtual bool is_client_present(t_size p_playlist) = 0; + //! Throws exception_autoplaylist or one of its subclasses on failure (eg. not an autoplaylist). + virtual autoplaylist_client_ptr query_client(t_size p_playlist) = 0; + virtual void remove_client(t_size p_playlist) = 0; + //! Helper; sets up an autoplaylist using standard autoplaylist_client implementation based on simple query/sort strings. When using this, you don't need to maintain own autoplaylist_client/autoplaylist_client_factory implementations, and autoplaylists that you create will not be lost when your DLL is removed, as opposed to using add_client() directly. + //! Throws exception_autoplaylist or one of its subclasses on failure. + //! @param p_flags See autoplaylist_flag_* constants. + virtual void add_client_simple(const char * p_query,const char * p_sort,t_size p_playlist,t_uint32 p_flags) = 0; + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(autoplaylist_manager) +}; + +//! \since 0.9.5.4 +//! Extended version of autoplaylist_manager, available from 0.9.5.4 up, with methods allowing modification of autoplaylist flags. +class NOVTABLE autoplaylist_manager_v2 : public autoplaylist_manager { + FB2K_MAKE_SERVICE_INTERFACE(autoplaylist_manager_v2, autoplaylist_manager) +public: + virtual t_uint32 get_client_flags(t_size playlist) = 0; + virtual void set_client_flags(t_size playlist, t_uint32 newFlags) = 0; + + //! For use with autoplaylist client configuration dialogs. It's recommended not to call this from anything else. + virtual t_uint32 get_client_flags(autoplaylist_client::ptr client) = 0; + //! For use with autoplaylist client configuration dialogs. It's recommended not to call this from anything else. + virtual void set_client_flags(autoplaylist_client::ptr client, t_uint32 newFlags) = 0; +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/cfg_var.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/cfg_var.cpp new file mode 100644 index 000000000..b37401416 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/cfg_var.cpp @@ -0,0 +1,57 @@ +#include "foobar2000.h" + +cfg_var_reader * cfg_var_reader::g_list = NULL; +cfg_var_writer * cfg_var_writer::g_list = NULL; + +void cfg_var_reader::config_read_file(stream_reader * p_stream,abort_callback & p_abort) +{ + pfc::map_t vars; + for(cfg_var_reader * walk = g_list; walk != NULL; walk = walk->m_next) { + vars.set(walk->m_guid,walk); + } + for(;;) { + + GUID guid; + t_uint32 size; + + if (p_stream->read(&guid,sizeof(guid),p_abort) != sizeof(guid)) break; + guid = pfc::byteswap_if_be_t(guid); + p_stream->read_lendian_t(size,p_abort); + + cfg_var_reader * var; + if (vars.query(guid,var)) { + stream_reader_limited_ref wrapper(p_stream,size); + try { + var->set_data_raw(&wrapper,size,p_abort); + } catch(exception_io_data) {} + wrapper.flush_remaining(p_abort); + } else { + p_stream->skip_object(size,p_abort); + } + } +} + +void cfg_var_writer::config_write_file(stream_writer * p_stream,abort_callback & p_abort) { + cfg_var_writer * ptr; + pfc::array_t temp; + for(ptr = g_list; ptr; ptr = ptr->m_next) { + temp.set_size(0); + ptr->get_data_raw(&stream_writer_buffer_append_ref_t >(temp),p_abort); + p_stream->write_lendian_t(ptr->m_guid,p_abort); + p_stream->write_lendian_t(pfc::downcast_guarded(temp.get_size()),p_abort); + if (temp.get_size() > 0) { + p_stream->write_object(temp.get_ptr(),temp.get_size(),p_abort); + } + } +} + + +void cfg_string::get_data_raw(stream_writer * p_stream,abort_callback & p_abort) { + p_stream->write_object(get_ptr(),length(),p_abort); +} + +void cfg_string::set_data_raw(stream_reader * p_stream,t_size p_sizehint,abort_callback & p_abort) { + pfc::string8_fastalloc temp; + p_stream->read_string_raw(temp,p_abort); + set_string(temp); +} diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/cfg_var.h b/tools/vio2sf/src/foobar/foobar2000/SDK/cfg_var.h new file mode 100644 index 000000000..e3f00388e --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/cfg_var.h @@ -0,0 +1,235 @@ +#ifndef _FOOBAR2000_SDK_CFG_VAR_H_ +#define _FOOBAR2000_SDK_CFG_VAR_H_ + +#define CFG_VAR_ASSERT_SAFEINIT PFC_ASSERT(!core_api::are_services_available());/*imperfect check for nonstatic instantiation*/ + + +//! Reader part of cfg_var object. In most cases, you should use cfg_var instead of using cfg_var_reader directly. +class NOVTABLE cfg_var_reader { +public: + //! @param p_guid GUID of the variable, used to identify variable implementations owning specific configuration file entries when reading the configuration file back. You must generate a new GUID every time you declare a new cfg_var. + cfg_var_reader(const GUID & guid) : m_guid(guid) { CFG_VAR_ASSERT_SAFEINIT; m_next = g_list; g_list = this; } + ~cfg_var_reader() { CFG_VAR_ASSERT_SAFEINIT; } + + //! Sets state of the variable. Called only from main thread, when reading configuration file. + //! @param p_stream Stream containing new state of the variable. + //! @param p_sizehint Number of bytes contained in the stream; reading past p_sizehint bytes will fail (EOF). + virtual void set_data_raw(stream_reader * p_stream,t_size p_sizehint,abort_callback & p_abort) = 0; + + //! For internal use only, do not call. + static void config_read_file(stream_reader * p_stream,abort_callback & p_abort); + + const GUID m_guid; +private: + static cfg_var_reader * g_list; + cfg_var_reader * m_next; + + PFC_CLASS_NOT_COPYABLE_EX(cfg_var_reader) +}; + +//! Writer part of cfg_var object. In most cases, you should use cfg_var instead of using cfg_var_writer directly. +class NOVTABLE cfg_var_writer { +public: + //! @param p_guid GUID of the variable, used to identify variable implementations owning specific configuration file entries when reading the configuration file back. You must generate a new GUID every time you declare a new cfg_var. + cfg_var_writer(const GUID & guid) : m_guid(guid) { CFG_VAR_ASSERT_SAFEINIT; m_next = g_list; g_list = this;} + ~cfg_var_writer() { CFG_VAR_ASSERT_SAFEINIT; } + + //! Retrieves state of the variable. Called only from main thread, when writing configuration file. + //! @param p_stream Stream receiving state of the variable. + virtual void get_data_raw(stream_writer * p_stream,abort_callback & p_abort) = 0; + + //! For internal use only, do not call. + static void config_write_file(stream_writer * p_stream,abort_callback & p_abort); + + const GUID m_guid; +private: + static cfg_var_writer * g_list; + cfg_var_writer * m_next; + + PFC_CLASS_NOT_COPYABLE_EX(cfg_var_writer) +}; + +//! Base class for configuration variable classes; provides self-registration mechaisms and methods to set/retrieve configuration data; those methods are automatically called for all registered instances by backend when configuration file is being read or written.\n +//! Note that cfg_var class and its derivatives may be only instantiated statically (as static objects or members of other static objects), NEVER dynamically (operator new, local variables, members of objects instantiated as such). +class NOVTABLE cfg_var : public cfg_var_reader, public cfg_var_writer { +protected: + //! @param p_guid GUID of the variable, used to identify variable implementations owning specific configuration file entries when reading the configuration file back. You must generate a new GUID every time you declare a new cfg_var. + cfg_var(const GUID & p_guid) : cfg_var_reader(p_guid), cfg_var_writer(p_guid) {} +public: + GUID get_guid() const {return cfg_var_reader::m_guid;} +}; + +//! Generic integer config variable class. Template parameter can be used to specify integer type to use.\n +//! Note that cfg_var class and its derivatives may be only instantiated statically (as static objects or members of other static objects), NEVER dynamically (operator new, local variables, members of objects instantiated as such). +template +class cfg_int_t : public cfg_var { +private: + t_inttype m_val; +protected: + void get_data_raw(stream_writer * p_stream,abort_callback & p_abort) {p_stream->write_lendian_t(m_val,p_abort);} + void set_data_raw(stream_reader * p_stream,t_size p_sizehint,abort_callback & p_abort) { + t_inttype temp; + p_stream->read_lendian_t(temp,p_abort);//alter member data only on success, this will throw an exception when something isn't right + m_val = temp; + } + +public: + //! @param p_guid GUID of the variable, used to identify variable implementations owning specific configuration file entries when reading the configuration file back. You must generate a new GUID every time you declare a new cfg_var. + //! @param p_default Default value of the variable. + explicit inline cfg_int_t(const GUID & p_guid,t_inttype p_default) : cfg_var(p_guid), m_val(p_default) {} + + inline const cfg_int_t & operator=(const cfg_int_t & p_val) {m_val=p_val.m_val;return *this;} + inline t_inttype operator=(t_inttype p_val) {m_val=p_val;return m_val;} + + inline operator t_inttype() const {return m_val;} + + inline t_inttype get_value() const {return m_val;} +}; + +typedef cfg_int_t cfg_int; +typedef cfg_int_t cfg_uint; +//! Since relevant byteswapping functions also understand GUIDs, this can be abused to declare a cfg_guid. +typedef cfg_int_t cfg_guid; +typedef cfg_int_t cfg_bool; + +//! String config variable. Stored in the stream with int32 header containing size in bytes, followed by non-null-terminated UTF-8 data.\n +//! Note that cfg_var class and its derivatives may be only instantiated statically (as static objects or members of other static objects), NEVER dynamically (operator new, local variables, members of objects instantiated as such). +class cfg_string : public cfg_var, public pfc::string8 +{ +protected: + void get_data_raw(stream_writer * p_stream,abort_callback & p_abort); + void set_data_raw(stream_reader * p_stream,t_size p_sizehint,abort_callback & p_abort); + +public: + //! @param p_guid GUID of the variable, used to identify variable implementations owning specific configuration file entries when reading the configuration file back. You must generate a new GUID every time you declare a new cfg_var. + //! @param p_defaultval Default/initial value of the variable. + explicit inline cfg_string(const GUID & p_guid,const char * p_defaultval) : cfg_var(p_guid), pfc::string8(p_defaultval) {} + + inline const cfg_string& operator=(const cfg_string & p_val) {set_string(p_val);return *this;} + inline const cfg_string& operator=(const char* p_val) {set_string(p_val);return *this;} + + inline operator const char * () const {return get_ptr();} + +}; + +//! Struct config variable template. Warning: not endian safe, should be used only for nonportable code.\n +//! Note that cfg_var class and its derivatives may be only instantiated statically (as static objects or members of other static objects), NEVER dynamically (operator new, local variables, members of objects instantiated as such). +template +class cfg_struct_t : public cfg_var { +private: + t_struct m_val; +protected: + + void get_data_raw(stream_writer * p_stream,abort_callback & p_abort) {p_stream->write_object(&m_val,sizeof(m_val),p_abort);} + void set_data_raw(stream_reader * p_stream,t_size p_sizehint,abort_callback & p_abort) { + t_struct temp; + p_stream->read_object(&temp,sizeof(temp),p_abort); + m_val = temp; + } +public: + //! @param p_guid GUID of the variable, used to identify variable implementations owning specific configuration file entries when reading the configuration file back. You must generate a new GUID every time you declare a new cfg_var. + inline cfg_struct_t(const GUID & p_guid,const t_struct & p_val) : cfg_var(p_guid), m_val(p_val) {} + //! @param p_guid GUID of the variable, used to identify variable implementations owning specific configuration file entries when reading the configuration file back. You must generate a new GUID every time you declare a new cfg_var. + inline cfg_struct_t(const GUID & p_guid,int filler) : cfg_var(p_guid) {memset(&m_val,filler,sizeof(t_struct));} + + inline const cfg_struct_t & operator=(const cfg_struct_t & p_val) {m_val = p_val.get_value();return *this;} + inline const cfg_struct_t & operator=(const t_struct & p_val) {m_val = p_val;return *this;} + + inline const t_struct& get_value() const {return m_val;} + inline t_struct& get_value() {return m_val;} + inline operator t_struct() const {return m_val;} +}; + + +template +class cfg_objList : public cfg_var, public pfc::list_t { +public: + cfg_objList(const GUID& guid) : cfg_var(guid) {} + template cfg_objList(const GUID& guid, const TSource (& source)[Count]) : cfg_var(guid) { + reset(source); + } + template void reset(const TSource (& source)[Count]) { + set_size(Count); for(t_size walk = 0; walk < Count; ++walk) (*this)[walk] = source[walk]; + } + void get_data_raw(stream_writer * p_stream,abort_callback & p_abort) { + stream_writer_formatter<> out(*p_stream,p_abort); + out << pfc::downcast_guarded(get_size()); + for(t_size walk = 0; walk < get_size(); ++walk) out << (*this)[walk]; + } + void set_data_raw(stream_reader * p_stream,t_size p_sizehint,abort_callback & p_abort) { + try { + stream_reader_formatter<> in(*p_stream,p_abort); + t_uint32 count; in >> count; + set_count(count); + for(t_uint32 walk = 0; walk < count; ++walk) in >> (*this)[walk]; + } catch(...) { + remove_all(); + throw; + } + } +}; +template +class cfg_objListEx : public cfg_var, public TList { +public: + cfg_objListEx(const GUID & guid) : cfg_var(guid) {} + void get_data_raw(stream_writer * p_stream, abort_callback & p_abort) { + stream_writer_formatter<> out(*p_stream,p_abort); + out << pfc::downcast_guarded(this->get_count()); + for(typename TList::const_iterator walk = this->first(); walk.is_valid(); ++walk) out << *walk; + } + void set_data_raw(stream_reader * p_stream,t_size p_sizehint,abort_callback & p_abort) { + remove_all(); + stream_reader_formatter<> in(*p_stream,p_abort); + t_uint32 count; in >> count; + for(t_uint32 walk = 0; walk < count; ++walk) { + typename TList::t_item item; in >> item; this->add_item(item); + } + } +}; + +template +class cfg_obj : public cfg_var, public TObj { +public: + cfg_obj(const GUID& guid) : cfg_var(guid), TObj() {} + template cfg_obj(const GUID& guid,const TInitData& initData) : cfg_var(guid), TObj(initData) {} + + TObj & val() {return *this;} + TObj const & val() const {return *this;} + + void get_data_raw(stream_writer * p_stream,abort_callback & p_abort) { + stream_writer_formatter<> out(*p_stream,p_abort); + const TObj * ptr = this; + out << *ptr; + } + void set_data_raw(stream_reader * p_stream,t_size p_sizehint,abort_callback & p_abort) { + stream_reader_formatter<> in(*p_stream,p_abort); + TObj * ptr = this; + in >> *ptr; + } +}; + +template class cfg_objListImporter : private cfg_var_reader { +public: + typedef cfg_objList TMasterVar; + cfg_objListImporter(TMasterVar & var, const GUID & guid) : m_var(var), cfg_var_reader(guid) {} + +private: + void set_data_raw(stream_reader * p_stream,t_size p_sizehint,abort_callback & p_abort) { + TImport temp; + try { + stream_reader_formatter<> in(*p_stream,p_abort); + t_uint32 count; in >> count; + m_var.set_count(count); + for(t_uint32 walk = 0; walk < count; ++walk) { + in >> temp; + m_var[walk] = temp; + } + } catch(...) { + m_var.remove_all(); + throw; + } + } + TMasterVar & m_var; +}; + +#endif diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/chapterizer.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/chapterizer.cpp new file mode 100644 index 000000000..e933088d1 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/chapterizer.cpp @@ -0,0 +1,24 @@ +#include "foobar2000.h" + +void chapter_list::copy(const chapter_list & p_source) +{ + t_size n, count = p_source.get_chapter_count(); + set_chapter_count(count); + for(n=0;n & p_out,const char * p_path,abort_callback & p_abort) +{ + service_ptr_t ptr; + service_enum_t e; + while(e.next(ptr)) + { + if (ptr->is_our_file(p_path,p_abort)) + { + p_out = ptr; + return true; + } + } + return false; +} \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/chapterizer.h b/tools/vio2sf/src/foobar/foobar2000/SDK/chapterizer.h new file mode 100644 index 000000000..0e340aecd --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/chapterizer.h @@ -0,0 +1,72 @@ +//! Interface for object storing list of chapters. +class NOVTABLE chapter_list { +public: + //! Returns number of chapters. + virtual t_size get_chapter_count() const = 0; + //! Queries description of specified chapter. + //! @param p_chapter Index of chapter to query, greater or equal zero and less than get_chapter_count() value. If p_chapter value is out of valid range, results are undefined (e.g. crash). + //! @returns reference to file_info object describing specified chapter (length part of file_info indicates distance between beginning of this chapter and next chapter mark). Returned reference value for temporary use only, becomes invalid after any non-const operation on the chapter_list object. + virtual const file_info & get_info(t_size p_chapter) const = 0; + + //! Sets number of chapters. + virtual void set_chapter_count(t_size p_count) = 0; + //! Modifies description of specified chapter. + //! @param p_chapter_index Index of chapter to modify, greater or equal zero and less than get_chapter_count() value. If p_chapter value is out of valid range, results are undefined (e.g. crash). + //! @param p_info New chapter description. Note that length part of file_info is used to calculate chapter marks. + virtual void set_info(t_size p_chapter,const file_info & p_info) = 0; + + //! Copies contents of specified chapter_list object to this object. + void copy(const chapter_list & p_source); + + inline const chapter_list & operator=(const chapter_list & p_source) {copy(p_source); return *this;} + +protected: + chapter_list() {} + ~chapter_list() {} +}; + +//! Implements chapter_list. +class chapter_list_impl : public chapter_list +{ +public: + chapter_list_impl(const chapter_list_impl & p_source) {copy(p_source);} + chapter_list_impl(const chapter_list & p_source) {copy(p_source);} + chapter_list_impl() {} + + const chapter_list_impl & operator=(const chapter_list_impl & p_source) {copy(p_source); return *this;} + const chapter_list_impl & operator=(const chapter_list & p_source) {copy(p_source); return *this;} + + t_size get_chapter_count() const {return m_infos.get_size();} + const file_info & get_info(t_size p_chapter) const {return m_infos[p_chapter];} + + void set_chapter_count(t_size p_count) {m_infos.set_size(p_count);} + void set_info(t_size p_chapter,const file_info & p_info) {m_infos[p_chapter] = p_info;} +private: + pfc::array_t m_infos; +}; + + +//! This service implements chapter list editing operations for various file formats, e.g. for MP4 chapters or CD images with embedded cuesheets. Used by converter "encode single file with chapters" feature. +class NOVTABLE chapterizer : public service_base { +public: + //! Tests whether specified path is supported by this implementation. + //! @param p_path Path of file to examine. + //! @param p_abort abort_callback object signaling user aborting the operation. + virtual bool is_our_file(const char * p_path,abort_callback & p_abort) = 0; + + //! Writes new chapter list to specified file. + //! @param p_path Path of file to modify. + //! @param p_list New chapter list to write. + //! @param p_abort abort_callback object signaling user aborting the operation. + virtual void set_chapters(const char * p_path,chapter_list const & p_list,abort_callback & p_abort) = 0; + //! Retrieves chapter list from specified file. + //! @param p_path Path of file to examine. + //! @param p_list Object receiving chapter list. + //! @param p_abort abort_callback object signaling user aborting the operation. + virtual void get_chapters(const char * p_path,chapter_list & p_list,abort_callback & p_abort) = 0; + + //! Static helper, tries to find chapterizer interface that supports specified file. + static bool g_find(service_ptr_t & p_out,const char * p_path,abort_callback & p_abort); + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(chapterizer); +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/commandline.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/commandline.cpp new file mode 100644 index 000000000..34708c3dd --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/commandline.cpp @@ -0,0 +1,24 @@ +#include "foobar2000.h" + +void commandline_handler_metadb_handle::on_file(const char * url) +{ + + abort_callback_dummy blah; + + { + playlist_loader_callback_impl callback(blah); + + bool fail = false; + try { + playlist_loader::g_process_path_ex(url,callback); + } catch(std::exception const & e) { + console::complain("Unhandled exception in playlist loader", e); + fail = true; + } + + if (!fail) { + t_size n,m=callback.get_count(); + for(n=0;n on_token() => deletion + scenario #2: + creation => on_token() returning RESULT_PROCESSED_EXPECT_FILES => on_file(), on_file().... => on_files_done() => deletion +*/ + +template +class commandline_handler_factory_t : public service_factory_t {}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/completion_notify.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/completion_notify.cpp new file mode 100644 index 000000000..0a183a8b0 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/completion_notify.cpp @@ -0,0 +1,25 @@ +#include "foobar2000.h" + +namespace { + class main_thread_callback_myimpl : public main_thread_callback { + public: + void callback_run() { + m_notify->on_completion(m_code); + } + + main_thread_callback_myimpl(completion_notify_ptr p_notify,unsigned p_code) : m_notify(p_notify), m_code(p_code) {} + private: + completion_notify_ptr m_notify; + unsigned m_code; + }; +} + +void completion_notify::g_signal_completion_async(completion_notify_ptr p_notify,unsigned p_code) { + if (p_notify.is_valid()) { + static_api_ptr_t()->add_callback(new service_impl_t(p_notify,p_code)); + } +} + +void completion_notify::on_completion_async(unsigned p_code) { + static_api_ptr_t()->add_callback(new service_impl_t(this,p_code)); +} \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/completion_notify.h b/tools/vio2sf/src/foobar/foobar2000/SDK/completion_notify.h new file mode 100644 index 000000000..f16c57361 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/completion_notify.h @@ -0,0 +1,89 @@ +//! Generic service for receiving notifications about async operation completion. Used by various other services. +class completion_notify : public service_base { +public: + //! Called when an async operation has been completed. Note that on_completion is always called from main thread. You can use on_completion_async() helper if you need to signal completion while your context is in another thread.\n + //! IMPLEMENTATION WARNING: If process being completed creates a window taking caller's window as parent, you must not destroy the parent window inside on_completion(). If you need to do so, use PostMessage() or main_thread_callback to delay the deletion. + //! @param p_code Context-specific status code. Possible values depend on the operation being performed. + virtual void on_completion(unsigned p_code) = 0; + + //! Helper. Queues a notification, using main_thread_callback. + void on_completion_async(unsigned p_code); + + //! Helper. Checks for null ptr and calls on_completion_async when the ptr is not null. + static void g_signal_completion_async(service_ptr_t p_notify,unsigned p_code); + + FB2K_MAKE_SERVICE_INTERFACE(completion_notify,service_base); +}; + +//! Implementation helper. +class completion_notify_dummy : public completion_notify { +public: + void on_completion(unsigned p_code) {} +}; + +//! Implementation helper. +class completion_notify_orphanable : public completion_notify { +public: + virtual void orphan() = 0; +}; + +//! Helper implementation. +//! IMPLEMENTATION WARNING: If process being completed creates a window taking caller's window as parent, you must not destroy the parent window inside on_task_completion(). If you need to do so, use PostMessage() or main_thread_callback to delay the deletion. +template +class completion_notify_impl : public completion_notify_orphanable { +public: + void on_completion(unsigned p_code) { + if (m_receiver != NULL) { + m_receiver->on_task_completion(m_taskid,p_code); + } + } + void setup(t_receiver * p_receiver, unsigned p_task_id) {m_receiver = p_receiver; m_taskid = p_task_id;} + void orphan() {m_receiver = NULL; m_taskid = 0;} +private: + t_receiver * m_receiver; + unsigned m_taskid; +}; + +template +service_ptr_t completion_notify_create(t_receiver * p_receiver,unsigned p_taskid) { + service_ptr_t > instance = new service_impl_t >(); + instance->setup(p_receiver,p_taskid); + return instance; +} + +typedef service_ptr_t completion_notify_ptr; +typedef service_ptr_t completion_notify_orphanable_ptr; + +//! Helper base class for classes that manage nonblocking tasks and get notified back thru completion_notify interface. +class completion_notify_receiver { +public: + completion_notify_ptr create_task(unsigned p_id) { + completion_notify_orphanable_ptr ptr; + if (m_tasks.query(p_id,ptr)) ptr->orphan(); + ptr = completion_notify_create(this,p_id); + m_tasks.set(p_id,ptr); + return ptr; + } + bool have_task(unsigned p_id) const { + return m_tasks.have_item(p_id); + } + void orphan_task(unsigned p_id) { + completion_notify_orphanable_ptr ptr; + if (m_tasks.query(p_id,ptr)) { + ptr->orphan(); + m_tasks.remove(p_id); + } + } + ~completion_notify_receiver() { + orphan_all_tasks(); + } + void orphan_all_tasks() { + m_tasks.enumerate(orphanfunc); + m_tasks.remove_all(); + } + + virtual void on_task_completion(unsigned p_id,unsigned p_status) {} +private: + static void orphanfunc(unsigned,completion_notify_orphanable_ptr p_item) {p_item->orphan();} + pfc::map_t m_tasks; +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/component.h b/tools/vio2sf/src/foobar/foobar2000/SDK/component.h new file mode 100644 index 000000000..7ae5cc556 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/component.h @@ -0,0 +1,44 @@ +#ifndef _COMPONENT_H_ +#define _COMPONENT_H_ + +#include "foobar2000.h" + +class NOVTABLE foobar2000_client +{ +public: + typedef service_factory_base* pservice_factory_base; + + enum {FOOBAR2000_CLIENT_VERSION_COMPATIBLE = 70, FOOBAR2000_CLIENT_VERSION = 73}; //changes everytime global compatibility is broken + virtual t_uint32 FB2KAPI get_version() = 0; + virtual pservice_factory_base FB2KAPI get_service_list() = 0; + + virtual void FB2KAPI get_config(stream_writer * p_stream,abort_callback & p_abort) = 0; + virtual void FB2KAPI set_config(stream_reader * p_stream,abort_callback & p_abort) = 0; + virtual void FB2KAPI set_library_path(const char * path,const char * name) = 0; + virtual void FB2KAPI services_init(bool val) = 0; + virtual bool is_debug() = 0; +protected: + foobar2000_client() {} + ~foobar2000_client() {} +}; + +class NOVTABLE foobar2000_api +{ +public: + virtual service_class_ref FB2KAPI service_enum_find_class(const GUID & p_guid) = 0; + virtual bool FB2KAPI service_enum_create(service_ptr_t & p_out,service_class_ref p_class,t_size p_index) = 0; + virtual t_size FB2KAPI service_enum_get_count(service_class_ref p_class) = 0; + virtual HWND FB2KAPI get_main_window()=0; + virtual bool FB2KAPI assert_main_thread()=0; + virtual bool FB2KAPI is_main_thread()=0; + virtual bool FB2KAPI is_shutting_down()=0; + virtual pcchar FB2KAPI get_profile_path()=0; + virtual bool FB2KAPI is_initializing() = 0; +protected: + foobar2000_api() {} + ~foobar2000_api() {} +}; + +extern foobar2000_api * g_api; + +#endif diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/component_client.h b/tools/vio2sf/src/foobar/foobar2000/SDK/component_client.h new file mode 100644 index 000000000..46aa84888 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/component_client.h @@ -0,0 +1,6 @@ +#ifndef _COMPONENT_CLIENT_H_ +#define _COMPONENT_CLIENT_H_ + + + +#endif //_COMPONENT_CLIENT_H_ \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/components_menu.h b/tools/vio2sf/src/foobar/foobar2000/SDK/components_menu.h new file mode 100644 index 000000000..835237331 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/components_menu.h @@ -0,0 +1,7 @@ +#ifndef _COMPONENTS_MENU_H_ +#define _COMPONENTS_MENU_H_ + +#error deprecated, see menu_item.h + + +#endif \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/componentversion.h b/tools/vio2sf/src/foobar/foobar2000/SDK/componentversion.h new file mode 100644 index 000000000..85ba58924 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/componentversion.h @@ -0,0 +1,56 @@ +//! Entrypoint interface for declaring component's version information. Instead of implementing this directly, use DECLARE_COMPONENT_VERSION(). +class NOVTABLE componentversion : public service_base { +public: + virtual void get_file_name(pfc::string_base & out)=0; + virtual void get_component_name(pfc::string_base & out)=0; + virtual void get_component_version(pfc::string_base & out)=0; + virtual void get_about_message(pfc::string_base & out)=0;//about message uses "\n" for line separators + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(componentversion); +}; + +//! Implementation helper. +class componentversion_impl_simple : public componentversion { + const char * name,*version,*about; +public: + //do not derive/override + virtual void get_file_name(pfc::string_base & out) {out.set_string(core_api::get_my_file_name());} + virtual void get_component_name(pfc::string_base & out) {out.set_string(name?name:"");} + virtual void get_component_version(pfc::string_base & out) {out.set_string(version?version:"");} + virtual void get_about_message(pfc::string_base & out) {out.set_string(about?about:"");} + explicit componentversion_impl_simple(const char * p_name,const char * p_version,const char * p_about) : name(p_name), version(p_version), about(p_about ? p_about : "") {} +}; + +//! Implementation helper. +class componentversion_impl_copy : public componentversion { + pfc::string8 name,version,about; +public: + //do not derive/override + virtual void get_file_name(pfc::string_base & out) {out.set_string(core_api::get_my_file_name());} + virtual void get_component_name(pfc::string_base & out) {out.set_string(name);} + virtual void get_component_version(pfc::string_base & out) {out.set_string(version);} + virtual void get_about_message(pfc::string_base & out) {out.set_string(about);} + explicit componentversion_impl_copy(const char * p_name,const char * p_version,const char * p_about) : name(p_name), version(p_version), about(p_about ? p_about : "") {} +}; + +typedef service_factory_single_transparent_t __componentversion_impl_simple_factory; +typedef service_factory_single_transparent_t __componentversion_impl_copy_factory; + +class componentversion_impl_simple_factory : public __componentversion_impl_simple_factory { +public: + componentversion_impl_simple_factory(const char * p_name,const char * p_version,const char * p_about) : __componentversion_impl_simple_factory(p_name,p_version,p_about) {} +}; + +class componentversion_impl_copy_factory : public __componentversion_impl_copy_factory { +public: + componentversion_impl_copy_factory(const char * p_name,const char * p_version,const char * p_about) : __componentversion_impl_copy_factory(p_name,p_version,p_about) {} +}; + +//! Use this to declare your component's version information. Parameters must ba plain const char * string constants. The ABOUT string can be NULL if you don't provide any information to show in the "About" dialog. \n +//! Example: DECLARE_COMPONENT_VERSION("blah","v1.337",NULL) +#define DECLARE_COMPONENT_VERSION(NAME,VERSION,ABOUT) \ + static componentversion_impl_simple_factory g_componentversion_service(NAME,VERSION,ABOUT); + +//! Same as DECLARE_COMPONENT_VERSION(), but parameters can be dynamically generated strings rather than compile-time constants. +#define DECLARE_COMPONENT_VERSION_COPY(NAME,VERSION,ABOUT) \ + static componentversion_impl_copy_factory g_componentversion_service(NAME,VERSION,ABOUT); diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/config_io_callback.h b/tools/vio2sf/src/foobar/foobar2000/SDK/config_io_callback.h new file mode 100644 index 000000000..16474a458 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/config_io_callback.h @@ -0,0 +1,15 @@ +//! Implementing this interface lets you maintain your own configuration files rather than depending on the cfg_var system. \n +//! Note that you must not make assumptions about what happens first: config_io_callback::on_read(), initialization of cfg_var values or config_io_callback::on_read() in other components. Order of these things is undefined and will change with each run. \n +//! Use service_factory_single_t to register your implementations. Do not call other people's implementations, core is responsible for doing that when appropriate. +class NOVTABLE config_io_callback : public service_base { +public: + //! Called on startup. You can read your configuration file from here. \n + //! Hint: use core_api::get_profile_path() to retrieve the path of the folder where foobar2000 configuration files are stored. + virtual void on_read() = 0; + //! Called on shutdown. You can write your configuration file from here. + //! Hint: use core_api::get_profile_path() to retrieve the path of the folder where foobar2000 configuration files are stored. + //! @param reset If set to true, our configuration is being reset, so you should wipe your files rather than rewrite them with current configuration. + virtual void on_write(bool reset) = 0; + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(config_io_callback); +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/config_object.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/config_object.cpp new file mode 100644 index 000000000..058c664c0 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/config_object.cpp @@ -0,0 +1,206 @@ +#include "foobar2000.h" + +void config_object_notify_manager::g_on_changed(const service_ptr_t & p_object) +{ + if (core_api::assert_main_thread()) + { + service_enum_t e; + service_ptr_t ptr; + while(e.next(ptr)) + ptr->on_changed(p_object); + } +} + +bool config_object::g_find(service_ptr_t & p_out,const GUID & p_guid) +{ + service_ptr_t ptr; + service_enum_t e; + while(e.next(ptr)) + { + if (ptr->get_guid() == p_guid) + { + p_out = ptr; + return true; + } + } + return false; +} + +void config_object::g_get_data_string(const GUID & p_guid,pfc::string_base & p_out) +{ + service_ptr_t ptr; + if (!g_find(ptr,p_guid)) throw exception_service_not_found(); + ptr->get_data_string(p_out); +} + +void config_object::g_set_data_string(const GUID & p_guid,const char * p_data,t_size p_length) +{ + service_ptr_t ptr; + if (!g_find(ptr,p_guid)) throw exception_service_not_found(); + ptr->set_data_string(p_data,p_length); +} + +void config_object::get_data_int32(t_int32 & p_out) +{ + t_int32 temp; + get_data_struct_t(temp); + byte_order::order_le_to_native_t(temp); + p_out = temp; +} + +void config_object::set_data_int32(t_int32 p_val) +{ + t_int32 temp = p_val; + byte_order::order_native_to_le_t(temp); + set_data_struct_t(temp); +} + +bool config_object::get_data_bool_simple(bool p_default) { + try { + bool ret = p_default; + get_data_bool(ret); + return ret; + } catch(...) {return p_default;} +} + +t_int32 config_object::get_data_int32_simple(t_int32 p_default) { + try { + t_int32 ret = p_default; + get_data_int32(ret); + return ret; + } catch(...) {return p_default;} +} + +void config_object::g_get_data_int32(const GUID & p_guid,t_int32 & p_out) { + service_ptr_t ptr; + if (!g_find(ptr,p_guid)) throw exception_service_not_found(); + ptr->get_data_int32(p_out); +} + +void config_object::g_set_data_int32(const GUID & p_guid,t_int32 p_val) { + service_ptr_t ptr; + if (!g_find(ptr,p_guid)) throw exception_service_not_found(); + ptr->set_data_int32(p_val); +} + +bool config_object::g_get_data_bool_simple(const GUID & p_guid,bool p_default) +{ + service_ptr_t ptr; + if (!g_find(ptr,p_guid)) throw exception_service_not_found(); + return ptr->get_data_bool_simple(p_default); +} + +t_int32 config_object::g_get_data_int32_simple(const GUID & p_guid,t_int32 p_default) +{ + service_ptr_t ptr; + if (!g_find(ptr,p_guid)) throw exception_service_not_found(); + return ptr->get_data_int32_simple(p_default); +} + +void config_object::get_data_bool(bool & p_out) {get_data_struct_t(p_out);} +void config_object::set_data_bool(bool p_val) {set_data_struct_t(p_val);} + +void config_object::g_get_data_bool(const GUID & p_guid,bool & p_out) {g_get_data_struct_t(p_guid,p_out);} +void config_object::g_set_data_bool(const GUID & p_guid,bool p_val) {g_set_data_struct_t(p_guid,p_val);} + +namespace { + class stream_writer_string : public stream_writer { + public: + void write(const void * p_buffer,t_size p_bytes,abort_callback & p_abort) { + m_out.add_string((const char*)p_buffer,p_bytes); + } + stream_writer_string(pfc::string_base & p_out) : m_out(p_out) {m_out.reset();} + private: + pfc::string_base & m_out; + }; + + class stream_writer_fixedbuffer : public stream_writer { + public: + void write(const void * p_buffer,t_size p_bytes,abort_callback & p_abort) { + if (p_bytes > 0) { + if (p_bytes > m_bytes - m_bytes_read) throw pfc::exception_overflow(); + memcpy((t_uint8*)m_out,p_buffer,p_bytes); + m_bytes_read += p_bytes; + } + } + stream_writer_fixedbuffer(void * p_out,t_size p_bytes,t_size & p_bytes_read) : m_out(p_out), m_bytes(p_bytes), m_bytes_read(p_bytes_read) {m_bytes_read = 0;} + private: + void * m_out; + t_size m_bytes; + t_size & m_bytes_read; + }; + + + + class stream_writer_get_length : public stream_writer { + public: + void write(const void * p_buffer,t_size p_bytes,abort_callback & p_abort) { + m_length += p_bytes; + } + stream_writer_get_length(t_size & p_length) : m_length(p_length) {m_length = 0;} + private: + t_size & m_length; + }; +}; + +t_size config_object::get_data_raw(void * p_out,t_size p_bytes) { + t_size ret = 0; + get_data(&stream_writer_fixedbuffer(p_out,p_bytes,ret),abort_callback_impl()); + return ret; +} + +t_size config_object::get_data_raw_length() { + t_size ret = 0; + get_data(&stream_writer_get_length(ret),abort_callback_impl()); + return ret; +} + +void config_object::set_data_raw(const void * p_data,t_size p_bytes, bool p_notify) { + set_data(&stream_reader_memblock_ref(p_data,p_bytes),abort_callback_impl(),p_notify); +} + +void config_object::set_data_string(const char * p_data,t_size p_length) { + set_data_raw(p_data,pfc::strlen_max(p_data,p_length)); +} + +void config_object::get_data_string(pfc::string_base & p_out) { + get_data(&stream_writer_string(p_out),abort_callback_impl()); +} + + +//config_object_impl stuff + + +void config_object_impl::get_data(stream_writer * p_stream,abort_callback & p_abort) const { + insync(m_sync); + p_stream->write_object(m_data.get_ptr(),m_data.get_size(),p_abort); +} + +void config_object_impl::set_data(stream_reader * p_stream,abort_callback & p_abort,bool p_notify) { + core_api::ensure_main_thread(); + + { + insync(m_sync); + m_data.set_size(0); + enum {delta = 1024}; + t_uint8 buffer[delta]; + for(;;) + { + t_size delta_done = p_stream->read(buffer,delta,p_abort); + + if (delta_done > 0) + { + m_data.append_fromptr(buffer,delta_done); + } + + if (delta_done != delta) break; + } + } + + if (p_notify) config_object_notify_manager::g_on_changed(this); +} + +config_object_impl::config_object_impl(const GUID & p_guid,const void * p_data,t_size p_bytes) : cfg_var(p_guid) +{ + m_data.set_data_fromptr((const t_uint8*)p_data,p_bytes); +} diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/config_object.h b/tools/vio2sf/src/foobar/foobar2000/SDK/config_object.h new file mode 100644 index 000000000..e460dc540 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/config_object.h @@ -0,0 +1,85 @@ +#ifndef _CONFIG_OBJECT_H_ +#define _CONFIG_OBJECT_H_ + +class config_object; + +class NOVTABLE config_object_notify_manager : public service_base +{ +public: + virtual void on_changed(const service_ptr_t & p_object) = 0; + static void g_on_changed(const service_ptr_t & p_object); + + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(config_object_notify_manager); +}; + +class NOVTABLE config_object : public service_base +{ +public: + //interface + virtual GUID get_guid() const = 0; + virtual void get_data(stream_writer * p_stream,abort_callback & p_abort) const = 0; + virtual void set_data(stream_reader * p_stream,abort_callback & p_abort,bool p_sendnotify = true) = 0; + + //helpers + static bool g_find(service_ptr_t & p_out,const GUID & p_guid); + + void set_data_raw(const void * p_data,t_size p_bytes,bool p_sendnotify = true); + t_size get_data_raw(void * p_out,t_size p_bytes); + t_size get_data_raw_length(); + + template void get_data_struct_t(T& p_out); + template void set_data_struct_t(const T& p_in); + template static void g_get_data_struct_t(const GUID & p_guid,T & p_out); + template static void g_set_data_struct_t(const GUID & p_guid,const T & p_in); + + void set_data_string(const char * p_data,t_size p_length); + void get_data_string(pfc::string_base & p_out); + + void get_data_bool(bool & p_out); + void set_data_bool(bool p_val); + void get_data_int32(t_int32 & p_out); + void set_data_int32(t_int32 p_val); + bool get_data_bool_simple(bool p_default); + t_int32 get_data_int32_simple(t_int32 p_default); + + static void g_get_data_string(const GUID & p_guid,pfc::string_base & p_out); + static void g_set_data_string(const GUID & p_guid,const char * p_data,t_size p_length = ~0); + + static void g_get_data_bool(const GUID & p_guid,bool & p_out); + static void g_set_data_bool(const GUID & p_guid,bool p_val); + static void g_get_data_int32(const GUID & p_guid,t_int32 & p_out); + static void g_set_data_int32(const GUID & p_guid,t_int32 p_val); + static bool g_get_data_bool_simple(const GUID & p_guid,bool p_default); + static t_int32 g_get_data_int32_simple(const GUID & p_guid,t_int32 p_default); + + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(config_object); +}; + +class standard_config_objects +{ +public: + static const GUID bool_remember_window_positions, bool_ui_always_on_top,bool_playlist_stop_after_current; + static const GUID bool_playback_follows_cursor, bool_cursor_follows_playback; + static const GUID bool_show_keyboard_shortcuts_in_menus; + static const GUID string_gui_last_directory_media,string_gui_last_directory_playlists; + static const GUID int32_dynamic_bitrate_display_rate; + + + inline static bool query_show_keyboard_shortcuts_in_menus() {return config_object::g_get_data_bool_simple(standard_config_objects::bool_show_keyboard_shortcuts_in_menus,true);} + inline static bool query_remember_window_positions() {return config_object::g_get_data_bool_simple(standard_config_objects::bool_remember_window_positions,true);} + +}; + +class config_object_notify : public service_base +{ +public: + virtual t_size get_watched_object_count() = 0; + virtual GUID get_watched_object(t_size p_index) = 0; + virtual void on_watched_object_changed(const service_ptr_t & p_object) = 0; + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(config_object_notify); +}; + +#endif _CONFIG_OBJECT_H_ diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/config_object_impl.h b/tools/vio2sf/src/foobar/foobar2000/SDK/config_object_impl.h new file mode 100644 index 000000000..00e3451cc --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/config_object_impl.h @@ -0,0 +1,174 @@ +#ifndef _CONFIG_OBJECT_IMPL_H_ +#define _CONFIG_OBJECT_IMPL_H_ + +//template function bodies from config_object class + +template +void config_object::get_data_struct_t(T& p_out) { + if (get_data_raw(&p_out,sizeof(T)) != sizeof(T)) throw exception_io_data_truncation(); +} + +template +void config_object::set_data_struct_t(const T& p_in) { + return set_data_raw(&p_in,sizeof(T)); +} + +template +void config_object::g_get_data_struct_t(const GUID & p_guid,T & p_out) { + service_ptr_t ptr; + if (!g_find(ptr,p_guid)) throw exception_service_not_found(); + return ptr->get_data_struct_t(p_out); +} + +template +void config_object::g_set_data_struct_t(const GUID & p_guid,const T & p_in) { + service_ptr_t ptr; + if (!g_find(ptr,p_guid)) throw exception_service_not_found(); + return ptr->set_data_struct_t(p_in); +} + + +class config_object_impl : public config_object, private cfg_var +{ +public: + GUID get_guid() const {return cfg_var::get_guid();} + void get_data(stream_writer * p_stream,abort_callback & p_abort) const ; + void set_data(stream_reader * p_stream,abort_callback & p_abort,bool p_notify); + + config_object_impl(const GUID & p_guid,const void * p_data,t_size p_bytes); +private: + + //cfg_var methods + void get_data_raw(stream_writer * p_stream,abort_callback & p_abort) {get_data(p_stream,p_abort);} + void set_data_raw(stream_reader * p_stream,t_size p_sizehint,abort_callback & p_abort) {set_data(p_stream,p_abort,false);} + + mutable critical_section m_sync; + pfc::array_t m_data; +}; + +typedef service_factory_single_transparent_t config_object_factory; + +template +class config_object_fixed_const_impl_t : public config_object { +public: + config_object_fixed_const_impl_t(const GUID & p_guid, const void * p_data) : m_guid(p_guid) {memcpy(m_data,p_data,p_size);} + GUID get_guid() const {return m_guid;} + + void get_data(stream_writer * p_stream, abort_callback & p_abort) const { p_stream->write_object(m_data,p_size,p_abort); } + void set_data(stream_reader * p_stream, abort_callback & p_abort, bool p_notify) { PFC_ASSERT(!"Should not get here."); } + +private: + t_uint8 m_data[p_size]; + const GUID m_guid; +}; + +template +class config_object_fixed_impl_t : public config_object, private cfg_var { +public: + GUID get_guid() const {return cfg_var::get_guid();} + + void get_data(stream_writer * p_stream,abort_callback & p_abort) const { + insync(m_sync); + p_stream->write_object(m_data,p_size,p_abort); + } + + void set_data(stream_reader * p_stream,abort_callback & p_abort,bool p_notify) { + core_api::ensure_main_thread(); + + { + t_uint8 temp[p_size]; + p_stream->read_object(temp,p_size,p_abort); + insync(m_sync); + memcpy(m_data,temp,p_size); + } + + if (p_notify) config_object_notify_manager::g_on_changed(this); + } + + config_object_fixed_impl_t (const GUID & p_guid,const void * p_data) + : cfg_var(p_guid) + { + memcpy(m_data,p_data,p_size); + } + +private: + //cfg_var methods + void get_data_raw(stream_writer * p_stream,abort_callback & p_abort) {get_data(p_stream,p_abort);} + void set_data_raw(stream_reader * p_stream,t_size p_sizehint,abort_callback & p_abort) {set_data(p_stream,p_abort,false);} + + mutable critical_section m_sync; + t_uint8 m_data[p_size]; + +}; + +template class _config_object_fixed_impl_switch; +template class _config_object_fixed_impl_switch { public: typedef config_object_fixed_impl_t type; }; +template class _config_object_fixed_impl_switch { public: typedef config_object_fixed_const_impl_t type; }; + +template +class config_object_fixed_factory_t : public service_factory_single_transparent_t< typename _config_object_fixed_impl_switch::type > +{ +public: + config_object_fixed_factory_t(const GUID & p_guid,const void * p_initval) + : + service_factory_single_transparent_t< typename _config_object_fixed_impl_switch::type > + (p_guid,p_initval) + {} +}; + + +class config_object_string_factory : public config_object_factory +{ +public: + config_object_string_factory(const GUID & p_guid,const char * p_string,t_size p_string_length = infinite) + : config_object_factory(p_guid,p_string,pfc::strlen_max(p_string,infinite)) {} + +}; + +template +class config_object_bool_factory_t : public config_object_fixed_factory_t<1,isConst> { +public: + config_object_bool_factory_t(const GUID & p_guid,bool p_initval) + : config_object_fixed_factory_t<1,isConst>(p_guid,&p_initval) {} +}; +typedef config_object_bool_factory_t<> config_object_bool_factory; + +template +class config_object_int_factory_t : public config_object_fixed_factory_t +{ +private: + template + struct t_initval + { + T m_initval; + t_initval(T p_initval) : m_initval(p_initval) {byte_order::order_native_to_le_t(m_initval);} + T * get_ptr() {return &m_initval;} + }; +public: + config_object_int_factory_t(const GUID & p_guid,T p_initval) + : config_object_fixed_factory_t(p_guid,t_initval(p_initval).get_ptr() ) + {} +}; + +typedef config_object_int_factory_t config_object_int32_factory; + + + +class config_object_notify_impl_simple : public config_object_notify +{ +public: + t_size get_watched_object_count() {return 1;} + GUID get_watched_object(t_size p_index) {return m_guid;} + void on_watched_object_changed(const service_ptr_t & p_object) {m_func(p_object);} + + typedef void (*t_func)(const service_ptr_t &); + + config_object_notify_impl_simple(const GUID & p_guid,t_func p_func) : m_guid(p_guid), m_func(p_func) {} +private: + GUID m_guid; + t_func m_func; +}; + +typedef service_factory_single_transparent_t config_object_notify_simple_factory; + +#endif _CONFIG_OBJECT_IMPL_H_ diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/console.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/console.cpp new file mode 100644 index 000000000..1becba922 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/console.cpp @@ -0,0 +1,50 @@ +#include "foobar2000.h" + + +void console::info(const char * p_message) {print(p_message);} +void console::error(const char * p_message) {complain("Error", p_message);} +void console::warning(const char * p_message) {complain("Warning", p_message);} + +void console::info_location(const playable_location & src) {print_location(src);} +void console::info_location(const metadb_handle_ptr & src) {print_location(src);} + +void console::print_location(const metadb_handle_ptr & src) +{ + print_location(src->get_location()); +} + +void console::print_location(const playable_location & src) +{ + formatter() << src; +} + +void console::complain(const char * what, const char * msg) { + formatter() << what << ": " << msg; +} +void console::complain(const char * what, std::exception const & e) { + complain(what, e.what()); +} + +void console::print(const char* p_message) +{ + if (core_api::are_services_available()) { + service_ptr_t ptr; + service_enum_t e; + while(e.next(ptr)) ptr->print(p_message,infinite); + } +} + +void console::printf(const char* p_format,...) +{ + va_list list; + va_start(list,p_format); + printfv(p_format,list); + va_end(list); +} + +void console::printfv(const char* p_format,va_list p_arglist) +{ + pfc::string8_fastalloc temp; + uPrintfV(temp,p_format,p_arglist); + print(temp); +} \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/console.h b/tools/vio2sf/src/foobar/foobar2000/SDK/console.h new file mode 100644 index 000000000..0b591c620 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/console.h @@ -0,0 +1,31 @@ +//! Namespace with functions for sending text to console. All functions are fully multi-thread safe, though they must not be called during dll initialization or deinitialization (e.g. static object constructors or destructors) when service system is not available. +namespace console +{ + void info(const char * p_message); + void error(const char * p_message); + void warning(const char * p_message); + void info_location(const playable_location & src); + void info_location(const metadb_handle_ptr & src); + void print_location(const playable_location & src); + void print_location(const metadb_handle_ptr & src); + + void print(const char*); + void printf(const char*,...); + void printfv(const char*,va_list p_arglist); + + //! Usage: console::formatter() << "blah " << somenumber << " asdf" << somestring; + class formatter : public pfc::string_formatter { + public: + ~formatter() {if (!is_empty()) console::print(get_ptr());} + }; + void complain(const char * what, const char * msg); + void complain(const char * what, std::exception const & e); +}; + +//! Interface receiving console output. Do not call directly; use console namespace functions instead. +class NOVTABLE console_receiver : public service_base { +public: + virtual void print(const char * p_message,t_size p_message_length) = 0; + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(console_receiver); +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/contextmenu.h b/tools/vio2sf/src/foobar/foobar2000/SDK/contextmenu.h new file mode 100644 index 000000000..1c601ef96 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/contextmenu.h @@ -0,0 +1,242 @@ +//! Reserved for future use. +typedef void * t_glyph; + + +class NOVTABLE contextmenu_item_node { +public: + enum t_flags { + FLAG_CHECKED = 1, + FLAG_DISABLED = 2, + FLAG_GRAYED = 4, + FLAG_DISABLED_GRAYED = FLAG_DISABLED|FLAG_GRAYED, + FLAG_RADIOCHECKED = 8, //new in 0.9.5.2 - overrides FLAG_CHECKED, set together with FLAG_CHECKED for backwards compatibility. + }; + + enum t_type { + TYPE_POPUP,TYPE_COMMAND,TYPE_SEPARATOR + }; + + virtual bool get_display_data(pfc::string_base & p_out,unsigned & p_displayflags,metadb_handle_list_cref p_data,const GUID & p_caller) = 0; + virtual t_type get_type() = 0; + virtual void execute(metadb_handle_list_cref p_data,const GUID & p_caller) = 0; + virtual t_glyph get_glyph(metadb_handle_list_cref p_data,const GUID & p_caller) {return 0;}//RESERVED + virtual t_size get_children_count() = 0; + virtual contextmenu_item_node * get_child(t_size p_index) = 0; + virtual bool get_description(pfc::string_base & p_out) = 0; + virtual GUID get_guid() = 0; + virtual bool is_mappable_shortcut() = 0; + +protected: + contextmenu_item_node() {} + ~contextmenu_item_node() {} +}; + +class NOVTABLE contextmenu_item_node_root : public contextmenu_item_node +{ +public: + virtual ~contextmenu_item_node_root() {} +}; + +class NOVTABLE contextmenu_item_node_leaf : public contextmenu_item_node +{ +public: + t_type get_type() {return TYPE_COMMAND;} + t_size get_children_count() {return 0;} + contextmenu_item_node * get_child(t_size) {return NULL;} +}; + +class NOVTABLE contextmenu_item_node_root_leaf : public contextmenu_item_node_root +{ +public: + t_type get_type() {return TYPE_COMMAND;} + t_size get_children_count() {return 0;} + contextmenu_item_node * get_child(t_size) {return NULL;} +}; + +class NOVTABLE contextmenu_item_node_popup : public contextmenu_item_node +{ +public: + t_type get_type() {return TYPE_POPUP;} + void execute(metadb_handle_list_cref data,const GUID & caller) {} + bool get_description(pfc::string_base & p_out) {return false;} +}; + +class NOVTABLE contextmenu_item_node_root_popup : public contextmenu_item_node_root +{ +public: + t_type get_type() {return TYPE_POPUP;} + void execute(metadb_handle_list_cref data,const GUID & caller) {} + bool get_description(pfc::string_base & p_out) {return false;} +}; + +class contextmenu_item_node_separator : public contextmenu_item_node +{ +public: + t_type get_type() {return TYPE_SEPARATOR;} + void execute(metadb_handle_list_cref data,const GUID & caller) {} + bool get_description(pfc::string_base & p_out) {return false;} + t_size get_children_count() {return 0;} + bool get_display_data(pfc::string_base & p_out,unsigned & p_displayflags,metadb_handle_list_cref p_data,const GUID & p_caller) + { + p_displayflags = 0; + p_out = "---"; + return true; + } + contextmenu_item_node * get_child(t_size) {return NULL;} + GUID get_guid() {return pfc::guid_null;} + bool is_mappable_shortcut() {return false;} +}; + +/*! +Service class for declaring context menu commands.\n +See contextmenu_item_simple for implementation helper without dynamic menu generation features.\n +All methods are valid from main app thread only. +*/ +class NOVTABLE contextmenu_item : public service_base { +public: + enum t_enabled_state { + FORCE_OFF, + DEFAULT_OFF, + DEFAULT_ON, + }; + + //! Retrieves number of menu items provided by this contextmenu_item implementation. + virtual unsigned get_num_items() = 0; + //! Instantiates a context menu item (including sub-node tree for items that contain dynamically-generated sub-items). + virtual contextmenu_item_node_root * instantiate_item(unsigned p_index,metadb_handle_list_cref p_data,const GUID & p_caller) = 0; + //! Retrieves GUID of the context menu item. + virtual GUID get_item_guid(unsigned p_index) = 0; + //! Retrieves human-readable name of the context menu item. + virtual void get_item_name(unsigned p_index,pfc::string_base & p_out) = 0; + //! Retrieves default path of the context menu item ("" for root). + virtual void get_item_default_path(unsigned p_index,pfc::string_base & p_out) = 0; + //! Retrieves item's description to show in the status bar. Set p_out to the string to be displayed and return true if you provide a description, return false otherwise. + virtual bool get_item_description(unsigned p_index,pfc::string_base & p_out) = 0; + //! Signals whether the item should be forcefully hidden (FORCE_OFF), hidden by default but possible to add (DEFAULT_OFF) or shown by default (DEFAULT_ON). + virtual t_enabled_state get_enabled_state(unsigned p_index) = 0; + //! Executes the menu item command without going thru the instantiate_item path. For items with dynamically-generated sub-items, p_node is identifies of the sub-item command to execute. + virtual void item_execute_simple(unsigned p_index,const GUID & p_node,metadb_handle_list_cref p_data,const GUID & p_caller) = 0; + + bool item_get_display_data_root(pfc::string_base & p_out,unsigned & displayflags,unsigned p_index,metadb_handle_list_cref p_data,const GUID & p_caller); + bool item_get_display_data(pfc::string_base & p_out,unsigned & displayflags,unsigned p_index,const GUID & p_node,metadb_handle_list_cref p_data,const GUID & p_caller); + + //! Deprecated - use caller_active_playlist_selection instead. + static const GUID caller_playlist; + + static const GUID caller_active_playlist_selection, caller_active_playlist, caller_playlist_manager, caller_now_playing, caller_keyboard_shortcut_list, caller_media_library_viewer; + static const GUID caller_undefined; + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(contextmenu_item); +}; + +//! contextmenu_item implementation helper for implementing non-dynamically-generated context menu items; derive from this instead of from contextmenu_item directly if your menu items are static. +class NOVTABLE contextmenu_item_simple : public contextmenu_item { +private: +public: + //! Same as contextmenu_item_node::t_flags. + enum t_flags + { + FLAG_CHECKED = 1, + FLAG_DISABLED = 2, + FLAG_GRAYED = 4, + FLAG_DISABLED_GRAYED = FLAG_DISABLED|FLAG_GRAYED, + FLAG_RADIOCHECKED = 8, //new in 0.9.5.2 - overrides FLAG_CHECKED, set together with FLAG_CHECKED for backwards compatibility. + }; + + + // Functions to be overridden by implementers (some are not mandatory). + virtual t_enabled_state get_enabled_state(unsigned p_index) {return contextmenu_item::DEFAULT_ON;} + virtual unsigned get_num_items() = 0; + virtual void get_item_name(unsigned p_index,pfc::string_base & p_out) = 0; + virtual void get_item_default_path(unsigned p_index,pfc::string_base & p_out) = 0; + virtual void context_command(unsigned p_index,metadb_handle_list_cref p_data,const GUID& p_caller) = 0; + virtual bool context_get_display(unsigned p_index,metadb_handle_list_cref p_data,pfc::string_base & p_out,unsigned & p_displayflags,const GUID & p_caller) { + PFC_ASSERT(p_index>=0 && p_indexget_display_data(m_index,p_data,p_out,p_displayflags,p_caller);} + void execute(metadb_handle_list_cref p_data,const GUID & p_caller) {m_owner->context_command(m_index,p_data,p_caller);} + bool get_description(pfc::string_base & p_out) {return m_owner->get_item_description(m_index,p_out);} + GUID get_guid() {return pfc::guid_null;} + bool is_mappable_shortcut() {return m_owner->item_is_mappable_shortcut(m_index);} + private: + service_ptr_t m_owner; + unsigned m_index; + }; + + contextmenu_item_node_root * instantiate_item(unsigned p_index,metadb_handle_list_cref p_data,const GUID & p_caller) + { + return new contextmenu_item_node_impl(this,p_index); + } + + + void item_execute_simple(unsigned p_index,const GUID & p_node,metadb_handle_list_cref p_data,const GUID & p_caller) + { + if (p_node == pfc::guid_null) + context_command(p_index,p_data,p_caller); + } + + virtual bool item_is_mappable_shortcut(unsigned p_index) + { + return true; + } + + + virtual bool get_display_data(unsigned n,metadb_handle_list_cref data,pfc::string_base & p_out,unsigned & displayflags,const GUID & caller) + { + bool rv = false; + assert(n>=0 && n0) + { + rv = context_get_display(n,data,p_out,displayflags,caller); + } + return rv; + } + +}; + + +//! Helper. +template +class contextmenu_item_factory_t : public service_factory_single_t {}; + + +//! Helper. +#define DECLARE_CONTEXT_MENU_ITEM(P_CLASSNAME,P_NAME,P_DEFAULTPATH,P_FUNC,P_GUID,P_DESCRIPTION) \ + namespace { \ + class P_CLASSNAME : public contextmenu_item_simple { \ + public: \ + unsigned get_num_items() {return 1;} \ + void get_item_name(unsigned p_index,pfc::string_base & p_out) {p_out = P_NAME;} \ + void get_item_default_path(unsigned p_index,pfc::string_base & p_out) {p_out = P_DEFAULTPATH;} \ + void context_command(unsigned p_index,metadb_handle_list_cref p_data,const GUID& p_caller) {P_FUNC(p_data);} \ + GUID get_item_guid(unsigned p_index) {return P_GUID;} \ + bool get_item_description(unsigned p_index,pfc::string_base & p_out) {if (P_DESCRIPTION[0] == 0) return false;p_out = P_DESCRIPTION; return true;} \ + }; \ + static contextmenu_item_factory_t g_##P_CLASSNAME##_factory; \ + } + + + + +//! New in 0.9.5.1. Static methods safe to use in prior versions as it will use slow fallback mode when the service isn't present. \n +//! Functionality provided by menu_item_resolver methods isn't much different from just walking all registered contextmenu_item / mainmenu_commands implementations to find the command we want, but it uses a hint map to locate the service we're looking for without walking all of them which may be significantly faster in certain scenarios. +class menu_item_resolver : public service_base { +public: + virtual bool resolve_context_command(const GUID & id, service_ptr_t & out, t_uint32 & out_index) = 0; + virtual bool resolve_main_command(const GUID & id, service_ptr_t & out, t_uint32 & out_index) = 0; + + static bool g_resolve_context_command(const GUID & id, service_ptr_t & out, t_uint32 & out_index); + static bool g_resolve_main_command(const GUID & id, service_ptr_t & out, t_uint32 & out_index); + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(menu_item_resolver) +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/contextmenu_manager.h b/tools/vio2sf/src/foobar/foobar2000/SDK/contextmenu_manager.h new file mode 100644 index 000000000..8bcbb21b0 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/contextmenu_manager.h @@ -0,0 +1,109 @@ +class NOVTABLE keyboard_shortcut_manager : public service_base +{ +public: + static bool g_get(service_ptr_t & p_out) {return service_enum_create_t(p_out,0);} + + enum shortcut_type + { + TYPE_MAIN, + TYPE_CONTEXT, + TYPE_CONTEXT_PLAYLIST, + TYPE_CONTEXT_NOW_PLAYING, + }; + + + virtual bool process_keydown(shortcut_type type,const pfc::list_base_const_t & data,unsigned keycode)=0; + virtual bool process_keydown_ex(shortcut_type type,const pfc::list_base_const_t & data,unsigned keycode,const GUID & caller)=0; + bool on_keydown(shortcut_type type,WPARAM wp); + bool on_keydown_context(const pfc::list_base_const_t & data,WPARAM wp,const GUID & caller); + + bool on_keydown_auto(WPARAM wp); + bool on_keydown_auto_playlist(WPARAM wp); + bool on_keydown_auto_context(const pfc::list_base_const_t & data,WPARAM wp,const GUID & caller); + + bool on_keydown_restricted_auto(WPARAM wp); + bool on_keydown_restricted_auto_playlist(WPARAM wp); + bool on_keydown_restricted_auto_context(const pfc::list_base_const_t & data,WPARAM wp,const GUID & caller); + + virtual bool get_key_description_for_action(const GUID & p_command,const GUID & p_subcommand, pfc::string_base & out, shortcut_type type, bool is_global)=0; + + static bool is_text_key(t_uint32 vkCode); + static bool is_typing_key(t_uint32 vkCode); + static bool is_typing_key_combo(t_uint32 vkCode, t_uint32 modifiers); + static bool is_typing_modifier(t_uint32 flags); + static bool is_typing_message(HWND editbox, const MSG * msg); + static bool is_typing_message(const MSG * msg); + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(keyboard_shortcut_manager); +}; + + +//! New in 0.9.5. +class keyboard_shortcut_manager_v2 : public keyboard_shortcut_manager { +public: + //! Deprecates old keyboard_shortcut_manager methods. If the action requires selected items, they're obtained from ui_selection_manager API automatically. + virtual bool process_keydown_simple(t_uint32 keycode) = 0; + + //! Helper for use with message filters. + bool pretranslate_message(const MSG * msg, HWND thisPopupWnd); + + FB2K_MAKE_SERVICE_INTERFACE(keyboard_shortcut_manager_v2,keyboard_shortcut_manager); +}; + +class NOVTABLE contextmenu_node { +public: + virtual contextmenu_item_node::t_type get_type()=0; + virtual const char * get_name()=0; + virtual t_size get_num_children()=0;//TYPE_POPUP only + virtual contextmenu_node * get_child(t_size n)=0;//TYPE_POPUP only + virtual unsigned get_display_flags()=0;//TYPE_COMMAND/TYPE_POPUP only, see contextmenu_item::FLAG_* + virtual unsigned get_id()=0;//TYPE_COMMAND only, returns zero-based index (helpful for win32 menu command ids) + virtual void execute()=0;//TYPE_COMMAND only + virtual bool get_description(pfc::string_base & out)=0;//TYPE_COMMAND only + virtual bool get_full_name(pfc::string_base & out)=0;//TYPE_COMMAND only + virtual void * get_glyph()=0;//RESERVED, do not use +protected: + contextmenu_node() {} + ~contextmenu_node() {} +}; + + + +class NOVTABLE contextmenu_manager : public service_base +{ +public: + enum + { + FLAG_SHOW_SHORTCUTS = 1, + FLAG_SHOW_SHORTCUTS_GLOBAL = 2, + }; + virtual void init_context(const pfc::list_base_const_t & data,unsigned flags)=0;//flags - see FLAG_* above + virtual void init_context_playlist(unsigned flags)=0; + virtual contextmenu_node * get_root()=0;//releasing contextmenu_manager service releaases nodes; root may be null in case of error or something + virtual contextmenu_node * find_by_id(unsigned id)=0; + virtual void set_shortcut_preference(const keyboard_shortcut_manager::shortcut_type * data,unsigned count)=0; + + + + static void g_create(service_ptr_t & p_out) {p_out = standard_api_create_t();} + +#ifdef WIN32 + static void win32_build_menu(HMENU menu,contextmenu_node * parent,int base_id,int max_id);//menu item identifiers are base_id<=N & data, const POINT * pt = 0,unsigned flags = 0); + static void win32_run_menu_context_playlist(HWND parent,const POINT * pt = 0,unsigned flags = 0); + void win32_run_menu_popup(HWND parent,const POINT * pt = 0); + void win32_build_menu(HMENU menu,int base_id,int max_id) {win32_build_menu(menu,get_root(),base_id,max_id);} + + +#endif + + virtual void init_context_ex(const pfc::list_base_const_t & data,unsigned flags,const GUID & caller)=0; + virtual bool init_context_now_playing(unsigned flags)=0;//returns false if not playing + + bool execute_by_id(unsigned id); + + bool get_description_by_id(unsigned id,pfc::string_base & out); + + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(contextmenu_manager); +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/core_api.h b/tools/vio2sf/src/foobar/foobar2000/SDK/core_api.h new file mode 100644 index 000000000..19fc53fd4 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/core_api.h @@ -0,0 +1,33 @@ +#ifndef _CORE_API_H_ +#define _CORE_API_H_ + +namespace core_api { + + //! Exception thrown by APIs locked to main app thread when called from another thread. + PFC_DECLARE_EXCEPTION(exception_wrong_thread,pfc::exception_bug_check,"This method can be called only from the main thread"); + + //! Retrieves HINSTANCE of calling DLL. + HINSTANCE get_my_instance(); + //! Retrieves filename of calling dll, excluding extension, e.g. "foo_asdf" + const char * get_my_file_name(); + //! Retrieves full path of calling dll, e.g. file://c:\blah\foobar2000\foo_asdf.dll + const char * get_my_full_path(); + //! Retrieves main app window. WARNING: this is provided for parent of dialog windows and such only; using it for anything else (such as hooking windowproc to alter app behaviors) is absolutely illegal. + HWND get_main_window(); + //! Tests whether services are available at this time. They are not available only during DLL startup or shutdown (e.g. inside static object constructors or destructors). + bool are_services_available(); + //! Tests whether calling thread is main app thread, and shows diagnostic message in debugger output if it's not. + bool assert_main_thread(); + //! Throws exception_wrong_thread if calling thread is not main app thread. + void ensure_main_thread(); + //! Returns true if calling thread is main app thread, false otherwise. + bool is_main_thread(); + //! Returns whether the app is currently shutting down. + bool is_shutting_down(); + //! Returns whether the app is currently initializing. + bool is_initializing(); + //! Returns filesystem path to directory with user settings, e.g. file://c:\documents_and_settings\username\blah\foobar2000 + const char * get_profile_path(); +}; + +#endif diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/coreversion.h b/tools/vio2sf/src/foobar/foobar2000/SDK/coreversion.h new file mode 100644 index 000000000..f786444b4 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/coreversion.h @@ -0,0 +1,36 @@ +class NOVTABLE core_version_info : public service_base { +public: + virtual const char * get_version_string() = 0; + static const char * g_get_version_string() {return static_api_ptr_t()->get_version_string();} + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(core_version_info); +}; + +struct t_core_version_data { + t_uint32 m_major, m_minor1, m_minor2, m_minor3; +}; + +//! New (0.9.4.2) +class NOVTABLE core_version_info_v2 : public core_version_info { +public: + virtual const char * get_name() = 0;//"foobar2000" + virtual const char * get_version_as_text() = 0;//"N.N.N.N" + virtual t_core_version_data get_version() = 0; + + //! Determine whether running foobar2000 version is newer or equal to the specified version, eg. test_version(0,9,5,0) for 0.9.5. + bool test_version(t_uint32 major, t_uint32 minor1, t_uint32 minor2, t_uint32 minor3) { + const t_core_version_data v = get_version(); + if (v.m_major < major) return false; + else if (v.m_major > major) return true; + // major version matches + else if (v.m_minor1 < minor1) return false; + else if (v.m_minor1 > minor1) return true; + // minor1 version matches + else if (v.m_minor2 < minor2) return false; + else if (v.m_minor2 > minor2) return true; + // minor2 version matches + else if (v.m_minor3 < minor3) return false; + else return true; + } + + FB2K_MAKE_SERVICE_INTERFACE(core_version_info_v2, core_version_info); +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/dsp.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/dsp.cpp new file mode 100644 index 000000000..d7b39d5e0 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/dsp.cpp @@ -0,0 +1,395 @@ +#include "foobar2000.h" +#include + +t_size dsp_chunk_list_impl::get_count() const {return m_data.get_count();} + +audio_chunk * dsp_chunk_list_impl::get_item(t_size n) const {return n>=0 && n=0 && idxmax) idx = max; + pfc::rcptr_t ret; + if (m_recycled.get_count()>0) + { + t_size best; + if (hint_size>0) + { + best = 0; + t_size best_found = m_recycled[0]->get_data_size(), n, total = m_recycled.get_count(); + for(n=1;nget_data_size(); + int delta_old = abs((int)best_found - (int)hint_size), delta_new = abs((int)size - (int)hint_size); + if (delta_new < delta_old) + { + best_found = size; + best = n; + } + } + } + else best = m_recycled.get_count()-1; + + ret = m_recycled.remove_by_idx(best); + ret->set_sample_count(0); + ret->set_channels(0); + ret->set_srate(0); + } + else ret = pfc::rcnew_t(); + if (idx==max) m_data.add_item(ret); + else m_data.insert_item(ret,idx); + return &*ret; +} + +void dsp_chunk_list::remove_bad_chunks() +{ + bool blah = false; + t_size idx; + for(idx=0;idxis_valid()) + { + chunk->reset(); + remove_by_idx(idx); + blah = true; + } + else idx++; + } + if (blah) console::info("one or more bad chunks removed from dsp chunk list"); +} + + +bool dsp_entry::g_instantiate(service_ptr_t & p_out,const dsp_preset & p_preset) +{ + service_ptr_t ptr; + if (!g_get_interface(ptr,p_preset.get_owner())) return false; + return ptr->instantiate(p_out,p_preset); +} + +bool dsp_entry::g_instantiate_default(service_ptr_t & p_out,const GUID & p_guid) +{ + service_ptr_t ptr; + if (!g_get_interface(ptr,p_guid)) return false; + dsp_preset_impl preset; + if (!ptr->get_default_preset(preset)) return false; + return ptr->instantiate(p_out,preset); +} + +bool dsp_entry::g_name_from_guid(pfc::string_base & p_out,const GUID & p_guid) +{ + service_ptr_t ptr; + if (!g_get_interface(ptr,p_guid)) return false; + ptr->get_name(p_out); + return true; +} + +bool dsp_entry::g_dsp_exists(const GUID & p_guid) +{ + service_ptr_t blah; + return g_get_interface(blah,p_guid); +} + +bool dsp_entry::g_get_default_preset(dsp_preset & p_out,const GUID & p_guid) +{ + service_ptr_t ptr; + if (!g_get_interface(ptr,p_guid)) return false; + return ptr->get_default_preset(p_out); +} + +void dsp_chain_config::contents_to_stream(stream_writer * p_stream,abort_callback & p_abort) const { + t_size n, count = get_count(); + p_stream->write_lendian_t(count,p_abort); + for(n=0;nread_lendian_t(count,p_abort); + + dsp_preset_impl temp; + + for(n=0;n & p_out) +{ + p_out.remove_all(); + t_size n, m = get_count(); + for(n=0;n temp; + if (dsp_entry::g_instantiate(temp,get_item(n))) + p_out.add_item(temp); + } +} + +t_size dsp_chain_config_impl::get_count() const +{ + return m_data.get_count(); +} + +const dsp_preset & dsp_chain_config_impl::get_item(t_size p_index) const +{ + return *m_data[p_index]; +} + +void dsp_chain_config_impl::replace_item(const dsp_preset & p_data,t_size p_index) +{ + *m_data[p_index] = p_data; +} + +void dsp_chain_config_impl::insert_item(const dsp_preset & p_data,t_size p_index) +{ + m_data.insert_item(new dsp_preset_impl(p_data),p_index); +} + +void dsp_chain_config_impl::remove_mask(const bit_array & p_mask) +{ + m_data.delete_mask(p_mask); +} + +dsp_chain_config_impl::~dsp_chain_config_impl() +{ + m_data.delete_all(); +} + +void dsp_preset::contents_to_stream(stream_writer * p_stream,abort_callback & p_abort) const { + t_size size = get_data_size(); + p_stream->write_lendian_t(get_owner(),p_abort); + p_stream->write_lendian_t(size,p_abort); + if (size > 0) { + p_stream->write_object(get_data(),size,p_abort); + } +} + +void dsp_preset::contents_from_stream(stream_reader * p_stream,abort_callback & p_abort) { + t_uint32 size; + GUID guid; + p_stream->read_lendian_t(guid,p_abort); + set_owner(guid); + p_stream->read_lendian_t(size,p_abort); + if (size > 1024*1024*32) throw exception_io_data(); + set_data_from_stream(p_stream,size,p_abort); +} + +void dsp_preset::g_contents_from_stream_skip(stream_reader * p_stream,abort_callback & p_abort) { + t_uint32 size; + GUID guid; + p_stream->read_lendian_t(guid,p_abort); + p_stream->read_lendian_t(size,p_abort); + if (size > 1024*1024*32) throw exception_io_data(); + p_stream->skip_object(size,p_abort); +} + +void dsp_preset_impl::set_data_from_stream(stream_reader * p_stream,t_size p_bytes,abort_callback & p_abort) { + m_data.set_size(p_bytes); + if (p_bytes > 0) p_stream->read_object(m_data.get_ptr(),p_bytes,p_abort); +} + +void dsp_chain_config::copy(const dsp_chain_config & p_source) { + remove_all(); + t_size n, m = p_source.get_count(); + for(n=0;n entry; + if (!g_get_interface(entry,p_guid)) return false; + return entry->have_config_popup(); +} + +bool dsp_entry::g_have_config_popup(const dsp_preset & p_preset) +{ + return g_have_config_popup(p_preset.get_owner()); +} + +bool dsp_entry::g_show_config_popup(dsp_preset & p_preset,HWND p_parent) +{ + service_ptr_t entry; + if (!g_get_interface(entry,p_preset.get_owner())) return false; + return entry->show_config_popup(p_preset,p_parent); +} + +void dsp_entry::g_show_config_popup_v2(const dsp_preset & p_preset,HWND p_parent,dsp_preset_edit_callback & p_callback) { + service_ptr_t entry; + if (g_get_interface(entry,p_preset.get_owner())) { + service_ptr_t entry_v2; + if (entry->service_query_t(entry_v2)) { + entry_v2->show_config_popup_v2(p_preset,p_parent,p_callback); + } else { + dsp_preset_impl temp(p_preset); + if (entry->show_config_popup(temp,p_parent)) p_callback.on_preset_changed(temp); + } + } +} + +bool dsp_entry::g_get_interface(service_ptr_t & p_out,const GUID & p_guid) +{ + service_ptr_t ptr; + service_enum_t e; + e.reset(); + while(e.next(ptr)) + { + if (ptr->get_guid() == p_guid) + { + p_out = ptr; + return true; + } + } + return false; +} + +bool resampler_entry::g_get_interface(service_ptr_t & p_out,unsigned p_srate_from,unsigned p_srate_to) +{ + service_ptr_t ptr_dsp; + service_ptr_t ptr_resampler; + service_enum_t e; + e.reset(); + float found_priority = 0; + service_ptr_t found; + while(e.next(ptr_dsp)) + { + if (ptr_dsp->service_query_t(ptr_resampler)) + { + if (p_srate_from == 0 || ptr_resampler->is_conversion_supported(p_srate_from,p_srate_to)) + { + float priority = ptr_resampler->get_priority(); + if (found.is_empty() || priority > found_priority) + { + found = ptr_resampler; + found_priority = priority; + } + } + } + } + if (found.is_empty()) return false; + p_out = found; + return true; +} + +bool resampler_entry::g_create_preset(dsp_preset & p_out,unsigned p_srate_from,unsigned p_srate_to,float p_qualityscale) +{ + service_ptr_t entry; + if (!g_get_interface(entry,p_srate_from,p_srate_to)) return false; + return entry->create_preset(p_out,p_srate_to,p_qualityscale); +} + +bool resampler_entry::g_create(service_ptr_t & p_out,unsigned p_srate_from,unsigned p_srate_to,float p_qualityscale) +{ + service_ptr_t entry; + if (!g_get_interface(entry,p_srate_from,p_srate_to)) return false; + dsp_preset_impl preset; + if (!entry->create_preset(preset,p_srate_to,p_qualityscale)) return false; + return entry->instantiate(p_out,preset); +} + + +void dsp_chain_config::get_name_list(pfc::string_base & p_out) const +{ + const t_size count = get_count(); + bool added = false; + for(unsigned n=0;n ptr; + if (dsp_entry::g_get_interface(ptr,get_item(n).get_owner())) + { + if (added) p_out += ", "; + added = true; + + pfc::string8 temp; + ptr->get_name(temp); + p_out += temp; + } + } +} + +void dsp::run_abortable(dsp_chunk_list * p_chunk_list,const metadb_handle_ptr & p_cur_file,int p_flags,abort_callback & p_abort) { + service_ptr_t this_v2; + if (this->service_query_t(this_v2)) this_v2->run_v2(p_chunk_list,p_cur_file,p_flags,p_abort); + else run(p_chunk_list,p_cur_file,p_flags); +} + +namespace { + class dsp_preset_edit_callback_impl : public dsp_preset_edit_callback { + public: + dsp_preset_edit_callback_impl(dsp_preset & p_data) : m_data(p_data) {} + void on_preset_changed(const dsp_preset & p_data) {m_data = p_data;} + private: + dsp_preset & m_data; + }; +}; + +bool dsp_entry_v2::show_config_popup(dsp_preset & p_data,HWND p_parent) { + PFC_ASSERT(p_data.get_owner() == get_guid()); + dsp_preset_impl temp(p_data); + show_config_popup_v2(p_data,p_parent,dsp_preset_edit_callback_impl(temp)); + PFC_ASSERT(temp.get_owner() == get_guid()); + if (temp == p_data) return false; + p_data = temp; + return true; +} \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/dsp.h b/tools/vio2sf/src/foobar/foobar2000/SDK/dsp.h new file mode 100644 index 000000000..8f94d5d68 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/dsp.h @@ -0,0 +1,482 @@ +//! Interface to a DSP chunk list. A DSP chunk list object is passed to the DSP chain each time, since DSPs are allowed to remove processed chunks or insert new ones. +class NOVTABLE dsp_chunk_list { +public: + virtual t_size get_count() const = 0; + virtual audio_chunk * get_item(t_size n) const = 0; + virtual void remove_by_idx(t_size idx) = 0; + virtual void remove_mask(const bit_array & mask) = 0; + virtual audio_chunk * insert_item(t_size idx,t_size hint_size=0) = 0; + + audio_chunk * add_item(t_size hint_size=0) {return insert_item(get_count(),hint_size);} + + void remove_all() {remove_mask(bit_array_true());} + + double get_duration() { + double rv = 0; + t_size n,m = get_count(); + for(n=0;nget_duration(); + return rv; + } + + void add_chunk(const audio_chunk * chunk) { + audio_chunk * dst = insert_item(get_count(),chunk->get_data_length()); + if (dst) dst->copy(*chunk); + } + + void remove_bad_chunks(); +protected: + dsp_chunk_list() {} + ~dsp_chunk_list() {} +}; + +class dsp_chunk_list_impl : public dsp_chunk_list//implementation +{ + pfc::list_t > m_data, m_recycled; +public: + t_size get_count() const; + audio_chunk * get_item(t_size n) const; + void remove_by_idx(t_size idx); + void remove_mask(const bit_array & mask); + audio_chunk * insert_item(t_size idx,t_size hint_size=0); +}; + +//! Instance of a DSP.\n +//! Implementation: Derive from dsp_impl_base instead of deriving from dsp directly.\n +//! Instantiation: Use dsp_entry static helper methods to instantiate DSPs, or dsp_chain_config / dsp_manager to deal with entire DSP chains. +class NOVTABLE dsp : public service_base { +public: + enum { + //! Flush whatever you need to when tracks change. + END_OF_TRACK = 1, + //! Flush everything. + FLUSH = 2 + }; + + //! @param p_chunk_list List of chunks to process. The implementation may alter the list in any way, inserting chunks of different sample rate / channel configuration etc. + //! @param p_cur_file Optional, location of currently decoded file. May be null. + //! @param p_flags Flags. Can be null, or a combination of END_OF_TRACK and FLUSH constants. + virtual void run(dsp_chunk_list * p_chunk_list,const metadb_handle_ptr & p_cur_file,int p_flags)=0; + + //! Flushes the DSP (reinitializes / drops any buffered data). Called after seeking, etc. + virtual void flush() = 0; + + //! Retrieves amount of data buffered by the DSP, for syncing visualisation. + //! @returns Amount of buffered audio data, in seconds. + virtual double get_latency() = 0; + //! Returns true if DSP needs to know exact track change point (eg. for crossfading, removing silence).\n + //! Signaling this will force-flush any DSPs placed before this DSP so when it gets END_OF_TRACK, relevant chunks contain last samples of the track.\n + //! Signaling this will often break regular gapless playback so don't use it unless you have reasons to. + virtual bool need_track_change_mark() = 0; + + void run_abortable(dsp_chunk_list * p_chunk_list,const metadb_handle_ptr & p_cur_file,int p_flags,abort_callback & p_abort); + + FB2K_MAKE_SERVICE_INTERFACE(dsp,service_base); +}; + +//! Backwards-compatible extension to dsp interface, allows abortable operation. Introduced in 0.9.2. +class NOVTABLE dsp_v2 : public dsp { +public: + //! Abortable version of dsp::run(). See dsp::run() for descriptions of parameters. + virtual void run_v2(dsp_chunk_list * p_chunk_list,const metadb_handle_ptr & p_cur_file,int p_flags,abort_callback & p_abort) = 0; +private: + void run(dsp_chunk_list * p_chunk_list,const metadb_handle_ptr & p_cur_file,int p_flags) { + run_v2(p_chunk_list,p_cur_file,p_flags,abort_callback_dummy()); + } + + FB2K_MAKE_SERVICE_INTERFACE(dsp_v2,dsp); +}; + +//! Helper class for implementing dsps. You should derive from dsp_impl_base instead of from dsp directly.\n +//! The dsp_impl_base_t template allows you to use a custom interface class as a base class for your implementation, in case you provide extended functionality.\n +//! Use dsp_factory_t<> template to register your dsp implementation. +//! The implementation - as required by dsp_factory_t<> template - must also provide following methods:\n +//! A constructor taking const dsp_preset&, initializing the DSP with specified preset data.\n +//! static void g_get_name(pfc::string_base &); - retrieving human-readable name of the DSP to display.\n +//! static bool g_get_default_preset(dsp_preset &); - retrieving default preset for this DSP. Return value is reserved for future use and should always be true.\n +//! static GUID g_get_guid(); - retrieving GUID of your DSP implementation, to be used to identify it when storing DSP chain configuration.\n +//! static bool g_have_config_popup(); - retrieving whether your DSP implementation supplies a popup dialog for configuring it.\n +//! static void g_show_config_popup(const dsp_preset & p_data,HWND p_parent, dsp_preset_edit_callback & p_callback); - displaying your DSP's settings dialog; called only when g_have_config_popup() returns true; call p_callback.on_preset_changed() whenever user has made adjustments to the preset data.\n +template +class dsp_impl_base_t : public t_baseclass { +private: + typedef dsp_impl_base_t t_self; + dsp_chunk_list * m_list; + t_size m_chunk_ptr; + metadb_handle* m_cur_file; + void run_v2(dsp_chunk_list * p_list,const metadb_handle_ptr & p_cur_file,int p_flags,abort_callback & p_abort); +protected: + bool get_cur_file(metadb_handle_ptr & p_out) {p_out = m_cur_file; return p_out.is_valid();}// call only from on_chunk / on_endoftrack (on_endoftrack will give info on track being finished); may return null !! + + dsp_impl_base_t() : m_list(NULL), m_cur_file(NULL), m_chunk_ptr(0) {} + + audio_chunk * insert_chunk(t_size p_hint_size = 0) //call only from on_endoftrack / on_endofplayback / on_chunk + {//hint_size - optional, amout of buffer space you want to use + PFC_ASSERT(m_list != NULL); + return m_list->insert_item(m_chunk_ptr++,p_hint_size); + } + + + //! To be overridden by a DSP implementation.\n + //! Called on track change. You can use insert_chunk() to dump any data you have to flush. \n + //! Note that you must implement need_track_change_mark() to return true if you need this method called. + virtual void on_endoftrack(abort_callback & p_abort) = 0; + //! To be overridden by a DSP implementation.\n + //! Called at the end of played stream, typically at the end of last played track, to allow the DSP to return all data it has buffered-ahead.\n + //! Use insert_chunk() to return any data you have buffered.\n + //! Note that this call does not imply that the DSP will be destroyed next. \n + //! This is also called on track changes if some DSP placed after your DSP requests track change marks. + virtual void on_endofplayback(abort_callback & p_abort) = 0; + //! To be overridden by a DSP implementation.\n + //! Processes a chunk of audio data.\n + //! You can call insert_chunk() from inside on_chunk() to insert any audio data before currently processed chunk.\n + //! @param p_chunk Current chunk being processed. You can alter it in any way you like. + //! @returns True to keep p_chunk (with alterations made inside on_chunk()) in the stream, false to remove it. + virtual bool on_chunk(audio_chunk * p_chunk,abort_callback & p_abort) = 0; + +public: + //! To be overridden by a DSP implementation.\n + //! Flushes the DSP (reinitializes / drops any buffered data). Called after seeking, etc. + virtual void flush() = 0; + //! To be overridden by a DSP implementation.\n + //! Retrieves amount of data buffered by the DSP, for syncing visualisation. + //! @returns Amount of buffered audio data, in seconds. + virtual double get_latency() = 0; + //! To be overridden by a DSP implementation.\n + //! Returns true if DSP needs to know exact track change point (eg. for crossfading, removing silence).\n + //! Signaling this will force-flush any DSPs placed before this DSP so when it gets on_endoftrack(), relevant chunks contain last samples of the track.\n + //! Signaling this may interfere with gapless playback in certain scenarios (forces flush of DSPs placed before you) so don't use it unless you have reasons to. + virtual bool need_track_change_mark() = 0; +private: + dsp_impl_base_t(const t_self&) {throw pfc::exception_bug_check_v2();} + const t_self & operator=(const t_self &) {throw pfc::exception_bug_check_v2();} +}; + +template +void dsp_impl_base_t::run_v2(dsp_chunk_list * p_list,const metadb_handle_ptr & p_cur_file,int p_flags,abort_callback & p_abort) { + pfc::vartoggle_t l_list_toggle(m_list,p_list); + pfc::vartoggle_t l_cur_file_toggle(m_cur_file,p_cur_file.get_ptr()); + + for(m_chunk_ptr = 0;m_chunk_ptrget_count();m_chunk_ptr++) { + audio_chunk * c = m_list->get_item(m_chunk_ptr); + if (c->is_empty() || !on_chunk(c,p_abort)) + m_list->remove_by_idx(m_chunk_ptr--); + } + + if (p_flags & FLUSH) { + on_endofplayback(p_abort); + } else if (p_flags & END_OF_TRACK) { + if (need_track_change_mark()) on_endoftrack(p_abort); + } +} + + +typedef dsp_impl_base_t dsp_impl_base; + +class NOVTABLE dsp_preset { +public: + virtual GUID get_owner() const = 0; + virtual void set_owner(const GUID & p_owner) = 0; + virtual const void * get_data() const = 0; + virtual t_size get_data_size() const = 0; + virtual void set_data(const void * p_data,t_size p_data_size) = 0; + virtual void set_data_from_stream(stream_reader * p_stream,t_size p_bytes,abort_callback & p_abort) = 0; + + const dsp_preset & operator=(const dsp_preset & p_source) {copy(p_source); return *this;} + + void copy(const dsp_preset & p_source) {set_owner(p_source.get_owner());set_data(p_source.get_data(),p_source.get_data_size());} + + void contents_to_stream(stream_writer * p_stream,abort_callback & p_abort) const; + void contents_from_stream(stream_reader * p_stream,abort_callback & p_abort); + static void g_contents_from_stream_skip(stream_reader * p_stream,abort_callback & p_abort); + + bool operator==(const dsp_preset & p_other) const { + if (get_owner() != p_other.get_owner()) return false; + if (get_data_size() != p_other.get_data_size()) return false; + if (memcmp(get_data(),p_other.get_data(),get_data_size()) != 0) return false; + return true; + } + bool operator!=(const dsp_preset & p_other) const { + return !(*this == p_other); + } +protected: + dsp_preset() {} + ~dsp_preset() {} +}; + +class dsp_preset_writer : public stream_writer { +public: + void write(const void * p_buffer,t_size p_bytes,abort_callback & p_abort) { + p_abort.check(); + m_data.append_fromptr((const t_uint8 *) p_buffer,p_bytes); + } + void flush(dsp_preset & p_preset) { + p_preset.set_data(m_data.get_ptr(),m_data.get_size()); + m_data.set_size(0); + } +private: + pfc::array_t m_data; +}; + +class dsp_preset_reader : public stream_reader { +public: + dsp_preset_reader() : m_walk(0) {} + dsp_preset_reader(const dsp_preset_reader & p_source) : m_walk(0) {*this = p_source;} + void init(const dsp_preset & p_preset) { + m_data.set_data_fromptr( (const t_uint8*) p_preset.get_data(), p_preset.get_data_size() ); + m_walk = 0; + } + t_size read(void * p_buffer,t_size p_bytes,abort_callback & p_abort) { + p_abort.check(); + t_size todo = pfc::min_t(p_bytes,m_data.get_size()-m_walk); + memcpy(p_buffer,m_data.get_ptr()+m_walk,todo); + m_walk += todo; + return todo; + } + bool is_finished() {return m_walk == m_data.get_size();} +private: + t_size m_walk; + pfc::array_t m_data; +}; + +class dsp_preset_impl : public dsp_preset +{ +public: + dsp_preset_impl() {} + dsp_preset_impl(const dsp_preset_impl & p_source) {copy(p_source);} + dsp_preset_impl(const dsp_preset & p_source) {copy(p_source);} + + const dsp_preset_impl& operator=(const dsp_preset_impl & p_source) {copy(p_source); return *this;} + const dsp_preset_impl& operator=(const dsp_preset & p_source) {copy(p_source); return *this;} + + GUID get_owner() const {return m_owner;} + void set_owner(const GUID & p_owner) {m_owner = p_owner;} + const void * get_data() const {return m_data.get_ptr();} + t_size get_data_size() const {return m_data.get_size();} + void set_data(const void * p_data,t_size p_data_size) {m_data.set_data_fromptr((const t_uint8*)p_data,p_data_size);} + void set_data_from_stream(stream_reader * p_stream,t_size p_bytes,abort_callback & p_abort); +private: + GUID m_owner; + pfc::array_t m_data; +}; + +class NOVTABLE dsp_preset_edit_callback { +public: + virtual void on_preset_changed(const dsp_preset &) = 0; +private: + dsp_preset_edit_callback(const dsp_preset_edit_callback&) {throw pfc::exception_not_implemented();} + const dsp_preset_edit_callback & operator=(const dsp_preset_edit_callback &) {throw pfc::exception_not_implemented();} +protected: + dsp_preset_edit_callback() {} + ~dsp_preset_edit_callback() {} +}; + +class NOVTABLE dsp_entry : public service_base { +public: + virtual void get_name(pfc::string_base & p_out) = 0; + virtual bool get_default_preset(dsp_preset & p_out) = 0; + virtual bool instantiate(service_ptr_t & p_out,const dsp_preset & p_preset) = 0; + virtual GUID get_guid() = 0; + virtual bool have_config_popup() = 0; + virtual bool show_config_popup(dsp_preset & p_data,HWND p_parent) = 0; + + + static bool g_get_interface(service_ptr_t & p_out,const GUID & p_guid); + static bool g_instantiate(service_ptr_t & p_out,const dsp_preset & p_preset); + static bool g_instantiate_default(service_ptr_t & p_out,const GUID & p_guid); + static bool g_name_from_guid(pfc::string_base & p_out,const GUID & p_guid); + static bool g_dsp_exists(const GUID & p_guid); + static bool g_get_default_preset(dsp_preset & p_out,const GUID & p_guid); + static bool g_have_config_popup(const GUID & p_guid); + static bool g_have_config_popup(const dsp_preset & p_preset); + static bool g_show_config_popup(dsp_preset & p_preset,HWND p_parent); + + static void g_show_config_popup_v2(const dsp_preset & p_preset,HWND p_parent,dsp_preset_edit_callback & p_callback); + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(dsp_entry); +}; + +class NOVTABLE dsp_entry_v2 : public dsp_entry { +public: + virtual void show_config_popup_v2(const dsp_preset & p_data,HWND p_parent,dsp_preset_edit_callback & p_callback) = 0; + +private: + bool show_config_popup(dsp_preset & p_data,HWND p_parent); + + FB2K_MAKE_SERVICE_INTERFACE(dsp_entry_v2,dsp_entry); +}; + +template +class dsp_entry_impl_nopreset_t : public t_entry { +public: + void get_name(pfc::string_base & p_out) {T::g_get_name(p_out);} + bool get_default_preset(dsp_preset & p_out) + { + p_out.set_owner(T::g_get_guid()); + p_out.set_data(0,0); + return true; + } + bool instantiate(service_ptr_t & p_out,const dsp_preset & p_preset) + { + if (p_preset.get_owner() == T::g_get_guid() && p_preset.get_data_size() == 0) + { + p_out = new service_impl_t(); + return p_out.is_valid(); + } + else return false; + } + GUID get_guid() {return T::g_get_guid();} + + bool have_config_popup() {return false;} + bool show_config_popup(dsp_preset & p_data,HWND p_parent) {return false;} +}; + +template +class dsp_entry_impl_t : public t_entry { +public: + void get_name(pfc::string_base & p_out) {T::g_get_name(p_out);} + bool get_default_preset(dsp_preset & p_out) {return T::g_get_default_preset(p_out);} + bool instantiate(service_ptr_t & p_out,const dsp_preset & p_preset) { + if (p_preset.get_owner() == T::g_get_guid()) { + p_out = new service_impl_t(p_preset); + return true; + } + else return false; + } + GUID get_guid() {return T::g_get_guid();} + + bool have_config_popup() {return T::g_have_config_popup();} + bool show_config_popup(dsp_preset & p_data,HWND p_parent) {return T::g_show_config_popup(p_data,p_parent);} + //void show_config_popup_v2(const dsp_preset & p_data,HWND p_parent,dsp_preset_edit_callback & p_callback) {T::g_show_config_popup(p_data,p_parent,p_callback);} +}; + +template +class dsp_entry_v2_impl_t : public t_entry { +public: + void get_name(pfc::string_base & p_out) {T::g_get_name(p_out);} + bool get_default_preset(dsp_preset & p_out) {return T::g_get_default_preset(p_out);} + bool instantiate(service_ptr_t & p_out,const dsp_preset & p_preset) { + if (p_preset.get_owner() == T::g_get_guid()) { + p_out = new service_impl_t(p_preset); + return true; + } + else return false; + } + GUID get_guid() {return T::g_get_guid();} + + bool have_config_popup() {return T::g_have_config_popup();} + //bool show_config_popup(dsp_preset & p_data,HWND p_parent) {return T::g_show_config_popup(p_data,p_parent);} + void show_config_popup_v2(const dsp_preset & p_data,HWND p_parent,dsp_preset_edit_callback & p_callback) {T::g_show_config_popup(p_data,p_parent,p_callback);} +}; + + +template +class dsp_factory_nopreset_t : public service_factory_single_t > {}; + +template +class dsp_factory_t : public service_factory_single_t > {}; + +class NOVTABLE dsp_chain_config +{ +public: + virtual t_size get_count() const = 0; + virtual const dsp_preset & get_item(t_size p_index) const = 0; + virtual void replace_item(const dsp_preset & p_data,t_size p_index) = 0; + virtual void insert_item(const dsp_preset & p_data,t_size p_index) = 0; + virtual void remove_mask(const bit_array & p_mask) = 0; + + void remove_item(t_size p_index); + void remove_all(); + void add_item(const dsp_preset & p_data); + void copy(const dsp_chain_config & p_source); + + const dsp_chain_config & operator=(const dsp_chain_config & p_source) {copy(p_source); return *this;} + + void contents_to_stream(stream_writer * p_stream,abort_callback & p_abort) const; + void contents_from_stream(stream_reader * p_stream,abort_callback & p_abort); + + void instantiate(service_list_t & p_out); + + void get_name_list(pfc::string_base & p_out) const; +}; + +FB2K_STREAM_READER_OVERLOAD(dsp_chain_config) { + value.contents_from_stream(&stream.m_stream, stream.m_abort); return stream; +} + +FB2K_STREAM_WRITER_OVERLOAD(dsp_chain_config) { + value.contents_to_stream(&stream.m_stream, stream.m_abort); return stream; +} + +class dsp_chain_config_impl : public dsp_chain_config +{ +public: + dsp_chain_config_impl() {} + dsp_chain_config_impl(const dsp_chain_config & p_source) {copy(p_source);} + dsp_chain_config_impl(const dsp_chain_config_impl & p_source) {copy(p_source);} + t_size get_count() const; + const dsp_preset & get_item(t_size p_index) const; + void replace_item(const dsp_preset & p_data,t_size p_index); + void insert_item(const dsp_preset & p_data,t_size p_index); + void remove_mask(const bit_array & p_mask); + + const dsp_chain_config_impl & operator=(const dsp_chain_config & p_source) {copy(p_source); return *this;} + const dsp_chain_config_impl & operator=(const dsp_chain_config_impl & p_source) {copy(p_source); return *this;} + + ~dsp_chain_config_impl(); +private: + pfc::ptr_list_t m_data; +}; + +class cfg_dsp_chain_config : public cfg_var { +protected: + void get_data_raw(stream_writer * p_stream,abort_callback & p_abort); + void set_data_raw(stream_reader * p_stream,t_size p_sizehint,abort_callback & p_abort); +public: + void reset(); + inline cfg_dsp_chain_config(const GUID & p_guid) : cfg_var(p_guid) {} + t_size get_count() const {return m_data.get_count();} + const dsp_preset & get_item(t_size p_index) const {return m_data.get_item(p_index);} + bool get_data(dsp_chain_config & p_data) const; + void set_data(const dsp_chain_config & p_data); +private: + dsp_chain_config_impl m_data; + +}; + + + + +//! Helper. +class dsp_preset_parser : public stream_reader_formatter<> { +public: + dsp_preset_parser(const dsp_preset & in) : m_data(in), _m_stream(in.get_data(),in.get_data_size()), stream_reader_formatter(_m_stream,_m_abort) {} + + void reset() {_m_stream.reset();} + t_size get_remaining() const {return _m_stream.get_remaining();} + + void assume_empty() const { + if (get_remaining() != 0) throw exception_io_data(); + } + + GUID get_owner() const {return m_data.get_owner();} +private: + const dsp_preset & m_data; + abort_callback_dummy _m_abort; + stream_reader_memblock_ref _m_stream; +}; + +//! Helper. +class dsp_preset_builder : public stream_writer_formatter<> { +public: + dsp_preset_builder() : stream_writer_formatter(_m_stream,_m_abort) {} + void finish(const GUID & id, dsp_preset & out) { + out.set_owner(id); + out.set_data(_m_stream.m_buffer.get_ptr(), _m_stream.m_buffer.get_size()); + } + void reset() { + _m_stream.m_buffer.set_size(0); + } +private: + abort_callback_dummy _m_abort; + stream_writer_buffer_simple _m_stream; +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/dsp_manager.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/dsp_manager.cpp new file mode 100644 index 000000000..56a7e99de --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/dsp_manager.cpp @@ -0,0 +1,188 @@ +#include "foobar2000.h" + +void dsp_manager::close() { + m_chain.remove_all(); + m_config_changed = true; +} + +void dsp_manager::set_config( const dsp_chain_config & p_data ) +{ + //dsp_chain_config::g_instantiate(m_dsp_list,p_data); + m_config.copy(p_data); + m_config_changed = true; +} + +void dsp_manager::dsp_run(t_dsp_chain::const_iterator p_iter,dsp_chunk_list * p_list,const metadb_handle_ptr & cur_file,unsigned flags,double & latency,abort_callback & p_abort) +{ + p_list->remove_bad_chunks(); + + TRACK_CODE("dsp::run",p_iter->m_dsp->run_abortable(p_list,cur_file,flags,p_abort)); + TRACK_CODE("dsp::get_latency",latency += p_iter->m_dsp->get_latency()); +} + +double dsp_manager::run(dsp_chunk_list * p_list,const metadb_handle_ptr & p_cur_file,unsigned p_flags,abort_callback & p_abort) { + TRACK_CALL_TEXT("dsp_manager::run"); + + try { + fpu_control_default l_fpu_control; + + double latency=0; + bool done = false; + + t_dsp_chain::const_iterator flush_mark; + if ((p_flags & dsp::END_OF_TRACK) && ! (p_flags & dsp::FLUSH)) { + for(t_dsp_chain::const_iterator iter = m_chain.first(); iter.is_valid(); ++iter) { + if (iter->m_dsp->need_track_change_mark()) flush_mark = iter; + } + } + + if (m_config_changed) + { + t_dsp_chain newchain; + bool recycle_available = true; + + for(t_size n=0;n temp; + + const dsp_preset & preset = m_config.get_item(n); + if (dsp_entry::g_dsp_exists(preset.get_owner())) { + t_dsp_chain::iterator iter = newchain.insert_last(); + iter->m_preset = m_config.get_item(n); + iter->m_recycle_flag = false; + } + } + + + //HACK: recycle existing DSPs in a special case when user has apparently only altered settings of one of DSPs. + if (newchain.get_count() == m_chain.get_count()) { + t_size data_mismatch_count = 0; + t_size owner_mismatch_count = 0; + t_dsp_chain::iterator iter_src, iter_dst; + iter_src = m_chain.first(); iter_dst = newchain.first(); + while(iter_src.is_valid() && iter_dst.is_valid()) { + if (iter_src->m_preset.get_owner() != iter_dst->m_preset.get_owner()) { + owner_mismatch_count++; + } else if (iter_src->m_preset != iter_dst->m_preset) { + data_mismatch_count++; + } + ++iter_src; ++iter_dst; + } + recycle_available = (owner_mismatch_count == 0 && data_mismatch_count <= 1); + } else { + recycle_available = false; + } + + if (recycle_available) { + t_dsp_chain::iterator iter_src, iter_dst; + iter_src = m_chain.first(); iter_dst = newchain.first(); + while(iter_src.is_valid() && iter_dst.is_valid()) { + if (iter_src->m_preset == iter_dst->m_preset) { + iter_src->m_recycle_flag = true; + iter_dst->m_dsp = iter_src->m_dsp; + } + ++iter_src; ++iter_dst; + } + } + + for(t_dsp_chain::iterator iter = newchain.first(); iter.is_valid(); ++iter) { + if (iter->m_dsp.is_empty()) { + if (!dsp_entry::g_instantiate(iter->m_dsp,iter->m_preset)) throw pfc::exception_bug_check_v2(); + } + } + + if (m_chain.get_count()>0) { + bool flushflag = flush_mark.is_valid(); + for(t_dsp_chain::const_iterator iter = m_chain.first(); iter.is_valid(); ++iter) { + unsigned flags2 = p_flags; + if (iter == flush_mark) flushflag = false; + if (flushflag || !iter->m_recycle_flag) flags2|=dsp::FLUSH; + dsp_run(iter,p_list,p_cur_file,flags2,latency,p_abort); + } + done = true; + } + + m_chain = newchain; + m_config_changed = false; + } + + if (!done) + { + bool flushflag = flush_mark.is_valid(); + for(t_dsp_chain::const_iterator iter = m_chain.first(); iter.is_valid(); ++iter) { + unsigned flags2 = p_flags; + if (iter == flush_mark) flushflag = false; + if (flushflag) flags2|=dsp::FLUSH; + dsp_run(iter,p_list,p_cur_file,flags2,latency,p_abort); + } + done = true; + } + + p_list->remove_bad_chunks(); + + return latency; + } catch(...) { + p_list->remove_all(); + throw; + } +} + +void dsp_manager::flush() +{ + for(t_dsp_chain::const_iterator iter = m_chain.first(); iter.is_valid(); ++iter) { + TRACK_CODE("dsp::flush",iter->m_dsp->flush()); + } +} + + +bool dsp_manager::is_active() const {return m_config.get_count()>0;} + +void dsp_config_manager::core_enable_dsp(const dsp_preset & preset) { + dsp_chain_config_impl cfg; + get_core_settings(cfg); + + bool found = false; + bool changed = false; + t_size n,m = cfg.get_count(); + for(n=0;n m_dsp; + dsp_preset_impl m_preset; + bool m_recycle_flag; + }; + typedef pfc::chain_list_v2_t t_dsp_chain; + + t_dsp_chain m_chain; + dsp_chain_config_impl m_config; + bool m_config_changed; + + void dsp_run(t_dsp_chain::const_iterator p_iter,dsp_chunk_list * list,const metadb_handle_ptr & cur_file,unsigned flags,double & latency,abort_callback&); + + dsp_manager(const dsp_manager &) {throw pfc::exception_not_implemented();} + const dsp_manager & operator=(const dsp_manager&) {throw pfc::exception_not_implemented();} +}; + +//! Core API for accessing core playback DSP settings as well as spawning DSP configuration dialogs. \n +//! Use static_api_ptr_t() to instantiate. +class dsp_config_manager : public service_base { + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(dsp_config_manager); +public: + //! Retrieves current core playback DSP settings. + virtual void get_core_settings(dsp_chain_config & p_out) = 0; + //! Changes current core playback DSP settings. + virtual void set_core_settings(const dsp_chain_config & p_data) = 0; + + //! Runs a modal DSP settings dialog. + //! @param p_data DSP chain configuration to edit - contains initial configuration to put in the dialog when called, receives the new configuration on successful edit. + //! @returns True when user approved DSP configuration changes (pressed the "OK" button), false when the user cancelled them ("Cancel" button). + virtual bool configure_popup(dsp_chain_config & p_data,HWND p_parent,const char * p_title) = 0; + + //! Spawns an embedded DSP settings dialog. + //! @param p_initdata Initial DSP chain configuration to put in the dialog. + //! @param p_parent Parent window to contain the embedded dialog. + //! @param p_id Control ID of the embedded dialog. The parent window will receive a WM_COMMAND with BN_CLICKED and this identifier when user changes settings in the embedded dialog. + //! @param p_from_modal Must be set to true when the parent window is a modal dialog, false otherwise. + virtual HWND configure_embedded(const dsp_chain_config & p_initdata,HWND p_parent,unsigned p_id,bool p_from_modal) = 0; + //! Retrieves current settings from an embedded DSP settings dialog. See also: configure_embedded(). + virtual void configure_embedded_retrieve(HWND wnd,dsp_chain_config & p_data) = 0; + //! Changes current settings in an embedded DSP settings dialog. See also: configure_embedded(). + virtual void configure_embedded_change(HWND wnd,const dsp_chain_config & p_data) = 0; + + + //! Helper - enables a DSP in core playback settings. + void core_enable_dsp(const dsp_preset & preset); + //! Helper - disables a DSP in core playback settings. + void core_disable_dsp(const GUID & id); + //! Helper - if a DSP with the specified identifier is present in playback settings, retrieves its configuration and returns true, otherwise returns false. + bool core_query_dsp(const GUID & id, dsp_preset & out); +}; + +//! Callback class for getting notified about core playback DSP settings getting altered. \n +//! Register your implementations with static service_factory_single_t g_myclass_factory; +class NOVTABLE dsp_config_callback : public service_base { + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(dsp_config_callback); +public: + //! Called when core playback DSP settings change. \n + //! Note: you must not try to alter core playback DSP settings inside this callback, or call anything else that possibly alters core playback DSP settings. + virtual void on_core_settings_change(const dsp_chain_config & p_newdata) = 0; +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/event_logger.h b/tools/vio2sf/src/foobar/foobar2000/SDK/event_logger.h new file mode 100644 index 000000000..20e3f7c58 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/event_logger.h @@ -0,0 +1,19 @@ +class NOVTABLE event_logger : public service_base { + FB2K_MAKE_SERVICE_INTERFACE(event_logger, service_base); +public: + enum { + severity_status, + severity_warning, + severity_error + }; + void log_status(const char * line) {log_entry(line, severity_status);} + void log_warning(const char * line) {log_entry(line, severity_warning);} + void log_error(const char * line) {log_entry(line, severity_error);} + + virtual void log_entry(const char * line, unsigned severity) = 0; +}; + +class event_logger_fallback : public event_logger { +public: + void log_entry(const char * line, unsigned) {console::print(line);} +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/file_info.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/file_info.cpp new file mode 100644 index 000000000..11275416b --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/file_info.cpp @@ -0,0 +1,451 @@ +#include "foobar2000.h" + +t_size file_info::meta_find_ex(const char * p_name,t_size p_name_length) const +{ + t_size n, m = meta_get_count(); + for(n=0;n= max) return 0; + return meta_enum_value(index,p_index); +} + +const char * file_info::info_get_ex(const char * p_name,t_size p_name_length) const +{ + t_size index = info_find_ex(p_name,p_name_length); + if (index == infinite) return 0; + return info_enum_value(index); +} + +t_int64 file_info::info_get_int(const char * name) const +{ + PFC_ASSERT(pfc::is_valid_utf8(name)); + const char * val = info_get(name); + if (val==0) return 0; + return _atoi64(val); +} + +t_int64 file_info::info_get_length_samples() const +{ + t_int64 ret = 0; + double len = get_length(); + t_int64 srate = info_get_int("samplerate"); + + if (srate>0 && len>0) + { + ret = audio_math::time_to_samples(len,(unsigned)srate); + } + return ret; +} + +double file_info::info_get_float(const char * name) const +{ + const char * ptr = info_get(name); + if (ptr) return pfc::string_to_float(ptr); + else return 0; +} + +void file_info::info_set_int(const char * name,t_int64 value) +{ + PFC_ASSERT(pfc::is_valid_utf8(name)); + info_set(name,pfc::format_int(value)); +} + +void file_info::info_set_float(const char * name,double value,unsigned precision,bool force_sign,const char * unit) +{ + PFC_ASSERT(pfc::is_valid_utf8(name)); + PFC_ASSERT(unit==0 || strlen(unit) <= 64); + char temp[128]; + pfc::float_to_string(temp,64,value,precision,force_sign); + temp[63] = 0; + if (unit) + { + strcat(temp," "); + strcat(temp,unit); + } + info_set(name,temp); +} + + +void file_info::info_set_replaygain_album_gain(float value) +{ + replaygain_info temp = get_replaygain(); + temp.m_album_gain = value; + set_replaygain(temp); +} + +void file_info::info_set_replaygain_album_peak(float value) +{ + replaygain_info temp = get_replaygain(); + temp.m_album_peak = value; + set_replaygain(temp); +} + +void file_info::info_set_replaygain_track_gain(float value) +{ + replaygain_info temp = get_replaygain(); + temp.m_track_gain = value; + set_replaygain(temp); +} + +void file_info::info_set_replaygain_track_peak(float value) +{ + replaygain_info temp = get_replaygain(); + temp.m_track_peak = value; + set_replaygain(temp); +} + + +static bool is_valid_bps(t_int64 val) +{ + return val>0 && val<=256; +} + +unsigned file_info::info_get_decoded_bps() const +{ + t_int64 val = info_get_int("decoded_bitspersample"); + if (is_valid_bps(val)) return (unsigned)val; + val = info_get_int("bitspersample"); + if (is_valid_bps(val)) return (unsigned)val; + return 0; + +} + +void file_info::reset() +{ + info_remove_all(); + meta_remove_all(); + set_length(0); + reset_replaygain(); +} + +void file_info::reset_replaygain() +{ + replaygain_info temp; + temp.reset(); + set_replaygain(temp); +} + +void file_info::copy_meta_single_rename_ex(const file_info & p_source,t_size p_index,const char * p_new_name,t_size p_new_name_length) +{ + t_size n, m = p_source.meta_enum_value_count(p_index); + t_size new_index = infinite; + for(n=0;n 0); + for(val=0;val 0) out += separator; + out += meta_enum_value(index,val); + } +} + +bool file_info::meta_format(const char * p_name,pfc::string_base & p_out, const char * separator) const { + p_out.reset(); + t_size index = meta_find(p_name); + if (index == infinite) return false; + meta_format_entry(index, p_out, separator); + return true; +} + +void file_info::info_calculate_bitrate(t_filesize p_filesize,double p_length) +{ + info_set_bitrate((unsigned)floor((double)p_filesize * 8 / (p_length * 1000) + 0.5)); +} + +bool file_info::is_encoding_lossy() const { + const char * encoding = info_get("encoding"); + if (encoding != NULL) { + if (pfc::stricmp_ascii(encoding,"lossy") == 0 /*|| pfc::stricmp_ascii(encoding,"hybrid") == 0*/) return true; + } else { + //the old way + if (info_get("bitspersample") == NULL) return true; + } + return false; +} + +bool file_info::g_is_meta_equal(const file_info & p_item1,const file_info & p_item2) { + const t_size count = p_item1.meta_get_count(); + if (count != p_item2.meta_get_count()) { + //uDebugLog() << "meta count mismatch"; + return false; + } + pfc::map_t item2_meta_map; + for(t_size n=0; n= 32 && p_char < 127 && p_char != '=' && p_char != '%' && p_char != '<' && p_char != '>'; +} + +bool file_info::g_is_valid_field_name(const char * p_name,t_size p_length) { + t_size walk; + for(walk = 0; walk < p_length && p_name[walk] != 0; walk++) { + if (!is_valid_field_name_char(p_name[walk])) return false; + } + return walk > 0; +} diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/file_info.h b/tools/vio2sf/src/foobar/foobar2000/SDK/file_info.h new file mode 100644 index 000000000..9ffa6f6c9 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/file_info.h @@ -0,0 +1,230 @@ +#ifndef _FILE_INFO_H_ +#define _FILE_INFO_H_ + +//! Structure containing ReplayGain scan results from some playable object, also providing various helper methods to manipulate those results. +struct replaygain_info +{ + float m_album_gain,m_track_gain; + float m_album_peak,m_track_peak; + + enum {text_buffer_size = 16 }; + typedef char t_text_buffer[text_buffer_size]; + + enum { peak_invalid = -1, gain_invalid = -1000 }; + + static bool g_format_gain(float p_value,char p_buffer[text_buffer_size]); + static bool g_format_peak(float p_value,char p_buffer[text_buffer_size]); + + inline bool format_album_gain(char p_buffer[text_buffer_size]) const {return g_format_gain(m_album_gain,p_buffer);} + inline bool format_track_gain(char p_buffer[text_buffer_size]) const {return g_format_gain(m_track_gain,p_buffer);} + inline bool format_album_peak(char p_buffer[text_buffer_size]) const {return g_format_peak(m_album_peak,p_buffer);} + inline bool format_track_peak(char p_buffer[text_buffer_size]) const {return g_format_peak(m_track_peak,p_buffer);} + + void set_album_gain_text(const char * p_text,t_size p_text_len = infinite); + void set_track_gain_text(const char * p_text,t_size p_text_len = infinite); + void set_album_peak_text(const char * p_text,t_size p_text_len = infinite); + void set_track_peak_text(const char * p_text,t_size p_text_len = infinite); + + static bool g_is_meta_replaygain(const char * p_name,t_size p_name_len = infinite); + bool set_from_meta_ex(const char * p_name,t_size p_name_len,const char * p_value,t_size p_value_len); + inline bool set_from_meta(const char * p_name,const char * p_value) {return set_from_meta_ex(p_name,infinite,p_value,infinite);} + + inline bool is_album_gain_present() const {return m_album_gain != gain_invalid;} + inline bool is_track_gain_present() const {return m_track_gain != gain_invalid;} + inline bool is_album_peak_present() const {return m_album_peak != peak_invalid;} + inline bool is_track_peak_present() const {return m_track_peak != peak_invalid;} + + inline void remove_album_gain() {m_album_gain = gain_invalid;} + inline void remove_track_gain() {m_track_gain = gain_invalid;} + inline void remove_album_peak() {m_album_peak = peak_invalid;} + inline void remove_track_peak() {m_track_peak = peak_invalid;} + + t_size get_value_count(); + + static replaygain_info g_merge(replaygain_info r1,replaygain_info r2); + + static bool g_equal(const replaygain_info & item1,const replaygain_info & item2); + + void reset(); +}; + +inline bool operator==(const replaygain_info & item1,const replaygain_info & item2) {return replaygain_info::g_equal(item1,item2);} +inline bool operator!=(const replaygain_info & item1,const replaygain_info & item2) {return !replaygain_info::g_equal(item1,item2);} + +static const replaygain_info replaygain_info_invalid = {replaygain_info::gain_invalid,replaygain_info::gain_invalid,replaygain_info::peak_invalid,replaygain_info::peak_invalid}; + + +//! Main interface class for information about some playable object. +class NOVTABLE file_info { +public: + //! Retrieves length, in seconds. + virtual double get_length() const = 0; + //! Sets length, in seconds. + virtual void set_length(double p_length) = 0; + + //! Sets ReplayGain information. + virtual void set_replaygain(const replaygain_info & p_info) = 0; + //! Retrieves ReplayGain information. + virtual replaygain_info get_replaygain() const = 0; + + //! Retrieves count of metadata entries. + virtual t_size meta_get_count() const = 0; + //! Retrieves the name of metadata entry of specified index. Return value is a null-terminated UTF-8 encoded string. + virtual const char* meta_enum_name(t_size p_index) const = 0; + //! Retrieves count of values in metadata entry of specified index. The value is always equal to or greater than 1. + virtual t_size meta_enum_value_count(t_size p_index) const = 0; + //! Retrieves specified value from specified metadata entry. Return value is a null-terminated UTF-8 encoded string. + virtual const char* meta_enum_value(t_size p_index,t_size p_value_number) const = 0; + //! Finds index of metadata entry of specified name. Returns infinite when not found. + virtual t_size meta_find_ex(const char * p_name,t_size p_name_length) const; + //! Creates a new metadata entry of specified name with specified value. If an entry of same name already exists, it is erased. Return value is the index of newly created metadata entry. + virtual t_size meta_set_ex(const char * p_name,t_size p_name_length,const char * p_value,t_size p_value_length) = 0; + //! Inserts a new value into specified metadata entry. + virtual void meta_insert_value_ex(t_size p_index,t_size p_value_index,const char * p_value,t_size p_value_length) = 0; + //! Removes metadata entries according to specified bit mask. + virtual void meta_remove_mask(const bit_array & p_mask) = 0; + //! Reorders metadata entries according to specified permutation. + virtual void meta_reorder(const t_size * p_order) = 0; + //! Removes values according to specified bit mask from specified metadata entry. If all values are removed, entire metadata entry is removed as well. + virtual void meta_remove_values(t_size p_index,const bit_array & p_mask) = 0; + //! Alters specified value in specified metadata entry. + virtual void meta_modify_value_ex(t_size p_index,t_size p_value_index,const char * p_value,t_size p_value_length) = 0; + + //! Retrieves number of technical info entries. + virtual t_size info_get_count() const = 0; + //! Retrieves the name of specified technical info entry. Return value is a null-terminated UTF-8 encoded string. + virtual const char* info_enum_name(t_size p_index) const = 0; + //! Retrieves the value of specified technical info entry. Return value is a null-terminated UTF-8 encoded string. + virtual const char* info_enum_value(t_size p_index) const = 0; + //! Creates a new technical info entry with specified name and specified value. If an entry of the same name already exists, it is erased. Return value is the index of newly created entry. + virtual t_size info_set_ex(const char * p_name,t_size p_name_length,const char * p_value,t_size p_value_length) = 0; + //! Removes technical info entries indicated by specified bit mask. + virtual void info_remove_mask(const bit_array & p_mask) = 0; + //! Finds technical info entry of specified name. Returns index of found entry on success, infinite on failure. + virtual t_size info_find_ex(const char * p_name,t_size p_name_length) const; + + //! Copies entire file_info contents from specified file_info object. + virtual void copy(const file_info & p_source);//virtualized for performance reasons, can be faster in two-pass + //! Copies metadata from specified file_info object. + virtual void copy_meta(const file_info & p_source);//virtualized for performance reasons, can be faster in two-pass + //! Copies technical info from specified file_info object. + virtual void copy_info(const file_info & p_source);//virtualized for performance reasons, can be faster in two-pass + + bool meta_exists_ex(const char * p_name,t_size p_name_length) const; + void meta_remove_field_ex(const char * p_name,t_size p_name_length); + void meta_remove_index(t_size p_index); + void meta_remove_all(); + void meta_remove_value(t_size p_index,t_size p_value); + const char * meta_get_ex(const char * p_name,t_size p_name_length,t_size p_index) const; + t_size meta_get_count_by_name_ex(const char * p_name,t_size p_name_length) const; + void meta_add_value_ex(t_size p_index,const char * p_value,t_size p_value_length); + t_size meta_add_ex(const char * p_name,t_size p_name_length,const char * p_value,t_size p_value_length); + t_size meta_calc_total_value_count() const; + bool meta_format(const char * p_name,pfc::string_base & p_out, const char * separator = ", ") const; + void meta_format_entry(t_size index, pfc::string_base & p_out, const char * separator = ", ") const;//same as meta_format but takes index instead of meta name. + + + bool info_exists_ex(const char * p_name,t_size p_name_length) const; + void info_remove_index(t_size p_index); + void info_remove_all(); + bool info_remove_ex(const char * p_name,t_size p_name_length); + const char * info_get_ex(const char * p_name,t_size p_name_length) const; + + inline t_size meta_find(const char * p_name) const {return meta_find_ex(p_name,infinite);} + inline bool meta_exists(const char * p_name) const {return meta_exists_ex(p_name,infinite);} + inline void meta_remove_field(const char * p_name) {meta_remove_field_ex(p_name,infinite);} + inline t_size meta_set(const char * p_name,const char * p_value) {return meta_set_ex(p_name,infinite,p_value,infinite);} + inline void meta_insert_value(t_size p_index,t_size p_value_index,const char * p_value) {meta_insert_value_ex(p_index,p_value_index,p_value,infinite);} + inline void meta_add_value(t_size p_index,const char * p_value) {meta_add_value_ex(p_index,p_value,infinite);} + inline const char* meta_get(const char * p_name,t_size p_index) const {return meta_get_ex(p_name,infinite,p_index);} + inline t_size meta_get_count_by_name(const char * p_name) const {return meta_get_count_by_name_ex(p_name,infinite);} + inline t_size meta_add(const char * p_name,const char * p_value) {return meta_add_ex(p_name,infinite,p_value,infinite);} + inline void meta_modify_value(t_size p_index,t_size p_value_index,const char * p_value) {meta_modify_value_ex(p_index,p_value_index,p_value,infinite);} + + + + inline t_size info_set(const char * p_name,const char * p_value) {return info_set_ex(p_name,infinite,p_value,infinite);} + inline t_size info_find(const char * p_name) const {return info_find_ex(p_name,infinite);} + inline t_size info_exists(const char * p_name) const {return info_exists_ex(p_name,infinite);} + inline bool info_remove(const char * p_name) {return info_remove_ex(p_name,infinite);} + inline const char * info_get(const char * p_name) const {return info_get_ex(p_name,infinite);} + + bool info_set_replaygain_ex(const char * p_name,t_size p_name_len,const char * p_value,t_size p_value_len); + inline bool info_set_replaygain(const char * p_name,const char * p_value) {return info_set_replaygain_ex(p_name,infinite,p_value,infinite);} + void info_set_replaygain_auto_ex(const char * p_name,t_size p_name_len,const char * p_value,t_size p_value_len); + inline void info_set_replaygain_auto(const char * p_name,const char * p_value) {info_set_replaygain_auto_ex(p_name,infinite,p_value,infinite);} + + + + void copy_meta_single(const file_info & p_source,t_size p_index); + void copy_info_single(const file_info & p_source,t_size p_index); + void copy_meta_single_by_name_ex(const file_info & p_source,const char * p_name,t_size p_name_length); + void copy_info_single_by_name_ex(const file_info & p_source,const char * p_name,t_size p_name_length); + inline void copy_meta_single_by_name(const file_info & p_source,const char * p_name) {copy_meta_single_by_name_ex(p_source,p_name,infinite);} + inline void copy_info_single_by_name(const file_info & p_source,const char * p_name) {copy_info_single_by_name_ex(p_source,p_name,infinite);} + void reset(); + void reset_replaygain(); + void copy_meta_single_rename_ex(const file_info & p_source,t_size p_index,const char * p_new_name,t_size p_new_name_length); + inline void copy_meta_single_rename(const file_info & p_source,t_size p_index,const char * p_new_name) {copy_meta_single_rename_ex(p_source,p_index,p_new_name,infinite);} + void overwrite_info(const file_info & p_source); + + t_int64 info_get_int(const char * name) const; + t_int64 info_get_length_samples() const; + double info_get_float(const char * name) const; + void info_set_int(const char * name,t_int64 value); + void info_set_float(const char * name,double value,unsigned precision,bool force_sign = false,const char * unit = 0); + void info_set_replaygain_track_gain(float value); + void info_set_replaygain_album_gain(float value); + void info_set_replaygain_track_peak(float value); + void info_set_replaygain_album_peak(float value); + + inline t_int64 info_get_bitrate_vbr() const {return info_get_int("bitrate_dynamic");} + inline void info_set_bitrate_vbr(t_int64 val) {info_set_int("bitrate_dynamic",val);} + inline t_int64 info_get_bitrate() const {return info_get_int("bitrate");} + inline void info_set_bitrate(t_int64 val) {info_set_int("bitrate",val);} + bool is_encoding_lossy() const; + + void info_calculate_bitrate(t_filesize p_filesize,double p_length); + + unsigned info_get_decoded_bps() const;//what bps the stream originally was (before converting to audio_sample), 0 if unknown + + void merge(const pfc::list_base_const_t & p_sources); + + bool are_meta_fields_identical(t_size p_index1,t_size p_index2) const; + + inline const file_info & operator=(const file_info & p_source) {copy(p_source);return *this;} + + static bool g_is_meta_equal(const file_info & p_item1,const file_info & p_item2); + static bool g_is_info_equal(const file_info & p_item1,const file_info & p_item2); + + //! Unsafe - does not check whether the field already exists and will result in duplicates if it does - call only when appropriate checks have been applied externally. + t_size __meta_add_unsafe_ex(const char * p_name,t_size p_name_length,const char * p_value,t_size p_value_length) {return meta_set_nocheck_ex(p_name,p_name_length,p_value,p_value_length);} + //! Unsafe - does not check whether the field already exists and will result in duplicates if it does - call only when appropriate checks have been applied externally. + t_size __meta_add_unsafe(const char * p_name,const char * p_value) {return meta_set_nocheck_ex(p_name,infinite,p_value,infinite);} + + //! Unsafe - does not check whether the field already exists and will result in duplicates if it does - call only when appropriate checks have been applied externally. + t_size __info_add_unsafe_ex(const char * p_name,t_size p_name_length,const char * p_value,t_size p_value_length) {return info_set_nocheck_ex(p_name,p_name_length,p_value,p_value_length);} + //! Unsafe - does not check whether the field already exists and will result in duplicates if it does - call only when appropriate checks have been applied externally. + t_size __info_add_unsafe(const char * p_name,const char * p_value) {return info_set_nocheck_ex(p_name,infinite,p_value,infinite);} + + static bool g_is_valid_field_name(const char * p_name,t_size p_length = infinite); + //typedef pfc::comparator_stricmp_ascii field_name_comparator; + typedef pfc::string::comparatorCaseInsensitiveASCII field_name_comparator; +protected: + file_info() {} + ~file_info() {} + void copy_meta_single_nocheck(const file_info & p_source,t_size p_index); + void copy_info_single_nocheck(const file_info & p_source,t_size p_index); + void copy_meta_single_by_name_nocheck_ex(const file_info & p_source,const char * p_name,t_size p_name_length); + void copy_info_single_by_name_nocheck_ex(const file_info & p_source,const char * p_name,t_size p_name_length); + inline void copy_meta_single_by_name_nocheck(const file_info & p_source,const char * p_name) {copy_meta_single_by_name_nocheck_ex(p_source,p_name,infinite);} + inline void copy_info_single_by_name_nocheck(const file_info & p_source,const char * p_name) {copy_info_single_by_name_nocheck_ex(p_source,p_name,infinite);} + + virtual t_size meta_set_nocheck_ex(const char * p_name,t_size p_name_length,const char * p_value,t_size p_value_length) = 0; + virtual t_size info_set_nocheck_ex(const char * p_name,t_size p_name_length,const char * p_value,t_size p_value_length) = 0; + inline t_size meta_set_nocheck(const char * p_name,const char * p_value) {return meta_set_nocheck_ex(p_name,infinite,p_value,infinite);} + inline t_size info_set_nocheck(const char * p_name,const char * p_value) {return info_set_nocheck_ex(p_name,infinite,p_value,infinite);} +}; + + +#endif //_FILE_INFO_H_ diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/file_info_impl.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/file_info_impl.cpp new file mode 100644 index 000000000..f55be0ec2 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/file_info_impl.cpp @@ -0,0 +1,243 @@ +#include "foobar2000.h" + + +t_size file_info_impl::meta_get_count() const +{ + return m_meta.get_count(); +} + +const char* file_info_impl::meta_enum_name(t_size p_index) const +{ + return m_meta.get_name(p_index); +} + +t_size file_info_impl::meta_enum_value_count(t_size p_index) const +{ + return m_meta.get_value_count(p_index); +} + +const char* file_info_impl::meta_enum_value(t_size p_index,t_size p_value_number) const +{ + return m_meta.get_value(p_index,p_value_number); +} + +t_size file_info_impl::meta_set_ex(const char * p_name,t_size p_name_length,const char * p_value,t_size p_value_length) +{ + meta_remove_field_ex(p_name,p_name_length); + return meta_set_nocheck_ex(p_name,p_name_length,p_value,p_value_length); +} + +t_size file_info_impl::meta_set_nocheck_ex(const char * p_name,t_size p_name_length,const char * p_value,t_size p_value_length) +{ + return m_meta.add_entry(p_name,p_name_length,p_value,p_value_length); +} + +void file_info_impl::meta_insert_value_ex(t_size p_index,t_size p_value_index,const char * p_value,t_size p_value_length) +{ + m_meta.insert_value(p_index,p_value_index,p_value,p_value_length); +} + +void file_info_impl::meta_remove_mask(const bit_array & p_mask) +{ + m_meta.remove_mask(p_mask); +} + +void file_info_impl::meta_reorder(const t_size * p_order) +{ + m_meta.reorder(p_order); +} + +void file_info_impl::meta_remove_values(t_size p_index,const bit_array & p_mask) +{ + m_meta.remove_values(p_index,p_mask); + if (m_meta.get_value_count(p_index) == 0) + m_meta.remove_mask(bit_array_one(p_index)); +} + +t_size file_info_impl::info_get_count() const +{ + return m_info.get_count(); +} + +const char* file_info_impl::info_enum_name(t_size p_index) const +{ + return m_info.get_name(p_index); +} + +const char* file_info_impl::info_enum_value(t_size p_index) const +{ + return m_info.get_value(p_index); +} + +t_size file_info_impl::info_set_ex(const char * p_name,t_size p_name_length,const char * p_value,t_size p_value_length) +{ + info_remove_ex(p_name,p_name_length); + return info_set_nocheck_ex(p_name,p_name_length,p_value,p_value_length); +} + +t_size file_info_impl::info_set_nocheck_ex(const char * p_name,t_size p_name_length,const char * p_value,t_size p_value_length) +{ + return m_info.add_item(p_name,p_name_length,p_value,p_value_length); +} + +void file_info_impl::info_remove_mask(const bit_array & p_mask) +{ + m_info.remove_mask(p_mask); +} + + +file_info_impl::file_info_impl(const file_info & p_source) : m_length(0) +{ + copy(p_source); +} + +file_info_impl::file_info_impl(const file_info_impl & p_source) : m_length(0) +{ + copy(p_source); +} + +const file_info_impl & file_info_impl::operator=(const file_info_impl & p_source) +{ + copy(p_source); + return *this; +} + +file_info_impl::file_info_impl() : m_length(0) +{ + m_replaygain.reset(); +} + +double file_info_impl::get_length() const +{ + return m_length; +} + +void file_info_impl::set_length(double p_length) +{ + m_length = p_length; +} + +void file_info_impl::meta_modify_value_ex(t_size p_index,t_size p_value_index,const char * p_value,t_size p_value_length) +{ + m_meta.modify_value(p_index,p_value_index,p_value,p_value_length); +} + +replaygain_info file_info_impl::get_replaygain() const +{ + return m_replaygain; +} + +void file_info_impl::set_replaygain(const replaygain_info & p_info) +{ + m_replaygain = p_info; +} + + + + +file_info_impl::~file_info_impl() +{ +} + +t_size file_info_impl_utils::info_storage::add_item(const char * p_name,t_size p_name_length,const char * p_value,t_size p_value_length) { + t_size index = m_info.get_size(); + m_info.set_size(index + 1); + m_info[index].init(p_name,p_name_length,p_value,p_value_length); + return index; +} + +void file_info_impl_utils::info_storage::remove_mask(const bit_array & p_mask) { + pfc::remove_mask_t(m_info,p_mask); +} + + + +t_size file_info_impl_utils::meta_storage::add_entry(const char * p_name,t_size p_name_length,const char * p_value,t_size p_value_length) +{ + meta_entry temp(p_name,p_name_length,p_value,p_value_length); + return pfc::append_swap_t(m_data,temp); +} + +void file_info_impl_utils::meta_storage::insert_value(t_size p_index,t_size p_value_index,const char * p_value,t_size p_value_length) +{ + m_data[p_index].insert_value(p_value_index,p_value,p_value_length); +} + +void file_info_impl_utils::meta_storage::modify_value(t_size p_index,t_size p_value_index,const char * p_value,t_size p_value_length) +{ + m_data[p_index].modify_value(p_value_index,p_value,p_value_length); +} + +void file_info_impl_utils::meta_storage::remove_values(t_size p_index,const bit_array & p_mask) +{ + m_data[p_index].remove_values(p_mask); +} + +void file_info_impl_utils::meta_storage::remove_mask(const bit_array & p_mask) +{ + pfc::remove_mask_t(m_data,p_mask); +} + + +file_info_impl_utils::meta_entry::meta_entry(const char * p_name,t_size p_name_len,const char * p_value,t_size p_value_len) +{ + m_name.set_string(p_name,p_name_len); + m_values.set_size(1); + m_values[0].set_string(p_value,p_value_len); +} + + +void file_info_impl_utils::meta_entry::remove_values(const bit_array & p_mask) +{ + pfc::remove_mask_t(m_values,p_mask); +} + +void file_info_impl_utils::meta_entry::insert_value(t_size p_value_index,const char * p_value,t_size p_value_length) +{ + pfc::string_simple temp; + temp.set_string(p_value,p_value_length); + pfc::insert_swap_t(m_values,temp,p_value_index); +} + +void file_info_impl_utils::meta_entry::modify_value(t_size p_value_index,const char * p_value,t_size p_value_length) +{ + m_values[p_value_index].set_string(p_value,p_value_length); +} + +void file_info_impl_utils::meta_storage::reorder(const t_size * p_order) +{ + pfc::reorder_t(m_data,p_order,m_data.get_size()); +} + +void file_info_impl::copy_meta(const file_info & p_source) +{ + m_meta.copy_from(p_source); +} + +void file_info_impl::copy_info(const file_info & p_source) +{ + m_info.copy_from(p_source); +} + +void file_info_impl_utils::meta_storage::copy_from(const file_info & p_info) +{ + t_size meta_index,meta_count = p_info.meta_get_count(); + m_data.set_size(meta_count); + for(meta_index=0;meta_index info_entry_array; + +} + +namespace pfc { + template<> class traits_t : public traits_t {}; +}; + + +namespace file_info_impl_utils { + class info_storage + { + public: + t_size add_item(const char * p_name,t_size p_name_length,const char * p_value,t_size p_value_length); + void remove_mask(const bit_array & p_mask); + inline t_size get_count() const {return m_info.get_count();} + inline const char * get_name(t_size p_index) const {return m_info[p_index].get_name();} + inline const char * get_value(t_size p_index) const {return m_info[p_index].get_value();} + void copy_from(const file_info & p_info); + private: + info_entry_array m_info; + }; +} + + +namespace file_info_impl_utils { + typedef pfc::array_hybrid_t meta_value_array; + struct meta_entry { + meta_entry() {} + meta_entry(const char * p_name,t_size p_name_len,const char * p_value,t_size p_value_len); + + void remove_values(const bit_array & p_mask); + void insert_value(t_size p_value_index,const char * p_value,t_size p_value_length); + void modify_value(t_size p_value_index,const char * p_value,t_size p_value_length); + + inline const char * get_name() const {return m_name;} + inline const char * get_value(t_size p_index) const {return m_values[p_index];} + inline t_size get_value_count() const {return m_values.get_size();} + + + pfc::string_simple m_name; + meta_value_array m_values; + }; + typedef pfc::array_hybrid_t meta_entry_array; +} +namespace pfc { + template<> class traits_t : public pfc::traits_combined {}; +} + + +namespace file_info_impl_utils { + class meta_storage + { + public: + t_size add_entry(const char * p_name,t_size p_name_length,const char * p_value,t_size p_value_length); + void insert_value(t_size p_index,t_size p_value_index,const char * p_value,t_size p_value_length); + void modify_value(t_size p_index,t_size p_value_index,const char * p_value,t_size p_value_length); + void remove_values(t_size p_index,const bit_array & p_mask); + void remove_mask(const bit_array & p_mask); + void copy_from(const file_info & p_info); + + inline void reorder(const t_size * p_order); + + inline t_size get_count() const {return m_data.get_size();} + + inline const char * get_name(t_size p_index) const {assert(p_index < m_data.get_size()); return m_data[p_index].get_name();} + inline const char * get_value(t_size p_index,t_size p_value_index) const {assert(p_index < m_data.get_size()); return m_data[p_index].get_value(p_value_index);} + inline t_size get_value_count(t_size p_index) const {assert(p_index < m_data.get_size()); return m_data[p_index].get_value_count();} + + private: + meta_entry_array m_data; + }; +} + +//! Implements file_info. +class file_info_impl : public file_info +{ +public: + file_info_impl(const file_info_impl & p_source); + file_info_impl(const file_info & p_source); + file_info_impl(); + ~file_info_impl(); + + double get_length() const; + void set_length(double p_length); + + void copy_meta(const file_info & p_source);//virtualized for performance reasons, can be faster in two-pass + void copy_info(const file_info & p_source);//virtualized for performance reasons, can be faster in two-pass + + t_size meta_get_count() const; + const char* meta_enum_name(t_size p_index) const; + t_size meta_enum_value_count(t_size p_index) const; + const char* meta_enum_value(t_size p_index,t_size p_value_number) const; + t_size meta_set_ex(const char * p_name,t_size p_name_length,const char * p_value,t_size p_value_length); + void meta_insert_value_ex(t_size p_index,t_size p_value_index,const char * p_value,t_size p_value_length); + void meta_remove_mask(const bit_array & p_mask); + void meta_reorder(const t_size * p_order); + void meta_remove_values(t_size p_index,const bit_array & p_mask); + void meta_modify_value_ex(t_size p_index,t_size p_value_index,const char * p_value,t_size p_value_length); + + t_size info_get_count() const; + const char* info_enum_name(t_size p_index) const; + const char* info_enum_value(t_size p_index) const; + t_size info_set_ex(const char * p_name,t_size p_name_length,const char * p_value,t_size p_value_length); + void info_remove_mask(const bit_array & p_mask); + + const file_info_impl & operator=(const file_info_impl & p_source); + + replaygain_info get_replaygain() const; + void set_replaygain(const replaygain_info & p_info); + +protected: + t_size meta_set_nocheck_ex(const char * p_name,t_size p_name_length,const char * p_value,t_size p_value_length); + t_size info_set_nocheck_ex(const char * p_name,t_size p_name_length,const char * p_value,t_size p_value_length); +private: + + + file_info_impl_utils::meta_storage m_meta; + file_info_impl_utils::info_storage m_info; + + + double m_length; + + replaygain_info m_replaygain; +}; + +#endif diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/file_info_merge.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/file_info_merge.cpp new file mode 100644 index 000000000..e7aba0d2c --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/file_info_merge.cpp @@ -0,0 +1,130 @@ +#include "foobar2000.h" + +static t_size merge_tags_calc_rating_by_index(const file_info & p_info,t_size p_index) { + t_size n,m = p_info.meta_enum_value_count(p_index); + t_size ret = 0; + for(n=0;ninfo_get(field); + if (val) to->info_set(field,val); +} + +namespace { + struct meta_merge_entry { + meta_merge_entry() : m_rating(0) {} + t_size m_rating; + pfc::array_t m_data; + }; + + class meta_merge_map_enumerator { + public: + meta_merge_map_enumerator(file_info & p_out) : m_out(p_out) { + m_out.meta_remove_all(); + } + void operator() (const char * p_name, const meta_merge_entry & p_entry) { + if (p_entry.m_data.get_size() > 0) { + t_size index = m_out.__meta_add_unsafe(p_name,p_entry.m_data[0]); + for(t_size walk = 1; walk < p_entry.m_data.get_size(); ++walk) { + m_out.meta_add_value(index,p_entry.m_data[walk]); + } + } + } + private: + file_info & m_out; + }; +} + +static void merge_meta(file_info & p_out,const pfc::list_base_const_t & p_in) { + pfc::map_t map; + for(t_size in_walk = 0; in_walk < p_in.get_count(); in_walk++) { + const file_info & in = * p_in[in_walk]; + for(t_size meta_walk = 0, meta_count = in.meta_get_count(); meta_walk < meta_count; meta_walk++ ) { + meta_merge_entry & entry = map.find_or_add(in.meta_enum_name(meta_walk)); + t_size rating = merge_tags_calc_rating_by_index(in,meta_walk); + if (rating > entry.m_rating) { + entry.m_rating = rating; + const t_size value_count = in.meta_enum_value_count(meta_walk); + entry.m_data.set_size(value_count); + for(t_size value_walk = 0; value_walk < value_count; value_walk++ ) { + entry.m_data[value_walk] = in.meta_enum_value(meta_walk,value_walk); + } + } + } + } + + map.enumerate(meta_merge_map_enumerator(p_out)); +} + +void file_info::merge(const pfc::list_base_const_t & p_in) +{ + t_size in_count = p_in.get_count(); + if (in_count == 0) + { + meta_remove_all(); + return; + } + else if (in_count == 1) + { + const file_info * info = p_in[0]; + + copy_meta(*info); + + set_replaygain(replaygain_info::g_merge(get_replaygain(),info->get_replaygain())); + + overwrite_info(*info); + + //copy_info_single_by_name(*info,"tagtype"); + + return; + } + + merge_meta(*this,p_in); + + { + pfc::string8_fastalloc tagtype; + replaygain_info rg = get_replaygain(); + t_size in_ptr; + for(in_ptr = 0; in_ptr < in_count; in_ptr++ ) + { + const file_info * info = p_in[in_ptr]; + rg = replaygain_info::g_merge(rg, info->get_replaygain()); + t_size field_ptr, field_max = info->info_get_count(); + for(field_ptr = 0; field_ptr < field_max; field_ptr++ ) + { + const char * field_name = info->info_enum_name(field_ptr), * field_value = info->info_enum_value(field_ptr); + if (*field_value) + { + if (!stricmp_utf8(field_name,"tagtype")) + { + if (!tagtype.is_empty()) tagtype += "|"; + tagtype += field_value; + } + } + } + } + if (!tagtype.is_empty()) info_set("tagtype",tagtype); + set_replaygain(rg); + } +} + +void file_info::overwrite_info(const file_info & p_source) { + t_size count = p_source.info_get_count(); + for(t_size n=0;n & p_items) +{ + static_api_ptr_t()->on_files_deleted_sorted(p_items); + static_api_ptr_t()->on_files_deleted_sorted(p_items); + + service_ptr_t ptr; + service_enum_t e; + while(e.next(ptr)) + { + ptr->on_files_deleted_sorted(p_items); + } +} + +static void g_on_files_moved_sorted(const pfc::list_base_const_t & p_from,const pfc::list_base_const_t & p_to) +{ + static_api_ptr_t()->on_files_moved_sorted(p_from,p_to); + static_api_ptr_t()->on_files_deleted_sorted(p_from); + + service_ptr_t ptr; + service_enum_t e; + while(e.next(ptr)) + { + ptr->on_files_moved_sorted(p_from,p_to); + } +} + +static void g_on_files_copied_sorted(const pfc::list_base_const_t & p_from,const pfc::list_base_const_t & p_to) +{ + service_ptr_t ptr; + service_enum_t e; + while(e.next(ptr)) + { + ptr->on_files_copied_sorted(p_from,p_to); + } +} + +void file_operation_callback::g_on_files_deleted(const pfc::list_base_const_t & p_items) +{ + core_api::ensure_main_thread(); + t_size count = p_items.get_count(); + if (count > 0) + { + if (count == 1) g_on_files_deleted_sorted(p_items); + else + { + pfc::array_t order; order.set_size(count); + order_helper::g_fill(order); + p_items.sort_get_permutation_t(metadb::path_compare,order.get_ptr()); + g_on_files_deleted_sorted(pfc::list_permutation_t(p_items,order.get_ptr(),count)); + } + } +} + +void file_operation_callback::g_on_files_moved(const pfc::list_base_const_t & p_from,const pfc::list_base_const_t & p_to) +{ + core_api::ensure_main_thread(); + pfc::dynamic_assert(p_from.get_count() == p_to.get_count()); + t_size count = p_from.get_count(); + if (count > 0) + { + if (count == 1) g_on_files_moved_sorted(p_from,p_to); + else + { + pfc::array_t order; order.set_size(count); + order_helper::g_fill(order); + p_from.sort_get_permutation_t(metadb::path_compare,order.get_ptr()); + g_on_files_moved_sorted(pfc::list_permutation_t(p_from,order.get_ptr(),count),pfc::list_permutation_t(p_to,order.get_ptr(),count)); + } + } +} + +void file_operation_callback::g_on_files_copied(const pfc::list_base_const_t & p_from,const pfc::list_base_const_t & p_to) +{ + if (core_api::assert_main_thread()) + { + assert(p_from.get_count() == p_to.get_count()); + t_size count = p_from.get_count(); + if (count > 0) + { + if (count == 1) g_on_files_copied_sorted(p_from,p_to); + else + { + pfc::array_t order; order.set_size(count); + order_helper::g_fill(order); + p_from.sort_get_permutation_t(metadb::path_compare,order.get_ptr()); + g_on_files_copied_sorted(pfc::list_permutation_t(p_from,order.get_ptr(),count),pfc::list_permutation_t(p_to,order.get_ptr(),count)); + } + } + } +} +bool file_operation_callback::g_search_sorted_list(const pfc::list_base_const_t & p_list,const char * p_string,t_size & p_index) { + return pfc::binarySearch::run(p_list,0,p_list.get_count(),p_string,p_index); +} + +bool file_operation_callback::g_update_list_on_moved_ex(metadb_handle_list_ref p_list,t_pathlist p_from,t_pathlist p_to, metadb_handle_list_ref itemsAdded, metadb_handle_list_ref itemsRemoved) { + static_api_ptr_t api; + bool changed = false; + itemsAdded.remove_all(); itemsRemoved.remove_all(); + for(t_size walk = 0; walk < p_list.get_count(); ++walk) { + metadb_handle_ptr item = p_list[walk]; + t_size index; + if (g_search_sorted_list(p_from,item->get_path(),index)) { + metadb_handle_ptr newItem; + api->handle_create_replace_path_canonical(newItem,item,p_to[index]); + p_list.replace_item(walk,newItem); + changed = true; + itemsAdded.add_item(newItem); itemsRemoved.add_item(item); + } + } + return changed; +} +bool file_operation_callback::g_update_list_on_moved(metadb_handle_list_ref p_list,const pfc::list_base_const_t & p_from,const pfc::list_base_const_t & p_to) { + static_api_ptr_t api; + bool changed = false; + for(t_size walk = 0; walk < p_list.get_count(); ++walk) { + metadb_handle_ptr item = p_list[walk]; + t_size index; + if (g_search_sorted_list(p_from,item->get_path(),index)) { + metadb_handle_ptr newItem; + api->handle_create_replace_path_canonical(newItem,item,p_to[index]); + p_list.replace_item(walk,newItem); + changed = true; + } + } + return changed; +} + + +bool file_operation_callback::g_mark_dead_entries(metadb_handle_list_cref items, bit_array_var & mask, t_pathlist deadPaths) { + bool found = false; + const t_size total = items.get_count(); + for(t_size walk = 0; walk < total; ++walk) { + t_size index; + if (g_search_sorted_list(deadPaths,items[walk]->get_path(),index)) { + mask.set(walk,true); found = true; + } else { + mask.set(walk,false); + } + } + return found; +} diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/file_operation_callback.h b/tools/vio2sf/src/foobar/foobar2000/SDK/file_operation_callback.h new file mode 100644 index 000000000..7118e5050 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/file_operation_callback.h @@ -0,0 +1,66 @@ +#ifndef _FILE_OPERATION_CALLBACK_H_ +#define _FILE_OPERATION_CALLBACK_H_ + +//! Interface to notify component system about files being deleted or moved. Operates in app's main thread only. + +class NOVTABLE file_operation_callback : public service_base { +public: + typedef const pfc::list_base_const_t & t_pathlist; + //! p_items is a metadb::path_compare sorted list of files that have been deleted. + virtual void on_files_deleted_sorted(t_pathlist p_items) = 0; + //! p_from is a metadb::path_compare sorted list of files that have been moved, p_to is a list of corresponding target locations. + virtual void on_files_moved_sorted(t_pathlist p_from,t_pathlist p_to) = 0; + //! p_from is a metadb::path_compare sorted list of files that have been copied, p_to is a list of corresponding target locations. + virtual void on_files_copied_sorted(t_pathlist p_from,t_pathlist p_to) = 0; + + static void g_on_files_deleted(const pfc::list_base_const_t & p_items); + static void g_on_files_moved(const pfc::list_base_const_t & p_from,const pfc::list_base_const_t & p_to); + static void g_on_files_copied(const pfc::list_base_const_t & p_from,const pfc::list_base_const_t & p_to); + + static bool g_search_sorted_list(const pfc::list_base_const_t & p_list,const char * p_string,t_size & p_index); + static bool g_update_list_on_moved(metadb_handle_list_ref p_list,t_pathlist p_from,t_pathlist p_to); + + static bool g_update_list_on_moved_ex(metadb_handle_list_ref p_list,t_pathlist p_from,t_pathlist p_to, metadb_handle_list_ref itemsAdded, metadb_handle_list_ref itemsRemoved); + + static bool g_mark_dead_entries(metadb_handle_list_cref items, bit_array_var & mask, t_pathlist deadPaths); + + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(file_operation_callback); +}; + + + +//! New in 0.9.5. +class NOVTABLE file_operation_callback_dynamic { +public: + //! p_items is a metadb::path_compare sorted list of files that have been deleted. + virtual void on_files_deleted_sorted(const pfc::list_base_const_t & p_items) = 0; + //! p_from is a metadb::path_compare sorted list of files that have been moved, p_to is a list of corresponding target locations. + virtual void on_files_moved_sorted(const pfc::list_base_const_t & p_from,const pfc::list_base_const_t & p_to) = 0; + //! p_from is a metadb::path_compare sorted list of files that have been copied, p_to is a list of corresponding target locations. + virtual void on_files_copied_sorted(const pfc::list_base_const_t & p_from,const pfc::list_base_const_t & p_to) = 0; +}; + +//! New in 0.9.5. +class NOVTABLE file_operation_callback_dynamic_manager : public service_base { +public: + virtual void register_callback(file_operation_callback_dynamic * p_callback) = 0; + virtual void unregister_callback(file_operation_callback_dynamic * p_callback) = 0; + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(file_operation_callback_dynamic_manager); +}; + +//! New in 0.9.5. +class file_operation_callback_dynamic_impl_base : public file_operation_callback_dynamic { +public: + file_operation_callback_dynamic_impl_base() {static_api_ptr_t()->register_callback(this);} + ~file_operation_callback_dynamic_impl_base() {static_api_ptr_t()->unregister_callback(this);} + + void on_files_deleted_sorted(const pfc::list_base_const_t & p_items) {} + void on_files_moved_sorted(const pfc::list_base_const_t & p_from,const pfc::list_base_const_t & p_to) {} + void on_files_copied_sorted(const pfc::list_base_const_t & p_from,const pfc::list_base_const_t & p_to) {} + + PFC_CLASS_NOT_COPYABLE_EX(file_operation_callback_dynamic_impl_base); +}; + +#endif //_FILE_OPERATION_CALLBACK_H_ diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/filesystem.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/filesystem.cpp new file mode 100644 index 000000000..1f3517fbd --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/filesystem.cpp @@ -0,0 +1,863 @@ +#include "foobar2000.h" + + +void unpacker::g_open(service_ptr_t & p_out,const service_ptr_t & p,abort_callback & p_abort) +{ + service_enum_t e; + service_ptr_t ptr; + if (e.first(ptr)) do { + p->reopen(p_abort); + try { + ptr->open(p_out,p,p_abort); + return; + } catch(exception_io_data const &) {} + } while(e.next(ptr)); + throw exception_io_data(); +} + +void file::seek_ex(t_sfilesize p_position, file::t_seek_mode p_mode, abort_callback &p_abort) { + switch(p_mode) { + case seek_from_beginning: + seek(p_position,p_abort); + break; + case seek_from_current: + seek(p_position + get_position(p_abort),p_abort); + break; + case seek_from_eof: + seek(p_position + get_size_ex(p_abort),p_abort); + break; + default: + throw exception_io_data(); + } +} + +t_filesize file::g_transfer(stream_reader * p_src,stream_writer * p_dst,t_filesize p_bytes,abort_callback & p_abort) { + enum {BUFSIZE = 1024*1024*8}; + pfc::array_t temp; + temp.set_size((t_size)pfc::min_t(BUFSIZE,p_bytes)); + void* ptr = temp.get_ptr(); + t_filesize done = 0; + while(done(BUFSIZE,p_bytes-done); + delta = p_src->read(ptr,delta,p_abort); + if (delta<=0) break; + p_dst->write(ptr,delta,p_abort); + done += delta; + } + return done; +} + +void file::g_transfer_object(stream_reader * p_src,stream_writer * p_dst,t_filesize p_bytes,abort_callback & p_abort) { + if (g_transfer(p_src,p_dst,p_bytes,p_abort) != p_bytes) + throw exception_io_data_truncation(); +} + + +void filesystem::g_get_canonical_path(const char * path,pfc::string_base & out) +{ + TRACK_CALL_TEXT("filesystem::g_get_canonical_path"); + + service_enum_t e; + service_ptr_t ptr; + if (e.first(ptr)) do { + if (ptr->get_canonical_path(path,out)) return; + } while(e.next(ptr)); + //no one wants to process this, let's copy over + out = path; +} + +void filesystem::g_get_display_path(const char * path,pfc::string_base & out) +{ + TRACK_CALL_TEXT("filesystem::g_get_display_path"); + service_ptr_t ptr; + if (!g_get_interface(ptr,path)) + { + //no one wants to process this, let's copy over + out = path; + } + else + { + if (!ptr->get_display_path(path,out)) + out = path; + } +} + +bool filesystem::g_get_interface(service_ptr_t & p_out,const char * path) +{ + service_enum_t e; + service_ptr_t ptr; + if (e.first(ptr)) do { + if (ptr->is_our_path(path)) + { + p_out = ptr; + return true; + } + } while(e.next(ptr)); + return false; +} + + +void filesystem::g_open(service_ptr_t & p_out,const char * path,t_open_mode mode,abort_callback & p_abort) +{ + TRACK_CALL_TEXT("filesystem::g_open"); + service_ptr_t fs; + if (!g_get_interface(fs,path)) throw exception_io_no_handler_for_path(); + fs->open(p_out,path,mode,p_abort); +} + +void filesystem::g_open_timeout(service_ptr_t & p_out,const char * p_path,t_open_mode p_mode,double p_timeout,abort_callback & p_abort) { + pfc::lores_timer timer; + timer.start(); + for(;;) { + try { + g_open(p_out,p_path,p_mode,p_abort); + break; + } catch(exception_io_sharing_violation) { + if (timer.query() > p_timeout) throw; + p_abort.sleep(0.01); + } + } +} + +bool filesystem::g_exists(const char * p_path,abort_callback & p_abort) +{ + t_filestats stats; + bool dummy; + try { + g_get_stats(p_path,stats,dummy,p_abort); + } catch(exception_io_not_found) {return false;} + return true; +} + +bool filesystem::g_exists_writeable(const char * p_path,abort_callback & p_abort) +{ + t_filestats stats; + bool writeable; + try { + g_get_stats(p_path,stats,writeable,p_abort); + } catch(exception_io_not_found) {return false;} + return writeable; +} + +void filesystem::g_remove(const char * p_path,abort_callback & p_abort) { + service_ptr_t fs; + if (!g_get_interface(fs,p_path)) throw exception_io_no_handler_for_path(); + fs->remove(p_path,p_abort); +} + +void filesystem::g_remove_timeout(const char * p_path,double p_timeout,abort_callback & p_abort) { + pfc::lores_timer timer; + timer.start(); + for(;;) { + try { + g_remove(p_path,p_abort); + break; + } catch(exception_io_sharing_violation) { + if (timer.query() > p_timeout) throw; + p_abort.sleep(0.01); + } + } +} + +void filesystem::g_move_timeout(const char * p_src,const char * p_dst,double p_timeout,abort_callback & p_abort) { + pfc::lores_timer timer; + timer.start(); + for(;;) { + try { + g_move(p_src,p_dst,p_abort); + break; + } catch(exception_io_sharing_violation) { + if (timer.query() > p_timeout) throw; + p_abort.sleep(0.01); + } + } +} + +void filesystem::g_copy_timeout(const char * p_src,const char * p_dst,double p_timeout,abort_callback & p_abort) { + pfc::lores_timer timer; + timer.start(); + for(;;) { + try { + g_copy(p_src,p_dst,p_abort); + break; + } catch(exception_io_sharing_violation) { + if (timer.query() > p_timeout) throw; + p_abort.sleep(0.01); + } + } +} + +void filesystem::g_create_directory(const char * p_path,abort_callback & p_abort) +{ + service_ptr_t fs; + if (!g_get_interface(fs,p_path)) throw exception_io_no_handler_for_path(); + fs->create_directory(p_path,p_abort); +} + +void filesystem::g_move(const char * src,const char * dst,abort_callback & p_abort) { + service_enum_t e; + service_ptr_t ptr; + if (e.first(ptr)) do { + if (ptr->is_our_path(src) && ptr->is_our_path(dst)) { + ptr->move(src,dst,p_abort); + return; + } + } while(e.next(ptr)); + throw exception_io_no_handler_for_path(); +} + +void filesystem::g_list_directory(const char * p_path,directory_callback & p_out,abort_callback & p_abort) +{ + TRACK_CALL_TEXT("filesystem::g_list_directory"); + service_ptr_t ptr; + if (!g_get_interface(ptr,p_path)) throw exception_io_no_handler_for_path(); + ptr->list_directory(p_path,p_out,p_abort); +} + + +static void path_pack_string(pfc::string_base & out,const char * src) +{ + out.add_char('|'); + out << strlen(src); + out.add_char('|'); + out << src; + out.add_char('|'); +} + +static int path_unpack_string(pfc::string8 & out,const char * src) +{ + int ptr=0; + if (src[ptr++]!='|') return -1; + int len = atoi(src+ptr); + if (len<=0) return -1; + while(src[ptr]!=0 && src[ptr]!='|') ptr++; + if (src[ptr]!='|') return -1; + ptr++; + int start = ptr; + while(ptr-start & p_out,const char * p_path,abort_callback & p_abort) { + service_ptr_t fs; + if (!g_get_interface(fs,p_path)) throw exception_io_no_handler_for_path(); + if (fs->is_remote(p_path)) throw exception_io_object_is_remote(); + fs->open(p_out,p_path,open_mode_read,p_abort); +} + +bool filesystem::g_is_remote(const char * p_path) { + service_ptr_t fs; + if (g_get_interface(fs,p_path)) return fs->is_remote(p_path); + else throw exception_io_no_handler_for_path(); +} + +bool filesystem::g_is_recognized_and_remote(const char * p_path) { + service_ptr_t fs; + if (g_get_interface(fs,p_path)) return fs->is_remote(p_path); + else return false; +} + +bool filesystem::g_is_remote_or_unrecognized(const char * p_path) { + service_ptr_t fs; + if (g_get_interface(fs,p_path)) return fs->is_remote(p_path); + else return true; +} + +bool filesystem::g_relative_path_create(const char * file_path,const char * playlist_path,pfc::string_base & out) +{ + + bool rv = false; + service_ptr_t fs; + + if (g_get_interface(fs,file_path)) + rv = fs->relative_path_create(file_path,playlist_path,out); + + return rv; +} + +bool filesystem::g_relative_path_parse(const char * relative_path,const char * playlist_path,pfc::string_base & out) +{ + service_enum_t e; + service_ptr_t ptr; + if (e.first(ptr)) do { + if (ptr->relative_path_parse(relative_path,playlist_path,out)) return true; + } while(e.next(ptr)); + return false; +} + + + +bool archive_impl::get_canonical_path(const char * path,pfc::string_base & out) +{ + if (is_our_path(path)) + { + pfc::string8 archive,file,archive_canonical; + if (g_parse_unpack_path(path,archive,file)) + { + g_get_canonical_path(archive,archive_canonical); + make_unpack_path(out,archive_canonical,file); + + return true; + } + else return false; + } + else return false; +} + +bool archive_impl::is_our_path(const char * path) +{ + if (strncmp(path,"unpack://",9)) return false; + const char * type = get_archive_type(); + path += 9; + while(*type) + { + if (*type!=*path) return false; + type++; + path++; + } + if (*path!='|') return false; + return true; +} + +bool archive_impl::get_display_path(const char * path,pfc::string_base & out) +{ + pfc::string8 archive,file; + if (g_parse_unpack_path(path,archive,file)) + { + g_get_display_path(archive,out); + out.add_string("|"); + out.add_string(file); + return true; + } + else return false; +} + +void archive_impl::open(service_ptr_t & p_out,const char * path,t_open_mode mode, abort_callback & p_abort) +{ + if (mode != open_mode_read) throw exception_io_denied(); + pfc::string8 archive,file; + if (!g_parse_unpack_path(path,archive,file)) throw exception_io_not_found(); + open_archive(p_out,archive,file,p_abort); +} + + +void archive_impl::remove(const char * path,abort_callback & p_abort) { + throw exception_io_denied(); +} + +void archive_impl::move(const char * src,const char * dst,abort_callback & p_abort) { + throw exception_io_denied(); +} + +bool archive_impl::is_remote(const char * src) { + pfc::string8 archive,file; + if (g_parse_unpack_path(src,archive,file)) return g_is_remote(archive); + else throw exception_io_not_found(); +} + +bool archive_impl::relative_path_create(const char * file_path,const char * playlist_path,pfc::string_base & out) { + pfc::string8 archive,file; + if (g_parse_unpack_path(file_path,archive,file)) + { + pfc::string8 archive_rel; + if (g_relative_path_create(archive,playlist_path,archive_rel)) + { + pfc::string8 out_path; + make_unpack_path(out_path,archive_rel,file); + out.set_string(out_path); + return true; + } + } + return false; +} + +bool archive_impl::relative_path_parse(const char * relative_path,const char * playlist_path,pfc::string_base & out) +{ + if (!is_our_path(relative_path)) return false; + pfc::string8 archive_rel,file; + if (g_parse_unpack_path(relative_path,archive_rel,file)) + { + pfc::string8 archive; + if (g_relative_path_parse(archive_rel,playlist_path,archive)) + { + pfc::string8 out_path; + make_unpack_path(out_path,archive,file); + out.set_string(out_path); + return true; + } + } + return false; +} + +bool archive_impl::g_parse_unpack_path(const char * path,pfc::string8 & archive,pfc::string8 & file) +{ + path = strchr(path,'|'); + if (!path) return false; + int delta = path_unpack_string(archive,path); + if (delta<0) return false; + path += delta; + file = path; + return true; +} + +void archive_impl::g_make_unpack_path(pfc::string_base & path,const char * archive,const char * file,const char * name) +{ + path = "unpack://"; + path += name; + path_pack_string(path,archive); + path += file; +} + +void archive_impl::make_unpack_path(pfc::string_base & path,const char * archive,const char * file) {g_make_unpack_path(path,archive,file,get_archive_type());} + + +FILE * filesystem::streamio_open(const char * path,const char * flags) +{ + FILE * ret = 0; + pfc::string8 temp; + g_get_canonical_path(path,temp); + if (!strncmp(temp,"file://",7)) + { + ret = _wfopen(pfc::stringcvt::string_wide_from_utf8(path+7),pfc::stringcvt::string_wide_from_utf8(flags)); + } + return ret; +} + + +namespace { + + class directory_callback_isempty : public directory_callback + { + bool m_isempty; + public: + directory_callback_isempty() : m_isempty(true) {} + bool on_entry(filesystem * owner,abort_callback & p_abort,const char * url,bool is_subdirectory,const t_filestats & p_stats) + { + m_isempty = false; + return false; + } + bool isempty() {return m_isempty;} + }; + + class directory_callback_dummy : public directory_callback + { + public: + bool on_entry(filesystem * owner,abort_callback & p_abort,const char * url,bool is_subdirectory,const t_filestats & p_stats) {return false;} + }; + +} + +bool filesystem::g_is_empty_directory(const char * path,abort_callback & p_abort) +{ + directory_callback_isempty callback; + try { + g_list_directory(path,callback,p_abort); + } catch(exception_io const &) {return false;} + return callback.isempty(); +} + +bool filesystem::g_is_valid_directory(const char * path,abort_callback & p_abort) { + try { + g_list_directory(path,directory_callback_dummy(),p_abort); + return true; + } catch(exception_io const &) {return false;} +} + +bool directory_callback_impl::on_entry(filesystem * owner,abort_callback & p_abort,const char * url,bool is_subdirectory,const t_filestats & p_stats) { + p_abort.check_e(); + if (is_subdirectory) { + if (m_recur) { + try { + owner->list_directory(url,*this,p_abort); + } catch(exception_io const &) {} + } + } else { + m_data.add_item(pfc::rcnew_t(url,p_stats)); + } + return true; +} + +namespace { + class directory_callback_impl_copy : public directory_callback + { + public: + directory_callback_impl_copy(const char * p_target) + { + m_target = p_target; + m_target.fix_dir_separator('\\'); + } + + bool on_entry(filesystem * owner,abort_callback & p_abort,const char * url,bool is_subdirectory,const t_filestats & p_stats) { + const char * fn = url + pfc::scan_filename(url); + t_size truncat = m_target.length(); + m_target += fn; + if (is_subdirectory) { + try { + filesystem::g_create_directory(m_target,p_abort); + } catch(exception_io_already_exists) {} + m_target += "\\"; + owner->list_directory(url,*this,p_abort); + } else { + filesystem::g_copy(url,m_target,p_abort); + } + m_target.truncate(truncat); + return true; + } + private: + pfc::string8_fastalloc m_target; + }; +} + +void filesystem::g_copy_directory(const char * src,const char * dst,abort_callback & p_abort) { + //UNTESTED + filesystem::g_list_directory(src,directory_callback_impl_copy(dst),p_abort); +} + +void filesystem::g_copy(const char * src,const char * dst,abort_callback & p_abort) { + service_ptr_t r_src,r_dst; + t_filesize size; + + g_open(r_src,src,open_mode_read,p_abort); + size = r_src->get_size_ex(p_abort); + g_open(r_dst,dst,open_mode_write_new,p_abort); + + if (size > 0) { + try { + file::g_transfer_object(r_src,r_dst,size,p_abort); + } catch(...) { + r_dst.release(); + try {g_remove(dst,abort_callback_impl());} catch(...) {} + throw; + } + } +} + +void stream_reader::read_object(void * p_buffer,t_size p_bytes,abort_callback & p_abort) { + if (read(p_buffer,p_bytes,p_abort) != p_bytes) throw exception_io_data_truncation(); +} + +t_filestats file::get_stats(abort_callback & p_abort) +{ + t_filestats temp; + temp.m_size = get_size(p_abort); + temp.m_timestamp = get_timestamp(p_abort); + return temp; +} + +t_filesize stream_reader::skip(t_filesize p_bytes,abort_callback & p_abort) +{ + t_uint8 temp[256]; + t_filesize todo = p_bytes, done = 0; + while(todo > 0) { + t_size delta,deltadone; + delta = sizeof(temp); + if (delta > todo) delta = (t_size) todo; + deltadone = read(temp,delta,p_abort); + done += deltadone; + todo -= deltadone; + if (deltadone < delta) break; + } + return done; +} + +void stream_reader::skip_object(t_filesize p_bytes,abort_callback & p_abort) { + if (skip(p_bytes,p_abort) != p_bytes) throw exception_io_data_truncation(); +} + +void filesystem::g_open_write_new(service_ptr_t & p_out,const char * p_path,abort_callback & p_abort) { + g_open(p_out,p_path,open_mode_write_new,p_abort); +} +void file::g_transfer_file(const service_ptr_t & p_from,const service_ptr_t & p_to,abort_callback & p_abort) { + t_filesize length = p_from->get_size_ex(p_abort); + p_from->seek(0,p_abort); + p_to->seek(0,p_abort); + p_to->set_eof(p_abort); + if (length > 0) { + g_transfer_object(p_from,p_to,length,p_abort); + } +} + +void filesystem::g_open_temp(service_ptr_t & p_out,abort_callback & p_abort) { + g_open(p_out,"tempfile://",open_mode_write_new,p_abort); +} + +void filesystem::g_open_tempmem(service_ptr_t & p_out,abort_callback & p_abort) { + g_open(p_out,"tempmem://",open_mode_write_new,p_abort); +} + +void archive_impl::list_directory(const char * p_path,directory_callback & p_out,abort_callback & p_abort) { + throw exception_io_not_found(); +} + +void archive_impl::create_directory(const char * path,abort_callback &) { + throw exception_io_denied(); +} + +void filesystem::g_get_stats(const char * p_path,t_filestats & p_stats,bool & p_is_writeable,abort_callback & p_abort) { + TRACK_CALL_TEXT("filesystem::g_get_stats"); + service_ptr_t fs; + if (!g_get_interface(fs,p_path)) throw exception_io_no_handler_for_path(); + return fs->get_stats(p_path,p_stats,p_is_writeable,p_abort); +} + +void archive_impl::get_stats(const char * p_path,t_filestats & p_stats,bool & p_is_writeable,abort_callback & p_abort) { + pfc::string8 archive,file; + if (g_parse_unpack_path(p_path,archive,file)) { + if (g_is_remote(archive)) throw exception_io_object_is_remote(); + p_is_writeable = false; + p_stats = get_stats_in_archive(archive,file,p_abort); + } + else throw exception_io_not_found(); +} + + +bool file::is_eof(abort_callback & p_abort) { + t_filesize position,size; + position = get_position(p_abort); + size = get_size(p_abort); + if (size == filesize_invalid) return false; + return position >= size; +} + + +t_filetimestamp foobar2000_io::filetimestamp_from_system_timer() +{ + t_filetimestamp ret; + GetSystemTimeAsFileTime((FILETIME*)&ret); + return ret; +} + +void stream_reader::read_string_ex(pfc::string_base & p_out,t_size p_bytes,abort_callback & p_abort) { + char * ptr = p_out.lock_buffer(p_bytes); + try { + read_object(ptr,p_bytes,p_abort); + } catch(...) { + p_out.unlock_buffer(); + throw; + } + p_out.unlock_buffer(); +} +void stream_reader::read_string(pfc::string_base & p_out,abort_callback & p_abort) +{ + t_uint32 length; + read_lendian_t(length,p_abort); + read_string_ex(p_out,length,p_abort); +} + +void stream_reader::read_string_raw(pfc::string_base & p_out,abort_callback & p_abort) { + enum {delta = 256}; + char buffer[delta]; + p_out.reset(); + for(;;) { + t_size delta_done; + delta_done = read(buffer,delta,p_abort); + p_out.add_string(buffer,delta_done); + if (delta_done < delta) break; + } +} +void stream_writer::write_string(const char * p_string,t_size p_len,abort_callback & p_abort) { + t_uint32 len = pfc::downcast_guarded(pfc::strlen_max(p_string,p_len)); + write_lendian_t(len,p_abort); + write_object(p_string,len,p_abort); +} + +void stream_writer::write_string(const char * p_string,abort_callback & p_abort) { + write_string(p_string,infinite,p_abort); +} + +void stream_writer::write_string_raw(const char * p_string,abort_callback & p_abort) { + write_object(p_string,strlen(p_string),p_abort); +} + +void file::truncate(t_uint64 p_position,abort_callback & p_abort) { + if (p_position < get_size(p_abort)) resize(p_position,p_abort); +} + + +#ifdef _WIN32 +namespace { + //rare/weird win32 errors that didn't make it to the main API + PFC_DECLARE_EXCEPTION(exception_io_device_not_ready, exception_io,"Device not ready"); + PFC_DECLARE_EXCEPTION(exception_io_invalid_drive, exception_io_not_found,"Drive not found"); + PFC_DECLARE_EXCEPTION(exception_io_win32, exception_io,"Generic win32 I/O error"); + PFC_DECLARE_EXCEPTION(exception_io_buffer_overflow, exception_io,"The file name is too long"); + PFC_DECLARE_EXCEPTION(exception_io_invalid_path_syntax, exception_io,"Invalid path syntax"); + + class exception_io_win32_ex : public exception_io_win32 { + public: + exception_io_win32_ex(DWORD p_code) : m_msg(pfc::string_formatter() << "I/O error (win32 #" << (t_uint32)p_code << ")") {} + exception_io_win32_ex(const exception_io_win32_ex & p_other) {*this = p_other;} + const char * what() const throw() {return m_msg;} + private: + pfc::string8 m_msg; + }; +} +void foobar2000_io::exception_io_from_win32(DWORD p_code) { + switch(p_code) { + case ERROR_ALREADY_EXISTS: + case ERROR_FILE_EXISTS: + throw exception_io_already_exists(); + case ERROR_NETWORK_ACCESS_DENIED: + case ERROR_ACCESS_DENIED: + throw exception_io_denied(); + case ERROR_WRITE_PROTECT: + throw exception_io_write_protected(); + case ERROR_BUSY: + case ERROR_PATH_BUSY: + case ERROR_SHARING_VIOLATION: + case ERROR_LOCK_VIOLATION: + throw exception_io_sharing_violation(); + case ERROR_HANDLE_DISK_FULL: + case ERROR_DISK_FULL: + throw exception_io_device_full(); + case ERROR_FILE_NOT_FOUND: + case ERROR_PATH_NOT_FOUND: + throw exception_io_not_found(); + case ERROR_BROKEN_PIPE: + case ERROR_NO_DATA: + throw exception_io_no_data(); + case ERROR_NETWORK_UNREACHABLE: + case ERROR_NETNAME_DELETED: + throw exception_io_network_not_reachable(); + case ERROR_NOT_READY: + throw exception_io_device_not_ready(); + case ERROR_INVALID_DRIVE: + throw exception_io_invalid_drive(); + case ERROR_CRC: + case ERROR_FILE_CORRUPT: + case ERROR_DISK_CORRUPT: + throw exception_io_file_corrupted(); + case ERROR_BUFFER_OVERFLOW: + throw exception_io_buffer_overflow(); + case ERROR_DISK_CHANGE: + throw exception_io_disk_change(); + case ERROR_DIR_NOT_EMPTY: + throw exception_io_directory_not_empty(); + case ERROR_INVALID_NAME: + throw exception_io_invalid_path_syntax(); + default: + throw exception_io_win32_ex(p_code); + } +} +#endif + +t_filesize file::get_size_ex(abort_callback & p_abort) { + t_filesize temp = get_size(p_abort); + if (temp == filesize_invalid) throw exception_io_no_length(); + return temp; +} + +void file::ensure_local() { + if (is_remote()) throw exception_io_object_is_remote(); +} + +void file::ensure_seekable() { + if (!can_seek()) throw exception_io_object_not_seekable(); +} + +bool filesystem::g_is_recognized_path(const char * p_path) { + return g_get_interface(service_ptr_t(),p_path); +} + +t_filesize file::get_remaining(abort_callback & p_abort) { + t_filesize length = get_size_ex(p_abort); + t_filesize position = get_position(p_abort); + pfc::dynamic_assert(position <= length); + return length - position; +} + + +t_filesize file::g_transfer(service_ptr_t p_src,service_ptr_t p_dst,t_filesize p_bytes,abort_callback & p_abort) { + return g_transfer(pfc::safe_cast(p_src.get_ptr()),pfc::safe_cast(p_dst.get_ptr()),p_bytes,p_abort); +} + +void file::g_transfer_object(service_ptr_t p_src,service_ptr_t p_dst,t_filesize p_bytes,abort_callback & p_abort) { + if (p_bytes > 1024) /* don't bother on small objects */ + { + t_filesize oldsize = p_dst->get_size(p_abort); + if (oldsize != filesize_invalid) { + t_filesize newpos = p_dst->get_position(p_abort) + p_bytes; + if (newpos > oldsize) p_dst->resize(newpos ,p_abort); + } + } + g_transfer_object(pfc::safe_cast(p_src.get_ptr()),pfc::safe_cast(p_dst.get_ptr()),p_bytes,p_abort); +} + + +void foobar2000_io::generate_temp_location_for_file(pfc::string_base & p_out, const char * p_origpath,const char * p_extension,const char * p_magic) { + hasher_md5_result hash; + { + static_api_ptr_t hasher; + hasher_md5_state state; + hasher->initialize(state); + hasher->process(state,p_origpath,strlen(p_origpath)); + hasher->process(state,p_extension,strlen(p_extension)); + hasher->process(state,p_magic,strlen(p_magic)); + hash = hasher->get_result(state); + } + + p_out = p_origpath; + p_out.truncate(p_out.scan_filename()); + p_out += "temp-"; + p_out += pfc::format_hexdump(hash.m_data,sizeof(hash.m_data),""); + p_out += "."; + p_out += p_extension; +} + + +t_filesize file::skip(t_filesize p_bytes,abort_callback & p_abort) { + if (p_bytes > 1024 && can_seek()) { + const t_filesize size = get_size(p_abort); + if (size != filesize_invalid) { + const t_filesize position = get_position(p_abort); + const t_filesize toskip = pfc::min_t( p_bytes, size - position ); + seek(position + toskip,p_abort); + return toskip; + } + } + return stream_reader::skip(p_bytes,p_abort); +} + +bool foobar2000_io::_extract_native_path_ptr(const char * & p_fspath) { + static const char header[] = "file://"; static const t_size headerLen = 7; + if (strncmp(p_fspath,header,headerLen) != 0) return false; + p_fspath += headerLen; + return true; +} +bool foobar2000_io::extract_native_path(const char * p_fspath,pfc::string_base & p_native) { + if (!_extract_native_path_ptr(p_fspath)) return false; + p_native = p_fspath; + return true; +} + +bool foobar2000_io::extract_native_path_ex(const char * p_fspath, pfc::string_base & p_native) { + if (!_extract_native_path_ptr(p_fspath)) return false; + if (p_fspath[0] != '\\' || p_fspath[0] != '\\') { + p_native = "\\\\?\\"; + p_native += p_fspath; + } else { + p_native = p_fspath; + } + return true; +} + +pfc::string stream_reader::read_string(abort_callback & p_abort) { + t_uint32 len; + read_lendian_t(len,p_abort); + return read_string_ex(len,p_abort); +} +pfc::string stream_reader::read_string_ex(t_size p_len,abort_callback & p_abort) { + pfc::rcptr_t temp; temp.new_t(); + read_object(temp->lock_buffer(p_len),p_len,p_abort); + temp->unlock_buffer(); + return pfc::string::t_data(temp); +} diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/filesystem.h b/tools/vio2sf/src/foobar/foobar2000/SDK/filesystem.h new file mode 100644 index 000000000..7404e0d98 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/filesystem.h @@ -0,0 +1,598 @@ +class file_info; + +//! Contains various I/O related structures and interfaces. + +namespace foobar2000_io +{ + //! Type used for file size related variables. + typedef t_uint64 t_filesize; + //! Type used for file size related variables when signed value is needed. + typedef t_int64 t_sfilesize; + //! Type used for file timestamp related variables. 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601; 0 for invalid/unknown time. + typedef t_uint64 t_filetimestamp; + //! Invalid/unknown file timestamp constant. Also see: t_filetimestamp. + const t_filetimestamp filetimestamp_invalid = 0; + //! Invalid/unknown file size constant. Also see: t_filesize. + static const t_filesize filesize_invalid = (t_filesize)(~0); + + static const t_filetimestamp filetimestamp_1second_increment = 10000000; + + //! Generic I/O error. Root class for I/O failure exception. See relevant default message for description of each derived exception class. + PFC_DECLARE_EXCEPTION(exception_io, pfc::exception,"I/O error"); + //! Object not found. + PFC_DECLARE_EXCEPTION(exception_io_not_found, exception_io,"Object not found"); + //! Access denied. + PFC_DECLARE_EXCEPTION(exception_io_denied, exception_io,"Access denied"); + //! Unsupported format or corrupted file (unexpected data encountered). + PFC_DECLARE_EXCEPTION(exception_io_data, exception_io,"Unsupported format or corrupted file"); + //! Unsupported format or corrupted file (truncation encountered). + PFC_DECLARE_EXCEPTION(exception_io_data_truncation, exception_io_data,"Unsupported format or corrupted file"); + //! Unsupported format (a subclass of "unsupported format or corrupted file" exception). + PFC_DECLARE_EXCEPTION(exception_io_unsupported_format, exception_io_data,"Unsupported file format"); + //! Object is remote, while specific operation is supported only for local objects. + PFC_DECLARE_EXCEPTION(exception_io_object_is_remote, exception_io,"This operation is not supported on remote objects"); + //! Sharing violation. + PFC_DECLARE_EXCEPTION(exception_io_sharing_violation, exception_io,"Sharing violation"); + //! Device full. + PFC_DECLARE_EXCEPTION(exception_io_device_full, exception_io,"Device full"); + //! Attempt to seek outside valid range. + PFC_DECLARE_EXCEPTION(exception_io_seek_out_of_range, exception_io,"Seek offset out of range"); + //! This operation requires a seekable object. + PFC_DECLARE_EXCEPTION(exception_io_object_not_seekable, exception_io,"Object is not seekable"); + //! This operation requires an object with known length. + PFC_DECLARE_EXCEPTION(exception_io_no_length, exception_io,"Length of object is unknown"); + //! Invalid path. + PFC_DECLARE_EXCEPTION(exception_io_no_handler_for_path, exception_io,"Invalid path"); + //! Object already exists. + PFC_DECLARE_EXCEPTION(exception_io_already_exists, exception_io,"Object already exists"); + //! Pipe error. + PFC_DECLARE_EXCEPTION(exception_io_no_data, exception_io,"The process receiving or sending data has terminated"); + //! Network not reachable. + PFC_DECLARE_EXCEPTION(exception_io_network_not_reachable,exception_io,"Network not reachable"); + //! Media is write protected. + PFC_DECLARE_EXCEPTION(exception_io_write_protected, exception_io_denied,"The media is write protected"); + //! File is corrupted. This indicates filesystem call failure, not actual invalid data being read by the app. + PFC_DECLARE_EXCEPTION(exception_io_file_corrupted, exception_io,"The file is corrupted"); + //! The disc required for requested operation is not available. + PFC_DECLARE_EXCEPTION(exception_io_disk_change, exception_io,"Disc not available"); + //! The directory is not empty. + PFC_DECLARE_EXCEPTION(exception_io_directory_not_empty, exception_io,"Directory not empty"); + + //! Stores file stats (size and timestamp). + struct t_filestats { + //! Size of the file. + t_filesize m_size; + //! Time of last file modification. + t_filetimestamp m_timestamp; + + inline bool operator==(const t_filestats & param) const {return m_size == param.m_size && m_timestamp == param.m_timestamp;} + inline bool operator!=(const t_filestats & param) const {return m_size != param.m_size || m_timestamp != param.m_timestamp;} + }; + + //! Invalid/unknown file stats constant. See: t_filestats. + static const t_filestats filestats_invalid = {filesize_invalid,filetimestamp_invalid}; + +#ifdef _WIN32 + void exception_io_from_win32(DWORD p_code); +#define WIN32_IO_OP(X) {SetLastError(NO_ERROR); if (!(X)) exception_io_from_win32(GetLastError());} +#endif + + //! Generic interface to read data from a nonseekable stream. Also see: stream_writer, file. \n + //! Error handling: all methods may throw exception_io or one of derivatives on failure; exception_aborted when abort_callback is signaled. + class NOVTABLE stream_reader { + public: + //! Attempts to reads specified number of bytes from the stream. + //! @param p_buffer Receives data being read. Must have at least p_bytes bytes of space allocated. + //! @param p_bytes Number of bytes to read. + //! @param p_abort abort_callback object signaling user aborting the operation. + //! @returns Number of bytes actually read. May be less than requested when EOF was reached. + virtual t_size read(void * p_buffer,t_size p_bytes,abort_callback & p_abort) = 0; + //! Reads specified number of bytes from the stream. If requested amount of bytes can't be read (e.g. EOF), throws exception_io_data_truncation. + //! @param p_buffer Receives data being read. Must have at least p_bytes bytes of space allocated. + //! @param p_bytes Number of bytes to read. + //! @param p_abort abort_callback object signaling user aborting the operation. + virtual void read_object(void * p_buffer,t_size p_bytes,abort_callback & p_abort); + //! Attempts to skip specified number of bytes in the stream. + //! @param p_bytes Number of bytes to skip. + //! @param p_abort abort_callback object signaling user aborting the operation. + //! @returns Number of bytes actually skipped, May be less than requested when EOF was reached. + virtual t_filesize skip(t_filesize p_bytes,abort_callback & p_abort); + //! Skips specified number of bytes in the stream. If requested amount of bytes can't be skipped (e.g. EOF), throws exception_io_data_truncation. + //! @param p_bytes Number of bytes to skip. + //! @param p_abort abort_callback object signaling user aborting the operation. + virtual void skip_object(t_filesize p_bytes,abort_callback & p_abort); + + //! Helper template built around read_object. Reads single raw object from the stream. + //! @param p_object Receives object read from the stream on success. + //! @param p_abort abort_callback object signaling user aborting the operation. + template inline void read_object_t(T& p_object,abort_callback & p_abort) {pfc::assert_raw_type(); read_object(&p_object,sizeof(p_object),p_abort);} + //! Helper template built around read_object. Reads single raw object from the stream; corrects byte order assuming stream uses little endian order. + //! @param p_object Receives object read from the stream on success. + //! @param p_abort abort_callback object signaling user aborting the operation. + template inline void read_lendian_t(T& p_object,abort_callback & p_abort) {read_object_t(p_object,p_abort); byte_order::order_le_to_native_t(p_object);} + //! Helper template built around read_object. Reads single raw object from the stream; corrects byte order assuming stream uses big endian order. + //! @param p_object Receives object read from the stream on success. + //! @param p_abort abort_callback object signaling user aborting the operation. + template inline void read_bendian_t(T& p_object,abort_callback & p_abort) {read_object_t(p_object,p_abort); byte_order::order_be_to_native_t(p_object);} + + //! Helper function; reads a string (with a 32-bit header indicating length in bytes followed by UTF-8 encoded data without a null terminator). + void read_string(pfc::string_base & p_out,abort_callback & p_abort); + //! Helper function; alternate way of storing strings; assumes string takes space up to end of stream. + void read_string_raw(pfc::string_base & p_out,abort_callback & p_abort); + //! Helper function; reads a string (with a 32-bit header indicating length in bytes followed by UTF-8 encoded data without a null terminator). + pfc::string read_string(abort_callback & p_abort); + + //! Helper function; reads a string of specified length from the stream. + void read_string_ex(pfc::string_base & p_out,t_size p_bytes,abort_callback & p_abort); + //! Helper function; reads a string of specified length from the stream. + pfc::string read_string_ex(t_size p_len,abort_callback & p_abort); + protected: + stream_reader() {} + ~stream_reader() {} + }; + + + //! Generic interface to write data to a nonseekable stream. Also see: stream_reader, file. \n + //! Error handling: all methods may throw exception_io or one of derivatives on failure; exception_aborted when abort_callback is signaled. + class NOVTABLE stream_writer { + public: + //! Writes specified number of bytes from specified buffer to the stream. + //! @param p_buffer Buffer with data to write. Must contain at least p_bytes bytes. + //! @param p_bytes Number of bytes to write. + //! @param p_abort abort_callback object signaling user aborting the operation. + virtual void write(const void * p_buffer,t_size p_bytes,abort_callback & p_abort) = 0; + + //! Helper. Same as write(), provided for consistency. + inline void write_object(const void * p_buffer,t_size p_bytes,abort_callback & p_abort) {write(p_buffer,p_bytes,p_abort);} + + //! Helper template. Writes single raw object to the stream. + //! @param p_object Object to write. + //! @param p_abort abort_callback object signaling user aborting the operation. + template inline void write_object_t(const T & p_object, abort_callback & p_abort) {pfc::assert_raw_type(); write_object(&p_object,sizeof(p_object),p_abort);} + //! Helper template. Writes single raw object to the stream; corrects byte order assuming stream uses little endian order. + //! @param p_object Object to write. + //! @param p_abort abort_callback object signaling user aborting the operation. + template inline void write_lendian_t(const T & p_object, abort_callback & p_abort) {T temp = p_object; byte_order::order_native_to_le_t(temp); write_object_t(temp,p_abort);} + //! Helper template. Writes single raw object to the stream; corrects byte order assuming stream uses big endian order. + //! @param p_object Object to write. + //! @param p_abort abort_callback object signaling user aborting the operation. + template inline void write_bendian_t(const T & p_object, abort_callback & p_abort) {T temp = p_object; byte_order::order_native_to_be_t(temp); write_object_t(temp,p_abort);} + + //! Helper function; writes string (with 32-bit header indicating length in bytes followed by UTF-8 encoded data without null terminator). + void write_string(const char * p_string,abort_callback & p_abort); + void write_string(const char * p_string,t_size p_len,abort_callback & p_abort); + + template + void write_string(const T& val,abort_callback & p_abort) {write_string(pfc::stringToPtr(val),p_abort);} + + //! Helper function; writes raw string to the stream, with no length info or null terminators. + void write_string_raw(const char * p_string,abort_callback & p_abort); + protected: + stream_writer() {} + ~stream_writer() {} + }; + + //! A class providing abstraction for an open file object, with reading/writing/seeking methods. See also: stream_reader, stream_writer (which it inherits read/write methods from). \n + //! Error handling: all methods may throw exception_io or one of derivatives on failure; exception_aborted when abort_callback is signaled. + class NOVTABLE file : public service_base, public stream_reader, public stream_writer { + public: + + //! Seeking mode constants. Note: these are purposedly defined to same values as standard C SEEK_* constants + enum t_seek_mode { + //! Seek relative to beginning of file (same as seeking to absolute offset). + seek_from_beginning = 0, + //! Seek relative to current position. + seek_from_current = 1, + //! Seek relative to end of file. + seek_from_eof = 2, + }; + + //! Retrieves size of the file. + //! @param p_abort abort_callback object signaling user aborting the operation. + //! @returns File size on success; filesize_invalid if unknown (nonseekable stream etc). + virtual t_filesize get_size(abort_callback & p_abort) = 0; + + + //! Retrieves read/write cursor position in the file. In case of non-seekable stream, this should return number of bytes read so far since open/reopen call. + //! @param p_abort abort_callback object signaling user aborting the operation. + //! @returns Read/write cursor position + virtual t_filesize get_position(abort_callback & p_abort) = 0; + + //! Resizes file to the specified size in bytes. + //! @param p_abort abort_callback object signaling user aborting the operation. + virtual void resize(t_filesize p_size,abort_callback & p_abort) = 0; + + //! Sets read/write cursor position to the specified offset. + //! @param p_position position to seek to. + //! @param p_abort abort_callback object signaling user aborting the operation. + virtual void seek(t_filesize p_position,abort_callback & p_abort) = 0; + + + //! Sets read/write cursor position to the specified offset; extended form allowing seeking relative to current position or to end of file. + //! @param p_position Position to seek to; interpretation of this value depends on p_mode parameter. + //! @param p_mode Seeking mode; see t_seek_mode enum values for further description. + //! @param p_abort abort_callback object signaling user aborting the operation. + virtual void seek_ex(t_sfilesize p_position,t_seek_mode p_mode,abort_callback & p_abort); + + //! Returns whether the file is seekable or not. If can_seek() returns false, all seek() or seek_ex() calls will fail; reopen() is still usable on nonseekable streams. + virtual bool can_seek() = 0; + + //! Retrieves mime type of the file. + //! @param p_out Receives content type string on success. + virtual bool get_content_type(pfc::string_base & p_out) = 0; + + //! Hint, returns whether the file is already fully buffered into memory. + virtual bool is_in_memory() {return false;} + + //! Optional, called by owner thread before sleeping. + //! @param p_abort abort_callback object signaling user aborting the operation. + virtual void on_idle(abort_callback & p_abort) {} + + //! Retrieves last modification time of the file. + //! @param p_abort abort_callback object signaling user aborting the operation. + //! @returns Last modification time o fthe file; filetimestamp_invalid if N/A. + virtual t_filetimestamp get_timestamp(abort_callback & p_abort) {return filetimestamp_invalid;} + + //! Resets non-seekable stream, or seeks to zero on seekable file. + //! @param p_abort abort_callback object signaling user aborting the operation. + virtual void reopen(abort_callback & p_abort) = 0; + + //! Indicates whether the file is a remote resource and non-sequential access may be slowed down by lag. This is typically returns to true on non-seekable sources but may also return true on seekable sources indicating that seeking is supported but will be relatively slow. + virtual bool is_remote() = 0; + + //! Retrieves file stats structure. Usese get_size() and get_timestamp(). + t_filestats get_stats(abort_callback & p_abort); + + //! Returns whether read/write cursor position is at the end of file. + bool is_eof(abort_callback & p_abort); + + //! Truncates file to specified size (while preserving read/write cursor position if possible); uses set_eof(). + void truncate(t_filesize p_position,abort_callback & p_abort); + + //! Truncates the file at current read/write cursor position. + void set_eof(abort_callback & p_abort) {resize(get_position(p_abort),p_abort);} + + + //! Helper; retrieves size of the file. If size is not available (get_size() returns filesize_invalid), throws exception_io_no_length. + t_filesize get_size_ex(abort_callback & p_abort); + + //! Helper; retrieves amount of bytes between read/write cursor position and end of file. Fails when length can't be determined. + t_filesize get_remaining(abort_callback & p_abort); + + //! Helper; throws exception_io_object_not_seekable if file is not seekable. + void ensure_seekable(); + + //! Helper; throws exception_io_object_is_remote if the file is remote. + void ensure_local(); + + //! Helper; transfers specified number of bytes between streams. + //! @returns number of bytes actually transferred. May be less than requested if e.g. EOF is reached. + static t_filesize g_transfer(stream_reader * src,stream_writer * dst,t_filesize bytes,abort_callback & p_abort); + //! Helper; transfers specified number of bytes between streams. Throws exception if requested number of bytes could not be read (EOF). + static void g_transfer_object(stream_reader * src,stream_writer * dst,t_filesize bytes,abort_callback & p_abort); + //! Helper; transfers entire file content from one file to another, erasing previous content. + static void g_transfer_file(const service_ptr_t & p_from,const service_ptr_t & p_to,abort_callback & p_abort); + + //! Helper; improved performance over g_transfer on streams (avoids disk fragmentation when transferring large blocks). + static t_filesize g_transfer(service_ptr_t p_src,service_ptr_t p_dst,t_filesize p_bytes,abort_callback & p_abort); + //! Helper; improved performance over g_transfer_file on streams (avoids disk fragmentation when transferring large blocks). + static void g_transfer_object(service_ptr_t p_src,service_ptr_t p_dst,t_filesize p_bytes,abort_callback & p_abort); + + + t_filesize skip(t_filesize p_bytes,abort_callback & p_abort); + + FB2K_MAKE_SERVICE_INTERFACE(file,service_base); + }; + + typedef service_ptr_t file_ptr; + + //! Special hack for shoutcast metadata nonsense handling. Documentme. + class file_dynamicinfo : public file { + public: + //! Retrieves "static" info that doesn't change in the middle of stream, such as station names etc. Returns true on success; false when static info is not available. + virtual bool get_static_info(class file_info & p_out) = 0; + //! Returns whether dynamic info is available on this stream or not. + virtual bool is_dynamic_info_enabled()=0; + //! Retrieves dynamic stream info (e.g. online stream track titles). Returns true on success, false when info has not changed since last call. + virtual bool get_dynamic_info(class file_info & p_out) = 0; + + FB2K_MAKE_SERVICE_INTERFACE(file_dynamicinfo,file); + }; + + //! Implementation helper - contains dummy implementations of methods that modify the file + template class file_readonly_t : public t_base { + public: + void resize(t_filesize p_size,abort_callback & p_abort) {throw exception_io_denied();} + void write(const void * p_buffer,t_size p_bytes,abort_callback & p_abort) {throw exception_io_denied();} + }; + typedef file_readonly_t file_readonly; + + class filesystem; + + class NOVTABLE directory_callback { + public: + //! @returns true to continue enumeration, false to abort. + virtual bool on_entry(filesystem * p_owner,abort_callback & p_abort,const char * p_url,bool p_is_subdirectory,const t_filestats & p_stats)=0; + }; + + + //! Entrypoint service for all filesystem operations.\n + //! Implementation: standard implementations for local filesystem etc are provided by core.\n + //! Instantiation: use static helper functions rather than calling filesystem interface methods directly, e.g. filesystem::g_open() to open a file. + class NOVTABLE filesystem : public service_base { + public: + //! Enumeration specifying how to open a file. See: filesystem::open(), filesystem::g_open(). + enum t_open_mode { + //! Opens an existing file for reading; if the file does not exist, the operation will fail. + open_mode_read, + //! Opens an existing file for writing; if the file does not exist, the operation will fail. + open_mode_write_existing, + //! Opens a new file for writing; if the file exists, its contents will be wiped. + open_mode_write_new, + }; + + virtual bool get_canonical_path(const char * p_path,pfc::string_base & p_out)=0; + virtual bool is_our_path(const char * p_path)=0; + virtual bool get_display_path(const char * p_path,pfc::string_base & p_out)=0; + + virtual void open(service_ptr_t & p_out,const char * p_path, t_open_mode p_mode,abort_callback & p_abort)=0; + virtual void remove(const char * p_path,abort_callback & p_abort)=0; + virtual void move(const char * p_src,const char * p_dst,abort_callback & p_abort)=0; + //! Queries whether a file at specified path belonging to this filesystem is a remove object or not. + virtual bool is_remote(const char * p_src) = 0; + + //! Retrieves stats of a file at specified path. + virtual void get_stats(const char * p_path,t_filestats & p_stats,bool & p_is_writeable,abort_callback & p_abort) = 0; + + virtual bool relative_path_create(const char * file_path,const char * playlist_path,pfc::string_base & out) {return false;} + virtual bool relative_path_parse(const char * relative_path,const char * playlist_path,pfc::string_base & out) {return false;} + + //! Creates a directory. + virtual void create_directory(const char * p_path,abort_callback & p_abort) = 0; + + virtual void list_directory(const char * p_path,directory_callback & p_out,abort_callback & p_abort)=0; + + //! Hint; returns whether this filesystem supports mime types. \n + //! When this returns false, all file::get_content_type() calls on files opened thru this filesystem implementation will return false; otherwise, file::get_content_type() calls may return true depending on the file. + virtual bool supports_content_types() = 0; + + static void g_get_canonical_path(const char * path,pfc::string_base & out); + static void g_get_display_path(const char * path,pfc::string_base & out); + + static bool g_get_interface(service_ptr_t & p_out,const char * path);//path is AFTER get_canonical_path + static bool g_is_remote(const char * p_path);//path is AFTER get_canonical_path + static bool g_is_recognized_and_remote(const char * p_path);//path is AFTER get_canonical_path + static bool g_is_remote_safe(const char * p_path) {return g_is_recognized_and_remote(p_path);} + static bool g_is_remote_or_unrecognized(const char * p_path); + static bool g_is_recognized_path(const char * p_path); + + //! Opens file at specified path, with specified access privileges. + static void g_open(service_ptr_t & p_out,const char * p_path,t_open_mode p_mode,abort_callback & p_abort); + //! Attempts to open file at specified path; if the operation fails with sharing violation error, keeps retrying (with short sleep period between retries) for specified amount of time. + static void g_open_timeout(service_ptr_t & p_out,const char * p_path,t_open_mode p_mode,double p_timeout,abort_callback & p_abort); + static void g_open_write_new(service_ptr_t & p_out,const char * p_path,abort_callback & p_abort); + static void g_open_read(service_ptr_t & p_out,const char * path,abort_callback & p_abort) {return g_open(p_out,path,open_mode_read,p_abort);} + static void g_open_precache(service_ptr_t & p_out,const char * path,abort_callback & p_abort);//open only for precaching data (eg. will fail on http etc) + static bool g_exists(const char * p_path,abort_callback & p_abort); + static bool g_exists_writeable(const char * p_path,abort_callback & p_abort); + //! Removes file at specified path. + static void g_remove(const char * p_path,abort_callback & p_abort); + //! Attempts to remove file at specified path; if the operation fails with a sharing violation error, keeps retrying (with short sleep period between retries) for specified amount of time. + static void g_remove_timeout(const char * p_path,double p_timeout,abort_callback & p_abort); + //! Moves file from one path to another. + static void g_move(const char * p_src,const char * p_dst,abort_callback & p_abort); + //! Attempts to move file from one path to another; if the operation fails with a sharing violation error, keeps retrying (with short sleep period between retries) for specified amount of time. + static void g_move_timeout(const char * p_src,const char * p_dst,double p_timeout,abort_callback & p_abort); + + static void g_copy(const char * p_src,const char * p_dst,abort_callback & p_abort);//needs canonical path + static void g_copy_timeout(const char * p_src,const char * p_dst,double p_timeout,abort_callback & p_abort);//needs canonical path + static void g_copy_directory(const char * p_src,const char * p_dst,abort_callback & p_abort);//needs canonical path + static void g_get_stats(const char * p_path,t_filestats & p_stats,bool & p_is_writeable,abort_callback & p_abort); + static bool g_relative_path_create(const char * p_file_path,const char * p_playlist_path,pfc::string_base & out); + static bool g_relative_path_parse(const char * p_relative_path,const char * p_playlist_path,pfc::string_base & out); + + static void g_create_directory(const char * p_path,abort_callback & p_abort); + + //! If for some bloody reason you ever need stream io compatibility, use this, INSTEAD of calling fopen() on the path string you've got; will only work with file:// (and not with http://, unpack:// or whatever) + static FILE * streamio_open(const char * p_path,const char * p_flags); + + static void g_open_temp(service_ptr_t & p_out,abort_callback & p_abort); + static void g_open_tempmem(service_ptr_t & p_out,abort_callback & p_abort); + + static void g_list_directory(const char * p_path,directory_callback & p_out,abort_callback & p_abort);// path must be canonical + + static bool g_is_valid_directory(const char * path,abort_callback & p_abort); + static bool g_is_empty_directory(const char * path,abort_callback & p_abort); + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(filesystem); + }; + + class directory_callback_impl : public directory_callback + { + struct t_entry + { + pfc::string_simple m_path; + t_filestats m_stats; + t_entry(const char * p_path, const t_filestats & p_stats) : m_path(p_path), m_stats(p_stats) {} + }; + + + pfc::list_t > m_data; + bool m_recur; + + static int sortfunc(const pfc::rcptr_t & p1, const pfc::rcptr_t & p2) {return stricmp_utf8(p1->m_path,p2->m_path);} + public: + bool on_entry(filesystem * owner,abort_callback & p_abort,const char * url,bool is_subdirectory,const t_filestats & p_stats); + + directory_callback_impl(bool p_recur) : m_recur(p_recur) {} + t_size get_count() {return m_data.get_count();} + const char * operator[](t_size n) const {return m_data[n]->m_path;} + const char * get_item(t_size n) const {return m_data[n]->m_path;} + const t_filestats & get_item_stats(t_size n) const {return m_data[n]->m_stats;} + void sort() {m_data.sort_t(sortfunc);} + }; + + class archive; + + class NOVTABLE archive_callback : public abort_callback { + public: + virtual bool on_entry(archive * owner,const char * url,const t_filestats & p_stats,const service_ptr_t & p_reader) = 0; + }; + + //! Interface for archive reader services. When implementing, derive from archive_impl rather than from deriving from archive directly. + class NOVTABLE archive : public filesystem { + public: + virtual void archive_list(const char * p_path,const service_ptr_t & p_reader,archive_callback & p_callback,bool p_want_readers) = 0; + + FB2K_MAKE_SERVICE_INTERFACE(archive,filesystem); + }; + + //! Root class for archive implementations. Derive from this instead of from archive directly. + class NOVTABLE archive_impl : public archive { + private: + //do not override these + bool get_canonical_path(const char * path,pfc::string_base & out); + bool is_our_path(const char * path); + bool get_display_path(const char * path,pfc::string_base & out); + void remove(const char * path,abort_callback & p_abort); + void move(const char * src,const char * dst,abort_callback & p_abort); + bool is_remote(const char * src); + bool relative_path_create(const char * file_path,const char * playlist_path,pfc::string_base & out); + bool relative_path_parse(const char * relative_path,const char * playlist_path,pfc::string_base & out); + void open(service_ptr_t & p_out,const char * path, t_open_mode mode,abort_callback & p_abort); + void create_directory(const char * path,abort_callback &); + void list_directory(const char * p_path,directory_callback & p_out,abort_callback & p_abort); + void get_stats(const char * p_path,t_filestats & p_stats,bool & p_is_writeable,abort_callback & p_abort); + protected: + //override these + virtual const char * get_archive_type()=0;//eg. "zip", must be lowercase + virtual t_filestats get_stats_in_archive(const char * p_archive,const char * p_file,abort_callback & p_abort) = 0; + virtual void open_archive(service_ptr_t & p_out,const char * archive,const char * file, abort_callback & p_abort)=0;//opens for reading + public: + //override these + + virtual void archive_list(const char * path,const service_ptr_t & p_reader,archive_callback & p_out,bool p_want_readers)=0; + + static bool g_parse_unpack_path(const char * path,pfc::string8 & archive,pfc::string8 & file); + static void g_make_unpack_path(pfc::string_base & path,const char * archive,const char * file,const char * name); + void make_unpack_path(pfc::string_base & path,const char * archive,const char * file); + + + }; + + template + class archive_factory_t : public service_factory_single_t {}; + + + t_filetimestamp filetimestamp_from_system_timer(); + +#ifdef _WIN32 + inline t_filetimestamp import_filetimestamp(FILETIME ft) { + return *reinterpret_cast(&ft); + } +#endif + + void generate_temp_location_for_file(pfc::string_base & p_out, const char * p_origpath,const char * p_extension,const char * p_magic); + + + static file_ptr fileOpen(const char * p_path,filesystem::t_open_mode p_mode,abort_callback & p_abort,double p_timeout) { + file_ptr temp; filesystem::g_open_timeout(temp,p_path,p_mode,p_timeout,p_abort); PFC_ASSERT(temp.is_valid()); return temp; + } + + static file_ptr fileOpenReadExisting(const char * p_path,abort_callback & p_abort,double p_timeout = 0) { + return fileOpen(p_path,filesystem::open_mode_read,p_abort,p_timeout); + } + static file_ptr fileOpenWriteExisting(const char * p_path,abort_callback & p_abort,double p_timeout = 0) { + return fileOpen(p_path,filesystem::open_mode_write_existing,p_abort,p_timeout); + } + static file_ptr fileOpenWriteNew(const char * p_path,abort_callback & p_abort,double p_timeout = 0) { + return fileOpen(p_path,filesystem::open_mode_write_new,p_abort,p_timeout); + } + + template + class directory_callback_retrieveList : public directory_callback { + public: + directory_callback_retrieveList(t_list & p_list,bool p_getFiles,bool p_getSubDirectories) : m_list(p_list), m_getFiles(p_getFiles), m_getSubDirectories(p_getSubDirectories) {} + bool on_entry(filesystem * p_owner,abort_callback & p_abort,const char * p_url,bool p_is_subdirectory,const t_filestats & p_stats) { + p_abort.check(); + if (p_is_subdirectory ? m_getSubDirectories : m_getFiles) { + m_list.add_item(p_url); + } + return true; + } + private: + const bool m_getSubDirectories; + const bool m_getFiles; + t_list & m_list; + }; + template + class directory_callback_retrieveListEx : public directory_callback { + public: + directory_callback_retrieveListEx(t_list & p_files, t_list & p_directories) : m_files(p_files), m_directories(p_directories) {} + bool on_entry(filesystem * p_owner,abort_callback & p_abort,const char * p_url,bool p_is_subdirectory,const t_filestats & p_stats) { + p_abort.check(); + if (p_is_subdirectory) m_directories += p_url; + else m_files += p_url; + return true; + } + private: + t_list & m_files; + t_list & m_directories; + }; + template class directory_callback_retrieveListRecur : public directory_callback { + public: + directory_callback_retrieveListRecur(t_list & p_list) : m_list(p_list) {} + bool on_entry(filesystem * owner,abort_callback & p_abort,const char * path, bool isSubdir, const t_filestats&) { + if (isSubdir) { + try { owner->list_directory(path,*this,p_abort); } catch(exception_io) {} + } else { + m_list.add_item(path); + } + return true; + } + private: + t_list & m_list; + }; + + template + static void listFiles(const char * p_path,t_list & p_out,abort_callback & p_abort) { + directory_callback_retrieveList callback(p_out,true,false); + filesystem::g_list_directory(p_path,callback,p_abort); + } + template + static void listDirectories(const char * p_path,t_list & p_out,abort_callback & p_abort) { + directory_callback_retrieveList callback(p_out,false,true); + filesystem::g_list_directory(p_path,callback,p_abort); + } + template + static void listFilesAndDirectories(const char * p_path,t_list & p_files,t_list & p_directories,abort_callback & p_abort) { + directory_callback_retrieveListEx callback(p_files,p_directories); + filesystem::g_list_directory(p_path,callback,p_abort); + } + template + static void listFilesRecur(const char * p_path,t_list & p_out,abort_callback & p_abort) { + directory_callback_retrieveListRecur callback(p_out); + filesystem::g_list_directory(p_path,callback,p_abort); + } + + bool extract_native_path(const char * p_fspath,pfc::string_base & p_native); + bool _extract_native_path_ptr(const char * & p_fspath); + bool extract_native_path_ex(const char * p_fspath, pfc::string_base & p_native);//prepends \\?\ where needed + + template + pfc::string getPathDisplay(const T& source) { + pfc::string_formatter temp; + filesystem::g_get_display_path(pfc::stringToPtr(source),temp); + return temp.toString(); + } + template + pfc::string getPathCanonical(const T& source) { + pfc::string_formatter temp; + filesystem::g_get_canonical_path(pfc::stringToPtr(source),temp); + return temp.toString(); + } +} + +using namespace foobar2000_io; + +#include "filesystem_helper.h" diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/filesystem_helper.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/filesystem_helper.cpp new file mode 100644 index 000000000..e8feb4e2c --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/filesystem_helper.cpp @@ -0,0 +1,106 @@ +#include "foobar2000.h" + +void stream_writer_chunk::write(const void * p_buffer,t_size p_bytes,abort_callback & p_abort) { + t_size remaining = p_bytes, written = 0; + while(remaining > 0) { + t_size delta = sizeof(m_buffer) - m_buffer_state; + if (delta > remaining) delta = remaining; + memcpy(m_buffer,(const t_uint8*)p_buffer + written,delta); + written += delta; + remaining -= delta; + + if (m_buffer_state == sizeof(m_buffer)) { + m_writer->write_lendian_t((t_uint8)m_buffer_state,p_abort); + m_writer->write_object(m_buffer,m_buffer_state,p_abort); + m_buffer_state = 0; + } + } +} + +void stream_writer_chunk::flush(abort_callback & p_abort) +{ + m_writer->write_lendian_t((t_uint8)m_buffer_state,p_abort); + if (m_buffer_state > 0) { + m_writer->write_object(m_buffer,m_buffer_state,p_abort); + m_buffer_state = 0; + } +} + +/* + stream_writer * m_writer; + unsigned m_buffer_state; + unsigned char m_buffer[255]; +*/ + +t_size stream_reader_chunk::read(void * p_buffer,t_size p_bytes,abort_callback & p_abort) +{ + t_size todo = p_bytes, done = 0; + while(todo > 0) { + if (m_buffer_size == m_buffer_state) { + if (m_eof) break; + t_uint8 temp; + m_reader->read_lendian_t(temp,p_abort); + m_buffer_size = temp; + if (temp != sizeof(m_buffer)) m_eof = true; + m_buffer_state = 0; + if (m_buffer_size>0) { + m_reader->read_object(m_buffer,m_buffer_size,p_abort); + } + } + + + t_size delta = m_buffer_size - m_buffer_state; + if (delta > todo) delta = todo; + if (delta > 0) { + memcpy((unsigned char*)p_buffer + done,m_buffer + m_buffer_state,delta); + todo -= delta; + done += delta; + m_buffer_state += delta; + } + } + return done; +} + +void stream_reader_chunk::flush(abort_callback & p_abort) { + while(!m_eof) { + p_abort.check_e(); + t_uint8 temp; + m_reader->read_lendian_t(temp,p_abort); + m_buffer_size = temp; + if (temp != sizeof(m_buffer)) m_eof = true; + m_buffer_state = 0; + if (m_buffer_size>0) { + m_reader->skip_object(m_buffer_size,p_abort); + } + } +} + +/* + stream_reader * m_reader; + unsigned m_buffer_state, m_buffer_size; + bool m_eof; + unsigned char m_buffer[255]; +*/ + +void stream_reader_chunk::g_skip(stream_reader * p_stream,abort_callback & p_abort) { + stream_reader_chunk(p_stream).flush(p_abort); +} + +t_size reader_membuffer_base::read(void * p_buffer,t_size p_bytes,abort_callback & p_abort) { + p_abort.check_e(); + t_size max = get_buffer_size(); + if (max < m_offset) throw pfc::exception_bug_check_v2(); + max -= m_offset; + t_size delta = p_bytes; + if (delta > max) delta = max; + memcpy(p_buffer,(char*)get_buffer() + m_offset,delta); + m_offset += delta; + return delta; +} + +void reader_membuffer_base::seek(t_filesize position,abort_callback & p_abort) { + p_abort.check_e(); + t_filesize max = get_buffer_size(); + if (position == filesize_invalid || position > max) throw exception_io_seek_out_of_range(); + m_offset = (t_size)position; +} diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/filesystem_helper.h b/tools/vio2sf/src/foobar/foobar2000/SDK/filesystem_helper.h new file mode 100644 index 000000000..579e426aa --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/filesystem_helper.h @@ -0,0 +1,579 @@ +//helper +class file_path_canonical { +public: + file_path_canonical(const char * src) {filesystem::g_get_canonical_path(src,m_data);} + operator const char * () const {return m_data.get_ptr();} + const char * get_ptr() const {return m_data.get_ptr();} + t_size get_length() const {return m_data.get_length();} +private: + pfc::string8 m_data; +}; + +class file_path_display { +public: + file_path_display(const char * src) {filesystem::g_get_display_path(src,m_data);} + operator const char * () const {return m_data.get_ptr();} + const char * get_ptr() const {return m_data.get_ptr();} + t_size get_length() const {return m_data.get_length();} +private: + pfc::string8 m_data; +}; + + +class NOVTABLE reader_membuffer_base : public file_readonly { +public: + reader_membuffer_base() : m_offset(0) {} + + t_size read(void * p_buffer,t_size p_bytes,abort_callback & p_abort); + + void write(const void * p_buffer,t_size p_bytes,abort_callback & p_abort) {throw exception_io_denied();} + + t_filesize get_size(abort_callback & p_abort) {return get_buffer_size();} + t_filesize get_position(abort_callback & p_abort) {return m_offset;} + void seek(t_filesize position,abort_callback & p_abort); + void reopen(abort_callback & p_abort) {seek(0,p_abort);} + + bool can_seek() {return true;} + bool is_in_memory() {return true;} + +protected: + virtual const void * get_buffer() = 0; + virtual t_size get_buffer_size() = 0; + virtual t_filetimestamp get_timestamp(abort_callback & p_abort) = 0; + virtual bool get_content_type(pfc::string_base &) {return false;} + inline void seek_internal(t_size p_offset) {if (p_offset > get_buffer_size()) throw exception_io_seek_out_of_range(); m_offset = p_offset;} +private: + t_size m_offset; +}; + +class reader_membuffer_mirror : public reader_membuffer_base +{ +public: + t_filetimestamp get_timestamp(abort_callback & p_abort) {return m_timestamp;} + bool is_remote() {return m_remote;} + + //! Returns false when the object could not be mirrored (too big) or did not need mirroring. + static bool g_create(service_ptr_t & p_out,const service_ptr_t & p_src,abort_callback & p_abort) { + service_ptr_t ptr = new service_impl_t(); + if (!ptr->init(p_src,p_abort)) return false; + p_out = ptr.get_ptr(); + return true; + } + +private: + const void * get_buffer() {return m_buffer.get_ptr();} + t_size get_buffer_size() {return m_buffer.get_size();} + + bool init(const service_ptr_t & p_src,abort_callback & p_abort) { + if (p_src->is_in_memory()) return false;//already buffered + m_remote = p_src->is_remote(); + + t_size size = pfc::downcast_guarded(p_src->get_size(p_abort)); + + m_buffer.set_size(size); + + p_src->reopen(p_abort); + + p_src->read_object(m_buffer.get_ptr(),size,p_abort); + + m_timestamp = p_src->get_timestamp(p_abort); + + return true; + } + + + t_filetimestamp m_timestamp; + pfc::array_t m_buffer; + bool m_remote; + +}; + +class reader_limited : public file_readonly { + service_ptr_t r; + t_filesize begin; + t_filesize end; + +public: + static file::ptr g_create(file::ptr base, t_filesize offset, t_filesize size, abort_callback & abort) { + service_ptr_t r = new service_impl_t(); + if (offset + size < offset) throw pfc::exception_overflow(); + r->init(base, offset, offset + size, abort); + return r; + } + reader_limited() {begin=0;end=0;} + reader_limited(const service_ptr_t & p_r,t_filesize p_begin,t_filesize p_end,abort_callback & p_abort) { + r = p_r; + begin = p_begin; + end = p_end; + r->seek(begin,p_abort); + } + + void init(const service_ptr_t & p_r,t_filesize p_begin,t_filesize p_end,abort_callback & p_abort) { + r = p_r; + begin = p_begin; + end = p_end; + r->seek(begin,p_abort); + } + + t_filetimestamp get_timestamp(abort_callback & p_abort) {return r->get_timestamp(p_abort);} + + t_size read(void *p_buffer, t_size p_bytes,abort_callback & p_abort) { + t_filesize pos; + pos = r->get_position(p_abort); + if (p_bytes > end - pos) p_bytes = (t_size)(end - pos); + return r->read(p_buffer,p_bytes,p_abort); + } + + t_filesize get_size(abort_callback & p_abort) {return end-begin;} + + t_filesize get_position(abort_callback & p_abort) { + return r->get_position(p_abort) - begin; + } + + void seek(t_filesize position,abort_callback & p_abort) { + r->seek(position+begin,p_abort); + } + bool can_seek() {return r->can_seek();} + bool is_remote() {return r->is_remote();} + + bool get_content_type(pfc::string_base &) {return false;} + + void reopen(abort_callback & p_abort) {seek(0,p_abort);} +}; + +class stream_reader_memblock_ref : public stream_reader +{ +public: + template stream_reader_memblock_ref(const t_array & p_array) : m_data(p_array.get_ptr()), m_data_size(p_array.get_size()), m_pointer(0) { + pfc::assert_byte_type(); + } + stream_reader_memblock_ref(const void * p_data,t_size p_data_size) : m_data((const unsigned char*)p_data), m_data_size(p_data_size), m_pointer(0) {} + stream_reader_memblock_ref() : m_data(NULL), m_data_size(0), m_pointer(0) {} + + template void set_data(const t_array & data) { + pfc::assert_byte_type(); + set_data(data.get_ptr(), data.get_size()); + } + + void set_data(const void * data, t_size dataSize) { + m_pointer = 0; + m_data = reinterpret_cast(data); + m_data_size = dataSize; + } + + t_size read(void * p_buffer,t_size p_bytes,abort_callback & p_abort) { + t_size remaining = m_data_size - m_pointer; + t_size toread = p_bytes; + if (toread > remaining) toread = remaining; + if (toread > 0) { + memcpy(p_buffer,m_data+m_pointer,toread); + m_pointer += toread; + } + + return toread; + } + t_size get_remaining() const {return m_data_size - m_pointer;} + void reset() {m_pointer = 0;} +private: + const unsigned char * m_data; + t_size m_data_size,m_pointer; +}; + +class stream_writer_buffer_simple : public stream_writer { +public: + void write(const void * p_buffer,t_size p_bytes,abort_callback & p_abort) { + p_abort.check(); + t_size base = m_buffer.get_size(); + if (base + p_bytes < base) throw std::bad_alloc(); + m_buffer.set_size(base + p_bytes); + memcpy( (t_uint8*) m_buffer.get_ptr() + base, p_buffer, p_bytes ); + } + + typedef pfc::array_t t_buffer; + + pfc::array_t m_buffer; +}; + +template +class stream_writer_buffer_append_ref_t : public stream_writer +{ +public: + stream_writer_buffer_append_ref_t(t_storage & p_output) : m_output(p_output) {} + void write(const void * p_buffer,t_size p_bytes,abort_callback & p_abort) { + pfc::static_assert< sizeof(m_output[0]) == 1>(); + p_abort.check(); + t_size base = m_output.get_size(); + if (base + p_bytes < base) throw std::bad_alloc(); + m_output.set_size(base + p_bytes); + memcpy( (t_uint8*) m_output.get_ptr() + base, p_buffer, p_bytes ); + } +private: + t_storage & m_output; +}; + +class stream_reader_limited_ref : public stream_reader { +public: + stream_reader_limited_ref(stream_reader * p_reader,t_filesize p_limit) : m_reader(p_reader), m_remaining(p_limit) {} + + t_size read(void * p_buffer,t_size p_bytes,abort_callback & p_abort) { + if (p_bytes > m_remaining) p_bytes = (t_size)m_remaining; + + t_size done = m_reader->read(p_buffer,p_bytes,p_abort); + m_remaining -= done; + return done; + } + + inline t_filesize get_remaining() const {return m_remaining;} + + t_filesize skip(t_filesize p_bytes,abort_callback & p_abort) { + if (p_bytes > m_remaining) p_bytes = m_remaining; + t_filesize done = m_reader->skip(p_bytes,p_abort); + m_remaining -= done; + return done; + } + + void flush_remaining(abort_callback & p_abort) { + if (m_remaining > 0) skip_object(m_remaining,p_abort); + } + +private: + stream_reader * m_reader; + t_filesize m_remaining; +}; + +class stream_writer_chunk_dwordheader : public stream_writer +{ +public: + stream_writer_chunk_dwordheader(const service_ptr_t & p_writer) : m_writer(p_writer) {} + + void initialize(abort_callback & p_abort) { + m_headerposition = m_writer->get_position(p_abort); + m_written = 0; + m_writer->write_lendian_t((t_uint32)0,p_abort); + } + + void finalize(abort_callback & p_abort) { + t_filesize end_offset; + end_offset = m_writer->get_position(p_abort); + m_writer->seek(m_headerposition,p_abort); + m_writer->write_lendian_t(pfc::downcast_guarded(m_written),p_abort); + m_writer->seek(end_offset,p_abort); + } + + void write(const void * p_buffer,t_size p_bytes,abort_callback & p_abort) { + m_writer->write(p_buffer,p_bytes,p_abort); + m_written += p_bytes; + } + +private: + service_ptr_t m_writer; + t_filesize m_headerposition; + t_filesize m_written; +}; + +class stream_writer_chunk : public stream_writer +{ +public: + stream_writer_chunk(stream_writer * p_writer) : m_writer(p_writer), m_buffer_state(0) {} + + void write(const void * p_buffer,t_size p_bytes,abort_callback & p_abort); + + void flush(abort_callback & p_abort);//must be called after writing before object is destroyed + +private: + stream_writer * m_writer; + unsigned m_buffer_state; + unsigned char m_buffer[255]; +}; + +class stream_reader_chunk : public stream_reader +{ +public: + stream_reader_chunk(stream_reader * p_reader) : m_reader(p_reader), m_buffer_state(0), m_buffer_size(0), m_eof(false) {} + + t_size read(void * p_buffer,t_size p_bytes,abort_callback & p_abort); + + void flush(abort_callback & p_abort);//must be called after reading before object is destroyed + + static void g_skip(stream_reader * p_stream,abort_callback & p_abort); + +private: + stream_reader * m_reader; + t_size m_buffer_state, m_buffer_size; + bool m_eof; + unsigned char m_buffer[255]; +}; + +class stream_reader_dummy : public stream_reader { t_size read(void * p_buffer,t_size p_bytes,abort_callback & p_abort) {return 0;} }; + + + + + + + + + + + + + + + + + + +template class stream_reader_formatter { +public: + stream_reader_formatter(stream_reader & p_stream,abort_callback & p_abort) : m_stream(p_stream), m_abort(p_abort) {} + + template void read_int(t_int & p_out) { + if (isBigEndian) m_stream.read_bendian_t(p_out,m_abort); + else m_stream.read_lendian_t(p_out,m_abort); + } + + void read_raw(void * p_buffer,t_size p_bytes) { + m_stream.read_object(p_buffer,p_bytes,m_abort); + } + + void skip(t_size p_bytes) {m_stream.skip_object(p_bytes,m_abort);} + + template void read_raw(TArray& data) { + pfc::assert_byte_type(); + read_raw(data.get_ptr(),data.get_size()); + } + template void read_byte_block(TArray & data) { + pfc::assert_byte_type(); + t_uint32 size; read_int(size); data.set_size(size); + read_raw(data); + } + template void read_array(TArray & data) { + t_uint32 size; *this >> size; data.set_size(size); + for(t_uint32 walk = 0; walk < size; ++walk) *this >> data[walk]; + } + + stream_reader & m_stream; + abort_callback & m_abort; +}; + +template class stream_writer_formatter { +public: + stream_writer_formatter(stream_writer & p_stream,abort_callback & p_abort) : m_stream(p_stream), m_abort(p_abort) {} + + template void write_int(t_int p_int) { + if (isBigEndian) m_stream.write_bendian_t(p_int,m_abort); + else m_stream.write_lendian_t(p_int,m_abort); + } + + void write_raw(const void * p_buffer,t_size p_bytes) { + m_stream.write_object(p_buffer,p_bytes,m_abort); + } + template void write_raw(const TArray& data) { + pfc::assert_byte_type(); + write_raw(data.get_ptr(),data.get_size()); + } + + template void write_byte_block(const TArray& data) { + pfc::assert_byte_type(); + write_int( pfc::downcast_guarded(data.get_size()) ); + write_raw( data ); + } + template void write_array(const TArray& data) { + const t_uint32 size = pfc::downcast_guarded(data.get_size()); + *this << size; + for(t_uint32 walk = 0; walk < size; ++walk) *this << data[walk]; + } + + void write_string(const char * str) { + const t_size len = strlen(str); + *this << pfc::downcast_guarded(len); + write_raw(str, len); + } + void write_string(const char * str, t_size len_) { + const t_size len = pfc::strlen_max(str, len_); + *this << pfc::downcast_guarded(len); + write_raw(str, len); + } + + stream_writer & m_stream; + abort_callback & m_abort; +}; + +#define __DECLARE_UINT_OVERLOADS(TYPE) \ + template inline stream_reader_formatter & operator>>(stream_reader_formatter & p_stream,TYPE & p_int) {p_stream.read_int(p_int); return p_stream;} \ + template inline stream_writer_formatter & operator<<(stream_writer_formatter & p_stream,TYPE p_int) {p_stream.write_int(p_int); return p_stream;} + +__DECLARE_UINT_OVERLOADS(t_uint8); +__DECLARE_UINT_OVERLOADS(t_uint16); +__DECLARE_UINT_OVERLOADS(t_uint32); +__DECLARE_UINT_OVERLOADS(t_uint64); + +#ifdef _MSC_VER +//SPECIAL FIX +__DECLARE_UINT_OVERLOADS(unsigned long); +#endif + +#undef __DECLARE_UINT_OVERLOADS + +#define __DECLARE_INT_OVERLOADS(TYPE) \ + template inline stream_reader_formatter & operator>>(stream_reader_formatter & p_stream,TYPE & p_int) {typename pfc::sized_int_t::t_unsigned temp;p_stream.read_int(temp); p_int = (TYPE) temp; return p_stream;} \ + template inline stream_writer_formatter & operator<<(stream_writer_formatter & p_stream,TYPE p_int) {p_stream.write_int((typename pfc::sized_int_t::t_unsigned)p_int); return p_stream;} + +__DECLARE_INT_OVERLOADS(t_int8); +__DECLARE_INT_OVERLOADS(t_int16); +__DECLARE_INT_OVERLOADS(t_int32); +__DECLARE_INT_OVERLOADS(t_int64); + +#ifdef _MSC_VER +//SPECIAL FIX +__DECLARE_INT_OVERLOADS(long); +#endif + +#undef __DECLARE_INT_OVERLOADS + +template class __IsTypeByte { +public: + enum {value = pfc::is_same_type::value || pfc::is_same_type::value}; +}; + +template stream_reader_formatter & operator>>(stream_reader_formatter & p_stream,TVal (& p_array)[Count]) { + if (__IsTypeByte::value) { + p_stream.read_raw(p_array,Count); + } else { + for(t_size walk = 0; walk < Count; ++walk) p_stream >> p_array[walk]; + } + return p_stream; +} + +template stream_writer_formatter & operator<<(stream_writer_formatter & p_stream,TVal const (& p_array)[Count]) { + if (__IsTypeByte::value) { + p_stream.write_raw(p_array,Count); + } else { + for(t_size walk = 0; walk < Count; ++walk) p_stream << p_array[walk]; + } + return p_stream; +} + +#define FB2K_STREAM_READER_OVERLOAD(type) \ + template stream_reader_formatter & operator>>(stream_reader_formatter & stream,type & value) + +#define FB2K_STREAM_WRITER_OVERLOAD(type) \ + template stream_writer_formatter & operator<<(stream_writer_formatter & stream,const type & value) + +FB2K_STREAM_READER_OVERLOAD(GUID) { + return stream >> value.Data1 >> value.Data2 >> value.Data3 >> value.Data4; +} + +FB2K_STREAM_WRITER_OVERLOAD(GUID) { + return stream << value.Data1 << value.Data2 << value.Data3 << value.Data4; +} + +FB2K_STREAM_READER_OVERLOAD(pfc::string) { + t_uint32 len; stream >> len; + value = stream.m_stream.read_string_ex(len,stream.m_abort); + return stream; +} + +FB2K_STREAM_WRITER_OVERLOAD(pfc::string) { + stream << pfc::downcast_guarded(value.length()); + stream.write_raw(value.ptr(),value.length()); + return stream; +} + +FB2K_STREAM_READER_OVERLOAD(pfc::string_base) { + t_uint32 len; stream >> len; + try { + char * buf = value.lock_buffer(len); + stream.read_raw(buf,len); + } catch(...) { + value.unlock_buffer(); throw; + } + value.unlock_buffer(); + return stream; +} +FB2K_STREAM_WRITER_OVERLOAD(pfc::string_base) { + const char * val = value.get_ptr(); + const t_size len = strlen(val); + stream << pfc::downcast_guarded(len); + stream.write_raw(val,len); + return stream; +} + + +FB2K_STREAM_WRITER_OVERLOAD(float) { + union { + float f; t_uint32 i; + } u; u.f = value; + return stream << u.i; +} + +FB2K_STREAM_READER_OVERLOAD(float) { + union { float f; t_uint32 i;} u; + stream >> u.i; value = u.f; + return stream; +} + +FB2K_STREAM_WRITER_OVERLOAD(double) { + union { + double f; t_uint64 i; + } u; u.f = value; + return stream << u.i; +} + +FB2K_STREAM_READER_OVERLOAD(double) { + union { double f; t_uint64 i;} u; + stream >> u.i; value = u.f; + return stream; +} + + +template +class stream_writer_formatter_simple : public stream_writer_formatter { +public: + stream_writer_formatter_simple() : stream_writer_formatter(_m_stream,_m_abort), m_buffer(_m_stream.m_buffer) {} + + typedef stream_writer_buffer_simple::t_buffer t_buffer; + t_buffer & m_buffer; +private: + stream_writer_buffer_simple _m_stream; + abort_callback_dummy _m_abort; +}; + +template +class stream_reader_formatter_simple_ref : public stream_reader_formatter { +public: + stream_reader_formatter_simple_ref(const void * source, t_size sourceSize) : stream_reader_formatter(_m_stream,_m_abort), _m_stream(source,sourceSize) {} + template stream_reader_formatter_simple_ref(const TSource& source) : stream_reader_formatter(_m_stream,_m_abort), _m_stream(source) {} + stream_reader_formatter_simple_ref() : stream_reader_formatter(_m_stream,_m_abort) {} + + void set_data(const void * source, t_size sourceSize) {_m_stream.set_data(source,sourceSize);} + template void set_data(const TSource & source) {_m_stream.set_data(source);} + + void reset() {_m_stream.reset();} + t_size get_remaining() {return _m_stream.get_remaining();} +private: + stream_reader_memblock_ref _m_stream; + abort_callback_dummy _m_abort; +}; + +template +class stream_reader_formatter_simple : public stream_reader_formatter_simple_ref { +public: + stream_reader_formatter_simple() {} + stream_reader_formatter_simple(const void * source, t_size sourceSize) {set_data(source,sourceSize);} + template stream_reader_formatter_simple(const TSource & source) {set_data(source);} + + void set_data(const void * source, t_size sourceSize) { + m_content.set_data_fromptr(reinterpret_cast(source), sourceSize); + onContentChange(); + } + template void set_data(const TSource & source) { + m_content = source; + onContentChange(); + } +private: + void onContentChange() { + stream_reader_formatter_simple_ref::set_data(m_content); + } + pfc::array_t m_content; +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/foobar2000.h b/tools/vio2sf/src/foobar/foobar2000/SDK/foobar2000.h new file mode 100644 index 000000000..07191c7d0 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/foobar2000.h @@ -0,0 +1,95 @@ +// This is the master foobar2000 SDK header file; it includes headers for all functionality exposed through the SDK project. #include this in your source code, never reference any of the other headers directly. + +#ifndef _FOOBAR2000_H_ +#define _FOOBAR2000_H_ + +#ifndef UNICODE +#error Only UNICODE environment supported. +#endif + +#include "../../pfc/pfc.h" + +#include "../shared/shared.h" + +#ifndef NOTHROW +#ifdef _MSC_VER +#define NOTHROW __declspec(nothrow) +#else +#define NOTHROW +#endif +#endif + +#define FB2KAPI /*NOTHROW*/ + +typedef const char * pcchar; + +#include "core_api.h" +#include "service.h" + +#include "completion_notify.h" +#include "abort_callback.h" +#include "componentversion.h" +#include "preferences_page.h" +#include "coreversion.h" +#include "filesystem.h" +#include "audio_chunk.h" +#include "cfg_var.h" +#include "mem_block_container.h" +#include "audio_postprocessor.h" +#include "playable_location.h" +#include "file_info.h" +#include "file_info_impl.h" +#include "metadb_handle.h" +#include "metadb.h" +#include "console.h" +#include "dsp.h" +#include "dsp_manager.h" +#include "initquit.h" +#include "event_logger.h" +#include "input.h" +#include "input_impl.h" +#include "menu.h" +#include "contextmenu.h" +#include "contextmenu_manager.h" +#include "menu_helpers.h" +#include "modeless_dialog.h" +#include "playback_control.h" +#include "play_callback.h" +#include "playlist.h" +#include "playlist_loader.h" +#include "replaygain.h" +#include "resampler.h" +#include "tag_processor.h" +#include "titleformat.h" +#include "ui.h" +#include "unpack.h" +#include "vis.h" +#include "packet_decoder.h" +#include "commandline.h" +#include "genrand.h" +#include "file_operation_callback.h" +#include "library_manager.h" +#include "config_io_callback.h" +#include "popup_message.h" +#include "app_close_blocker.h" +#include "config_object.h" +#include "config_object_impl.h" +#include "threaded_process.h" +#include "hasher_md5.h" +#include "message_loop.h" +#include "input_file_type.h" +#include "chapterizer.h" +#include "link_resolver.h" +#include "main_thread_callback.h" +#include "advconfig.h" +#include "info_lookup_handler.h" +#include "track_property.h" + +#include "album_art.h" +#include "icon_remap.h" +#include "ole_interaction.h" +#include "search_tools.h" +#include "autoplaylist.h" +#include "replaygain_scanner.h" + +#endif //_FOOBAR2000_H_ diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/foobar2000_SDK.vcproj b/tools/vio2sf/src/foobar/foobar2000/SDK/foobar2000_SDK.vcproj new file mode 100644 index 000000000..25a4a28b5 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/foobar2000_SDK.vcproj @@ -0,0 +1,1810 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/genrand.h b/tools/vio2sf/src/foobar/foobar2000/SDK/genrand.h new file mode 100644 index 000000000..430754024 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/genrand.h @@ -0,0 +1,13 @@ +//! PRNG service. Implemented by the core, do not reimplement. Use g_create() helper function to instantiate. +class NOVTABLE genrand_service : public service_base +{ +public: + //! Seeds the PRNG with specified value. + virtual void seed(unsigned val) = 0; + //! Returns random value N, where 0 <= N < range. + virtual unsigned genrand(unsigned range)=0; + + static service_ptr_t g_create() {return standard_api_create_t();} + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(genrand_service); +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/guids.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/guids.cpp new file mode 100644 index 000000000..8f8920820 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/guids.cpp @@ -0,0 +1,1115 @@ +#include "foobar2000.h" + +// {4B897EC8-A2F9-478d-A95E-1A2110A40078} +FOOGUIDDECL const GUID hasher_md5::class_guid = +{ 0x4b897ec8, 0xa2f9, 0x478d, { 0xa9, 0x5e, 0x1a, 0x21, 0x10, 0xa4, 0x0, 0x78 } }; + +// {74497D81-6158-48ba-9657-386A5520D0FF} +FOOGUIDDECL const GUID config_io_callback::class_guid = +{ 0x74497d81, 0x6158, 0x48ba, { 0x96, 0x57, 0x38, 0x6a, 0x55, 0x20, 0xd0, 0xff } }; + +// {10BB3EBD-DDF7-4975-A3CC-23084829453E} +FOOGUIDDECL const GUID componentversion::class_guid = +{ 0x10bb3ebd, 0xddf7, 0x4975, { 0xa3, 0xcc, 0x23, 0x8, 0x48, 0x29, 0x45, 0x3e } }; + +// {7255E8D0-3FCF-4781-B93B-D06CB88DFAFA} +FOOGUIDDECL const GUID preferences_page::class_guid = +{ 0x7255e8d0, 0x3fcf, 0x4781, { 0xb9, 0x3b, 0xd0, 0x6c, 0xb8, 0x8d, 0xfa, 0xfa } }; + +// {8146A883-F146-401b-BAF6-4FB2E306F2EB} +FOOGUIDDECL const GUID preferences_branch::class_guid = +{ 0x8146a883, 0xf146, 0x401b, { 0xba, 0xf6, 0x4f, 0xb2, 0xe3, 0x6, 0xf2, 0xeb } }; + +// {90DF5270-65BB-4dba-BAF5-86BE9E59DC20} +FOOGUIDDECL const GUID console_receiver::class_guid = +{ 0x90df5270, 0x65bb, 0x4dba, { 0xba, 0xf5, 0x86, 0xbe, 0x9e, 0x59, 0xdc, 0x20 } }; + +// {0C36A649-9EA0-4f48-B229-0CB2AA9AB6F4} +FOOGUIDDECL const GUID core_version_info::class_guid = +{ 0xc36a649, 0x9ea0, 0x4f48, { 0xb2, 0x29, 0xc, 0xb2, 0xaa, 0x9a, 0xb6, 0xf4 } }; + +// {61C4E6E4-C31E-4c89-A759-BF0949DFC528} +FOOGUIDDECL const GUID audio_postprocessor::class_guid = +{ 0x61c4e6e4, 0xc31e, 0x4c89, { 0xa7, 0x59, 0xbf, 0x9, 0x49, 0xdf, 0xc5, 0x28 } }; + +// {EE65D408-70D6-40f6-940D-D9F537F1BEF1} +FOOGUIDDECL const GUID dsp_config_manager::class_guid = +{ 0xee65d408, 0x70d6, 0x40f6, { 0x94, 0xd, 0xd9, 0xf5, 0x37, 0xf1, 0xbe, 0xf1 } }; + +// {F8F03D26-C2DA-47ed-8748-1DBACBCEA508} +FOOGUIDDECL const GUID dsp_config_callback::class_guid = +{ 0xf8f03d26, 0xc2da, 0x47ed, { 0x87, 0x48, 0x1d, 0xba, 0xcb, 0xce, 0xa5, 0x8 } }; + +// {0D048731-8AA8-4704-8AD6-189E24D48C88} +FOOGUIDDECL const GUID dsp_entry::class_guid = +{ 0xd048731, 0x8aa8, 0x4704, { 0x8a, 0xd6, 0x18, 0x9e, 0x24, 0xd4, 0x8c, 0x88 } }; + +// {2A42AFEA-940B-455b-AEFF-CFDACAF52AFF} +FOOGUIDDECL const GUID dsp::class_guid = +{ 0x2a42afea, 0x940b, 0x455b, { 0xae, 0xff, 0xcf, 0xda, 0xca, 0xf5, 0x2a, 0xff } }; + +// {113773C4-B387-4b48-8BDF-AB58BC6CE538} +FOOGUIDDECL const GUID initquit::class_guid = +{ 0x113773c4, 0xb387, 0x4b48, { 0x8b, 0xdf, 0xab, 0x58, 0xbc, 0x6c, 0xe5, 0x38 } }; + +FOOGUIDDECL const GUID metadb_display_field_provider::class_guid = { 0x5923fa2a, 0x504b, 0x4022, { 0xb2, 0x86, 0x0, 0x22, 0x75, 0x38, 0x45, 0x5e } }; + +// {609D48C8-C6A6-4784-8BBD-FDD32BF0740E} +FOOGUIDDECL const GUID metadb::class_guid = +{ 0x609d48c8, 0xc6a6, 0x4784, { 0x8b, 0xbd, 0xfd, 0xd3, 0x2b, 0xf0, 0x74, 0xe } }; + +// {D5286BB4-FDED-47ef-A623-4C3FF056DEC1} +FOOGUIDDECL const GUID metadb_io_callback::class_guid = +{ 0xd5286bb4, 0xfded, 0x47ef, { 0xa6, 0x23, 0x4c, 0x3f, 0xf0, 0x56, 0xde, 0xc1 } }; + +// {1C0802F7-CF24-49ef-B914-8B9866F19779} +FOOGUIDDECL const GUID contextmenu_item::class_guid = +{ 0x1c0802f7, 0xcf24, 0x49ef, { 0xb9, 0x14, 0x8b, 0x98, 0x66, 0xf1, 0x97, 0x79 } }; + +// {98B00B13-8C0E-49ff-B17C-5E537D3AE4B7} +FOOGUIDDECL const GUID visualisation_manager::class_guid = +{ 0x98b00b13, 0x8c0e, 0x49ff, { 0xb1, 0x7c, 0x5e, 0x53, 0x7d, 0x3a, 0xe4, 0xb7 } }; + +// {4A4B1DD8-82FF-4071-A6E2-BD043F4C251C} +FOOGUIDDECL const GUID visualisation_stream::class_guid = +{ 0x4a4b1dd8, 0x82ff, 0x4071, { 0xa6, 0xe2, 0xbd, 0x4, 0x3f, 0x4c, 0x25, 0x1c } }; + +// {015A6C0E-1571-49bd-A367-30B4BD889C34} +FOOGUIDDECL const GUID packet_decoder::class_guid = +{ 0x15a6c0e, 0x1571, 0x49bd, { 0xa3, 0x67, 0x30, 0xb4, 0xbd, 0x88, 0x9c, 0x34 } }; + +// {D815032D-AFEB-46c6-8AA3-6FD530A4CE67} +FOOGUIDDECL const GUID packet_decoder_streamparse::class_guid = +{ 0xd815032d, 0xafeb, 0x46c6, { 0x8a, 0xa3, 0x6f, 0xd5, 0x30, 0xa4, 0xce, 0x67 } }; + +// {53006A71-C03C-4c38-822F-9A34A5655095} +FOOGUIDDECL const GUID packet_decoder_entry::class_guid = +{ 0x53006a71, 0xc03c, 0x4c38, { 0x82, 0x2f, 0x9a, 0x34, 0xa5, 0x65, 0x50, 0x95 } }; + +// {D3BD5F53-A6D6-4346-991F-CF14DFAD2B3A} +FOOGUIDDECL const GUID contextmenu_manager::class_guid = +{ 0xd3bd5f53, 0xa6d6, 0x4346, { 0x99, 0x1f, 0xcf, 0x14, 0xdf, 0xad, 0x2b, 0x3a } }; + +// {640E006E-2934-4d6c-8327-4FA9F341ECF2} +FOOGUIDDECL const GUID input_file_type::class_guid = +{ 0x640e006e, 0x2934, 0x4d6c, { 0x83, 0x27, 0x4f, 0xa9, 0xf3, 0x41, 0xec, 0xf2 } }; + +// {8835B30A-36A6-49bc-B96D-D0609B0EF2BA} +FOOGUIDDECL const GUID input_file_type_v2::class_guid = +{ 0x8835b30a, 0x36a6, 0x49bc, { 0xb9, 0x6d, 0xd0, 0x60, 0x9b, 0xe, 0xf2, 0xba } }; + +// {2DC57FF7-476D-42f5-A05A-60499896134A} +FOOGUIDDECL const GUID ui_control::class_guid = +{ 0x2dc57ff7, 0x476d, 0x42f5, { 0xa0, 0x5a, 0x60, 0x49, 0x98, 0x96, 0x13, 0x4a } }; + +// {392B88DE-50FC-43b0-9F03-2D79B071CAF6} +FOOGUIDDECL const GUID ui_status_text_override::class_guid = +{ 0x392b88de, 0x50fc, 0x43b0, { 0x9f, 0x3, 0x2d, 0x79, 0xb0, 0x71, 0xca, 0xf6 } }; + +// {52BD7A17-540C-4a97-B812-72BC84EC4FF5} +FOOGUIDDECL const GUID ui_drop_item_callback::class_guid = +{ 0x52bd7a17, 0x540c, 0x4a97, { 0xb8, 0x12, 0x72, 0xbc, 0x84, 0xec, 0x4f, 0xf5 } }; + +// {550B3A19-42A4-4c0f-91F2-90550189CBFF} +FOOGUIDDECL const GUID commandline_handler::class_guid = +{ 0x550b3a19, 0x42a4, 0x4c0f, { 0x91, 0xf2, 0x90, 0x55, 0x1, 0x89, 0xcb, 0xff } }; + +// {C71B99BD-12C5-48fe-A9C0-469F6FEA88BF} +FOOGUIDDECL const GUID modeless_dialog_manager::class_guid = +{ 0xc71b99bd, 0x12c5, 0x48fe, { 0xa9, 0xc0, 0x46, 0x9f, 0x6f, 0xea, 0x88, 0xbf } }; + +// {78BCBFA1-DFB9-487f-AB16-CD82BF90CCF7} +FOOGUIDDECL const GUID play_callback_manager::class_guid = +{ 0x78bcbfa1, 0xdfb9, 0x487f, { 0xab, 0x16, 0xcd, 0x82, 0xbf, 0x90, 0xcc, 0xf7 } }; + +// {8E4EED7A-C6B8-49c7-99FE-97E04AAA63A8} +FOOGUIDDECL const GUID play_callback_static::class_guid = +{ 0x8e4eed7a, 0xc6b8, 0x49c7, { 0x99, 0xfe, 0x97, 0xe0, 0x4a, 0xaa, 0x63, 0xa8 } }; + +// {BF803668-2977-4c71-B9AB-5C77C338C970} +FOOGUIDDECL const GUID playback_control::class_guid = +{ 0xbf803668, 0x2977, 0x4c71, { 0xb9, 0xab, 0x5c, 0x77, 0xc3, 0x38, 0xc9, 0x70 } }; + +// {242D9341-211A-4637-A69F-F6684B52F9D6} +FOOGUIDDECL const GUID playlist_callback_static::class_guid = +{ 0x242d9341, 0x211a, 0x4637, { 0xa6, 0x9f, 0xf6, 0x68, 0x4b, 0x52, 0xf9, 0xd6 } }; + +// {95E9F11B-4C99-4d0a-AB9F-367196B10925} +FOOGUIDDECL const GUID playlist_callback_single_static::class_guid = +{ 0x95e9f11b, 0x4c99, 0x4d0a, { 0xab, 0x9f, 0x36, 0x71, 0x96, 0xb1, 0x9, 0x25 } }; + +// {88D7EDB1-A850-42a4-BBAB-49E955F4B81F} +FOOGUIDDECL const GUID playlist_lock::class_guid = +{ 0x88d7edb1, 0xa850, 0x42a4, { 0xbb, 0xab, 0x49, 0xe9, 0x55, 0xf4, 0xb8, 0x1f } }; + +// {D2E5F92B-3424-4822-AE60-8663E6D26EAB} +FOOGUIDDECL const GUID playlist_loader::class_guid = +{ 0xd2e5f92b, 0x3424, 0x4822, { 0xae, 0x60, 0x86, 0x63, 0xe6, 0xd2, 0x6e, 0xab } }; + +// {2FBCE1E5-902E-49e0-B9CF-CE0FBA765348} +FOOGUIDDECL const GUID filesystem::class_guid = +{ 0x2fbce1e5, 0x902e, 0x49e0, { 0xb9, 0xcf, 0xce, 0xf, 0xba, 0x76, 0x53, 0x48 } }; + +// {9098AF12-61A3-4caa-8AA9-BB95C2EF8346} +FOOGUIDDECL const GUID unpacker::class_guid = +{ 0x9098af12, 0x61a3, 0x4caa, { 0x8a, 0xa9, 0xbb, 0x95, 0xc2, 0xef, 0x83, 0x46 } }; + +// {EC707440-FA3E-4d12-9876-FC369F04D4A4} +FOOGUIDDECL const GUID archive::class_guid = +{ 0xec707440, 0xfa3e, 0x4d12, { 0x98, 0x76, 0xfc, 0x36, 0x9f, 0x4, 0xd4, 0xa4 } }; + +// {B2F9FC40-3E55-4b23-A2C9-22BAAD8795B1} +FOOGUIDDECL const GUID file::class_guid = +{ 0xb2f9fc40, 0x3e55, 0x4b23, { 0xa2, 0xc9, 0x22, 0xba, 0xad, 0x87, 0x95, 0xb1 } }; + +// {6374340F-82D4-4471-A24B-A754B1398285} +FOOGUIDDECL const GUID file_dynamicinfo::class_guid = +{ 0x6374340f, 0x82d4, 0x4471, { 0xa2, 0x4b, 0xa7, 0x54, 0xb1, 0x39, 0x82, 0x85 } }; + +// {A00CB77D-ED72-4031-806B-4E45AF995241} +FOOGUIDDECL const GUID replaygain_manager::class_guid = +{ 0xa00cb77d, 0xed72, 0x4031, { 0x80, 0x6b, 0x4e, 0x45, 0xaf, 0x99, 0x52, 0x41 } }; + +// {3FEED4FC-A400-4a30-8E73-F0ECD114D7E8} +FOOGUIDDECL const GUID resampler_entry::class_guid = +{ 0x3feed4fc, 0xa400, 0x4a30, { 0x8e, 0x73, 0xf0, 0xec, 0xd1, 0x14, 0xd7, 0xe8 } }; + +// {3F7674AB-044C-4796-8801-6C443C244D88} +FOOGUIDDECL const GUID titleformat_compiler::class_guid = +{ 0x3f7674ab, 0x44c, 0x4796, { 0x88, 0x1, 0x6c, 0x44, 0x3c, 0x24, 0x4d, 0x88 } }; + +// {1ADD4DC4-B278-4a0c-A105-2629F4B312F4} +FOOGUIDDECL const GUID user_interface::class_guid = +{ 0x1add4dc4, 0xb278, 0x4a0c, { 0xa1, 0x5, 0x26, 0x29, 0xf4, 0xb3, 0x12, 0xf4 } }; + +// {994C0D0E-319E-45f3-92FC-518616E73ADC} +FOOGUIDDECL const GUID contextmenu_item::caller_now_playing = +{ 0x994c0d0e, 0x319e, 0x45f3, { 0x92, 0xfc, 0x51, 0x86, 0x16, 0xe7, 0x3a, 0xdc } }; + +// {47502BA1-816D-4a3e-ADE5-A7A9860A67DB} +FOOGUIDDECL const GUID contextmenu_item::caller_active_playlist_selection = +{ 0x47502ba1, 0x816d, 0x4a3e, { 0xad, 0xe5, 0xa7, 0xa9, 0x86, 0xa, 0x67, 0xdb } }; + +// Deprecated. +FOOGUIDDECL const GUID contextmenu_item::caller_playlist = caller_active_playlist_selection; + +// {B3CC1030-EF26-45cf-A84A-7FC169BC9FFB} +FOOGUIDDECL const GUID contextmenu_item::caller_active_playlist = +{ 0xb3cc1030, 0xef26, 0x45cf, { 0xa8, 0x4a, 0x7f, 0xc1, 0x69, 0xbc, 0x9f, 0xfb } }; + +// {5FDCD5E8-6EB2-4454-9EDA-527522893BED} +FOOGUIDDECL const GUID contextmenu_item::caller_playlist_manager = +{ 0x5fdcd5e8, 0x6eb2, 0x4454, { 0x9e, 0xda, 0x52, 0x75, 0x22, 0x89, 0x3b, 0xed } }; + +// {00000000-0000-0000-0000-000000000000} +FOOGUIDDECL const GUID contextmenu_item::caller_undefined = +{ 0x00000000, 0x0000, 0x0000, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }; + +// {FABEE3E9-8901-4df4-A2D7-B9898D86C39B} +FOOGUIDDECL const GUID contextmenu_item::caller_keyboard_shortcut_list = +{ 0xfabee3e9, 0x8901, 0x4df4, { 0xa2, 0xd7, 0xb9, 0x89, 0x8d, 0x86, 0xc3, 0x9b } }; + +// {FDA07C56-05D0-4b84-9FBD-A8BE556D474D} +FOOGUIDDECL const GUID contextmenu_item::caller_media_library_viewer = +{ 0xfda07c56, 0x5d0, 0x4b84, { 0x9f, 0xbd, 0xa8, 0xbe, 0x55, 0x6d, 0x47, 0x4d } }; + +// {95DE5842-30F5-4f72-B40C-191663782F80} +FOOGUIDDECL const GUID keyboard_shortcut_manager::class_guid = +{ 0x95de5842, 0x30f5, 0x4f72, { 0xb4, 0xc, 0x19, 0x16, 0x63, 0x78, 0x2f, 0x80 } }; + +// {CD19C870-DA6A-4b8a-A118-732A8102D07D} +FOOGUIDDECL const GUID keyboard_shortcut_manager_v2::class_guid = +{ 0xcd19c870, 0xda6a, 0x4b8a, { 0xa1, 0x18, 0x73, 0x2a, 0x81, 0x2, 0xd0, 0x7d } }; + +// {30F95BEB-FDF4-4a75-B597-60CAF93B39C4} +FOOGUIDDECL const GUID packet_decoder::owner_MP4 = +{ 0x30f95beb, 0xfdf4, 0x4a75, { 0xb5, 0x97, 0x60, 0xca, 0xf9, 0x3b, 0x39, 0xc4 } }; + +// {8F450CB3-A083-4b83-8D85-ADCE5EA6D57F} +FOOGUIDDECL const GUID packet_decoder::owner_MP4_ALAC = +{ 0x8f450cb3, 0xa083, 0x4b83, { 0x8d, 0x85, 0xad, 0xce, 0x5e, 0xa6, 0xd5, 0x7f } }; + +// {40017871-50A9-48b6-BF60-BD181A227F9B} +FOOGUIDDECL const GUID packet_decoder::owner_MP4_AMR = +{ 0x40017871, 0x50a9, 0x48b6, { 0xbf, 0x60, 0xbd, 0x18, 0x1a, 0x22, 0x7f, 0x9b } }; + +// {2E729EA0-6BEB-4392-BF24-75C69B60166D} +FOOGUIDDECL const GUID packet_decoder::owner_MP4_AMR_WB = +{ 0x2e729ea0, 0x6beb, 0x4392, { 0xbf, 0x24, 0x75, 0xc6, 0x9b, 0x60, 0x16, 0x6d } }; + +// {AF5B7CB0-A08E-404a-A3C0-5C5EA1A8A05C} +FOOGUIDDECL const GUID packet_decoder::owner_ADTS = +{ 0xaf5b7cb0, 0xa08e, 0x404a, { 0xa3, 0xc0, 0x5c, 0x5e, 0xa1, 0xa8, 0xa0, 0x5c } }; + +// {F72D2EAE-835C-4dfb-97C6-624343EFAFB0} +FOOGUIDDECL const GUID packet_decoder::owner_ADIF = +{ 0xf72d2eae, 0x835c, 0x4dfb, { 0x97, 0xc6, 0x62, 0x43, 0x43, 0xef, 0xaf, 0xb0 } }; + +// {5C2DE804-EAEE-4b8e-8C14-9207A2549BBE} +FOOGUIDDECL const GUID packet_decoder::owner_matroska = +{ 0x5c2de804, 0xeaee, 0x4b8e, { 0x8c, 0x14, 0x92, 0x7, 0xa2, 0x54, 0x9b, 0xbe } }; + +// {7B741A69-1AC7-440d-A01D-88536DD4DE1C} +FOOGUIDDECL const GUID packet_decoder::owner_MP3 = +{ 0x7b741a69, 0x1ac7, 0x440d, { 0xa0, 0x1d, 0x88, 0x53, 0x6d, 0xd4, 0xde, 0x1c } }; + +// {17B300A0-3110-4400-A434-C18FBEEABA81} +FOOGUIDDECL const GUID packet_decoder::owner_MP2 = +{ 0x17b300a0, 0x3110, 0x4400, { 0xa4, 0x34, 0xc1, 0x8f, 0xbe, 0xea, 0xba, 0x81 } }; + +// {1C068E5E-DD65-4639-BF85-78B297C8FFAC} +FOOGUIDDECL const GUID packet_decoder::owner_MP1 = +{ 0x1c068e5e, 0xdd65, 0x4639, { 0xbf, 0x85, 0x78, 0xb2, 0x97, 0xc8, 0xff, 0xac } }; + +// {BC73F9FC-0107-480e-BF0E-BE58AF7AF328} +FOOGUIDDECL const GUID packet_decoder::property_samplerate = +{ 0xbc73f9fc, 0x107, 0x480e, { 0xbf, 0xe, 0xbe, 0x58, 0xaf, 0x7a, 0xf3, 0x28 } }; + +// {E5D19AAD-931B-48ac-AA6E-95E2C23BEC37} +FOOGUIDDECL const GUID packet_decoder::property_bitspersample = +{ 0xe5d19aad, 0x931b, 0x48ac, { 0xaa, 0x6e, 0x95, 0xe2, 0xc2, 0x3b, 0xec, 0x37 } }; + +// {1AFA1145-E774-4c26-91D6-3F5DD61E260E} +FOOGUIDDECL const GUID packet_decoder::property_channels = +{ 0x1afa1145, 0xe774, 0x4c26, { 0x91, 0xd6, 0x3f, 0x5d, 0xd6, 0x1e, 0x26, 0xe } }; + +// {29C556DA-065A-4d24-8A11-0F9DBC05A817} +FOOGUIDDECL const GUID packet_decoder::property_byteorder = +{ 0x29c556da, 0x65a, 0x4d24, { 0x8a, 0x11, 0xf, 0x9d, 0xbc, 0x5, 0xa8, 0x17 } }; + +// {0759C32F-E78E-4479-B0C0-B653DFA014D8} +FOOGUIDDECL const GUID packet_decoder::property_signed = +{ 0x759c32f, 0xe78e, 0x4479, { 0xb0, 0xc0, 0xb6, 0x53, 0xdf, 0xa0, 0x14, 0xd8 } }; + +// {BB31669E-0C30-4c5f-AAF0-20CD49D46058} +FOOGUIDDECL const GUID packet_decoder::property_channelmask = +{ 0xbb31669e, 0xc30, 0x4c5f, { 0xaa, 0xf0, 0x20, 0xcd, 0x49, 0xd4, 0x60, 0x58 } }; + +// {6F441057-1D18-4a58-9AC4-8F409CDA7DFD} +FOOGUIDDECL const GUID standard_commands::guid_context_file_properties = +{ 0x6f441057, 0x1d18, 0x4a58, { 0x9a, 0xc4, 0x8f, 0x40, 0x9c, 0xda, 0x7d, 0xfd } }; + +// {EFC1E9C8-EEEF-427a-8F42-E5781605846D} +FOOGUIDDECL const GUID standard_commands::guid_context_file_open_directory = +{ 0xefc1e9c8, 0xeeef, 0x427a, { 0x8f, 0x42, 0xe5, 0x78, 0x16, 0x5, 0x84, 0x6d } }; + +// {FFE18008-BCA2-4b29-AB88-8816B492C434} +FOOGUIDDECL const GUID standard_commands::guid_context_copy_names = +{ 0xffe18008, 0xbca2, 0x4b29, { 0xab, 0x88, 0x88, 0x16, 0xb4, 0x92, 0xc4, 0x34 } }; + +// {44B8F02B-5408-4361-8240-18DEC881B95E} +FOOGUIDDECL const GUID standard_commands::guid_context_send_to_playlist = +{ 0x44b8f02b, 0x5408, 0x4361, { 0x82, 0x40, 0x18, 0xde, 0xc8, 0x81, 0xb9, 0x5e } }; + +// {8C3BA2CB-BC4D-4752-8282-C6F9AED75A78} +FOOGUIDDECL const GUID standard_commands::guid_context_reload_info = +{ 0x8c3ba2cb, 0xbc4d, 0x4752, { 0x82, 0x82, 0xc6, 0xf9, 0xae, 0xd7, 0x5a, 0x78 } }; + +// {BD045EA4-E5E9-4206-8FF9-12AD9F5DCDE1} +FOOGUIDDECL const GUID standard_commands::guid_context_reload_info_if_changed = +{ 0xbd045ea4, 0xe5e9, 0x4206, { 0x8f, 0xf9, 0x12, 0xad, 0x9f, 0x5d, 0xcd, 0xe1 } }; + +// {684D9FBB-4383-44a2-9789-7EE1376209C6} +FOOGUIDDECL const GUID standard_commands::guid_context_rewrite_info = +{ 0x684d9fbb, 0x4383, 0x44a2, { 0x97, 0x89, 0x7e, 0xe1, 0x37, 0x62, 0x9, 0xc6 } }; + +// {860179B7-962F-4340-ACAD-0DDAF060A6B8} +FOOGUIDDECL const GUID standard_commands::guid_context_remove_tags = +{ 0x860179b7, 0x962f, 0x4340, { 0xac, 0xad, 0xd, 0xda, 0xf0, 0x60, 0xa6, 0xb8 } }; + +// {A7E7ECB7-1943-4907-83B3-60E92353C7FA} +FOOGUIDDECL const GUID standard_commands::guid_context_convert_run = +{ 0xa7e7ecb7, 0x1943, 0x4907, { 0x83, 0xb3, 0x60, 0xe9, 0x23, 0x53, 0xc7, 0xfa } }; + +// {BED4FB6E-C4F2-40dd-B528-1DE1450DDFE9} +FOOGUIDDECL const GUID standard_commands::guid_context_convert_run_withcue = +{ 0xbed4fb6e, 0xc4f2, 0x40dd, { 0xb5, 0x28, 0x1d, 0xe1, 0x45, 0xd, 0xdf, 0xe9 } }; + +// {A58AE6EA-A34F-4879-B25C-F31F2CBC4DA9} +FOOGUIDDECL const GUID standard_commands::guid_context_convert_run_singlefile = +{ 0xa58ae6ea, 0xa34f, 0x4879, { 0xb2, 0x5c, 0xf3, 0x1f, 0x2c, 0xbc, 0x4d, 0xa9 } }; + +// {A8EFA42D-76CB-42bc-8803-70516567B13D} +FOOGUIDDECL const GUID standard_commands::guid_context_write_cd = +{ 0xa8efa42d, 0x76cb, 0x42bc, { 0x88, 0x3, 0x70, 0x51, 0x65, 0x67, 0xb1, 0x3d } }; + +// {487DAED1-02FB-4336-A813-5E90317AB041} +FOOGUIDDECL const GUID standard_commands::guid_context_rg_scan_track = +{ 0x487daed1, 0x2fb, 0x4336, { 0xa8, 0x13, 0x5e, 0x90, 0x31, 0x7a, 0xb0, 0x41 } }; + +// {3850F34C-F619-4296-B8A0-26C617B1D16C} +FOOGUIDDECL const GUID standard_commands::guid_context_rg_scan_album = +{ 0x3850f34c, 0xf619, 0x4296, { 0xb8, 0xa0, 0x26, 0xc6, 0x17, 0xb1, 0xd1, 0x6c } }; + +// {6A2DBA02-260C-436f-8F41-0190A4298266} +FOOGUIDDECL const GUID standard_commands::guid_context_rg_scan_album_multi = +{ 0x6a2dba02, 0x260c, 0x436f, { 0x8f, 0x41, 0x1, 0x90, 0xa4, 0x29, 0x82, 0x66 } }; + +// {54C82A92-5824-4381-8D1B-79FBB1E2ABB8} +FOOGUIDDECL const GUID standard_commands::guid_context_rg_remove = +{ 0x54c82a92, 0x5824, 0x4381, { 0x8d, 0x1b, 0x79, 0xfb, 0xb1, 0xe2, 0xab, 0xb8 } }; + +// {69EAA594-13D9-4237-9BD7-11A39FDD1454} +FOOGUIDDECL const GUID standard_commands::guid_context_save_playlist = +{ 0x69eaa594, 0x13d9, 0x4237, { 0x9b, 0xd7, 0x11, 0xa3, 0x9f, 0xdd, 0x14, 0x54 } }; + +// {2BEB6836-C657-40ef-BB6E-D5B222AB89CE} +FOOGUIDDECL const GUID standard_commands::guid_context_masstag_edit = +{ 0x2beb6836, 0xc657, 0x40ef, { 0xbb, 0x6e, 0xd5, 0xb2, 0x22, 0xab, 0x89, 0xce } }; + +// {A579FF07-5D0B-48ed-A071-B6FCE4385AA9} +FOOGUIDDECL const GUID standard_commands::guid_context_masstag_rename = +{ 0xa579ff07, 0x5d0b, 0x48ed, { 0xa0, 0x71, 0xb6, 0xfc, 0xe4, 0x38, 0x5a, 0xa9 } }; + +// {77CFBCD0-98DC-4015-B327-D7142C664806} +FOOGUIDDECL const GUID standard_commands::guid_main_always_on_top = +{ 0x77cfbcd0, 0x98dc, 0x4015, { 0xb3, 0x27, 0xd7, 0x14, 0x2c, 0x66, 0x48, 0x6 } }; + +// {11213A01-9F36-4e69-A1BB-7A72F418DE3A} +FOOGUIDDECL const GUID standard_commands::guid_main_preferences = +{ 0x11213a01, 0x9f36, 0x4e69, { 0xa1, 0xbb, 0x7a, 0x72, 0xf4, 0x18, 0xde, 0x3a } }; + +// {EDA23441-5D38-4499-A22C-FE0CE0A987D9} +FOOGUIDDECL const GUID standard_commands::guid_main_about = +{ 0xeda23441, 0x5d38, 0x4499, { 0xa2, 0x2c, 0xfe, 0xc, 0xe0, 0xa9, 0x87, 0xd9 } }; + +// {6D38C73A-15D8-472c-8E68-6F946B82ECB4} +FOOGUIDDECL const GUID standard_commands::guid_main_exit = +{ 0x6d38c73a, 0x15d8, 0x472c, { 0x8e, 0x68, 0x6f, 0x94, 0x6b, 0x82, 0xec, 0xb4 } }; + +// {EF9B60FE-CB03-4c40-A8FD-3F1821020B37} +FOOGUIDDECL const GUID standard_commands::guid_main_restart = +{ 0xef9b60fe, 0xcb03, 0x4c40, { 0xa8, 0xfd, 0x3f, 0x18, 0x21, 0x2, 0xb, 0x37 } }; + +// {90500F09-F16F-415e-A047-AC5045C95FFE} +FOOGUIDDECL const GUID standard_commands::guid_main_activate = +{ 0x90500f09, 0xf16f, 0x415e, { 0xa0, 0x47, 0xac, 0x50, 0x45, 0xc9, 0x5f, 0xfe } }; + +// {13C17E8D-0D6F-41a4-B24A-59371043E925} +FOOGUIDDECL const GUID standard_commands::guid_main_hide = +{ 0x13c17e8d, 0xd6f, 0x41a4, { 0xb2, 0x4a, 0x59, 0x37, 0x10, 0x43, 0xe9, 0x25 } }; + +// {D9473FB2-BF11-4be0-972F-0E43F166A118} +FOOGUIDDECL const GUID standard_commands::guid_main_activate_or_hide = +{ 0xd9473fb2, 0xbf11, 0x4be0, { 0x97, 0x2f, 0xe, 0x43, 0xf1, 0x66, 0xa1, 0x18 } }; + +// {91E349DA-8800-42e5-BC8C-F3A92577AE84} +FOOGUIDDECL const GUID standard_commands::guid_main_titleformat_help = +{ 0x91e349da, 0x8800, 0x42e5, { 0xbc, 0x8c, 0xf3, 0xa9, 0x25, 0x77, 0xae, 0x84 } }; + +// {FBCFE01C-6C57-4e6a-A9F1-62334640DC91} +FOOGUIDDECL const GUID standard_commands::guid_main_playback_follows_cursor= +{ 0xfbcfe01c, 0x6c57, 0x4e6a, { 0xa9, 0xf1, 0x62, 0x33, 0x46, 0x40, 0xdc, 0x91 } }; + +// {0E1C730A-1EA9-41cc-9C30-25700ABDD9FA} +FOOGUIDDECL const GUID standard_commands::guid_main_cursor_follows_playback= +{ 0xe1c730a, 0x1ea9, 0x41cc, { 0x9c, 0x30, 0x25, 0x70, 0xa, 0xbd, 0xd9, 0xfa } }; + +// {E58895A0-A2F0-45b6-8799-1440E4DB7284} +FOOGUIDDECL const GUID standard_commands::guid_main_next = +{ 0xe58895a0, 0xa2f0, 0x45b6, { 0x87, 0x99, 0x14, 0x40, 0xe4, 0xdb, 0x72, 0x84 } }; + +// {059C4566-4708-4ebf-8139-6A8EA5A9DFC8} +FOOGUIDDECL const GUID standard_commands::guid_main_previous = +{ 0x59c4566, 0x4708, 0x4ebf, { 0x81, 0x39, 0x6a, 0x8e, 0xa5, 0xa9, 0xdf, 0xc8 } }; + +// {18B1278A-F1BB-4b48-BC3D-6EC9EF80AD19} +FOOGUIDDECL const GUID standard_commands::guid_main_next_or_random = +{ 0x18b1278a, 0xf1bb, 0x4b48, { 0xbc, 0x3d, 0x6e, 0xc9, 0xef, 0x80, 0xad, 0x19 } }; + +// {42BDA765-30A8-40fa-BFA4-6A4E2F2B2CE9} +FOOGUIDDECL const GUID standard_commands::guid_main_random = +{ 0x42bda765, 0x30a8, 0x40fa, { 0xbf, 0xa4, 0x6a, 0x4e, 0x2f, 0x2b, 0x2c, 0xe9 } }; + +// {FCEF5262-7FA5-452e-A527-C14E0CB582DE} +FOOGUIDDECL const GUID standard_commands::guid_main_pause = +{ 0xfcef5262, 0x7fa5, 0x452e, { 0xa5, 0x27, 0xc1, 0x4e, 0xc, 0xb5, 0x82, 0xde } }; + +// {D3F83B15-D4AF-4586-8BD0-4EA415E31FE1} +FOOGUIDDECL const GUID standard_commands::guid_main_play = +{ 0xd3f83b15, 0xd4af, 0x4586, { 0x8b, 0xd0, 0x4e, 0xa4, 0x15, 0xe3, 0x1f, 0xe1 } }; + +// {8DEBC44E-EDA2-48d4-8696-31FC29D1F383} +FOOGUIDDECL const GUID standard_commands::guid_main_play_or_pause = +{ 0x8debc44e, 0xeda2, 0x48d4, { 0x86, 0x96, 0x31, 0xfc, 0x29, 0xd1, 0xf3, 0x83 } }; + +// {2DF17F25-80B9-4a43-B21D-620458FDDE1E} +FOOGUIDDECL const GUID standard_commands::guid_main_rg_set_album = +{ 0x2df17f25, 0x80b9, 0x4a43, { 0xb2, 0x1d, 0x62, 0x4, 0x58, 0xfd, 0xde, 0x1e } }; + +// {C26F1955-5753-4836-887F-84A563DD6DD9} +FOOGUIDDECL const GUID standard_commands::guid_main_rg_set_track = +{ 0xc26f1955, 0x5753, 0x4836, { 0x88, 0x7f, 0x84, 0xa5, 0x63, 0xdd, 0x6d, 0xd9 } }; + +// {8D2D808E-6AA2-455b-A2F1-CDB019328140} +FOOGUIDDECL const GUID standard_commands::guid_main_rg_disable = +{ 0x8d2d808e, 0x6aa2, 0x455b, { 0xa2, 0xf1, 0xcd, 0xb0, 0x19, 0x32, 0x81, 0x40 } }; + +// {C3378028-165F-4374-966C-2FA2E0FCD3A8} +FOOGUIDDECL const GUID standard_commands::guid_main_stop = +{ 0xc3378028, 0x165f, 0x4374, { 0x96, 0x6c, 0x2f, 0xa2, 0xe0, 0xfc, 0xd3, 0xa8 } }; + +// {EE057982-22F9-4862-A986-859E463316FB} +FOOGUIDDECL const GUID standard_commands::guid_main_stop_after_current = +{ 0xee057982, 0x22f9, 0x4862, { 0xa9, 0x86, 0x85, 0x9e, 0x46, 0x33, 0x16, 0xfb } }; + +// {11DC6526-73C4-44f0-91B1-DE5C2D26B0C7} +FOOGUIDDECL const GUID standard_commands::guid_main_volume_down = +{ 0x11dc6526, 0x73c4, 0x44f0, { 0x91, 0xb1, 0xde, 0x5c, 0x2d, 0x26, 0xb0, 0xc7 } }; + +// {A313E630-A04A-4ae8-B5B4-0A944AC964FF} +FOOGUIDDECL const GUID standard_commands::guid_main_volume_up = +{ 0xa313e630, 0xa04a, 0x4ae8, { 0xb5, 0xb4, 0xa, 0x94, 0x4a, 0xc9, 0x64, 0xff } }; + +// {4A36285B-B4AF-46ed-A1AA-6333057F485B} +FOOGUIDDECL const GUID standard_commands::guid_main_volume_mute = +{ 0x4a36285b, 0xb4af, 0x46ed, { 0xa1, 0xaa, 0x63, 0x33, 0x5, 0x7f, 0x48, 0x5b } }; + +// {2DC43C22-CA09-4ef9-A61E-7A0C1DAAE21E} +FOOGUIDDECL const GUID standard_commands::guid_main_add_directory = +{ 0x2dc43c22, 0xca09, 0x4ef9, { 0xa6, 0x1e, 0x7a, 0xc, 0x1d, 0xaa, 0xe2, 0x1e } }; + +// {FC89C278-4475-4853-96C9-F7F05E8CC837} +FOOGUIDDECL const GUID standard_commands::guid_main_add_files = +{ 0xfc89c278, 0x4475, 0x4853, { 0x96, 0xc9, 0xf7, 0xf0, 0x5e, 0x8c, 0xc8, 0x37 } }; + +// {9CA39D38-AC9B-4cca-B0CE-C0F62D188114} +FOOGUIDDECL const GUID standard_commands::guid_main_add_location = +{ 0x9ca39d38, 0xac9b, 0x4cca, { 0xb0, 0xce, 0xc0, 0xf6, 0x2d, 0x18, 0x81, 0x14 } }; + +// {73D6E69D-0DC9-4d5c-A7EE-FF4BE3896B08} +FOOGUIDDECL const GUID standard_commands::guid_main_add_playlist = +{ 0x73d6e69d, 0xdc9, 0x4d5c, { 0xa7, 0xee, 0xff, 0x4b, 0xe3, 0x89, 0x6b, 0x8 } }; + +// {55559142-7AEA-4c20-9B72-1D48E970A274} +FOOGUIDDECL const GUID standard_commands::guid_main_clear_playlist = +{ 0x55559142, 0x7aea, 0x4c20, { 0x9b, 0x72, 0x1d, 0x48, 0xe9, 0x70, 0xa2, 0x74 } }; + +// {BF72488F-36AC-46b3-A36D-193E60C79BC5} +FOOGUIDDECL const GUID standard_commands::guid_main_create_playlist = +{ 0xbf72488f, 0x36ac, 0x46b3, { 0xa3, 0x6d, 0x19, 0x3e, 0x60, 0xc7, 0x9b, 0xc5 } }; + +// {59E99BEE-42A3-4526-B06D-56C0C49F0BC1} +FOOGUIDDECL const GUID standard_commands::guid_main_highlight_playing = +{ 0x59e99bee, 0x42a3, 0x4526, { 0xb0, 0x6d, 0x56, 0xc0, 0xc4, 0x9f, 0xb, 0xc1 } }; + +// {D94393D4-9DBB-4e5c-BE8C-BE9CA80E214D} +FOOGUIDDECL const GUID standard_commands::guid_main_load_playlist = +{ 0xd94393d4, 0x9dbb, 0x4e5c, { 0xbe, 0x8c, 0xbe, 0x9c, 0xa8, 0xe, 0x21, 0x4d } }; + +// {EE1308C5-EBD2-48f1-959D-2627069C2E0F} +FOOGUIDDECL const GUID standard_commands::guid_main_next_playlist = +{ 0xee1308c5, 0xebd2, 0x48f1, { 0x95, 0x9d, 0x26, 0x27, 0x6, 0x9c, 0x2e, 0xf } }; + +// {486ECDA3-7BA2-49e9-BB44-4DB9DF9320C7} +FOOGUIDDECL const GUID standard_commands::guid_main_previous_playlist = +{ 0x486ecda3, 0x7ba2, 0x49e9, { 0xbb, 0x44, 0x4d, 0xb9, 0xdf, 0x93, 0x20, 0xc7 } }; + +// {69C778AA-B836-40a0-89CD-7A2E50C102CB} +FOOGUIDDECL const GUID standard_commands::guid_main_open = +{ 0x69c778aa, 0xb836, 0x40a0, { 0x89, 0xcd, 0x7a, 0x2e, 0x50, 0xc1, 0x2, 0xcb } }; + +// {EB7FB5A4-5904-4d2c-B66C-D882A3B15277} +FOOGUIDDECL const GUID standard_commands::guid_main_remove_playlist = +{ 0xeb7fb5a4, 0x5904, 0x4d2c, { 0xb6, 0x6c, 0xd8, 0x82, 0xa3, 0xb1, 0x52, 0x77 } }; + +// {C297BADB-8098-45a9-A5E8-B53A0D780CE3} +FOOGUIDDECL const GUID standard_commands::guid_main_remove_dead_entries = +{ 0xc297badb, 0x8098, 0x45a9, { 0xa5, 0xe8, 0xb5, 0x3a, 0xd, 0x78, 0xc, 0xe3 } }; + +// {D08C2921-7750-4979-98F9-3A513A31FF96} +FOOGUIDDECL const GUID standard_commands::guid_main_remove_duplicates = +{ 0xd08c2921, 0x7750, 0x4979, { 0x98, 0xf9, 0x3a, 0x51, 0x3a, 0x31, 0xff, 0x96 } }; + +// {D3A25E47-BA98-4e6b-95AD-A7502919EB75} +FOOGUIDDECL const GUID standard_commands::guid_main_rename_playlist = +{ 0xd3a25e47, 0xba98, 0x4e6b, { 0x95, 0xad, 0xa7, 0x50, 0x29, 0x19, 0xeb, 0x75 } }; + +// {0FDCFC65-9B39-445a-AA88-4D245F217480} +FOOGUIDDECL const GUID standard_commands::guid_main_save_all_playlists = +{ 0xfdcfc65, 0x9b39, 0x445a, { 0xaa, 0x88, 0x4d, 0x24, 0x5f, 0x21, 0x74, 0x80 } }; + +// {370B720B-4CF7-465b-908C-2D2ADD027900} +FOOGUIDDECL const GUID standard_commands::guid_main_save_playlist = +{ 0x370b720b, 0x4cf7, 0x465b, { 0x90, 0x8c, 0x2d, 0x2a, 0xdd, 0x2, 0x79, 0x0 } }; + +// {A6CFC2A8-56B3-4d12-88E7-0237961AC47E} +FOOGUIDDECL const GUID standard_commands::guid_main_playlist_search = +{ 0xa6cfc2a8, 0x56b3, 0x4d12, { 0x88, 0xe7, 0x2, 0x37, 0x96, 0x1a, 0xc4, 0x7e } }; + +// {383D4E8D-7E30-4fb8-B5DD-8C975D89E58E} +FOOGUIDDECL const GUID standard_commands::guid_main_playlist_sel_crop = +{ 0x383d4e8d, 0x7e30, 0x4fb8, { 0xb5, 0xdd, 0x8c, 0x97, 0x5d, 0x89, 0xe5, 0x8e } }; + +// {E0EEA319-E282-4e6c-8B82-4DFD42A1D4ED} +FOOGUIDDECL const GUID standard_commands::guid_main_playlist_sel_remove = +{ 0xe0eea319, 0xe282, 0x4e6c, { 0x8b, 0x82, 0x4d, 0xfd, 0x42, 0xa1, 0xd4, 0xed } }; + +// {F0845920-7F6D-40ac-B2EB-3D00C2C8260B} +FOOGUIDDECL const GUID standard_commands::guid_main_playlist_sel_invert = +{ 0xf0845920, 0x7f6d, 0x40ac, { 0xb2, 0xeb, 0x3d, 0x0, 0xc2, 0xc8, 0x26, 0xb } }; + +// {29910B33-79E9-40da-992B-5A4AA4281F78} +FOOGUIDDECL const GUID standard_commands::guid_main_playlist_undo = +{ 0x29910b33, 0x79e9, 0x40da, { 0x99, 0x2b, 0x5a, 0x4a, 0xa4, 0x28, 0x1f, 0x78 } }; + +// {7A9D9450-A8BF-4a88-B44F-DCD83A49DD7A} +FOOGUIDDECL const GUID standard_commands::guid_main_playlist_redo = +{ 0x7a9d9450, 0xa8bf, 0x4a88, { 0xb4, 0x4f, 0xdc, 0xd8, 0x3a, 0x49, 0xdd, 0x7a } }; + +// {02D89A8A-5F7D-41c3-A215-6731D8621036} +FOOGUIDDECL const GUID standard_commands::guid_main_show_console = +{ 0x2d89a8a, 0x5f7d, 0x41c3, { 0xa2, 0x15, 0x67, 0x31, 0xd8, 0x62, 0x10, 0x36 } }; + +// {E6970E91-33BE-4288-AC01-4B02F07B5D38} +FOOGUIDDECL const GUID standard_commands::guid_main_play_cd = +{ 0xe6970e91, 0x33be, 0x4288, { 0xac, 0x1, 0x4b, 0x2, 0xf0, 0x7b, 0x5d, 0x38 } }; + +// {1073AB1D-38ED-4957-8B06-38BC878C1F40} +FOOGUIDDECL const GUID standard_commands::guid_main_restart_resetconfig = +{ 0x1073ab1d, 0x38ed, 0x4957, { 0x8b, 0x6, 0x38, 0xbc, 0x87, 0x8c, 0x1f, 0x40 } }; + +// {FDC8A1C2-93EF-4415-8C20-60B6517F0B5F} +FOOGUIDDECL const GUID standard_commands::guid_main_record = +{ 0xfdc8a1c2, 0x93ef, 0x4415, { 0x8c, 0x20, 0x60, 0xb6, 0x51, 0x7f, 0xb, 0x5f } }; + +// {45EB37D2-3CD9-4f0a-9B20-8EAE649D7A9F} +FOOGUIDDECL const GUID standard_commands::guid_main_playlist_moveback = +{ 0x45eb37d2, 0x3cd9, 0x4f0a, { 0x9b, 0x20, 0x8e, 0xae, 0x64, 0x9d, 0x7a, 0x9f } }; + +// {02298938-596A-41f7-A398-19766A06E6EB} +FOOGUIDDECL const GUID standard_commands::guid_main_playlist_moveforward = +{ 0x2298938, 0x596a, 0x41f7, { 0xa3, 0x98, 0x19, 0x76, 0x6a, 0x6, 0xe6, 0xeb } }; + +// {E910ACC6-A81A-4a20-9F62-19015BCD1013} +FOOGUIDDECL const GUID standard_commands::guid_main_saveconfig = +{ 0xe910acc6, 0xa81a, 0x4a20, { 0x9f, 0x62, 0x19, 0x1, 0x5b, 0xcd, 0x10, 0x13 } }; + +// {03445FCC-71D9-4e01-AE02-A557D30B4CD7} +FOOGUIDDECL const GUID standard_commands::guid_main_playlist_select_all = +{ 0x3445fcc, 0x71d9, 0x4e01, { 0xae, 0x2, 0xa5, 0x57, 0xd3, 0xb, 0x4c, 0xd7 } }; + +// {919FA72B-1DF9-49ee-A8F1-D8BA1DEAA7E9} +FOOGUIDDECL const GUID standard_commands::guid_main_show_now_playing = +{ 0x919fa72b, 0x1df9, 0x49ee, { 0xa8, 0xf1, 0xd8, 0xba, 0x1d, 0xea, 0xa7, 0xe9 } }; + +// {D8D51855-D79D-49b8-97A8-065785FA2426} +FOOGUIDDECL const GUID playlist_manager::class_guid= +{ 0xd8d51855, 0xd79d, 0x49b8, { 0x97, 0xa8, 0x6, 0x57, 0x85, 0xfa, 0x24, 0x26 } }; + +// {C303A0F1-8E88-4539-87E5-9E455B7D548C} +FOOGUIDDECL const GUID genrand_service::class_guid= +{ 0xc303a0f1, 0x8e88, 0x4539, { 0x87, 0xe5, 0x9e, 0x45, 0x5b, 0x7d, 0x54, 0x8c } }; + +// {EB8FA333-F365-46ad-8621-345671567BAA} +FOOGUIDDECL const GUID playlist_incoming_item_filter::class_guid= +{ 0xeb8fa333, 0xf365, 0x46ad, { 0x86, 0x21, 0x34, 0x56, 0x71, 0x56, 0x7b, 0xaa } }; + +// {FEBD85B5-C12D-45b5-B55D-0D3F432B0C6B} +FOOGUIDDECL const GUID library_manager::class_guid= +{ 0xfebd85b5, 0xc12d, 0x45b5, { 0xb5, 0x5d, 0xd, 0x3f, 0x43, 0x2b, 0xc, 0x6b } }; + +// {9A08B50F-E8C6-40c0-88C3-7530CF2C3115} +FOOGUIDDECL const GUID library_callback::class_guid= +{ 0x9a08b50f, 0xe8c6, 0x40c0, { 0x88, 0xc3, 0x75, 0x30, 0xcf, 0x2c, 0x31, 0x15 } }; + +// {D5CAC75A-3023-4dce-8B0D-B502BD056A7C} +FOOGUIDDECL const GUID popup_message::class_guid= +{ 0xd5cac75a, 0x3023, 0x4dce, { 0x8b, 0xd, 0xb5, 0x2, 0xbd, 0x5, 0x6a, 0x7c } }; + +// {13F9CB11-0EAE-4417-AF0C-8894DEB65E8B} +FOOGUIDDECL const GUID app_close_blocker::class_guid= +{ 0x13f9cb11, 0xeae, 0x4417, { 0xaf, 0xc, 0x88, 0x94, 0xde, 0xb6, 0x5e, 0x8b } }; + +// {5570A2D2-8F9E-48a7-AFAC-DAC00A3C1636} +FOOGUIDDECL const GUID file_operation_callback::class_guid= +{ 0x5570a2d2, 0x8f9e, 0x48a7, { 0xaf, 0xac, 0xda, 0xc0, 0xa, 0x3c, 0x16, 0x36 } }; + +// {340099D1-7BEC-4ac6-92A4-77FF01507891} +FOOGUIDDECL const GUID config_object::class_guid= +{ 0x340099d1, 0x7bec, 0x4ac6, { 0x92, 0xa4, 0x77, 0xff, 0x1, 0x50, 0x78, 0x91 } }; + +// {1BA04122-DE9A-4a90-9FC3-A6A7EC8F9626} +FOOGUIDDECL const GUID config_object_notify_manager::class_guid= +{ 0x1ba04122, 0xde9a, 0x4a90, { 0x9f, 0xc3, 0xa6, 0xa7, 0xec, 0x8f, 0x96, 0x26 } }; + +// {AD5138E6-CF8F-4482-89B2-B2EAAEDF3B4C} +FOOGUIDDECL const GUID standard_config_objects::bool_show_keyboard_shortcuts_in_menus= +{ 0xad5138e6, 0xcf8f, 0x4482, { 0x89, 0xb2, 0xb2, 0xea, 0xae, 0xdf, 0x3b, 0x4c } }; + +// {E91F618C-5741-470f-A178-21272C3ECA90} +FOOGUIDDECL const GUID standard_config_objects::bool_remember_window_positions= +{ 0xe91f618c, 0x5741, 0x470f, { 0xa1, 0x78, 0x21, 0x27, 0x2c, 0x3e, 0xca, 0x90 } }; + +// {5497FAA9-690C-4fb4-8BC0-678CEBCBBDC4} +FOOGUIDDECL const GUID standard_config_objects::bool_playback_follows_cursor= +{ 0x5497faa9, 0x690c, 0x4fb4, { 0x8b, 0xc0, 0x67, 0x8c, 0xeb, 0xcb, 0xbd, 0xc4 } }; + +// {58D3E2D6-DD6D-48dd-98EB-4EABF0ACFEB8} +FOOGUIDDECL const GUID standard_config_objects::bool_cursor_follows_playback= +{ 0x58d3e2d6, 0xdd6d, 0x48dd, { 0x98, 0xeb, 0x4e, 0xab, 0xf0, 0xac, 0xfe, 0xb8 } }; + +// {2DF7194D-86FC-4312-98DA-E820DA3E710D} +FOOGUIDDECL const GUID standard_config_objects::bool_ui_always_on_top= +{ 0x2df7194d, 0x86fc, 0x4312, { 0x98, 0xda, 0xe8, 0x20, 0xda, 0x3e, 0x71, 0xd } }; + +// {B572C86F-4206-40a0-8476-C7B27E74DB2D} +FOOGUIDDECL const GUID standard_config_objects::bool_playlist_stop_after_current= +{ 0xb572c86f, 0x4206, 0x40a0, { 0x84, 0x76, 0xc7, 0xb2, 0x7e, 0x74, 0xdb, 0x2d } }; + +// {FFDFDA96-699C-4617-A977-22DC2F039B00} +FOOGUIDDECL const GUID standard_config_objects::string_gui_last_directory_media= +{ 0xffdfda96, 0x699c, 0x4617, { 0xa9, 0x77, 0x22, 0xdc, 0x2f, 0x3, 0x9b, 0x0 } }; + +// {915D3B21-81CB-4b96-9762-1C90FBF371DF} +FOOGUIDDECL const GUID standard_config_objects::string_gui_last_directory_playlists= +{ 0x915d3b21, 0x81cb, 0x4b96, { 0x97, 0x62, 0x1c, 0x90, 0xfb, 0xf3, 0x71, 0xdf } }; + +// {338B6871-EB1F-4384-BF83-6BFACE5B66BC} +FOOGUIDDECL const GUID standard_config_objects::int32_dynamic_bitrate_display_rate= +{ 0x338b6871, 0xeb1f, 0x4384, { 0xbf, 0x83, 0x6b, 0xfa, 0xce, 0x5b, 0x66, 0xbc } }; + +// {3E35D949-DCDB-44e1-8013-9D1633C09756} +FOOGUIDDECL const GUID config_object_notify::class_guid= +{ 0x3e35d949, 0xdcdb, 0x44e1, { 0x80, 0x13, 0x9d, 0x16, 0x33, 0xc0, 0x97, 0x56 } }; + +// {4AC9408E-4D9C-4135-ACB5-2CAB35376FC9} +FOOGUIDDECL const GUID titleformat_object::class_guid= +{ 0x4ac9408e, 0x4d9c, 0x4135, { 0xac, 0xb5, 0x2c, 0xab, 0x35, 0x37, 0x6f, 0xc9 } }; + +// {25B0D20D-9BA3-4a7b-8D0E-89FAF75F916F} +FOOGUIDDECL const GUID tag_processor_id3v2::class_guid= +{ 0x25b0d20d, 0x9ba3, 0x4a7b, { 0x8d, 0xe, 0x89, 0xfa, 0xf7, 0x5f, 0x91, 0x6f } }; + +// {AD537D40-499D-4c29-81D4-C0FA496DD58C} +FOOGUIDDECL const GUID tag_processor_trailing::class_guid= +{ 0xad537d40, 0x499d, 0x4c29, { 0x81, 0xd4, 0xc0, 0xfa, 0x49, 0x6d, 0xd5, 0x8c } }; + +// {160885C6-3AA3-4f60-8718-1240615E6414} +FOOGUIDDECL const GUID metadb_handle::class_guid= +{ 0x160885c6, 0x3aa3, 0x4f60, { 0x87, 0x18, 0x12, 0x40, 0x61, 0x5e, 0x64, 0x14 } }; + +// {9DBC262F-4795-4292-824B-23A655011A3E} +FOOGUIDDECL const GUID threaded_process::class_guid= +{ 0x9dbc262f, 0x4795, 0x4292, { 0x82, 0x4b, 0x23, 0xa6, 0x55, 0x1, 0x1a, 0x3e } }; + +// {7B69141B-4271-4070-8998-10CD39249C12} +FOOGUIDDECL const GUID threaded_process_callback::class_guid= +{ 0x7b69141b, 0x4271, 0x4070, { 0x89, 0x98, 0x10, 0xcd, 0x39, 0x24, 0x9c, 0x12 } }; + + +// {64D18B80-5E97-40e4-A30C-A4640C60BCE5} +FOOGUIDDECL const GUID metadb_io::class_guid= +{ 0x64d18b80, 0x5e97, 0x40e4, { 0xa3, 0xc, 0xa4, 0x64, 0xc, 0x60, 0xbc, 0xe5 } }; + +FOOGUIDDECL const GUID preferences_page::guid_tagging = { 0x563107c3, 0xfc7d, 0x4022, { 0xa8, 0x72, 0xa8, 0x2a, 0x2b, 0x3f, 0xd5, 0x25 } }; + +// {B9218D23-F73D-4b61-A1D9-BFD420CDAC77} +FOOGUIDDECL const GUID preferences_page::guid_root= +{ 0xb9218d23, 0xf73d, 0x4b61, { 0xa1, 0xd9, 0xbf, 0xd4, 0x20, 0xcd, 0xac, 0x77 } }; + +// {2F0E2232-A5FD-43e4-B6AB-3839B8D1A707} +FOOGUIDDECL const GUID preferences_page::guid_hidden= +{ 0x2f0e2232, 0xa5fd, 0x43e4, { 0xb6, 0xab, 0x38, 0x39, 0xb8, 0xd1, 0xa7, 0x7 } }; + +// {627C0767-0793-44f8-8087-BE4934311282} +FOOGUIDDECL const GUID preferences_page::guid_tools= +{ 0x627c0767, 0x793, 0x44f8, { 0x80, 0x87, 0xbe, 0x49, 0x34, 0x31, 0x12, 0x82 } }; + +// {6AAA67B6-732F-4967-899A-18C5F8C70017} +FOOGUIDDECL const GUID preferences_page::guid_display= +{ 0x6aaa67b6, 0x732f, 0x4967, { 0x89, 0x9a, 0x18, 0xc5, 0xf8, 0xc7, 0x0, 0x17 } }; + +// {67508677-CFCC-4a1c-921C-49B39CC5B986} +FOOGUIDDECL const GUID preferences_page::guid_playback= +{ 0x67508677, 0xcfcc, 0x4a1c, { 0x92, 0x1c, 0x49, 0xb3, 0x9c, 0xc5, 0xb9, 0x86 } }; + +// {494326C8-88FF-4265-B2B2-E6470BEE13B3} +FOOGUIDDECL const GUID preferences_page::guid_visualisations= +{ 0x494326c8, 0x88ff, 0x4265, { 0xb2, 0xb2, 0xe6, 0x47, 0xb, 0xee, 0x13, 0xb3 } }; + +// {FC01B529-4BD7-47cd-BAF7-2FB632F0DBB6} +FOOGUIDDECL const GUID preferences_page::guid_input= +{ 0xfc01b529, 0x4bd7, 0x47cd, { 0xba, 0xf7, 0x2f, 0xb6, 0x32, 0xf0, 0xdb, 0xb6 } }; + +// {2E8E9647-4174-41b2-9EC4-910BE128082E} +FOOGUIDDECL const GUID preferences_page::guid_core= +{ 0x2e8e9647, 0x4174, 0x41b2, { 0x9e, 0xc4, 0x91, 0xb, 0xe1, 0x28, 0x8, 0x2e } }; + +// {7D0334E5-ADD7-4ff5-9DB8-A618B4824028} +FOOGUIDDECL const GUID preferences_page::guid_tag_writing= +{ 0x7d0334e5, 0xadd7, 0x4ff5, { 0x9d, 0xb8, 0xa6, 0x18, 0xb4, 0x82, 0x40, 0x28 } }; + +// {2D269FA9-6F78-4cec-9F1F-0A176EFCE77A} +FOOGUIDDECL const GUID preferences_page::guid_media_library= +{ 0x2d269fa9, 0x6f78, 0x4cec, { 0x9f, 0x1f, 0xa, 0x17, 0x6e, 0xfc, 0xe7, 0x7a } }; + +// {B8C5CEEA-A5F4-4278-AA2D-798E4403001F} +FOOGUIDDECL const GUID library_viewer::class_guid= +{ 0xb8c5ceea, 0xa5f4, 0x4278, { 0xaa, 0x2d, 0x79, 0x8e, 0x44, 0x3, 0x0, 0x1f } }; + +// {5CD49B5D-D604-4c07-A8FA-FFD8512AFD2B} +FOOGUIDDECL const GUID message_loop::class_guid= +{ 0x5cd49b5d, 0xd604, 0x4c07, { 0xa8, 0xfa, 0xff, 0xd8, 0x51, 0x2a, 0xfd, 0x2b } }; + +// {932EC96D-4DFD-4ed7-A07C-2A22BE770185} +FOOGUIDDECL const GUID chapterizer::class_guid= +{ 0x932ec96d, 0x4dfd, 0x4ed7, { 0xa0, 0x7c, 0x2a, 0x22, 0xbe, 0x77, 0x1, 0x85 } }; + +// {7EB442CD-FAD7-4a26-AD7E-16F6FC89207B} +FOOGUIDDECL const GUID input_decoder::class_guid = +{ 0x7eb442cd, 0xfad7, 0x4a26, { 0xad, 0x7e, 0x16, 0xf6, 0xfc, 0x89, 0x20, 0x7b } }; + +// {8E9BB1D4-A52B-4df6-A929-1AAE4075388A} +FOOGUIDDECL const GUID input_info_reader::class_guid = +{ 0x8e9bb1d4, 0xa52b, 0x4df6, { 0xa9, 0x29, 0x1a, 0xae, 0x40, 0x75, 0x38, 0x8a } }; + +// {FE40FF66-64C9-4234-B639-028DC8060CF7} +FOOGUIDDECL const GUID input_info_writer::class_guid = +{ 0xfe40ff66, 0x64c9, 0x4234, { 0xb6, 0x39, 0x2, 0x8d, 0xc8, 0x6, 0xc, 0xf7 } }; + +// {436547FC-C4EF-4322-B59E-E696A25FAB2C} +FOOGUIDDECL const GUID input_entry::class_guid = +{ 0x436547fc, 0xc4ef, 0x4322, { 0xb5, 0x9e, 0xe6, 0x96, 0xa2, 0x5f, 0xab, 0x2c } }; + +// {3296219B-EBA5-4c32-A193-C9BB174801DA} +FOOGUIDDECL const GUID link_resolver::class_guid = +{ 0x3296219b, 0xeba5, 0x4c32, { 0xa1, 0x93, 0xc9, 0xbb, 0x17, 0x48, 0x1, 0xda } }; + +// {A49E087E-D064-4b2e-A08D-11264F691FFE} +FOOGUIDDECL const GUID playback_queue_callback::class_guid = +{ 0xa49e087e, 0xd064, 0x4b2e, { 0xa0, 0x8d, 0x11, 0x26, 0x4f, 0x69, 0x1f, 0xfe } }; + +// {1131D64B-04CB-43ee-95EB-24D18B753248} +FOOGUIDDECL const GUID main_thread_callback_manager::class_guid = +{ 0x1131d64b, 0x4cb, 0x43ee, { 0x95, 0xeb, 0x24, 0xd1, 0x8b, 0x75, 0x32, 0x48 } }; + +// {87D2C583-7AFB-4e58-B21E-FBD3E6E8F5E7} +FOOGUIDDECL const GUID main_thread_callback::class_guid = +{ 0x87d2c583, 0x7afb, 0x4e58, { 0xb2, 0x1e, 0xfb, 0xd3, 0xe6, 0xe8, 0xf5, 0xe7 } }; + + + +// {21656AB9-0255-4f8c-8FB9-1A7748BCE93A} +FOOGUIDDECL const GUID mainmenu_group::class_guid = +{ 0x21656ab9, 0x255, 0x4f8c, { 0x8f, 0xb9, 0x1a, 0x77, 0x48, 0xbc, 0xe9, 0x3a } }; + +// {2E673A2E-A4EE-419c-94C8-9C838660414C} +FOOGUIDDECL const GUID mainmenu_group_popup::class_guid = +{ 0x2e673a2e, 0xa4ee, 0x419c, { 0x94, 0xc8, 0x9c, 0x83, 0x86, 0x60, 0x41, 0x4c } }; + +// {35077B8C-6E70-47ba-B9DD-D51500E12F2E} +FOOGUIDDECL const GUID mainmenu_commands::class_guid = +{ 0x35077b8c, 0x6e70, 0x47ba, { 0xb9, 0xdd, 0xd5, 0x15, 0x0, 0xe1, 0x2f, 0x2e } }; + +// {350B3EA8-6B3E-4346-B6D2-799E98EFC920} +FOOGUIDDECL const GUID mainmenu_manager::class_guid = +{ 0x350b3ea8, 0x6b3e, 0x4346, { 0xb6, 0xd2, 0x79, 0x9e, 0x98, 0xef, 0xc9, 0x20 } }; + + +// {8F487F1F-419F-47a7-8ECF-EC44AF4449A3} +FOOGUIDDECL const GUID mainmenu_groups::file = +{ 0x8f487f1f, 0x419f, 0x47a7, { 0x8e, 0xcf, 0xec, 0x44, 0xaf, 0x44, 0x49, 0xa3 } }; + +// {F8BE5604-165F-4bb9-B6A9-15E55E0E0D3A} +FOOGUIDDECL const GUID mainmenu_groups::view = +{ 0xf8be5604, 0x165f, 0x4bb9, { 0xb6, 0xa9, 0x15, 0xe5, 0x5e, 0xe, 0xd, 0x3a } }; + +// {8CDA6B10-0613-4cfd-8730-3B9CBF4C6A39} +FOOGUIDDECL const GUID mainmenu_groups::edit = +{ 0x8cda6b10, 0x613, 0x4cfd, { 0x87, 0x30, 0x3b, 0x9c, 0xbf, 0x4c, 0x6a, 0x39 } }; + +// {D8A4FC46-5E3D-47aa-97B7-947988228246} +FOOGUIDDECL const GUID mainmenu_groups::edit_part1 = +{ 0xd8a4fc46, 0x5e3d, 0x47aa, { 0x97, 0xb7, 0x94, 0x79, 0x88, 0x22, 0x82, 0x46 } }; + +// {007682CE-2A99-4b70-8F63-DE765D1C5555} +FOOGUIDDECL const GUID mainmenu_groups::edit_part2 = +{ 0x7682ce, 0x2a99, 0x4b70, { 0x8f, 0x63, 0xde, 0x76, 0x5d, 0x1c, 0x55, 0x55 } }; + +// {1F572090-D620-4940-85EC-0EFE499FAC03} +FOOGUIDDECL const GUID mainmenu_groups::edit_part3 = +{ 0x1f572090, 0xd620, 0x4940, { 0x85, 0xec, 0xe, 0xfe, 0x49, 0x9f, 0xac, 0x3 } }; + +// {65FA047A-1599-4b9c-B53D-C3FEB716339D} +FOOGUIDDECL const GUID mainmenu_groups::edit_part2_selection = +{ 0x65fa047a, 0x1599, 0x4b9c, { 0xb5, 0x3d, 0xc3, 0xfe, 0xb7, 0x16, 0x33, 0x9d } }; + +// {5B8AEF2C-6E1A-420d-B488-3E3A00E39E28} +FOOGUIDDECL const GUID mainmenu_groups::edit_part2_sort = +{ 0x5b8aef2c, 0x6e1a, 0x420d, { 0xb4, 0x88, 0x3e, 0x3a, 0x0, 0xe3, 0x9e, 0x28 } }; + +// {EE9D6F72-7BC7-4a60-8C28-B96DED252BD3} +FOOGUIDDECL const GUID mainmenu_groups::edit_part2_selection_sort = +{ 0xee9d6f72, 0x7bc7, 0x4a60, { 0x8c, 0x28, 0xb9, 0x6d, 0xed, 0x25, 0x2b, 0xd3 } }; + +// {53FA5B8A-FCBC-4296-B968-45BAE6888845} +FOOGUIDDECL const GUID mainmenu_groups::playback = +{ 0x53fa5b8a, 0xfcbc, 0x4296, { 0xb9, 0x68, 0x45, 0xba, 0xe6, 0x88, 0x88, 0x45 } }; + +// {15D22753-9D30-4929-AA14-5124016F7E68} +FOOGUIDDECL const GUID mainmenu_groups::library = +{ 0x15d22753, 0x9d30, 0x4929, { 0xaa, 0x14, 0x51, 0x24, 0x1, 0x6f, 0x7e, 0x68 } }; + +// {25DC3DB7-996A-4f48-AF53-712032EFA04F} +FOOGUIDDECL const GUID mainmenu_groups::help = +{ 0x25dc3db7, 0x996a, 0x4f48, { 0xaf, 0x53, 0x71, 0x20, 0x32, 0xef, 0xa0, 0x4f } }; + +// {8EED252D-0A0F-4fc9-9D81-8CF7209A8BF2} +FOOGUIDDECL const GUID mainmenu_groups::file_open = +{ 0x8eed252d, 0xa0f, 0x4fc9, { 0x9d, 0x81, 0x8c, 0xf7, 0x20, 0x9a, 0x8b, 0xf2 } }; + +// {9E650B8E-C3F3-4495-AF15-6B656060C3B9} +FOOGUIDDECL const GUID mainmenu_groups::file_add = +{ 0x9e650b8e, 0xc3f3, 0x4495, { 0xaf, 0x15, 0x6b, 0x65, 0x60, 0x60, 0xc3, 0xb9 } }; + +// {9995FAE6-B1C4-457f-A747-5BD120930210} +FOOGUIDDECL const GUID mainmenu_groups::file_playlist = +{ 0x9995fae6, 0xb1c4, 0x457f, { 0xa7, 0x47, 0x5b, 0xd1, 0x20, 0x93, 0x2, 0x10 } }; + +// {8A324F18-6173-42ec-A640-5E296AD446B3} +FOOGUIDDECL const GUID mainmenu_groups::file_etc = +{ 0x8a324f18, 0x6173, 0x42ec, { 0xa6, 0x40, 0x5e, 0x29, 0x6a, 0xd4, 0x46, 0xb3 } }; + +// {12F5E247-5A81-4734-8119-8F9BC114FE74} +FOOGUIDDECL const GUID mainmenu_groups::playback_controls = +{ 0x12f5e247, 0x5a81, 0x4734, { 0x81, 0x19, 0x8f, 0x9b, 0xc1, 0x14, 0xfe, 0x74 } }; + +// {1169B3EB-81B5-4199-8929-7D3EAFD4809F} +FOOGUIDDECL const GUID mainmenu_groups::playback_etc = +{ 0x1169b3eb, 0x81b5, 0x4199, { 0x89, 0x29, 0x7d, 0x3e, 0xaf, 0xd4, 0x80, 0x9f } }; + +// {29272FEC-21C7-4b00-A9A7-01A8CE675EBF} +FOOGUIDDECL const GUID mainmenu_groups::view_visualisations = +{ 0x29272fec, 0x21c7, 0x4b00, { 0xa9, 0xa7, 0x1, 0xa8, 0xce, 0x67, 0x5e, 0xbf } }; + +// {2DA055D4-0257-40b2-8281-7967866B485C} +FOOGUIDDECL const GUID mainmenu_groups::file_etc_preferences = +{ 0x2da055d4, 0x257, 0x40b2, { 0x82, 0x81, 0x79, 0x67, 0x86, 0x6b, 0x48, 0x5c } }; + +// {517BFAE8-A148-4cb2-8CCE-1AD2179FB910} +FOOGUIDDECL const GUID mainmenu_groups::file_etc_exit = +{ 0x517bfae8, 0xa148, 0x4cb2, { 0x8c, 0xce, 0x1a, 0xd2, 0x17, 0x9f, 0xb9, 0x10 } }; + +// {61190F78-3B3A-4fda-A431-2CF7DA1C96CE} +FOOGUIDDECL const GUID mainmenu_groups::view_alwaysontop = +{ 0x61190f78, 0x3b3a, 0x4fda, { 0xa4, 0x31, 0x2c, 0xf7, 0xda, 0x1c, 0x96, 0xce } }; + +// {E55F8D65-AE51-47bf-99F9-BB113421CB19} +FOOGUIDDECL const GUID mainmenu_groups::help_about = +{ 0xe55f8d65, 0xae51, 0x47bf, { 0x99, 0xf9, 0xbb, 0x11, 0x34, 0x21, 0xcb, 0x19 } }; + +// {696DF823-B7AE-4b73-95C8-C1E9A9410726} +FOOGUIDDECL const GUID mainmenu_groups::library_refresh= +{ 0x696df823, 0xb7ae, 0x4b73, { 0x95, 0xc8, 0xc1, 0xe9, 0xa9, 0x41, 0x7, 0x26 } }; + +// {004BF6ED-2F88-464f-BDC1-278F6E610C2F} +FOOGUIDDECL const GUID standard_commands::guid_seek_ahead_1s = +{ 0x4bf6ed, 0x2f88, 0x464f, { 0xbd, 0xc1, 0x27, 0x8f, 0x6e, 0x61, 0xc, 0x2f } }; + +// {5B56D124-2ECA-4b0f-9895-2A533B31D29E} +FOOGUIDDECL const GUID standard_commands::guid_seek_ahead_5s = +{ 0x5b56d124, 0x2eca, 0x4b0f, { 0x98, 0x95, 0x2a, 0x53, 0x3b, 0x31, 0xd2, 0x9e } }; + +// {B582E3CA-D86D-4568-8380-68BC9C93ED0E} +FOOGUIDDECL const GUID standard_commands::guid_seek_ahead_10s = +{ 0xb582e3ca, 0xd86d, 0x4568, { 0x83, 0x80, 0x68, 0xbc, 0x9c, 0x93, 0xed, 0xe } }; + +// {DE6B96B7-3074-4da9-A260-988E31CEE0F9} +FOOGUIDDECL const GUID standard_commands::guid_seek_ahead_30s = +{ 0xde6b96b7, 0x3074, 0x4da9, { 0xa2, 0x60, 0x98, 0x8e, 0x31, 0xce, 0xe0, 0xf9 } }; + +// {FEED4AD7-13D2-4846-8833-D91B5F8B4E94} +FOOGUIDDECL const GUID standard_commands::guid_seek_ahead_1min = +{ 0xfeed4ad7, 0x13d2, 0x4846, { 0x88, 0x33, 0xd9, 0x1b, 0x5f, 0x8b, 0x4e, 0x94 } }; + +// {ECCF4904-03CF-429a-9D99-7A87FA62FD10} +FOOGUIDDECL const GUID standard_commands::guid_seek_ahead_2min = +{ 0xeccf4904, 0x3cf, 0x429a, { 0x9d, 0x99, 0x7a, 0x87, 0xfa, 0x62, 0xfd, 0x10 } }; + +// {5F0F0AF7-F519-41e6-A8DB-04DF1390E69D} +FOOGUIDDECL const GUID standard_commands::guid_seek_ahead_5min = +{ 0x5f0f0af7, 0xf519, 0x41e6, { 0xa8, 0xdb, 0x4, 0xdf, 0x13, 0x90, 0xe6, 0x9d } }; + +// {9ABA4292-1B8F-42ac-93AC-34B2A74C6320} +FOOGUIDDECL const GUID standard_commands::guid_seek_ahead_10min = +{ 0x9aba4292, 0x1b8f, 0x42ac, { 0x93, 0xac, 0x34, 0xb2, 0xa7, 0x4c, 0x63, 0x20 } }; + +// {2F89AB1C-5646-4997-8E3F-92BEE0322A41} +FOOGUIDDECL const GUID standard_commands::guid_seek_back_1s = +{ 0x2f89ab1c, 0x5646, 0x4997, { 0x8e, 0x3f, 0x92, 0xbe, 0xe0, 0x32, 0x2a, 0x41 } }; + +// {0CE84538-2E21-4482-BFE1-BCEC471467CC} +FOOGUIDDECL const GUID standard_commands::guid_seek_back_5s = +{ 0xce84538, 0x2e21, 0x4482, { 0xbf, 0xe1, 0xbc, 0xec, 0x47, 0x14, 0x67, 0xcc } }; + +// {9F504218-AF5D-41a8-BCE3-26313FAE65EE} +FOOGUIDDECL const GUID standard_commands::guid_seek_back_10s = +{ 0x9f504218, 0xaf5d, 0x41a8, { 0xbc, 0xe3, 0x26, 0x31, 0x3f, 0xae, 0x65, 0xee } }; + +// {98239B89-F66E-4160-B650-D9B068C59E63} +FOOGUIDDECL const GUID standard_commands::guid_seek_back_30s = +{ 0x98239b89, 0xf66e, 0x4160, { 0xb6, 0x50, 0xd9, 0xb0, 0x68, 0xc5, 0x9e, 0x63 } }; + +// {6633226B-9AA9-4810-AFDA-185A281D9FE2} +FOOGUIDDECL const GUID standard_commands::guid_seek_back_1min = +{ 0x6633226b, 0x9aa9, 0x4810, { 0xaf, 0xda, 0x18, 0x5a, 0x28, 0x1d, 0x9f, 0xe2 } }; + +// {E2F8B8BB-C539-44f3-A300-13185DE52227} +FOOGUIDDECL const GUID standard_commands::guid_seek_back_2min = +{ 0xe2f8b8bb, 0xc539, 0x44f3, { 0xa3, 0x0, 0x13, 0x18, 0x5d, 0xe5, 0x22, 0x27 } }; + +// {7B41A130-01D2-4a1b-9CAD-6314633C61C4} +FOOGUIDDECL const GUID standard_commands::guid_seek_back_5min = +{ 0x7b41a130, 0x1d2, 0x4a1b, { 0x9c, 0xad, 0x63, 0x14, 0x63, 0x3c, 0x61, 0xc4 } }; + +// {0B012852-BAF9-4f6b-B947-FAB89AE76B79} +FOOGUIDDECL const GUID standard_commands::guid_seek_back_10min = +{ 0xb012852, 0xbaf9, 0x4f6b, { 0xb9, 0x47, 0xfa, 0xb8, 0x9a, 0xe7, 0x6b, 0x79 } }; + +// {97215C5E-7228-4237-B52C-A2B5504EF726} +FOOGUIDDECL const GUID playback_statistics_collector::class_guid = +{ 0x97215c5e, 0x7228, 0x4237, { 0xb5, 0x2c, 0xa2, 0xb5, 0x50, 0x4e, 0xf7, 0x26 } }; + +// {9FB1DA49-AF6F-4fd2-9C73-48A8A109003B} +FOOGUIDDECL const GUID dsp_v2::class_guid = +{ 0x9fb1da49, 0xaf6f, 0x4fd2, { 0x9c, 0x73, 0x48, 0xa8, 0xa1, 0x9, 0x0, 0x3b } }; + +// {9EC5D45E-10F5-46a7-9546-F3ACEC68B149} +FOOGUIDDECL const GUID dsp_entry_v2::class_guid = +{ 0x9ec5d45e, 0x10f5, 0x46a7, { 0x95, 0x46, 0xf3, 0xac, 0xec, 0x68, 0xb1, 0x49 } }; + + +FOOGUIDDECL const GUID advconfig_entry::guid_root = { 0x34949f34, 0xe655, 0x4f09, { 0xba, 0x50, 0xfa, 0xeb, 0x4d, 0x9b, 0x77, 0x69 } }; +FOOGUIDDECL const GUID advconfig_entry::class_guid = { 0x7e84602e, 0xdc49, 0x4047, { 0xaa, 0xee, 0x63, 0x71, 0x8b, 0xbc, 0x5a, 0x1f } }; +FOOGUIDDECL const GUID advconfig_branch::class_guid = { 0x6a60b472, 0x91ac, 0x4681, { 0x9d, 0xc2, 0x76, 0xc9, 0x94, 0x0, 0x5b, 0x63 } }; +FOOGUIDDECL const GUID advconfig_entry_checkbox::class_guid = { 0x5243aba4, 0x2a3d, 0x4627, { 0x88, 0xef, 0xce, 0xe3, 0x76, 0x1c, 0x7, 0x9c } }; +FOOGUIDDECL const GUID advconfig_entry::guid_branch_tagging = { 0xe8fe273f, 0xdd00, 0x476e, { 0xa7, 0x90, 0xe5, 0x9d, 0xf6, 0xb8, 0xf8, 0xd4 } }; +FOOGUIDDECL const GUID advconfig_entry::guid_branch_decoding = { 0x904c272b, 0x2317, 0x4c3c, { 0xb2, 0xff, 0xc5, 0xa0, 0x12, 0x5e, 0x2c, 0xc2 } }; +FOOGUIDDECL const GUID advconfig_entry_string::class_guid = { 0x185d582d, 0xfbd8, 0x4db3, { 0xbe, 0x23, 0x47, 0xaa, 0xc6, 0x75, 0xfc, 0x11 } }; +FOOGUIDDECL const GUID advconfig_entry::guid_branch_tools = { 0x35365484, 0xcc58, 0x4926, { 0x97, 0xe1, 0x5e, 0x63, 0xf3, 0xab, 0xb9, 0xe2 } }; +FOOGUIDDECL const GUID advconfig_entry::guid_branch_playback = { 0xc48d430d, 0x112, 0x4922, { 0x97, 0x23, 0x28, 0x38, 0xc7, 0xd9, 0x7d, 0xd7 } }; +FOOGUIDDECL const GUID advconfig_entry::guid_branch_display = { 0x6c4bc1c8, 0xbaf4, 0x40c3, { 0x9d, 0xb1, 0x9, 0x50, 0x7f, 0xc, 0xc, 0xb9 } }; + + + +FOOGUIDDECL const GUID playback_control_v2::class_guid = { 0x1eb67bda, 0x1345, 0x49ae, { 0x8e, 0x89, 0x50, 0x5, 0xd9, 0x1, 0x62, 0x89 } }; + +FOOGUIDDECL const GUID preferences_page_v2::class_guid = { 0xce4ebc9e, 0xab20, 0x46f9, { 0x92, 0x5f, 0x88, 0x3b, 0x8, 0x4f, 0x5, 0x69 } }; +FOOGUIDDECL const GUID preferences_branch_v2::class_guid = { 0x167ebeb9, 0x8334, 0x4b21, { 0xaf, 0x58, 0xa7, 0x40, 0xa5, 0xd5, 0xb6, 0x66 } }; + + + +FOOGUIDDECL const GUID advconfig_entry_enum::class_guid = { 0xb1451540, 0x98ec, 0x4d36, { 0x9f, 0x19, 0xe3, 0x10, 0xfb, 0xa7, 0xab, 0x5a } }; + +FOOGUIDDECL const GUID info_lookup_handler::class_guid = { 0x4fcfdab7, 0x55b5, 0x47d6, { 0xb1, 0x9d, 0xa4, 0xdc, 0x9f, 0xd7, 0x69, 0x4c } }; + +FOOGUIDDECL const GUID completion_notify::class_guid = { 0xdf26d586, 0xf7ec, 0x40c3, { 0x9f, 0xe8, 0x2e, 0xa0, 0x72, 0x5d, 0x76, 0xc0 } }; + +FOOGUIDDECL const GUID metadb_io_v2::class_guid = { 0x265c4ece, 0xffb2, 0x4299, { 0x91, 0xb5, 0x6c, 0xa6, 0x60, 0x3d, 0xa1, 0x53 } }; + +FOOGUIDDECL const GUID file_info_filter::class_guid = { 0x45d0b800, 0xde83, 0x4a77, { 0xad, 0x34, 0x3f, 0x84, 0x2d, 0x40, 0xe7, 0x95 } }; + +FOOGUIDDECL const GUID metadb_hint_list::class_guid = { 0x719dc072, 0x8d4d, 0x4aa6, { 0xa6, 0xf3, 0x90, 0x73, 0x7, 0xe5, 0xbc, 0xee } }; + +FOOGUIDDECL const GUID playlist_incoming_item_filter_v2::class_guid = { 0xf335802b, 0xa522, 0x434d, { 0xbe, 0x89, 0xe8, 0x6d, 0x59, 0x56, 0x16, 0x48 } }; + +FOOGUIDDECL const GUID process_locations_notify::class_guid = { 0x7d7eddac, 0xf93e, 0x4707, { 0x96, 0x9b, 0xcf, 0x44, 0xa9, 0xe1, 0xfb, 0x78 } }; + +FOOGUIDDECL const GUID library_manager_v2::class_guid = { 0x900eae79, 0x68d0, 0x4900, { 0xa4, 0xd8, 0x18, 0x20, 0x5, 0xae, 0x33, 0x7e } }; + +FOOGUIDDECL const GUID packet_decoder::owner_Ogg = { 0x8fa27457, 0xa021, 0x43b9, { 0xad, 0x20, 0xa7, 0x96, 0xdb, 0x94, 0x7c, 0xd1 } }; + +FOOGUIDDECL const GUID packet_decoder::property_ogg_header = { 0xbeb22c78, 0xeb49, 0x4f9e, { 0x9e, 0x37, 0x57, 0xd8, 0x87, 0x40, 0xfb, 0x4c } }; + +FOOGUIDDECL const GUID packet_decoder::property_ogg_query_sample_rate = { 0x6226bf73, 0x1c37, 0x4aa1, { 0xae, 0xb1, 0x18, 0x8b, 0x4a, 0xf3, 0xae, 0xf7 } }; + +FOOGUIDDECL const GUID packet_decoder::property_ogg_packet = { 0xade740be, 0x8e2e, 0x4d0b, { 0xa4, 0x0, 0x3f, 0x6e, 0x8a, 0xf7, 0x71, 0xe4 } }; + +FOOGUIDDECL const GUID track_property_provider::class_guid = { 0xefcdd365, 0x81fc, 0x4c82, { 0x96, 0x1c, 0xa2, 0xb5, 0x76, 0x1a, 0xf8, 0xb7 } }; + +FOOGUIDDECL const GUID track_property_provider_v2::class_guid = { 0x78e86595, 0xcffd, 0x4d10, { 0x85, 0x66, 0xbc, 0xf6, 0x6c, 0x89, 0x11, 0x16 } }; + + +FOOGUIDDECL const GUID library_manager_v3::class_guid = { 0x33dc0f1f, 0x16f0, 0x4e27, { 0xa7, 0x3, 0x63, 0x57, 0x72, 0x35, 0xb0, 0x1c } }; + +FOOGUIDDECL const GUID metadb_io_v3::class_guid = { 0x10e80560, 0xb1ef, 0x4e5e, { 0xb4, 0xc, 0x5d, 0xfc, 0x2e, 0x9a, 0xf1, 0x11 } }; + +FOOGUIDDECL const GUID search_filter::class_guid = { 0x4134bb34, 0xed5, 0x49f3, { 0x9c, 0xef, 0x43, 0xe3, 0xa4, 0xa3, 0xa8, 0xae } }; + +FOOGUIDDECL const GUID search_filter_manager::class_guid = { 0xad0baa03, 0xebd4, 0x4a72, { 0xa0, 0xa7, 0x98, 0x3, 0xa9, 0xe1, 0xe4, 0xf4 } }; + +FOOGUIDDECL const GUID playlist_manager_v2::class_guid = { 0x7fe9052a, 0x8ec2, 0x4054, { 0xa8, 0xcf, 0x77, 0xef, 0xb5, 0x2f, 0xe4, 0x8 } }; + +FOOGUIDDECL const GUID playlist_manager_v3::class_guid = { 0x3b6575c8, 0x21a, 0x4474, { 0xbb, 0x60, 0x6c, 0xfc, 0xfe, 0x33, 0xc3, 0x4f } }; + +FOOGUIDDECL const GUID titleformat_common_methods::class_guid = { 0x432fe059, 0xf087, 0x4785, { 0xa5, 0x18, 0xcb, 0xc1, 0x8b, 0x84, 0x9a, 0xc1 } }; + +FOOGUIDDECL const GUID core_version_info_v2::class_guid = { 0x273704d7, 0x99ba, 0x4b58, { 0xa0, 0x60, 0x82, 0xab, 0x1, 0xb4, 0x92, 0x25 } }; + +FOOGUIDDECL const GUID visualisation_stream_v2::class_guid = { 0xeb5b35b5, 0x267b, 0x443c, { 0xbe, 0x37, 0xc, 0x25, 0x73, 0x81, 0xa8, 0x6a } }; + +FOOGUIDDECL const GUID visualisation_stream_v3::class_guid = { 0xe1fd8e8b, 0x68f1, 0x4cea, { 0xa0, 0xe6, 0x61, 0x91, 0x1d, 0x14, 0x65, 0x42 } }; + +FOOGUIDDECL const GUID album_art_data::class_guid = { 0x9ddce05c, 0xaa3f, 0x4565, { 0xb3, 0x3a, 0xbd, 0x6a, 0xdc, 0xdd, 0x90, 0x37 } }; +FOOGUIDDECL const GUID album_art_manager::class_guid = { 0xab90fd55, 0xb6f, 0x47b2, { 0x8c, 0xd7, 0x61, 0x1d, 0x58, 0x6c, 0x4c, 0x45 } }; +FOOGUIDDECL const GUID album_art_manager_instance::class_guid = { 0x3c7b403b, 0xff99, 0x4d86, { 0x84, 0x4a, 0xd3, 0xea, 0xbb, 0xd6, 0x1f, 0x66 } }; +FOOGUIDDECL const GUID album_art_extractor::class_guid = { 0xe19ca3d3, 0x6267, 0x4271, { 0xb7, 0x89, 0x6a, 0x3f, 0x87, 0xfb, 0x3e, 0xbf } }; +FOOGUIDDECL const GUID album_art_extractor_instance::class_guid = { 0xf673700e, 0x3b6e, 0x4f70, { 0xa1, 0x6, 0xab, 0x74, 0x5c, 0x20, 0x20, 0x60 } }; +FOOGUIDDECL const GUID album_art_editor::class_guid = { 0x36b34487, 0xd7b9, 0x4533, { 0xa7, 0x3f, 0x39, 0x6e, 0x2d, 0x9f, 0x41, 0x5e } }; +FOOGUIDDECL const GUID album_art_editor_instance::class_guid = { 0x642a2ae1, 0x2259, 0x48f5, { 0xab, 0xdc, 0x63, 0xed, 0x4e, 0xb5, 0x90, 0x76 } }; + + +FOOGUIDDECL const GUID icon_remapping::class_guid = { 0x7c6aea96, 0x4a19, 0x471b, { 0x92, 0x5a, 0xa7, 0xc8, 0xb2, 0x8a, 0x59, 0xe7 } }; + +//FOOGUIDDECL const GUID now_playing_album_art_callback_manager::class_guid = { 0x6bd2ef21, 0x1e3f, 0x44b0, { 0xb5, 0x5c, 0xeb, 0xc9, 0x88, 0x56, 0x48, 0xaa } }; + +FOOGUIDDECL const GUID file_operation_callback_dynamic_manager::class_guid = { 0x1cb3a4dc, 0x7d79, 0x45cf, { 0x82, 0x2e, 0xf8, 0x67, 0x7b, 0x8d, 0xde, 0x37 } }; + +FOOGUIDDECL const GUID ui_selection_holder::class_guid = { 0x2ec9b7a, 0x93a5, 0x434d, { 0x85, 0x46, 0xed, 0x1d, 0xbb, 0x24, 0x35, 0xd0 } }; +FOOGUIDDECL const GUID ui_selection_manager::class_guid = { 0xd8ee46c7, 0x27ad, 0x4881, { 0xb1, 0x33, 0x14, 0x96, 0xc0, 0xe7, 0xee, 0x67 } }; + +FOOGUIDDECL const GUID ole_interaction::class_guid = { 0xfbee40c9, 0xef36, 0x410b, { 0x9d, 0x52, 0x7e, 0x56, 0x39, 0x59, 0xf3, 0xd1 } }; + +FOOGUIDDECL const GUID tag_processor_album_art_utils::class_guid = { 0x58768713, 0xc13c, 0x4406, { 0x97, 0x98, 0x21, 0x47, 0xcb, 0x97, 0x33, 0x2a } }; + +FOOGUIDDECL const GUID playlist_incoming_item_filter_v3::class_guid = { 0xd3332054, 0xbccd, 0x45cb, { 0xbc, 0x2, 0x0, 0xa1, 0x3a, 0x80, 0x25, 0x9f } }; + +FOOGUIDDECL const GUID menu_item_resolver::class_guid = { 0xac70ecdc, 0xe1d, 0x4db2, { 0x9c, 0xd0, 0xc9, 0xb8, 0xa9, 0xcd, 0x28, 0xfa } }; + +FOOGUIDDECL const GUID app_close_blocking_task_manager::class_guid = { 0x213f1454, 0x8a62, 0x44b6, { 0xb0, 0xcb, 0xc1, 0xe1, 0x5d, 0xa7, 0x3b, 0xc8 } }; + +FOOGUIDDECL const GUID message_loop_v2::class_guid = { 0x5d438080, 0xb269, 0x406d, { 0x94, 0xaf, 0xef, 0xd9, 0x29, 0x9f, 0x32, 0x5c } }; + + +FOOGUIDDECL const GUID autoplaylist_client::class_guid = { 0x7c90bda0, 0xf93d, 0x4a73, { 0x98, 0x51, 0xa0, 0x33, 0x6, 0x7, 0xcb, 0x28 } }; + +FOOGUIDDECL const GUID autoplaylist_client_factory::class_guid = { 0x764200cb, 0xe283, 0x4efd, { 0x88, 0xa5, 0x80, 0x38, 0xdd, 0xee, 0x77, 0xdb } }; + +FOOGUIDDECL const GUID autoplaylist_manager::class_guid = { 0x1571d0d, 0xc1e1, 0x44bf, { 0xb5, 0x29, 0x7a, 0xe, 0x4e, 0x89, 0x15, 0xbc } }; + + +FOOGUIDDECL const GUID replaygain_result::class_guid = { 0xe7f43102, 0xbc6e, 0x400b, { 0xbb, 0x81, 0x2d, 0x9b, 0xe4, 0x30, 0x3e, 0xcc } }; +FOOGUIDDECL const GUID replaygain_scanner::class_guid = { 0x2a40fcf9, 0xf1f7, 0x41da, { 0xad, 0x76, 0x29, 0xf7, 0x51, 0xed, 0xd3, 0x8a } }; +FOOGUIDDECL const GUID replaygain_scanner_entry::class_guid = { 0x278380f3, 0x6fc0, 0x4176, { 0x8a, 0x98, 0x1f, 0x66, 0x3a, 0x94, 0x79, 0xc5 } }; + + +FOOGUIDDECL const GUID search_filter_manager_v2::class_guid = { 0xac62a380, 0x7771, 0x4dc9, { 0x8a, 0x26, 0x41, 0x41, 0x39, 0xb4, 0x3e, 0xe2 } }; +FOOGUIDDECL const GUID search_filter_v2::class_guid = { 0xb7ca3c8, 0xaf23, 0x4a52, { 0x82, 0x66, 0xfe, 0x5, 0x4c, 0x49, 0xeb, 0x23 } }; + + +FOOGUIDDECL const GUID autoplaylist_client_v2::class_guid = { 0xfaa716f7, 0xebb1, 0x473c, { 0xbc, 0xf1, 0xb0, 0x1b, 0x8c, 0x9f, 0x1b, 0x95 } }; + +FOOGUIDDECL const GUID library_search_ui::class_guid = { 0xe5eb14fa, 0xbb08, 0x4564, { 0xaf, 0xfa, 0x6f, 0x27, 0x3f, 0x37, 0xbd, 0x3d } }; + +FOOGUIDDECL const GUID search_filter_v3::class_guid = { 0xdd6bc035, 0x7e33, 0x425a, { 0x89, 0x32, 0x6, 0xb5, 0xea, 0xb0, 0x39, 0xbc } }; + +FOOGUIDDECL const GUID input_decoder_v2::class_guid = { 0x2c5489eb, 0xd3c1, 0x4ad4, { 0xbe, 0xa3, 0xcf, 0x40, 0x8e, 0x16, 0x1b, 0x9b } }; + +FOOGUIDDECL const GUID event_logger::class_guid = { 0x5d336782, 0x69d6, 0x4225, { 0x9e, 0xa8, 0xcc, 0x29, 0x35, 0x7, 0xf9, 0xfe } }; + +FOOGUIDDECL const GUID playlist_manager_v4::class_guid = { 0xcea7b49e, 0xacf2, 0x4ea2, { 0x99, 0x86, 0x95, 0xa, 0x56, 0xa2, 0xc0, 0xef } }; + +FOOGUIDDECL const GUID ole_interaction_v2::class_guid = { 0x55738cab, 0x311d, 0x4dbe, { 0xa0, 0xbc, 0x51, 0xc1, 0xba, 0x27, 0xfe, 0x95 } }; + +FOOGUIDDECL const GUID autoplaylist_manager_v2::class_guid = { 0x67882220, 0xeea5, 0x4dbc, { 0x9a, 0xa3, 0x63, 0xde, 0x8c, 0xdd, 0x40, 0x82 } }; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/hasher_md5.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/hasher_md5.cpp new file mode 100644 index 000000000..dc738310d --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/hasher_md5.cpp @@ -0,0 +1,22 @@ +#include "foobar2000.h" + +GUID hasher_md5::guid_from_result(const hasher_md5_result & param) +{ + assert(sizeof(GUID) == sizeof(hasher_md5_result)); + GUID temp = * reinterpret_cast(¶m); + byte_order::order_le_to_native_t(temp); + return temp; +} + +hasher_md5_result hasher_md5::process_single(const void * p_buffer,t_size p_bytes) +{ + hasher_md5_state state; + initialize(state); + process(state,p_buffer,p_bytes); + return get_result(state); +} + +GUID hasher_md5::process_single_guid(const void * p_buffer,t_size p_bytes) +{ + return guid_from_result(process_single(p_buffer,p_bytes)); +} \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/hasher_md5.h b/tools/vio2sf/src/foobar/foobar2000/SDK/hasher_md5.h new file mode 100644 index 000000000..8cfceeed4 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/hasher_md5.h @@ -0,0 +1,73 @@ +struct hasher_md5_state { + char m_data[128]; +}; + +struct hasher_md5_result { + char m_data[16]; +}; + +inline bool operator==(const hasher_md5_result & p_item1,const hasher_md5_result & p_item2) {return memcmp(&p_item1,&p_item2,sizeof(hasher_md5_result)) == 0;} +inline bool operator!=(const hasher_md5_result & p_item1,const hasher_md5_result & p_item2) {return memcmp(&p_item1,&p_item2,sizeof(hasher_md5_result)) != 0;} + +namespace pfc { + template<> class traits_t : public traits_rawobject {}; + template<> class traits_t : public traits_rawobject {}; +} + +class NOVTABLE hasher_md5 : public service_base +{ +public: + + virtual void initialize(hasher_md5_state & p_state) = 0; + virtual void process(hasher_md5_state & p_state,const void * p_buffer,t_size p_bytes) = 0; + virtual hasher_md5_result get_result(const hasher_md5_state & p_state) = 0; + + + static GUID guid_from_result(const hasher_md5_result & param); + + hasher_md5_result process_single(const void * p_buffer,t_size p_bytes); + GUID process_single_guid(const void * p_buffer,t_size p_bytes); + GUID get_result_guid(const hasher_md5_state & p_state) {return guid_from_result(get_result(p_state));} + + + //! Helper + void process_string(hasher_md5_state & p_state,const char * p_string,t_size p_length = infinite) {return process(p_state,p_string,pfc::strlen_max(p_string,p_length));} + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(hasher_md5); +}; + + +class stream_writer_hasher_md5 : public stream_writer { +public: + stream_writer_hasher_md5() { + m_hasher->initialize(m_state); + } + void write(const void * p_buffer,t_size p_bytes,abort_callback & p_abort) { + p_abort.check(); + m_hasher->process(m_state,p_buffer,p_bytes); + } + hasher_md5_result result() const { + return m_hasher->get_result(m_state); + } + GUID resultGuid() const { + return hasher_md5::guid_from_result(result()); + } +private: + hasher_md5_state m_state; + static_api_ptr_t m_hasher; +}; +template +class stream_formatter_hasher_md5 : public stream_writer_formatter { +public: + stream_formatter_hasher_md5() : stream_writer_formatter(_m_stream,_m_abort) {} + + hasher_md5_result result() const { + return _m_stream.result(); + } + GUID resultGuid() const { + return hasher_md5::guid_from_result(result()); + } +private: + abort_callback_dummy _m_abort; + stream_writer_hasher_md5 _m_stream; +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/icon_remap.h b/tools/vio2sf/src/foobar/foobar2000/SDK/icon_remap.h new file mode 100644 index 000000000..0df7f77b5 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/icon_remap.h @@ -0,0 +1,26 @@ +//! New in 0.9.5; allows your file format to use another icon than .ico when registering the file type with Windows shell. \n +//! Implementation: use icon_remapping_impl, or simply: static service_factory_single_t myicon("ext","iconname.ico"); +class icon_remapping : public service_base { +public: + //! @param p_extension File type extension being queried. + //! @param p_iconname Receives the icon name to use, including the .ico extension. + //! @returns True when p_iconname has been set, false if we don't recognize the specified extension. + virtual bool query(const char * p_extension,pfc::string_base & p_iconname) = 0; + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(icon_remapping); +}; + +//! Standard implementation of icon_remapping. +class icon_remapping_impl : public icon_remapping { +public: + icon_remapping_impl(const char * p_extension,const char * p_iconname) : m_extension(p_extension), m_iconname(p_iconname) {} + bool query(const char * p_extension,pfc::string_base & p_iconname) { + if (stricmp_utf8(p_extension,m_extension) == 0) { + p_iconname = m_iconname; return true; + } else { + return false; + } + } +private: + pfc::string8 m_extension,m_iconname; +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/info_lookup_handler.h b/tools/vio2sf/src/foobar/foobar2000/SDK/info_lookup_handler.h new file mode 100644 index 000000000..fc68591cf --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/info_lookup_handler.h @@ -0,0 +1,24 @@ +//! Service used to access various external (online) track info lookup services, such as freedb, to update file tags with info retrieved from those services. +class NOVTABLE info_lookup_handler : public service_base { +public: + enum { + flag_album_lookup = 1 << 0, + flag_track_lookup = 1 << 1, + }; + + //! Retrieves human-readable name of the lookup handler to display in user interface. + virtual void get_name(pfc::string_base & p_out) = 0; + + //! Returns one or more of flag_track_lookup, and flag_album_lookup. + virtual t_uint32 get_flags() = 0; + + virtual HICON get_icon(int p_width, int p_height) = 0; + + //! Performs a lookup. Creates a modeless dialog and returns immediately. + //! @param p_items Items to look up. + //! @param p_notify Callback to notify caller when the operation has completed. Call on_completion with status code 0 to signal failure/abort, or with code 1 to signal success / new infos in metadb. + //! @param p_parent Parent window for the lookup dialog. Caller will typically disable the window while lookup is in progress and enable it back when completion is signaled. + virtual void lookup(const pfc::list_base_const_t & p_items,completion_notify_ptr p_notify,HWND p_parent) = 0; + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(info_lookup_handler); +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/initquit.h b/tools/vio2sf/src/foobar/foobar2000/SDK/initquit.h new file mode 100644 index 000000000..5edd5f1f9 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/initquit.h @@ -0,0 +1,13 @@ +//! Basic callback startup/shutdown callback, on_init is called after the main window has been created, on_quit is called before the main window is destroyed. +//! To register: static initquit_factory_t myclass_factory; +class NOVTABLE initquit : public service_base +{ +public: + virtual void on_init() {} + virtual void on_quit() {} + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(initquit); +}; + +template +class initquit_factory_t : public service_factory_single_t {}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/input.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/input.cpp new file mode 100644 index 000000000..ffb801820 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/input.cpp @@ -0,0 +1,248 @@ +#include "foobar2000.h" + + +bool input_entry::g_find_service_by_path(service_ptr_t & p_out,const char * p_path) +{ + service_ptr_t ptr; + service_enum_t e; + pfc::string_extension ext(p_path); + while(e.next(ptr)) + { + if (ptr->is_our_path(p_path,ext)) + { + p_out = ptr; + return true; + } + } + return false; +} + +bool input_entry::g_find_service_by_content_type(service_ptr_t & p_out,const char * p_content_type) +{ + service_ptr_t ptr; + service_enum_t e; + while(e.next(ptr)) + { + if (ptr->is_our_content_type(p_content_type)) + { + p_out = ptr; + return true; + } + } + return false; +} + + + +static void prepare_for_open(service_ptr_t & p_service,service_ptr_t & p_file,const char * p_path,filesystem::t_open_mode p_open_mode,abort_callback & p_abort,bool p_from_redirect) +{ + if (p_file.is_empty()) + { + service_ptr_t fs; + if (filesystem::g_get_interface(fs,p_path)) { + if (fs->supports_content_types()) { + fs->open(p_file,p_path,p_open_mode,p_abort); + } + } + } + + if (p_file.is_valid()) + { + pfc::string8 content_type; + if (p_file->get_content_type(content_type)) + { + if (input_entry::g_find_service_by_content_type(p_service,content_type)) + return; + } + } + + if (input_entry::g_find_service_by_path(p_service,p_path)) + { + if (p_from_redirect && p_service->is_redirect()) throw exception_io_unsupported_format(); + return; + } + + throw exception_io_unsupported_format(); +} + +namespace { + + bool g_find_inputs_by_content_type(pfc::list_base_t > & p_out,const char * p_content_type,bool p_from_redirect) { + service_enum_t e; + service_ptr_t ptr; + bool ret = false; + while(e.next(ptr)) { + if (!(p_from_redirect && ptr->is_redirect())) { + if (ptr->is_our_content_type(p_content_type)) {p_out.add_item(ptr); ret = true;} + } + } + return ret; + } + + bool g_find_inputs_by_path(pfc::list_base_t > & p_out,const char * p_path,bool p_from_redirect) { + service_enum_t e; + service_ptr_t ptr; + pfc::string_extension extension(p_path); + bool ret = false; + while(e.next(ptr)) { + if (!(p_from_redirect && ptr->is_redirect())) { + if (ptr->is_our_path(p_path,extension)) {p_out.add_item(ptr); ret = true;} + } + } + return ret; + } + + template void g_open_from_list(service_ptr_t & p_instance,pfc::list_base_const_t > const & p_list,service_ptr_t const & p_filehint,const char * p_path,abort_callback & p_abort) { + const t_size count = p_list.get_count(); + if (count == 1) { + p_list[0]->open(p_instance,p_filehint,p_path,p_abort); + } else { + bool got_bad_data = false, got_bad_data_multi = false; + bool done = false; + pfc::string8 bad_data_message; + for(t_size n=0;nopen(p_instance,p_filehint,p_path,p_abort); + done = true; + } catch(exception_io_unsupported_format) { + //do nothing, skip over + } catch(exception_io_data const & e) { + if (!got_bad_data) bad_data_message = e.what(); + else got_bad_data_multi = true; + got_bad_data = true; + } + } + if (!done) { + if (got_bad_data_multi) throw exception_io_data(); + else if (got_bad_data) throw exception_io_data(bad_data_message); + else throw exception_io_unsupported_format(); + } + } + } + + template bool needs_write_access() {return false;} + template<> bool needs_write_access() {return true;} + + template void g_open_t(service_ptr_t & p_instance,service_ptr_t const & p_filehint,const char * p_path,abort_callback & p_abort,bool p_from_redirect) { + service_ptr_t l_file = p_filehint; + if (l_file.is_empty()) { + service_ptr_t fs; + if (filesystem::g_get_interface(fs,p_path)) { + if (fs->supports_content_types()) { + fs->open(l_file,p_path,needs_write_access() ? filesystem::open_mode_write_existing : filesystem::open_mode_read,p_abort); + } + } + } + + if (l_file.is_valid()) { + pfc::string8 content_type; + if (l_file->get_content_type(content_type)) { + pfc::list_hybrid_t,4> list; + if (g_find_inputs_by_content_type(list,content_type,p_from_redirect)) { + g_open_from_list(p_instance,list,l_file,p_path,p_abort); + return; + } + } + } + + { + pfc::list_hybrid_t,4> list; + if (g_find_inputs_by_path(list,p_path,p_from_redirect)) { + g_open_from_list(p_instance,list,l_file,p_path,p_abort); + return; + } + } + + throw exception_io_unsupported_format(); + } +}; + +void input_entry::g_open_for_decoding(service_ptr_t & p_instance,service_ptr_t p_filehint,const char * p_path,abort_callback & p_abort,bool p_from_redirect) { + TRACK_CALL_TEXT("input_entry::g_open_for_decoding"); +#if 1 + g_open_t(p_instance,p_filehint,p_path,p_abort,p_from_redirect); +#else + service_ptr_t filehint = p_filehint; + service_ptr_t entry; + + prepare_for_open(entry,filehint,p_path,filesystem::open_mode_read,p_abort,p_from_redirect); + + entry->open_for_decoding(p_instance,filehint,p_path,p_abort); +#endif + +} + +void input_entry::g_open_for_info_read(service_ptr_t & p_instance,service_ptr_t p_filehint,const char * p_path,abort_callback & p_abort,bool p_from_redirect) { + TRACK_CALL_TEXT("input_entry::g_open_for_info_read"); +#if 1 + g_open_t(p_instance,p_filehint,p_path,p_abort,p_from_redirect); +#else + service_ptr_t filehint = p_filehint; + service_ptr_t entry; + + prepare_for_open(entry,filehint,p_path,filesystem::open_mode_read,p_abort,p_from_redirect); + + entry->open_for_info_read(p_instance,filehint,p_path,p_abort); +#endif +} + +void input_entry::g_open_for_info_write(service_ptr_t & p_instance,service_ptr_t p_filehint,const char * p_path,abort_callback & p_abort,bool p_from_redirect) { + TRACK_CALL_TEXT("input_entry::g_open_for_info_write"); +#if 1 + g_open_t(p_instance,p_filehint,p_path,p_abort,p_from_redirect); +#else + service_ptr_t filehint = p_filehint; + service_ptr_t entry; + + prepare_for_open(entry,filehint,p_path,filesystem::open_mode_write_existing,p_abort,p_from_redirect); + + entry->open_for_info_write(p_instance,filehint,p_path,p_abort); +#endif +} + +void input_entry::g_open_for_info_write_timeout(service_ptr_t & p_instance,service_ptr_t p_filehint,const char * p_path,abort_callback & p_abort,double p_timeout,bool p_from_redirect) { + pfc::lores_timer timer; + timer.start(); + for(;;) { + try { + g_open_for_info_write(p_instance,p_filehint,p_path,p_abort,p_from_redirect); + break; + } catch(exception_io_sharing_violation) { + if (timer.query() > p_timeout) throw; + p_abort.sleep(0.01); + } + } +} + +bool input_entry::g_is_supported_path(const char * p_path) +{ + service_ptr_t ptr; + service_enum_t e; + pfc::string_extension ext(p_path); + while(e.next(ptr)) + { + if (ptr->is_our_path(p_path,ext)) return true; + } + return false; +} + + + +void input_open_file_helper(service_ptr_t & p_file,const char * p_path,t_input_open_reason p_reason,abort_callback & p_abort) +{ + if (p_file.is_empty()) { + switch(p_reason) { + default: + throw pfc::exception_bug_check_v2(); + case input_open_info_read: + case input_open_decode: + filesystem::g_open(p_file,p_path,filesystem::open_mode_read,p_abort); + break; + case input_open_info_write: + filesystem::g_open(p_file,p_path,filesystem::open_mode_write_existing,p_abort); + break; + } + } else { + p_file->reopen(p_abort); + } +} \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/input.h b/tools/vio2sf/src/foobar/foobar2000/SDK/input.h new file mode 100644 index 000000000..80297e76f --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/input.h @@ -0,0 +1,189 @@ +enum { + input_flag_no_seeking = 1 << 0, + input_flag_no_looping = 1 << 1, + input_flag_playback = 1 << 2, + input_flag_testing_integrity = 1 << 3, + input_flag_allow_inaccurate_seeking = 1 << 4, + + input_flag_simpledecode = input_flag_no_seeking|input_flag_no_looping, +}; + +//! Class providing interface for retrieval of information (metadata, duration, replaygain, other tech infos) from files. Also see: file_info. \n +//! Instantiating: see input_entry.\n +//! Implementing: see input_impl. + +class NOVTABLE input_info_reader : public service_base +{ +public: + //! Retrieves count of subsongs in the file. 1 for non-multisubsong-enabled inputs. + //! Note: multi-subsong handling is disabled for remote files (see: filesystem::is_remote) for performance reasons. Remote files are always assumed to be single-subsong, with null index. + virtual t_uint32 get_subsong_count() = 0; + + //! Retrieves identifier of specified subsong; this identifier is meant to be used in playable_location as well as a parameter for input_info_reader::get_info(). + //! @param p_index Index of subsong to query. Must be >=0 and < get_subsong_count(). + virtual t_uint32 get_subsong(t_uint32 p_index) = 0; + + //! Retrieves information about specified subsong. + //! @param p_subsong Identifier of the subsong to query. See: input_info_reader::get_subsong(), playable_location. + //! @param p_info file_info object to fill. Must be empty on entry. + //! @param p_abort abort_callback object signaling user aborting the operation. + virtual void get_info(t_uint32 p_subsong,file_info & p_info,abort_callback & p_abort) = 0; + + //! Retrieves file stats. Equivalent to calling get_stats() on file object. + virtual t_filestats get_file_stats(abort_callback & p_abort) = 0; + + FB2K_MAKE_SERVICE_INTERFACE(input_info_reader,service_base); +}; + +//! Class providing interface for retrieval of PCM audio data from files.\n +//! Instantiating: see input_entry.\n +//! Implementing: see input_impl. + +class NOVTABLE input_decoder : public input_info_reader +{ +public: + //! Prepares to decode specified subsong; resets playback position to the beginning of specified subsong. This must be called first, before any other input_decoder methods (other than those inherited from input_info_reader). \n + //! It is legal to set initialize() more than once, with same or different subsong, to play either the same subsong again or another subsong from same file without full reopen.\n + //! Warning: this interface inherits from input_info_reader, it is legal to call any input_info_reader methods even during decoding! Call order is not defined, other than initialize() requirement before calling other input_decoder methods.\n + //! @param p_subsong Subsong to decode. Should always be 0 for non-multi-subsong-enabled inputs. + //! @param p_flags Specifies additional hints for decoding process. It can be null, or a combination of one or more following constants: \n + //! input_flag_no_seeking - Indicates that seek() will never be called. Can be used to avoid building potentially expensive seektables when only sequential reading is needed.\n + //! input_flag_no_looping - Certain input implementations can be configured to utilize looping info from file formats they process and keep playing single file forever, or keep repeating it specified number of times. This flag indicates that such features should be disabled, for e.g. ReplayGain scan or conversion.\n + //! input_flag_playback - Indicates that decoding process will be used for realtime playback rather than conversion. This can be used to reconfigure features that are relevant only for conversion and take a lot of resources, such as very slow secure CDDA reading. \n + //! input_flag_testing_integrity - Indicates that we're testing integrity of the file. Any recoverable problems where decoding would normally continue should cause decoder to fail with exception_io_data. + //! @param p_abort abort_callback object signaling user aborting the operation. + virtual void initialize(t_uint32 p_subsong,unsigned p_flags,abort_callback & p_abort) = 0; + + //! Reads/decodes one chunk of audio data. Use false return value to signal end of file (no more data to return). Before calling run(), decoding must be initialized by initialize() call. + //! @param p_chunk audio_chunk object receiving decoded data. Contents are valid only the method returns true. + //! @param p_abort abort_callback object signaling user aborting the operation. + //! @returns true on success (new data decoded), false on EOF. + virtual bool run(audio_chunk & p_chunk,abort_callback & p_abort) = 0; + + //! Seeks to specified time offset. Before seeking or other decoding calls, decoding must be initialized with initialize() call. + //! @param p_seconds Time to seek to, in seconds. If p_seconds exceeds length of the object being decoded, succeed, and then return false from next run() call. + //! @param p_abort abort_callback object signaling user aborting the operation. + virtual void seek(double p_seconds,abort_callback & p_abort) = 0; + + //! Queries whether resource being read/decoded is seekable. If p_value is set to false, all seek() calls will fail. Before calling can_seek() or other decoding calls, decoding must be initialized with initialize() call. + virtual bool can_seek() = 0; + + //! This function is used to signal dynamic VBR bitrate, etc. Called after each run() (or not called at all if caller doesn't care about dynamic info). + //! @param p_out Initially contains currently displayed info (either last get_dynamic_info result or current cached info), use this object to return changed info. + //! @param p_timestamp_delta Indicates when returned info should be displayed (in seconds, relative to first sample of last decoded chunk), initially set to 0. + //! @returns false to keep old info, or true to indicate that changes have been made to p_info and those should be displayed. + virtual bool get_dynamic_info(file_info & p_out, double & p_timestamp_delta) = 0; + + //! This function is used to signal dynamic live stream song titles etc. Called after each run() (or not called at all if caller doesn't care about dynamic info). The difference between this and get_dynamic_info() is frequency and relevance of dynamic info changes - get_dynamic_info_track() returns new info only on track change in the stream, returning new titles etc. + //! @param p_out Initially contains currently displayed info (either last get_dynamic_info_track result or current cached info), use this object to return changed info. + //! @param p_timestamp_delta Indicates when returned info should be displayed (in seconds, relative to first sample of last decoded chunk), initially set to 0. + //! @returns false to keep old info, or true to indicate that changes have been made to p_info and those should be displayed. + virtual bool get_dynamic_info_track(file_info & p_out, double & p_timestamp_delta) = 0; + + //! Called from playback thread before sleeping. + //! @param p_abort abort_callback object signaling user aborting the operation. + virtual void on_idle(abort_callback & p_abort) = 0; + + + FB2K_MAKE_SERVICE_INTERFACE(input_decoder,input_info_reader); +}; + + +class NOVTABLE input_decoder_v2 : public input_decoder { + FB2K_MAKE_SERVICE_INTERFACE(input_decoder_v2, input_decoder) +public: + + //! OPTIONAL, throws pfc::exception_not_implemented() when not supported by this implementation. + //! Special version of run(). Returns an audio_chunk object as well as a raw data block containing original PCM stream. This is mainly used for MD5 checks on lossless formats. \n + //! If you set a "MD5" tech info entry in get_info(), you should make sure that run_raw() returns data stream that can be used to verify it. \n + //! Returned raw data should be possible to cut into individual samples; size in bytes should be divisible by audio_chunk's sample count for splitting in case partial output is needed (with cuesheets etc). + virtual bool run_raw(audio_chunk & out, mem_block_container & outRaw, abort_callback & abort) = 0; + + //! OPTIONAL, the call is ignored if this implementation doesn't support status logging. \n + //! Mainly used to generate logs when ripping CDs etc. + virtual void set_logger(event_logger::ptr ptr) = 0; +}; + +//! Class providing interface for writing metadata and replaygain info to files. Also see: file_info. \n +//! Instantiating: see input_entry.\n +//! Implementing: see input_impl. + +class NOVTABLE input_info_writer : public input_info_reader +{ +public: + //! Tells the service to update file tags with new info for specified subsong. + //! @param p_subsong Subsong to update. Should be always 0 for non-multisubsong-enabled inputs. + //! @param p_info New info to write. Sometimes not all contents of p_info can be written. Caller will typically read info back after successful write, so e.g. tech infos that change with retag are properly maintained. + //! @param p_abort abort_callback object signaling user aborting the operation. WARNING: abort_callback object is provided for consistency; if writing tags actually gets aborted, user will be likely left with corrupted file. Anything calling this should make sure that aborting is either impossible, or gives appropriate warning to the user first. + virtual void set_info(t_uint32 p_subsong,const file_info & p_info,abort_callback & p_abort) = 0; + + //! Commits pending updates. In case of multisubsong inputs, set_info should queue the update and perform actual file access in commit(). Otherwise, actual writing can be done in set_info() and then Commit() can just do nothing and always succeed. + //! @param p_abort abort_callback object signaling user aborting the operation. WARNING: abort_callback object is provided for consistency; if writing tags actually gets aborted, user will be likely left with corrupted file. Anything calling this should make sure that aborting is either impossible, or gives appropriate warning to the user first. + virtual void commit(abort_callback & p_abort) = 0; + + FB2K_MAKE_SERVICE_INTERFACE(input_info_writer,input_info_reader); +}; + +class NOVTABLE input_entry : public service_base +{ +public: + //! Determines whether specified content type can be handled by this input. + //! @param p_type Content type string to test. + virtual bool is_our_content_type(const char * p_type)=0; + + //! Determines whether specified file type can be handled by this input. This must not use any kind of file access; the result should be only based on file path / extension. + //! @param p_full_path Full URL of file being tested. + //! @param p_extension Extension of file being tested, provided by caller for performance reasons. + virtual bool is_our_path(const char * p_full_path,const char * p_extension)=0; + + //! Opens specified resource for decoding. + //! @param p_instance Receives new input_decoder instance if successful. + //! @param p_filehint Optional; passes file object to use for the operation; if set to null, the service will handle opening file by itself. Note that not all inputs operate on physical files that can be reached through filesystem API, some of them require this parameter to be set to null (tone and silence generators for an example). + //! @param p_path URL of resource being opened. + //! @param p_abort abort_callback object signaling user aborting the operation. + virtual void open_for_decoding(service_ptr_t & p_instance,service_ptr_t p_filehint,const char * p_path,abort_callback & p_abort) = 0; + + //! Opens specified file for reading info. + //! @param p_instance Receives new input_info_reader instance if successful. + //! @param p_filehint Optional; passes file object to use for the operation; if set to null, the service will handle opening file by itself. Note that not all inputs operate on physical files that can be reached through filesystem API, some of them require this parameter to be set to null (tone and silence generators for an example). + //! @param p_path URL of resource being opened. + //! @param p_abort abort_callback object signaling user aborting the operation. + virtual void open_for_info_read(service_ptr_t & p_instance,service_ptr_t p_filehint,const char * p_path,abort_callback & p_abort) = 0; + + //! Opens specified file for writing info. + //! @param p_instance Receives new input_info_writer instance if successful. + //! @param p_filehint Optional; passes file object to use for the operation; if set to null, the service will handle opening file by itself. Note that not all inputs operate on physical files that can be reached through filesystem API, some of them require this parameter to be set to null (tone and silence generators for an example). + //! @param p_path URL of resource being opened. + //! @param p_abort abort_callback object signaling user aborting the operation. + virtual void open_for_info_write(service_ptr_t & p_instance,service_ptr_t p_filehint,const char * p_path,abort_callback & p_abort) = 0; + + //! Reserved for future use. Do nothing and return until specifications are finalized. + virtual void get_extended_data(service_ptr_t p_filehint,const playable_location & p_location,const GUID & p_guid,mem_block_container & p_out,abort_callback & p_abort) = 0; + + enum { + //! Indicates that this service implements some kind of redirector that opens another input for decoding, used to avoid circular call possibility. + flag_redirect = 1, + //! Indicates that multi-CPU optimizations should not be used. + flag_parallel_reads_slow = 2, + }; + //! See flag_* enums. + virtual unsigned get_flags() = 0; + + inline bool is_redirect() {return (get_flags() & flag_redirect) != 0;} + inline bool are_parallel_reads_slow() {return (get_flags() & flag_parallel_reads_slow) != 0;} + + static bool g_find_service_by_path(service_ptr_t & p_out,const char * p_path); + static bool g_find_service_by_content_type(service_ptr_t & p_out,const char * p_content_type); + static void g_open_for_decoding(service_ptr_t & p_instance,service_ptr_t p_filehint,const char * p_path,abort_callback & p_abort,bool p_from_redirect = false); + static void g_open_for_info_read(service_ptr_t & p_instance,service_ptr_t p_filehint,const char * p_path,abort_callback & p_abort,bool p_from_redirect = false); + static void g_open_for_info_write(service_ptr_t & p_instance,service_ptr_t p_filehint,const char * p_path,abort_callback & p_abort,bool p_from_redirect = false); + static void g_open_for_info_write_timeout(service_ptr_t & p_instance,service_ptr_t p_filehint,const char * p_path,abort_callback & p_abort,double p_timeout,bool p_from_redirect = false); + static bool g_is_supported_path(const char * p_path); + + + void open(service_ptr_t & p_instance,service_ptr_t const & p_filehint,const char * p_path,abort_callback & p_abort) {open_for_decoding(p_instance,p_filehint,p_path,p_abort);} + void open(service_ptr_t & p_instance,service_ptr_t const & p_filehint,const char * p_path,abort_callback & p_abort) {open_for_info_read(p_instance,p_filehint,p_path,p_abort);} + void open(service_ptr_t & p_instance,service_ptr_t const & p_filehint,const char * p_path,abort_callback & p_abort) {open_for_info_write(p_instance,p_filehint,p_path,p_abort);} + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(input_entry); +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/input_file_type.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/input_file_type.cpp new file mode 100644 index 000000000..749254bbc --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/input_file_type.cpp @@ -0,0 +1,65 @@ +#include "foobar2000.h" + +typedef pfc::avltree_t t_fnList; + +static void formatMaskList(pfc::string_base & out, t_fnList const & in) { + pfc::const_iterator walk = in.first(); + if (walk.is_valid()) { + out << *walk; ++walk; + while(walk.is_valid()) { + out << ";" << *walk; ++walk; + } + } +} +static void formatMaskList(pfc::string_base & out, t_fnList const & in, const char * label) { + if (in.get_count() > 0) { + out << label << "|"; + formatMaskList(out,in); + out << "|"; + } +} + +void input_file_type::build_openfile_mask(pfc::string_base & out, bool b_include_playlists) +{ + t_fnList extensionsAll, extensionsPl;; + + if (b_include_playlists) { + service_enum_t e; service_ptr_t ptr; + while(e.next(ptr)) { + if (ptr->is_associatable()) { + pfc::string_formatter temp; temp << "*." << ptr->get_extension(); + extensionsPl += temp; + extensionsAll += temp; + } + } + } + + typedef pfc::map_t t_masks; + t_masks masks; + { + service_enum_t e; + service_ptr_t ptr; + pfc::string_formatter name, mask; + while(e.next(ptr)) { + const unsigned count = ptr->get_count(); + for(unsigned n=0;nget_name(n,name) && ptr->get_mask(n,mask)) { + if (!strchr(name,'|') && !strchr(mask,'|')) { + masks.find_or_add(name) += mask; + extensionsAll += mask; + } + } + } + } + } + pfc::string_formatter outBuf; + outBuf << "All files|*.*|"; + formatMaskList(outBuf, extensionsAll, "All supported types"); + formatMaskList(outBuf, extensionsPl, "Playlists"); + for(t_masks::const_iterator walk = masks.first(); walk.is_valid(); ++walk) { + formatMaskList(outBuf,walk->m_value,walk->m_key); + } + out = outBuf; +} diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/input_file_type.h b/tools/vio2sf/src/foobar/foobar2000/SDK/input_file_type.h new file mode 100644 index 000000000..f7608c836 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/input_file_type.h @@ -0,0 +1,94 @@ +//! Entrypoint interface for registering media file types that can be opened through "open file" dialogs or associated with foobar2000 application in Windows shell. \n +//! Instead of implementing this directly, use DECLARE_FILE_TYPE() / DECLARE_FILE_TYPE_EX() macros. +class input_file_type : public service_base { +public: + virtual unsigned get_count()=0; + virtual bool get_name(unsigned idx,pfc::string_base & out)=0;//eg. "MPEG files" + virtual bool get_mask(unsigned idx,pfc::string_base & out)=0;//eg. "*.MP3;*.MP2"; separate with semicolons + virtual bool is_associatable(unsigned idx) = 0; + + static void build_openfile_mask(pfc::string_base & out,bool b_include_playlists=true); + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(input_file_type); +}; + +//! Extended interface for registering media file types that can be associated with foobar2000 application in Windows shell. \n +//! Instead of implementing this directly, use DECLARE_FILE_TYPE() / DECLARE_FILE_TYPE_EX() macros. +class input_file_type_v2 : public input_file_type { +public: + virtual void get_format_name(unsigned idx, pfc::string_base & out, bool isPlural) = 0; + virtual void get_extensions(unsigned idx, pfc::string_base & out) = 0; + + //Deprecated input_file_type method implementations: + bool get_name(unsigned idx, pfc::string_base & out) {get_format_name(idx, out, true); return true;} + bool get_mask(unsigned idx, pfc::string_base & out) { + pfc::string_formatter temp; get_extensions(idx,temp); + pfc::chain_list_v2_t exts; pfc::splitStringSimple_toList(exts,";",temp); + if (exts.get_count() == 0) return false;//should not happen + temp.reset(); + for(pfc::const_iterator walk = exts.first(); walk.is_valid(); ++walk) { + if (!temp.is_empty()) temp << ";"; + temp << "*." << walk->get_ptr(); + } + out = temp; + return true; + } + + FB2K_MAKE_SERVICE_INTERFACE(input_file_type_v2,input_file_type) +}; + + +//! Implementation helper. +class input_file_type_impl : public service_impl_single_t +{ + const char * name, * mask; + bool m_associatable; +public: + input_file_type_impl(const char * p_name, const char * p_mask,bool p_associatable) : name(p_name), mask(p_mask), m_associatable(p_associatable) {} + unsigned get_count() {return 1;} + bool get_name(unsigned idx,pfc::string_base & out) {if (idx==0) {out = name; return true;} else return false;} + bool get_mask(unsigned idx,pfc::string_base & out) {if (idx==0) {out = mask; return true;} else return false;} + bool is_associatable(unsigned idx) {return m_associatable;} +}; + + +//! Helper macro for registering our media file types. +//! Usage: DECLARE_FILE_TYPE("Blah files","*.blah;*.bleh"); +#define DECLARE_FILE_TYPE(NAME,MASK) \ + namespace { static input_file_type_impl g_filetype_instance(NAME,MASK,true); \ + static service_factory_single_ref_t g_filetype_service(g_filetype_instance); } + + + + +//! Implementation helper. +//! Usage: static input_file_type_factory mytype("blah type","*.bla;*.meh",true); +class input_file_type_factory : private service_factory_single_transparent_t +{ +public: + input_file_type_factory(const char * p_name,const char * p_mask,bool p_associatable) + : service_factory_single_transparent_t(p_name,p_mask,p_associatable) {} +}; + + + +class input_file_type_v2_impl : public input_file_type_v2 { +public: + input_file_type_v2_impl(const char * extensions,const char * name, const char * namePlural) : m_extensions(extensions), m_name(name), m_namePlural(namePlural) {} + unsigned get_count() {return 1;} + bool is_associatable(unsigned idx) {return true;} + void get_format_name(unsigned idx, pfc::string_base & out, bool isPlural) { + out = isPlural ? m_namePlural : m_name; + } + void get_extensions(unsigned idx, pfc::string_base & out) { + out = m_extensions; + } + +private: + const pfc::string8 m_name, m_namePlural, m_extensions; +}; + +//! Helper macro for registering our media file types, extended version providing separate singular/plural type names. +//! Usage: DECLARE_FILE_TYPE_EX("mp1;mp2;mp3","MPEG file","MPEG files") +#define DECLARE_FILE_TYPE_EX(extensions, name, namePlural) \ + namespace { static service_factory_single_t g_myfiletype(extensions, name, namePlural); } diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/input_impl.h b/tools/vio2sf/src/foobar/foobar2000/SDK/input_impl.h new file mode 100644 index 000000000..df3a9d3b5 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/input_impl.h @@ -0,0 +1,314 @@ +enum t_input_open_reason { + input_open_info_read, + input_open_decode, + input_open_info_write +}; + +//! Helper function for input implementation use; ensures that file is open with relevant access mode. This is typically called from input_impl::open() and such. +//! @param p_file File object pointer to process. If passed pointer is non-null, the function does nothing and always succeeds; otherwise it attempts to open the file using filesystem API methods. +//! @param p_path Path to the file. +//! @param p_reason Type of input operation requested. See: input_impl::open() parameters. +//! @param p_abort abort_callback object signaling user aborting the operation. +void input_open_file_helper(service_ptr_t & p_file,const char * p_path,t_input_open_reason p_reason,abort_callback & p_abort); + + +//! This is a class that just declares prototypes of functions that each input needs to implement. See input_decoder / input_info_reader / input_info_writer interfaces for full descriptions of member functions. Since input implementation class is instantiated using a template, you don't need to derive from input_impl as virtual functions are not used on implementation class level. Use input_factory_t template to register input class based on input_impl. +class input_impl +{ +public: + //! Opens specified file for info read / decoding / info write. This is called only once, immediately after object creation, before any other methods, and no other methods are called if open() fails. + //! @param p_filehint Optional; passes file object to use for the operation; if set to null, the implementation should handle opening file by itself. Note that not all inputs operate on physical files that can be reached through filesystem API, some of them require this parameter to be set to null (tone and silence generators for an example). Typically, an input implementation that requires file access calls input_open_file_helper() function to ensure that file is open with relevant access mode (read or read/write). + //! @param p_path URL of resource being opened. + //! @param p_reason Type of operation requested. Possible values are: \n + //! - input_open_info_read - info retrieval methods are valid; \n + //! - input_open_decode - info retrieval and decoding methods are valid; \n + //! - input_open_info_write - info retrieval and retagging methods are valid; \n + //! Note that info retrieval methods are valid in all cases, and they may be called at any point of decoding/retagging process. Results of info retrieval methods (other than get_subsong_count() / get_subsong()) between retag_set_info() and retag_commit() are undefined however; those should not be called during that period. + //! @param p_abort abort_callback object signaling user aborting the operation. + void open(service_ptr_t p_filehint,const char * p_path,t_input_open_reason p_reason,abort_callback & p_abort); + + //! See: input_info_reader::get_subsong_count(). Valid after open() with any reason. + unsigned get_subsong_count(); + //! See: input_info_reader::get_subsong(). Valid after open() with any reason. + t_uint32 get_subsong(unsigned p_index); + //! See: input_info_reader::get_info(). Valid after open() with any reason. + void get_info(t_uint32 p_subsong,file_info & p_info,abort_callback & p_abort); + //! See: input_info_reader::get_file_stats(). Valid after open() with any reason. + t_filestats get_file_stats(abort_callback & p_abort); + + //! See: input_decoder::initialize(). Valid after open() with input_open_decode reason. + void decode_initialize(t_uint32 p_subsong,unsigned p_flags,abort_callback & p_abort); + //! See: input_decoder::run(). Valid after decode_initialize(). + bool decode_run(audio_chunk & p_chunk,abort_callback & p_abort); + //! See: input_decoder::seek(). Valid after decode_initialize(). + void decode_seek(double p_seconds,abort_callback & p_abort); + //! See: input_decoder::can_seek(). Valid after decode_initialize(). + bool decode_can_seek(); + //! See: input_decoder::get_dynamic_info(). Valid after decode_initialize(). + bool decode_get_dynamic_info(file_info & p_out, double & p_timestamp_delta); + //! See: input_decoder::get_dynamic_info_track(). Valid after decode_initialize(). + bool decode_get_dynamic_info_track(file_info & p_out, double & p_timestamp_delta); + //! See: input_decoder::on_idle(). Valid after decode_initialize(). + void decode_on_idle(abort_callback & p_abort); + + //! See: input_info_writer::set_info(). Valid after open() with input_open_info_write reason. + void retag_set_info(t_uint32 p_subsong,const file_info & p_info,abort_callback & p_abort); + //! See: input_info_writer::commit(). Valid after open() with input_open_info_write reason. + void retag_commit(abort_callback & p_abort); + + //! See: input_entry::is_our_content_type(). + static bool g_is_our_content_type(const char * p_content_type); + //! See: input_entry::is_our_path(). + static bool g_is_our_path(const char * p_path,const char * p_extension); + +protected: + input_impl() {} + ~input_impl() {} +}; + +//! This is a class that just declares prototypes of functions that each non-multitrack-enabled input needs to implement. See input_decoder / input_info_reader / input_info_writer interfaces for full descriptions of member functions. Since input implementation class is instantiated using a template, you don't need to derive from input_singletrack_impl as virtual functions are not used on implementation class level. Use input_singletrack_factory_t template to register input class based on input_singletrack_impl. +class input_singletrack_impl +{ +public: + //! Opens specified file for info read / decoding / info write. This is called only once, immediately after object creation, before any other methods, and no other methods are called if open() fails. + //! @param p_filehint Optional; passes file object to use for the operation; if set to null, the implementation should handle opening file by itself. Note that not all inputs operate on physical files that can be reached through filesystem API, some of them require this parameter to be set to null (tone and silence generators for an example). Typically, an input implementation that requires file access calls input_open_file_helper() function to ensure that file is open with relevant access mode (read or read/write). + //! @param p_path URL of resource being opened. + //! @param p_reason Type of operation requested. Possible values are: \n + //! - input_open_info_read - info retrieval methods are valid; \n + //! - input_open_decode - info retrieval and decoding methods are valid; \n + //! - input_open_info_write - info retrieval and retagging methods are valid; \n + //! Note that info retrieval methods are valid in all cases, and they may be called at any point of decoding/retagging process. Results of info retrieval methods (other than get_subsong_count() / get_subsong()) between retag_set_info() and retag_commit() are undefined however; those should not be called during that period. + //! @param p_abort abort_callback object signaling user aborting the operation. + void open(service_ptr_t p_filehint,const char * p_path,t_input_open_reason p_reason,abort_callback & p_abort); + + //! See: input_info_reader::get_info(). Valid after open() with any reason. \n + //! Implementation warning: this is typically also called immediately after tag update and should return newly written content then. + void get_info(file_info & p_info,abort_callback & p_abort); + //! See: input_info_reader::get_file_stats(). Valid after open() with any reason. \n + //! Implementation warning: this is typically also called immediately after tag update and should return new values then. + t_filestats get_file_stats(abort_callback & p_abort); + + //! See: input_decoder::initialize(). Valid after open() with input_open_decode reason. + void decode_initialize(unsigned p_flags,abort_callback & p_abort); + //! See: input_decoder::run(). Valid after decode_initialize(). + bool decode_run(audio_chunk & p_chunk,abort_callback & p_abort); + //! See: input_decoder::seek(). Valid after decode_initialize(). + void decode_seek(double p_seconds,abort_callback & p_abort); + //! See: input_decoder::can_seek(). Valid after decode_initialize(). + bool decode_can_seek(); + //! See: input_decoder::get_dynamic_info(). Valid after decode_initialize(). + bool decode_get_dynamic_info(file_info & p_out, double & p_timestamp_delta); + //! See: input_decoder::get_dynamic_info_track(). Valid after decode_initialize(). + bool decode_get_dynamic_info_track(file_info & p_out, double & p_timestamp_delta); + //! See: input_decoder::on_idle(). Valid after decode_initialize(). + void decode_on_idle(abort_callback & p_abort); + + //! See: input_info_writer::set_info(). Note that input_info_writer::commit() call isn't forwarded because it's useless in case of non-multitrack-enabled inputs. Valid after open() with input_open_info_write reason. + void retag(const file_info & p_info,abort_callback & p_abort); + + //! See: input_entry::is_our_content_type(). + static bool g_is_our_content_type(const char * p_content_type); + //! See: input_entry::is_our_path(). + static bool g_is_our_path(const char * p_path,const char * p_extension); + +protected: + input_singletrack_impl() {} + ~input_singletrack_impl() {} +}; + + +//! Used internally by standard input_entry implementation; do not use directly. Translates input_decoder / input_info_reader / input_info_writer calls to input_impl calls. +template +class input_impl_interface_wrapper_t : public t_base +{ +public: + void open(service_ptr_t p_filehint,const char * p_path,t_input_open_reason p_reason,abort_callback & p_abort) { + m_instance.open(p_filehint,p_path,p_reason,p_abort); + } + + // input_info_reader methods + + t_uint32 get_subsong_count() { + return m_instance.get_subsong_count(); + } + + t_uint32 get_subsong(t_uint32 p_index) { + return m_instance.get_subsong(p_index); + } + + + void get_info(t_uint32 p_subsong,file_info & p_info,abort_callback & p_abort) { + m_instance.get_info(p_subsong,p_info,p_abort); + } + + t_filestats get_file_stats(abort_callback & p_abort) { + return m_instance.get_file_stats(p_abort); + } + + // input_decoder methods + + void initialize(t_uint32 p_subsong,unsigned p_flags,abort_callback & p_abort) { + m_instance.decode_initialize(p_subsong,p_flags,p_abort); + } + + bool run(audio_chunk & p_chunk,abort_callback & p_abort) { + return m_instance.decode_run(p_chunk,p_abort); + } + + bool run_raw(audio_chunk & p_chunk, mem_block_container & p_raw, abort_callback & p_abort) { + return m_instance.decode_run_raw(p_chunk, p_raw, p_abort); + } + + void seek(double p_seconds,abort_callback & p_abort) { + m_instance.decode_seek(p_seconds,p_abort); + } + + bool can_seek() { + return m_instance.decode_can_seek(); + } + + bool get_dynamic_info(file_info & p_out, double & p_timestamp_delta) { + return m_instance.decode_get_dynamic_info(p_out,p_timestamp_delta); + } + + bool get_dynamic_info_track(file_info & p_out, double & p_timestamp_delta) { + return m_instance.decode_get_dynamic_info_track(p_out,p_timestamp_delta); + } + + void on_idle(abort_callback & p_abort) { + m_instance.decode_on_idle(p_abort); + } + + void set_logger(event_logger::ptr ptr) { + m_instance.set_logger(ptr); + } + + // input_info_writer methods + + void set_info(t_uint32 p_subsong,const file_info & p_info,abort_callback & p_abort) { + m_instance.retag_set_info(p_subsong,p_info,p_abort); + } + + void commit(abort_callback & p_abort) { + m_instance.retag_commit(p_abort); + } + +private: + I m_instance; +}; + +//! Helper used by input_singletrack_factory_t, do not use directly. Translates input_impl calls to input_singletrack_impl calls. +template +class input_wrapper_singletrack_t +{ +public: + input_wrapper_singletrack_t() {} + + void open(service_ptr_t p_filehint,const char * p_path,t_input_open_reason p_reason,abort_callback & p_abort) { + m_instance.open(p_filehint,p_path,p_reason,p_abort); + } + + void get_info(t_uint32 p_subsong,file_info & p_info,abort_callback & p_abort) { + if (p_subsong != 0) throw exception_io_data(); + m_instance.get_info(p_info,p_abort); + } + + t_uint32 get_subsong_count() { + return 1; + } + + t_uint32 get_subsong(t_uint32 p_index) { + assert(p_index == 0); + return 0; + } + + t_filestats get_file_stats(abort_callback & p_abort) { + return m_instance.get_file_stats(p_abort); + } + + void decode_initialize(t_uint32 p_subsong,unsigned p_flags,abort_callback & p_abort) { + if (p_subsong != 0) throw exception_io_data(); + m_instance.decode_initialize(p_flags,p_abort); + } + + bool decode_run(audio_chunk & p_chunk,abort_callback & p_abort) {return m_instance.decode_run(p_chunk,p_abort);} + void decode_seek(double p_seconds,abort_callback & p_abort) {m_instance.decode_seek(p_seconds,p_abort);} + bool decode_can_seek() {return m_instance.decode_can_seek();} + bool decode_get_dynamic_info(file_info & p_out, double & p_timestamp_delta) {return m_instance.decode_get_dynamic_info(p_out,p_timestamp_delta);} + bool decode_get_dynamic_info_track(file_info & p_out, double & p_timestamp_delta) {return m_instance.decode_get_dynamic_info_track(p_out,p_timestamp_delta);} + void decode_on_idle(abort_callback & p_abort) {m_instance.decode_on_idle(p_abort);} + + void retag_set_info(t_uint32 p_subsong,const file_info & p_info,abort_callback & p_abort) { + if (p_subsong != 0) throw exception_io_data(); + m_instance.retag(p_info,p_abort); + } + + bool decode_run_raw(audio_chunk & p_chunk, mem_block_container & p_raw, abort_callback & p_abort) { + return m_instance.decode_run_raw(p_chunk, p_raw, p_abort); + } + + void set_logger(event_logger::ptr ptr) {m_instance.set_logger(ptr);} + + void retag_commit(abort_callback & p_abort) {} + + static bool g_is_our_content_type(const char * p_content_type) {return I::g_is_our_content_type(p_content_type);} + static bool g_is_our_path(const char * p_path,const char * p_extension) {return I::g_is_our_path(p_path,p_extension);} + + +private: + I m_instance; +}; + +//! Helper; standard input_entry implementation. Do not instantiate this directly, use input_factory_t or one of other input_*_factory_t helpers instead. +template +class input_entry_impl_t : public input_entry +{ +private: + + template + void instantiate_t(service_ptr_t & p_instance,service_ptr_t p_filehint,const char * p_path,t_input_open_reason p_reason,abort_callback & p_abort) + { + service_ptr_t< service_impl_t > > temp; + temp = new service_impl_t >(); + temp->open(p_filehint,p_path,p_reason,p_abort); + p_instance = temp.get_ptr(); + } +public: + bool is_our_content_type(const char * p_type) {return I::g_is_our_content_type(p_type);} + bool is_our_path(const char * p_full_path,const char * p_extension) {return I::g_is_our_path(p_full_path,p_extension);} + + void open_for_decoding(service_ptr_t & p_instance,service_ptr_t p_filehint,const char * p_path,abort_callback & p_abort) { + instantiate_t(p_instance,p_filehint,p_path,input_open_decode,p_abort); + } + + void open_for_info_read(service_ptr_t & p_instance,service_ptr_t p_filehint,const char * p_path,abort_callback & p_abort) { + instantiate_t(p_instance,p_filehint,p_path,input_open_info_read,p_abort); + } + + void open_for_info_write(service_ptr_t & p_instance,service_ptr_t p_filehint,const char * p_path,abort_callback & p_abort) { + instantiate_t(p_instance,p_filehint,p_path,input_open_info_write,p_abort); + } + + void get_extended_data(service_ptr_t p_filehint,const playable_location & p_location,const GUID & p_guid,mem_block_container & p_out,abort_callback & p_abort) { + p_out.reset(); + } + + unsigned get_flags() {return t_flags;} +}; + + +//! Stardard input factory. For reference of functions that must be supported by registered class, see input_impl.\n Usage: static input_factory_t g_myinputclass_factory;\n Note that input classes can't be registered through service_factory_t template directly. +template +class input_factory_t : public service_factory_single_t > {}; + +//! Non-multitrack-enabled input factory (helper) - hides multitrack management functions from input implementation; use this for inputs that handle file types where each physical file can contain only one user-visible playable track. For reference of functions that must be supported by registered class, see input_singletrack_impl.\n Usage: static input_singletrack_factory_t g_myinputclass_factory;\n Note that input classes can't be registered through service_factory_t template directly.template +template +class input_singletrack_factory_t : public service_factory_single_t,0> > {}; + +//! Extended version of input_factory_t, with non-default flags and supported interfaces. See: input_factory_t, input_entry::get_flags(). +template +class input_factory_ex_t : public service_factory_single_t > {}; + +//! Extended version of input_singletrack_factory_t, with non-default flags and supported interfaces. See: input_singletrack_factory_t, input_entry::get_flags(). +template +class input_singletrack_factory_ex_t : public service_factory_single_t,t_flags, t_decoder, t_inforeader, t_infowriter> > {}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/library_manager.h b/tools/vio2sf/src/foobar/foobar2000/SDK/library_manager.h new file mode 100644 index 000000000..fa8203290 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/library_manager.h @@ -0,0 +1,181 @@ +/*! +This service implements methods allowing you to interact with the Media Library.\n +All methods are valid from main thread only, unless noted otherwise.\n +To avoid race conditions, methods that alter library contents should not be called from inside global callbacks.\n +Usage: Use static_api_ptr_t to instantiate. \n + +Future compatibility notes: \n +In 0.9.6, the Media Library backend will be entirely reimplemented to perform tracking of folder content changes on its own. This API will still be provided for backwards compatibility, though most of methods will become stubs as their original purpose will be no longer valid. \n +To keep your component working sanely in future foobar2000 releases, do not depend on functions flagged as scheduled to be dropped - you can still call them, but keep in mind that they will become meaningless in the next major release. +*/ + +class NOVTABLE library_manager : public service_base { +public: + //! Interface for use with library_manager::enum_items(). + class NOVTABLE enum_callback { + public: + //! Return true to continue enumeration, false to abort. + virtual bool on_item(const metadb_handle_ptr & p_item) = 0; + }; + + //! Returns whether the specified item is in the Media Library or not. + virtual bool is_item_in_library(const metadb_handle_ptr & p_item) = 0; + //! Returns whether current user settings allow the specified item to be added to the Media Library or not. + virtual bool is_item_addable(const metadb_handle_ptr & p_item) = 0; + //! Returns whether current user settings allow the specified item path to be added to the Media Library or not. + virtual bool is_path_addable(const char * p_path) = 0; + //! Retrieves path of the specified item relative to the Media Library folder it is in. Returns true on success, false when the item is not in the Media Library. + //! SPECIAL WARNING: to allow multi-CPU optimizations to parse relative track paths, this API works in threads other than the main app thread. Main thread MUST be blocked while working in such scenarios, it's NOT safe to call from worker threads while the Media Library content/configuration might be getting altered. + virtual bool get_relative_path(const metadb_handle_ptr & p_item,pfc::string_base & p_out) = 0; + //! Calls callback method for every item in the Media Library. Note that order of items in Media Library is undefined. + virtual void enum_items(enum_callback & p_callback) = 0; + //! Scheduled to be dropped in 0.9.6 (will do nothing). \n + //! Adds specified items to the Media Library (items actually added will be filtered according to user settings). + virtual void add_items(const pfc::list_base_const_t & p_data) = 0; + //! Scheduled to be dropped in 0.9.6 (will do nothing). \n + //! Removes specified items from the Media Library (does nothing if specific item is not in the Media Library). + virtual void remove_items(const pfc::list_base_const_t & p_data) = 0; + //! Scheduled to be dropped in 0.9.6 (will do nothing). \n + //! Adds specified items to the Media Library (items actually added will be filtered according to user settings). The difference between this and add_items() is that items are not added immediately; the operation is queued and executed later, so it is safe to call from e.g. global callbacks. + virtual void add_items_async(const pfc::list_base_const_t & p_data) = 0; + + //! Scheduled to be dropped in 0.9.6 (will do nothing). \n + //! For internal use only; p_data must be sorted by metadb::path_compare; use file_operation_callback static methods instead of calling this directly. + virtual void on_files_deleted_sorted(const pfc::list_base_const_t & p_data) = 0; + + //! Retrieves the entire Media Library content. + virtual void get_all_items(pfc::list_base_t & p_out) = 0; + + //! Returns whether Media Library functionality is enabled or not (to be exact: whether there's at least one Media Library folder present in settings), for e.g. notifying the user to change settings when trying to use a Media Library viewer without having configured the Media Library first. + virtual bool is_library_enabled() = 0; + //! Pops up the Media Library preferences page. + virtual void show_preferences() = 0; + + //! Scheduled to be dropped in 0.9.6. \n + //! Deprecated; use library_manager_v2::rescan_async() when possible.\n + //! Rescans user-specified Media Library directories for new files and removes references to files that no longer exist from the Media Library.\n + //! Note that this function creates modal dialog and does not return until the operation has completed.\n + virtual void rescan() = 0; + + //! Scheduled to be dropped in 0.9.6. \n + //! Deprecated; use library_manager_v2::check_dead_entries_async() when possible.\n + //! Hints Media Library about possible dead items, typically used for "remove dead entries" context action in ML viewers. The implementation will verify whether the items are actually dead before ML contents are altered.\n + //! Note that this function creates modal dialog and does not return until the operation has completed.\n + virtual void check_dead_entries(const pfc::list_base_t & p_list) = 0; + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(library_manager); +}; + +//! \since 0.9.3 +class NOVTABLE library_manager_v2 : public library_manager { +public: + //! Scheduled to be dropped in 0.9.6 (will always return false). \n + //! Returns whether a rescan process is currently running. + virtual bool is_rescan_running() = 0; + + //! Scheduled to be dropped in 0.9.6 (will do nothing and instantly signal completion). \n + //! Starts an async rescan process. Note that if another process is already running, the process is silently aborted. + //! @param p_parent Parent window for displayed progress dialog. + //! @param p_notify Allows caller to receive notifications about the process finishing. Status code: 1 on success, 0 on user abort. Pass NULL if caller doesn't care. + virtual void rescan_async(HWND p_parent,completion_notify_ptr p_notify) = 0; + + //! Scheduled to be dropped in 0.9.6 (will do nothing and instantly signal completion). \n + //! Hints Media Library about possible dead items, typically used for "remove dead entries" context action in ML viewers. The implementation will verify whether the items are actually dead before ML contents are altered.\n + //! @param p_list List of items to process. + //! @param p_parent Parent window for displayed progress dialog. + //! @param p_notify Allows caller to receive notifications about the process finishing. Status code: 1 on success, 0 on user abort. Pass NULL if caller doesn't care. + virtual void check_dead_entries_async(const pfc::list_base_const_t & p_list,HWND p_parent,completion_notify_ptr p_notify) = 0; + + FB2K_MAKE_SERVICE_INTERFACE(library_manager_v2,library_manager); +}; + + +class NOVTABLE library_callback_dynamic { +public: + //! Called when new items are added to the Media Library. + virtual void on_items_added(const pfc::list_base_const_t & p_data) = 0; + //! Called when some items have been removed from the Media Library. + virtual void on_items_removed(const pfc::list_base_const_t & p_data) = 0; + //! Called when some items in the Media Library have been modified. + virtual void on_items_modified(const pfc::list_base_const_t & p_data) = 0; +}; + +//! \since 0.9.5 +class NOVTABLE library_manager_v3 : public library_manager_v2 { +public: + //! Retrieves directory path and subdirectory/filename formatting scheme for newly encoded/copied/moved tracks. + //! @returns True on success, false when the feature has not been configured. + virtual bool get_new_file_pattern_tracks(pfc::string_base & p_directory,pfc::string_base & p_format) = 0; + //! Retrieves directory path and subdirectory/filename formatting scheme for newly encoded/copied/moved full album images. + //! @returns True on success, false when the feature has not been configured. + virtual bool get_new_file_pattern_images(pfc::string_base & p_directory,pfc::string_base & p_format) = 0; + + virtual void register_callback(library_callback_dynamic * p_callback) = 0; + virtual void unregister_callback(library_callback_dynamic * p_callback) = 0; + + FB2K_MAKE_SERVICE_INTERFACE(library_manager_v3,library_manager_v2); +}; + +class library_callback_dynamic_impl_base : public library_callback_dynamic { +public: + library_callback_dynamic_impl_base() {static_api_ptr_t()->register_callback(this);} + ~library_callback_dynamic_impl_base() {static_api_ptr_t()->unregister_callback(this);} + + //stub implementations - avoid pure virtual function call issues + void on_items_added(metadb_handle_list_cref p_data) {} + void on_items_removed(metadb_handle_list_cref p_data) {} + void on_items_modified(metadb_handle_list_cref p_data) {} + + PFC_CLASS_NOT_COPYABLE_EX(library_callback_dynamic_impl_base); +}; + +//! Callback service receiving notifications about Media Library content changes. Methods called only from main thread.\n +//! Use library_callback_factory_t template to register. +class NOVTABLE library_callback : public service_base { +public: + //! Called when new items are added to the Media Library. + virtual void on_items_added(const pfc::list_base_const_t & p_data) = 0; + //! Called when some items have been removed from the Media Library. + virtual void on_items_removed(const pfc::list_base_const_t & p_data) = 0; + //! Called when some items in the Media Library have been modified. + virtual void on_items_modified(const pfc::list_base_const_t & p_data) = 0; + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(library_callback); +}; + +template +class library_callback_factory_t : public service_factory_single_t {}; + +//! Implement this service to appear on "library viewers" list in Media Library preferences page.\n +//! Use library_viewer_factory_t to register. +class NOVTABLE library_viewer : public service_base { +public: + //! Retrieves GUID of your preferences page (pfc::guid_null if you don't have one). + virtual GUID get_preferences_page() = 0; + //! Queries whether "activate" action is supported (relevant button will be disabled if it's not). + virtual bool have_activate() = 0; + //! Activates your Media Library viewer component (e.g. shows its window). + virtual void activate() = 0; + //! Retrieves GUID of your library_viewer implementation, for internal identification. Note that this not the same as preferences page GUID. + virtual GUID get_guid() = 0; + //! Retrieves name of your Media Library viewer, a null-terminated UTF-8 encoded string. + virtual const char * get_name() = 0; + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(library_viewer); +}; + +template +class library_viewer_factory_t : public service_factory_single_t {}; + + + + +//! \since 0.9.5.4 +//! Allows you to spawn a popup Media Library Search window with any query string that you specify. \n +//! Usage: static_api_ptr_t()->show("querygoeshere"); +class NOVTABLE library_search_ui : public service_base { +public: + virtual void show(const char * query) = 0; + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(library_search_ui) +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/link_resolver.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/link_resolver.cpp new file mode 100644 index 000000000..26c6c3ed4 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/link_resolver.cpp @@ -0,0 +1,17 @@ +#include "foobar2000.h" + +bool link_resolver::g_find(service_ptr_t & p_out,const char * p_path) +{ + service_enum_t e; + service_ptr_t ptr; + pfc::string_extension ext(p_path); + while(e.next(ptr)) + { + if (ptr->is_our_path(p_path,ext)) + { + p_out = ptr; + return true; + } + } + return false; +} diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/link_resolver.h b/tools/vio2sf/src/foobar/foobar2000/SDK/link_resolver.h new file mode 100644 index 000000000..8f09a1e02 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/link_resolver.h @@ -0,0 +1,33 @@ +#ifndef _foobar2000_sdk_link_resolver_h_ +#define _foobar2000_sdk_link_resolver_h_ + +//! Interface for resolving different sorts of link files. +//! Utilized by mechanisms that convert filesystem path into list of playable locations. +//! For security reasons, link may only point to playable object path, not to a playlist or another link. + +class NOVTABLE link_resolver : public service_base +{ +public: + + //! Tests whether specified file is supported by this link_resolver service. + //! @param p_path Path of file being queried. + //! @param p_extension Extension of file being queried. This is provided for performance reasons, path already includes it. + virtual bool is_our_path(const char * p_path,const char * p_extension) = 0; + + //! Resolves a link file. Before this is called, path must be accepted by is_our_path(). + //! @param p_filehint Optional file interface to use. If null/empty, implementation should open file by itself. + //! @param p_path Path of link file to resolve. + //! @param p_out Receives path the link is pointing to. + //! @param p_abort abort_callback object signaling user aborting the operation. + virtual void resolve(service_ptr_t p_filehint,const char * p_path,pfc::string_base & p_out,abort_callback & p_abort) = 0; + + //! Helper function; finds link_resolver interface that supports specified link file. + //! @param p_out Receives link_resolver interface on success. + //! @param p_path Path of file to query. + //! @returns True on success, false on failure (no interface that supports specified path could be found). + static bool g_find(service_ptr_t & p_out,const char * p_path); + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(link_resolver); +}; + +#endif //_foobar2000_sdk_link_resolver_h_ diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/main_thread_callback.h b/tools/vio2sf/src/foobar/foobar2000/SDK/main_thread_callback.h new file mode 100644 index 000000000..d5c6d89ac --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/main_thread_callback.h @@ -0,0 +1,20 @@ +//! Callback object class for main_thread_callback_manager service. +class NOVTABLE main_thread_callback : public service_base { +public: + //! Gets called from main app thread. See main_thread_callback_manager description for more info. + virtual void callback_run() = 0; + + FB2K_MAKE_SERVICE_INTERFACE(main_thread_callback,service_base); +}; + +/*! +Allows you to queue a callback object to be called from main app thread. This is commonly used to trigger main-thread-only API calls from worker threads.\n +This can be also used from main app thread, to avoid race conditions when trying to use APIs that dispatch global callbacks from inside some other global callback, or using message loops / modal dialogs inside global callbacks. +*/ +class NOVTABLE main_thread_callback_manager : public service_base { +public: + //! Queues a callback object. This can be called from any thread, implementation ensures multithread safety. Implementation will call p_callback->callback_run() once later. To get it called repeatedly, you would need to add your callback again. + virtual void add_callback(service_ptr_t p_callback) = 0; + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(main_thread_callback_manager); +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/mainmenu.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/mainmenu.cpp new file mode 100644 index 000000000..454b292ba --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/mainmenu.cpp @@ -0,0 +1,34 @@ +#include "foobar2000.h" + +bool mainmenu_commands::g_execute(const GUID & p_guid,service_ptr_t p_callback) { + service_enum_t e; + service_ptr_t ptr; + while(e.next(ptr)) { + const t_uint32 count = ptr->get_command_count(); + for(t_uint32 n=0;nget_command(n) == p_guid) { + ptr->execute(n,p_callback); + return true; + } + } + } + return false; +} + +bool mainmenu_commands::g_find_by_name(const char * p_name,GUID & p_guid) { + service_enum_t e; + service_ptr_t ptr; + pfc::string8_fastalloc temp; + while(e.next(ptr)) { + const t_uint32 count = ptr->get_command_count(); + for(t_uint32 n=0;nget_name(n,temp); + if (stricmp_utf8(temp,p_name) == 0) { + p_guid = ptr->get_command(n); + return true; + } + } + } + return false; + +} \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/mem_block_container.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/mem_block_container.cpp new file mode 100644 index 000000000..a1961b94a --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/mem_block_container.cpp @@ -0,0 +1,12 @@ +#include "foobar2000.h" + +void mem_block_container::from_stream(stream_reader * p_stream,t_size p_bytes,abort_callback & p_abort) { + if (p_bytes == 0) {set_size(0);} + set_size(p_bytes); + p_stream->read_object(get_ptr(),p_bytes,p_abort); +} + +void mem_block_container::set(const void * p_buffer,t_size p_size) { + set_size(p_size); + memcpy(get_ptr(),p_buffer,p_size); +} diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/mem_block_container.h b/tools/vio2sf/src/foobar/foobar2000/SDK/mem_block_container.h new file mode 100644 index 000000000..b1309ff25 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/mem_block_container.h @@ -0,0 +1,68 @@ +//! Generic interface for a memory block; used by various other interfaces to return memory blocks while allowing caller to allocate. +class NOVTABLE mem_block_container { +public: + virtual const void * get_ptr() const = 0; + virtual void * get_ptr() = 0; + virtual t_size get_size() const = 0; + virtual void set_size(t_size p_size) = 0; + + void from_stream(stream_reader * p_stream,t_size p_bytes,abort_callback & p_abort); + + void set(const void * p_buffer,t_size p_size); + void set(const mem_block_container & source) {copy(source);} + template void set(const t_source & source) { + pfc::static_assert(); + set(source.get_ptr(), source.get_size()); + } + + inline void copy(const mem_block_container & p_source) {set(p_source.get_ptr(),p_source.get_size());} + inline void reset() {set_size(0);} + + const mem_block_container & operator=(const mem_block_container & p_source) {copy(p_source);return *this;} + +protected: + mem_block_container() {} + ~mem_block_container() {} +}; + +//! mem_block_container implementation. +template class t_alloc = pfc::alloc_standard> +class mem_block_container_impl_t : public mem_block_container { +public: + const void * get_ptr() const {return m_data.get_ptr();} + void * get_ptr() {return m_data.get_ptr();} + t_size get_size() const {return m_data.get_size();} + void set_size(t_size p_size) { + m_data.set_size(p_size); + } +private: + pfc::array_t m_data; +}; + +typedef mem_block_container_impl_t<> mem_block_container_impl; + +class mem_block_container_temp_impl : public mem_block_container { +public: + mem_block_container_temp_impl(void * p_buffer,t_size p_size) : m_buffer(p_buffer), m_buffer_size(p_size), m_size(0) {} + const void * get_ptr() const {return m_buffer;} + void * get_ptr() {return m_buffer;} + t_size get_size() const {return m_size;} + void set_size(t_size p_size) {if (p_size > m_buffer_size) throw pfc::exception_overflow(); m_size = p_size;} +private: + t_size m_size,m_buffer_size; + void * m_buffer; +}; + +template +class mem_block_container_ref_impl : public mem_block_container { +public: + mem_block_container_ref_impl(t_ref & ref) : m_ref(ref) { + pfc::static_assert(); + } + const void * get_ptr() const {return m_ref.get_ptr();} + void * get_ptr() {return m_ref.get_ptr();} + t_size get_size() const {return m_ref.get_size();} + void set_size(t_size p_size) {m_ref.set_size(p_size);} +private: + t_ref & m_ref; +}; \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/menu.h b/tools/vio2sf/src/foobar/foobar2000/SDK/menu.h new file mode 100644 index 000000000..42fc903d1 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/menu.h @@ -0,0 +1,128 @@ +class NOVTABLE mainmenu_group : public service_base { +public: + virtual GUID get_guid() = 0; + virtual GUID get_parent() = 0; + virtual t_uint32 get_sort_priority() = 0; + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(mainmenu_group); +}; + +class NOVTABLE mainmenu_group_popup : public mainmenu_group { +public: + virtual void get_display_string(pfc::string_base & p_out) = 0; + + FB2K_MAKE_SERVICE_INTERFACE(mainmenu_group_popup,mainmenu_group); +}; + +class NOVTABLE mainmenu_commands : public service_base { +public: + enum { + flag_disabled = 1<<0, + flag_checked = 1<<1, + flag_radiochecked = 1<<2, + sort_priority_base = 0x10000, + sort_priority_dontcare = 0x80000000, + sort_priority_last = infinite, + }; + + //! Retrieves number of implemented commands. Index parameter of other methods must be in 0....command_count-1 range. + virtual t_uint32 get_command_count() = 0; + //! Retrieves GUID of specified command. + virtual GUID get_command(t_uint32 p_index) = 0; + //! Retrieves name of item, for list of commands to assign keyboard shortcuts to etc. + virtual void get_name(t_uint32 p_index,pfc::string_base & p_out) = 0; + //! Retrieves item's description for statusbar etc. + virtual bool get_description(t_uint32 p_index,pfc::string_base & p_out) = 0; + //! Retrieves GUID of owning menu group. + virtual GUID get_parent() = 0; + //! Retrieves sorting priority of the command; the lower the number, the upper in the menu your commands will appear. Third party components should use sorting_priority_base and up (values below are reserved for internal use). In case of equal priority, order is undefined. + virtual t_uint32 get_sort_priority() {return sort_priority_dontcare;} + //! Retrieves display string and display flags to use when menu is about to be displayed. If returns false, menu item won't be displayed. You can create keyboard-shortcut-only commands by always returning false from get_display(). + virtual bool get_display(t_uint32 p_index,pfc::string_base & p_text,t_uint32 & p_flags) {p_flags = 0;get_name(p_index,p_text);return true;} + //! Executes the command. p_callback parameter is reserved for future use and should be ignored / set to null pointer. + virtual void execute(t_uint32 p_index,service_ptr_t p_callback) = 0; + + static bool g_execute(const GUID & p_guid,service_ptr_t p_callback = service_ptr_t()); + static bool g_find_by_name(const char * p_name,GUID & p_guid); + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(mainmenu_commands); +}; + +class NOVTABLE mainmenu_manager : public service_base { +public: + enum { + flag_show_shortcuts = 1 << 0, + flag_show_shortcuts_global = 1 << 1, + }; + + virtual void instantiate(const GUID & p_root) = 0; + +#ifdef _WIN32 + virtual void generate_menu_win32(HMENU p_menu,t_uint32 p_id_base,t_uint32 p_id_count,t_uint32 p_flags) = 0; +#else +#error portme +#endif + //@param p_id Identifier of command to execute, relative to p_id_base of generate_menu_*() + //@returns true if command was executed successfully, false if not (e.g. command with given identifier not found). + virtual bool execute_command(t_uint32 p_id,service_ptr_t p_callback = service_ptr_t()) = 0; + + virtual bool get_description(t_uint32 p_id,pfc::string_base & p_out) = 0; + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(mainmenu_manager); +}; + +class mainmenu_groups { +public: + static const GUID file,view,edit,playback,library,help; + static const GUID file_open,file_add,file_playlist,file_etc; + static const GUID playback_controls,playback_etc; + static const GUID view_visualisations, view_alwaysontop; + static const GUID edit_part1,edit_part2,edit_part3; + static const GUID edit_part2_selection,edit_part2_sort,edit_part2_selection_sort; + static const GUID file_etc_preferences, file_etc_exit; + static const GUID help_about; + static const GUID library_refresh; + + enum {priority_edit_part1,priority_edit_part2,priority_edit_part3}; + enum {priority_edit_part2_commands,priority_edit_part2_selection,priority_edit_part2_sort}; + enum {priority_edit_part2_selection_commands,priority_edit_part2_selection_sort}; + enum {priority_file_open,priority_file_add,priority_file_playlist,priority_file_etc = mainmenu_commands::sort_priority_last}; +}; + + +class mainmenu_group_impl : public mainmenu_group { +public: + mainmenu_group_impl(const GUID & p_guid,const GUID & p_parent,t_uint32 p_priority) : m_guid(p_guid), m_parent(p_parent), m_priority(p_priority) {} + GUID get_guid() {return m_guid;} + GUID get_parent() {return m_parent;} + t_uint32 get_sort_priority() {return m_priority;} +private: + GUID m_guid,m_parent; t_uint32 m_priority; +}; + +class mainmenu_group_popup_impl : public mainmenu_group_popup { +public: + mainmenu_group_popup_impl(const GUID & p_guid,const GUID & p_parent,t_uint32 p_priority,const char * p_name) : m_guid(p_guid), m_parent(p_parent), m_priority(p_priority), m_name(p_name) {} + GUID get_guid() {return m_guid;} + GUID get_parent() {return m_parent;} + t_uint32 get_sort_priority() {return m_priority;} + void get_display_string(pfc::string_base & p_out) {p_out = m_name;} +private: + GUID m_guid,m_parent; t_uint32 m_priority; pfc::string8 m_name; +}; + +typedef service_factory_single_t __mainmenu_group_factory; +typedef service_factory_single_t __mainmenu_group_popup_factory; + +class mainmenu_group_factory : public __mainmenu_group_factory { +public: + inline mainmenu_group_factory(const GUID & p_guid,const GUID & p_parent,t_uint32 p_priority) : __mainmenu_group_factory(p_guid,p_parent,p_priority) {} +}; + +class mainmenu_group_popup_factory : public __mainmenu_group_popup_factory { +public: + inline mainmenu_group_popup_factory(const GUID & p_guid,const GUID & p_parent,t_uint32 p_priority,const char * p_name) : __mainmenu_group_popup_factory(p_guid,p_parent,p_priority,p_name) {} +}; + +template +class mainmenu_commands_factory_t : public service_factory_single_t {}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/menu_helpers.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/menu_helpers.cpp new file mode 100644 index 000000000..e3d8d39e5 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/menu_helpers.cpp @@ -0,0 +1,326 @@ +#include "foobar2000.h" + + +bool menu_helpers::context_get_description(const GUID& p_guid,pfc::string_base & out) { + service_ptr_t ptr; t_uint32 index; + if (!menu_item_resolver::g_resolve_context_command(p_guid, ptr, index)) return false; + bool rv = ptr->get_item_description(index, out); + if (!rv) out.reset(); + return rv; +} + +static bool run_context_command_internal(const GUID & p_command,const GUID & p_subcommand,const pfc::list_base_const_t & data,const GUID & caller) { + if (data.get_count() == 0) return false; + service_ptr_t ptr; t_uint32 index; + if (!menu_item_resolver::g_resolve_context_command(p_command, ptr, index)) return false; + + { + TRACK_CALL_TEXT("menu_helpers::run_command(), by GUID"); + ptr->item_execute_simple(index, p_subcommand, data, caller); + } + + return true; +} + +bool menu_helpers::run_command_context(const GUID & p_command,const GUID & p_subcommand,const pfc::list_base_const_t & data) +{ + return run_context_command_internal(p_command,p_subcommand,data,contextmenu_item::caller_undefined); +} + +bool menu_helpers::run_command_context_ex(const GUID & p_command,const GUID & p_subcommand,const pfc::list_base_const_t & data,const GUID & caller) +{ + return run_context_command_internal(p_command,p_subcommand,data,caller); +} + +bool menu_helpers::test_command_context(const GUID & p_guid) +{ + service_ptr_t ptr; t_uint32 index; + return menu_item_resolver::g_resolve_context_command(p_guid, ptr, index); +} + +static bool g_is_checked(const GUID & p_command,const GUID & p_subcommand,const pfc::list_base_const_t & data,const GUID & caller) +{ + service_ptr_t ptr; t_uint32 index; + if (!menu_item_resolver::g_resolve_context_command(p_command, ptr, index)) return false; + + unsigned displayflags = 0; + pfc::string_formatter dummystring; + if (!ptr->item_get_display_data(dummystring,displayflags,index,p_subcommand,data,caller)) return false; + return (displayflags & contextmenu_item_node::FLAG_CHECKED) != 0; + +} + +bool menu_helpers::is_command_checked_context(const GUID & p_command,const GUID & p_subcommand,const pfc::list_base_const_t & data) +{ + return g_is_checked(p_command,p_subcommand,data,contextmenu_item::caller_undefined); +} + +bool menu_helpers::is_command_checked_context_playlist(const GUID & p_command,const GUID & p_subcommand) +{ + metadb_handle_list temp; + static_api_ptr_t api; + api->activeplaylist_get_selected_items(temp); + return g_is_checked(p_command,p_subcommand,temp,contextmenu_item::caller_playlist); +} + + + + + + + +bool menu_helpers::run_command_context_playlist(const GUID & p_command,const GUID & p_subcommand) +{ + metadb_handle_list temp; + static_api_ptr_t api; + api->activeplaylist_get_selected_items(temp); + return run_command_context_ex(p_command,p_subcommand,temp,contextmenu_item::caller_playlist); +} + +bool menu_helpers::run_command_context_now_playing(const GUID & p_command,const GUID & p_subcommand) +{ + metadb_handle_ptr item; + if (!static_api_ptr_t()->get_now_playing(item)) return false;//not playing + return run_command_context_ex(p_command,p_subcommand,pfc::list_single_ref_t(item),contextmenu_item::caller_now_playing); +} + + +bool menu_helpers::guid_from_name(const char * p_name,unsigned p_name_len,GUID & p_out) +{ + service_enum_t e; + service_ptr_t ptr; + pfc::string8_fastalloc nametemp; + while(e.next(ptr)) + { + unsigned n, m = ptr->get_num_items(); + for(n=0;nget_item_name(n,nametemp); + if (!strcmp_ex(nametemp,infinite,p_name,p_name_len)) + { + p_out = ptr->get_item_guid(n); + return true; + } + } + } + return false; +} + +bool menu_helpers::name_from_guid(const GUID & p_guid,pfc::string_base & p_out) { + service_ptr_t ptr; t_uint32 index; + if (!menu_item_resolver::g_resolve_context_command(p_guid, ptr, index)) return false; + ptr->get_item_name(index, p_out); + return true; +} + + +static unsigned calc_total_action_count() +{ + service_enum_t e; + service_ptr_t ptr; + unsigned ret = 0; + while(e.next(ptr)) + ret += ptr->get_num_items(); + return ret; +} + + +const char * menu_helpers::guid_to_name_table::search(const GUID & p_guid) +{ + if (!m_inited) + { + m_data.set_size(calc_total_action_count()); + t_size dataptr = 0; + pfc::string8_fastalloc nametemp; + + service_enum_t e; + service_ptr_t ptr; + while(e.next(ptr)) + { + unsigned n, m = ptr->get_num_items(); + for(n=0;nget_item_name(n,nametemp); + m_data[dataptr].m_name = _strdup(nametemp); + m_data[dataptr].m_guid = ptr->get_item_guid(n); + dataptr++; + } + } + assert(dataptr == m_data.get_size()); + + pfc::sort_t(m_data,entry_compare,m_data.get_size()); + m_inited = true; + } + t_size index; + if (pfc::bsearch_t(m_data.get_size(),m_data,entry_compare_search,p_guid,index)) + return m_data[index].m_name; + else + return 0; +} + +int menu_helpers::guid_to_name_table::entry_compare_search(const entry & entry1,const GUID & entry2) +{ + return pfc::guid_compare(entry1.m_guid,entry2); +} + +int menu_helpers::guid_to_name_table::entry_compare(const entry & entry1,const entry & entry2) +{ + return pfc::guid_compare(entry1.m_guid,entry2.m_guid); +} + +menu_helpers::guid_to_name_table::guid_to_name_table() +{ + m_inited = false; +} + +menu_helpers::guid_to_name_table::~guid_to_name_table() +{ + t_size n, m = m_data.get_size(); + for(n=0;n e; + service_ptr_t ptr; + while(e.next(ptr)) + { + unsigned n, m = ptr->get_num_items(); + for(n=0;nget_item_name(n,nametemp); + m_data[dataptr].m_name = _strdup(nametemp); + m_data[dataptr].m_guid = ptr->get_item_guid(n); + dataptr++; + } + } + assert(dataptr == m_data.get_size()); + + pfc::sort_t(m_data,entry_compare,m_data.get_size()); + m_inited = true; + } + t_size index; + search_entry temp = {p_name,p_name_len}; + if (pfc::bsearch_t(m_data.get_size(),m_data,entry_compare_search,temp,index)) + { + p_out = m_data[index].m_guid; + return true; + } + else + return false; +} + +menu_helpers::name_to_guid_table::name_to_guid_table() +{ + m_inited = false; +} + +menu_helpers::name_to_guid_table::~name_to_guid_table() +{ + t_size n, m = m_data.get_size(); + for(n=0;n & p_item,unsigned & p_index) +{ + pfc::string8_fastalloc path,name; + service_enum_t e; + service_ptr_t ptr; + if (e.first(ptr)) do { +// if (ptr->get_type()==type) + { + unsigned action,num_actions = ptr->get_num_items(); + for(action=0;actionget_item_default_path(action,path); ptr->get_item_name(action,name); + if (!path.is_empty()) path += "/"; + path += name; + if (!stricmp_utf8(p_name,path)) + { + p_item = ptr; + p_index = action; + return true; + } + } + } + } while(e.next(ptr)); + return false; + +} + +bool menu_helpers::find_command_by_name(const char * p_name,GUID & p_command) +{ + service_ptr_t item; + unsigned index; + bool ret = find_command_by_name(p_name,item,index); + if (ret) p_command = item->get_item_guid(index); + return ret; +} + + +bool standard_commands::run_main(const GUID & p_guid) { + t_uint32 index; + mainmenu_commands::ptr ptr; + if (!menu_item_resolver::g_resolve_main_command(p_guid, ptr, index)) return false; + ptr->execute(index,service_ptr_t()); + return true; +} + +bool menu_item_resolver::g_resolve_context_command(const GUID & id, contextmenu_item::ptr & out, t_uint32 & out_index) { + menu_item_resolver::ptr api; + if (service_enum_t().first(api)) { + return api->resolve_context_command(id, out, out_index); + } else { + service_enum_t e; service_ptr_t ptr; + while(e.next(ptr)) { + const unsigned num_actions = ptr->get_num_items(); + for(unsigned action=0;actionget_item_guid(action)) { + out_index = action; out = ptr; return true; + } + } + } + return false; + } +} +bool menu_item_resolver::g_resolve_main_command(const GUID & id, mainmenu_commands::ptr & out, t_uint32 & out_index) { + menu_item_resolver::ptr api; + if (service_enum_t().first(api)) { + return api->resolve_main_command(id, out, out_index); + } else { + service_enum_t e; service_ptr_t ptr; + while(e.next(ptr)) { + const t_uint32 total = ptr->get_command_count(); + for(t_uint32 walk = 0; walk < total; ++walk) { + if (id == ptr->get_command(walk)) { + out_index = walk; out = ptr; return true; + } + } + } + return false; + } +} + diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/menu_helpers.h b/tools/vio2sf/src/foobar/foobar2000/SDK/menu_helpers.h new file mode 100644 index 000000000..623324528 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/menu_helpers.h @@ -0,0 +1,182 @@ +namespace menu_helpers { +#ifdef _WIN32 + void win32_auto_mnemonics(HMENU menu); +#endif + + bool run_command_context(const GUID & p_command,const GUID & p_subcommand,const pfc::list_base_const_t & data); + bool run_command_context_ex(const GUID & p_command,const GUID & p_subcommand,const pfc::list_base_const_t & data,const GUID & caller); + bool run_command_context_playlist(const GUID & p_command,const GUID & p_subcommand); + bool run_command_context_now_playing(const GUID & p_command,const GUID & p_subcommand); + + bool test_command_context(const GUID & p_guid); + + bool is_command_checked_context(const GUID & p_command,const GUID & p_subcommand,const pfc::list_base_const_t & data); + bool is_command_checked_context_playlist(const GUID & p_command,const GUID & p_subcommand); + + bool find_command_by_name(const char * p_name,service_ptr_t & p_item,unsigned & p_index); + bool find_command_by_name(const char * p_name,GUID & p_command); + + bool context_get_description(const GUID& p_guid,pfc::string_base & out); + + bool guid_from_name(const char * p_name,unsigned p_name_len,GUID & p_out); + bool name_from_guid(const GUID & p_guid,pfc::string_base & p_out); + + class guid_to_name_table + { + public: + guid_to_name_table(); + ~guid_to_name_table(); + const char * search(const GUID & p_guid); + private: + struct entry { + char* m_name; + GUID m_guid; + }; + pfc::array_t m_data; + bool m_inited; + + static int entry_compare_search(const entry & entry1,const GUID & entry2); + static int entry_compare(const entry & entry1,const entry & entry2); + }; + + class name_to_guid_table + { + public: + name_to_guid_table(); + ~name_to_guid_table(); + bool search(const char * p_name,unsigned p_name_len,GUID & p_out); + private: + struct entry { + char* m_name; + GUID m_guid; + }; + pfc::array_t m_data; + bool m_inited; + struct search_entry { + const char * m_name; unsigned m_name_len; + }; + + static int entry_compare_search(const entry & entry1,const search_entry & entry2); + static int entry_compare(const entry & entry1,const entry & entry2); + }; + +}; + + + +class standard_commands +{ +public: + static const GUID + guid_context_file_properties, guid_context_file_open_directory, guid_context_copy_names, + guid_context_send_to_playlist, guid_context_reload_info, guid_context_reload_info_if_changed, + guid_context_rewrite_info, guid_context_remove_tags, + guid_context_convert_run, guid_context_convert_run_singlefile,guid_context_convert_run_withcue, + guid_context_write_cd, + guid_context_rg_scan_track, guid_context_rg_scan_album, guid_context_rg_scan_album_multi, + guid_context_rg_remove, guid_context_save_playlist, guid_context_masstag_edit, + guid_context_masstag_rename, + guid_main_always_on_top, guid_main_preferences, guid_main_about, + guid_main_exit, guid_main_restart, guid_main_activate, + guid_main_hide, guid_main_activate_or_hide, guid_main_titleformat_help, + guid_main_next, guid_main_previous, + guid_main_next_or_random, guid_main_random, guid_main_pause, + guid_main_play, guid_main_play_or_pause, guid_main_rg_set_album, + guid_main_rg_set_track, guid_main_rg_disable, guid_main_stop, + guid_main_stop_after_current, guid_main_volume_down, guid_main_volume_up, + guid_main_volume_mute, guid_main_add_directory, guid_main_add_files, + guid_main_add_location, guid_main_add_playlist, guid_main_clear_playlist, + guid_main_create_playlist, guid_main_highlight_playing, guid_main_load_playlist, + guid_main_next_playlist, guid_main_previous_playlist, guid_main_open, + guid_main_remove_playlist, guid_main_remove_dead_entries, guid_main_remove_duplicates, + guid_main_rename_playlist, guid_main_save_all_playlists, guid_main_save_playlist, + guid_main_playlist_search, guid_main_playlist_sel_crop, guid_main_playlist_sel_remove, + guid_main_playlist_sel_invert, guid_main_playlist_undo, guid_main_show_console, + guid_main_play_cd, guid_main_restart_resetconfig, guid_main_record, + guid_main_playlist_moveback, guid_main_playlist_moveforward, guid_main_playlist_redo, + guid_main_playback_follows_cursor, guid_main_cursor_follows_playback, guid_main_saveconfig, + guid_main_playlist_select_all, guid_main_show_now_playing, + + guid_seek_ahead_1s, guid_seek_ahead_5s, guid_seek_ahead_10s, guid_seek_ahead_30s, + guid_seek_ahead_1min, guid_seek_ahead_2min, guid_seek_ahead_5min, guid_seek_ahead_10min, + + guid_seek_back_1s, guid_seek_back_5s, guid_seek_back_10s, guid_seek_back_30s, + guid_seek_back_1min, guid_seek_back_2min, guid_seek_back_5min, guid_seek_back_10min + ; + + static bool run_main(const GUID & guid); + static inline bool run_context(const GUID & guid,const pfc::list_base_const_t &data) {return menu_helpers::run_command_context(guid,pfc::guid_null,data);} + static inline bool run_context(const GUID & guid,const pfc::list_base_const_t &data,const GUID& caller) {return menu_helpers::run_command_context_ex(guid,pfc::guid_null,data,caller);} + + static inline bool context_file_properties(const pfc::list_base_const_t &data,const GUID& caller = contextmenu_item::caller_undefined) {return run_context(guid_context_file_properties,data,caller);} + static inline bool context_file_open_directory(const pfc::list_base_const_t &data,const GUID& caller = contextmenu_item::caller_undefined) {return run_context(guid_context_file_open_directory,data,caller);} + static inline bool context_copy_names(const pfc::list_base_const_t &data,const GUID& caller = contextmenu_item::caller_undefined) {return run_context(guid_context_copy_names,data,caller);} + static inline bool context_send_to_playlist(const pfc::list_base_const_t &data,const GUID& caller = contextmenu_item::caller_undefined) {return run_context(guid_context_send_to_playlist,data,caller);} + static inline bool context_reload_info(const pfc::list_base_const_t &data,const GUID& caller = contextmenu_item::caller_undefined) {return run_context(guid_context_reload_info,data,caller);} + static inline bool context_reload_info_if_changed(const pfc::list_base_const_t &data,const GUID& caller = contextmenu_item::caller_undefined) {return run_context(guid_context_reload_info_if_changed,data,caller);} + static inline bool context_rewrite_info(const pfc::list_base_const_t &data,const GUID& caller = contextmenu_item::caller_undefined) {return run_context(guid_context_rewrite_info,data,caller);} + static inline bool context_remove_tags(const pfc::list_base_const_t &data,const GUID& caller = contextmenu_item::caller_undefined) {return run_context(guid_context_remove_tags,data,caller);} + static inline bool context_convert_run(const pfc::list_base_const_t &data,const GUID& caller = contextmenu_item::caller_undefined) {return run_context(guid_context_convert_run,data,caller);} + static inline bool context_convert_run_singlefile(const pfc::list_base_const_t &data,const GUID& caller = contextmenu_item::caller_undefined) {return run_context(guid_context_convert_run_singlefile,data,caller);} + static inline bool context_write_cd(const pfc::list_base_const_t &data,const GUID& caller = contextmenu_item::caller_undefined) {return run_context(guid_context_write_cd,data,caller);} + static inline bool context_rg_scan_track(const pfc::list_base_const_t &data,const GUID& caller = contextmenu_item::caller_undefined) {return run_context(guid_context_rg_scan_track,data,caller);} + static inline bool context_rg_scan_album(const pfc::list_base_const_t &data,const GUID& caller = contextmenu_item::caller_undefined) {return run_context(guid_context_rg_scan_album,data,caller);} + static inline bool context_rg_scan_album_multi(const pfc::list_base_const_t &data,const GUID& caller = contextmenu_item::caller_undefined) {return run_context(guid_context_rg_scan_album_multi,data,caller);} + static inline bool context_rg_remove(const pfc::list_base_const_t &data,const GUID& caller = contextmenu_item::caller_undefined) {return run_context(guid_context_rg_remove,data,caller);} + static inline bool context_save_playlist(const pfc::list_base_const_t &data,const GUID& caller = contextmenu_item::caller_undefined) {return run_context(guid_context_save_playlist,data,caller);} + static inline bool context_masstag_edit(const pfc::list_base_const_t &data,const GUID& caller = contextmenu_item::caller_undefined) {return run_context(guid_context_masstag_edit,data,caller);} + static inline bool context_masstag_rename(const pfc::list_base_const_t &data,const GUID& caller = contextmenu_item::caller_undefined) {return run_context(guid_context_masstag_rename,data,caller);} + static inline bool main_always_on_top() {return run_main(guid_main_always_on_top);} + static inline bool main_preferences() {return run_main(guid_main_preferences);} + static inline bool main_about() {return run_main(guid_main_about);} + static inline bool main_exit() {return run_main(guid_main_exit);} + static inline bool main_restart() {return run_main(guid_main_restart);} + static inline bool main_activate() {return run_main(guid_main_activate);} + static inline bool main_hide() {return run_main(guid_main_hide);} + static inline bool main_activate_or_hide() {return run_main(guid_main_activate_or_hide);} + static inline bool main_titleformat_help() {return run_main(guid_main_titleformat_help);} + static inline bool main_playback_follows_cursor() {return run_main(guid_main_playback_follows_cursor);} + static inline bool main_next() {return run_main(guid_main_next);} + static inline bool main_previous() {return run_main(guid_main_previous);} + static inline bool main_next_or_random() {return run_main(guid_main_next_or_random);} + static inline bool main_random() {return run_main(guid_main_random);} + static inline bool main_pause() {return run_main(guid_main_pause);} + static inline bool main_play() {return run_main(guid_main_play);} + static inline bool main_play_or_pause() {return run_main(guid_main_play_or_pause);} + static inline bool main_rg_set_album() {return run_main(guid_main_rg_set_album);} + static inline bool main_rg_set_track() {return run_main(guid_main_rg_set_track);} + static inline bool main_rg_disable() {return run_main(guid_main_rg_disable);} + static inline bool main_stop() {return run_main(guid_main_stop);} + static inline bool main_stop_after_current() {return run_main(guid_main_stop_after_current);} + static inline bool main_volume_down() {return run_main(guid_main_volume_down);} + static inline bool main_volume_up() {return run_main(guid_main_volume_up);} + static inline bool main_volume_mute() {return run_main(guid_main_volume_mute);} + static inline bool main_add_directory() {return run_main(guid_main_add_directory);} + static inline bool main_add_files() {return run_main(guid_main_add_files);} + static inline bool main_add_location() {return run_main(guid_main_add_location);} + static inline bool main_add_playlist() {return run_main(guid_main_add_playlist);} + static inline bool main_clear_playlist() {return run_main(guid_main_clear_playlist);} + static inline bool main_create_playlist() {return run_main(guid_main_create_playlist);} + static inline bool main_highlight_playing() {return run_main(guid_main_highlight_playing);} + static inline bool main_load_playlist() {return run_main(guid_main_load_playlist);} + static inline bool main_next_playlist() {return run_main(guid_main_next_playlist);} + static inline bool main_previous_playlist() {return run_main(guid_main_previous_playlist);} + static inline bool main_open() {return run_main(guid_main_open);} + static inline bool main_remove_playlist() {return run_main(guid_main_remove_playlist);} + static inline bool main_remove_dead_entries() {return run_main(guid_main_remove_dead_entries);} + static inline bool main_remove_duplicates() {return run_main(guid_main_remove_duplicates);} + static inline bool main_rename_playlist() {return run_main(guid_main_rename_playlist);} + static inline bool main_save_all_playlists() {return run_main(guid_main_save_all_playlists);} + static inline bool main_save_playlist() {return run_main(guid_main_save_playlist);} + static inline bool main_playlist_search() {return run_main(guid_main_playlist_search);} + static inline bool main_playlist_sel_crop() {return run_main(guid_main_playlist_sel_crop);} + static inline bool main_playlist_sel_remove() {return run_main(guid_main_playlist_sel_remove);} + static inline bool main_playlist_sel_invert() {return run_main(guid_main_playlist_sel_invert);} + static inline bool main_playlist_undo() {return run_main(guid_main_playlist_undo);} + static inline bool main_show_console() {return run_main(guid_main_show_console);} + static inline bool main_play_cd() {return run_main(guid_main_play_cd);} + static inline bool main_restart_resetconfig() {return run_main(guid_main_restart_resetconfig);} + static inline bool main_playlist_moveback() {return run_main(guid_main_playlist_moveback);} + static inline bool main_playlist_moveforward() {return run_main(guid_main_playlist_moveforward);} + static inline bool main_saveconfig() {return run_main(guid_main_saveconfig);} +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/menu_item.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/menu_item.cpp new file mode 100644 index 000000000..b4e5cbf58 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/menu_item.cpp @@ -0,0 +1,40 @@ +#include "foobar2000.h" + + + +bool contextmenu_item::item_get_display_data_root(pfc::string_base & p_out,unsigned & p_displayflags,unsigned p_index,const pfc::list_base_const_t & p_data,const GUID & p_caller) +{ + bool status = false; + pfc::ptrholder_t root ( instantiate_item(p_index,p_data,p_caller) ); + if (root.is_valid()) status = root->get_display_data(p_out,p_displayflags,p_data,p_caller); + return status; +} + + +static contextmenu_item_node * g_find_node(const GUID & p_guid,contextmenu_item_node * p_parent) +{ + if (p_parent->get_guid() == p_guid) return p_parent; + else if (p_parent->get_type() == contextmenu_item_node::TYPE_POPUP) + { + t_size n, m = p_parent->get_children_count(); + for(n=0;nget_child(n)); + if (temp) return temp; + } + return 0; + } + else return 0; +} + +bool contextmenu_item::item_get_display_data(pfc::string_base & p_out,unsigned & p_displayflags,unsigned p_index,const GUID & p_node,const pfc::list_base_const_t & p_data,const GUID & p_caller) +{ + bool status = false; + pfc::ptrholder_t root ( instantiate_item(p_index,p_data,p_caller) ); + if (root.is_valid()) + { + contextmenu_item_node * node = g_find_node(p_node,root.get_ptr()); + if (node) status = node->get_display_data(p_out,p_displayflags,p_data,p_caller); + } + return status; +} diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/menu_manager.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/menu_manager.cpp new file mode 100644 index 000000000..e5cfc1608 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/menu_manager.cpp @@ -0,0 +1,401 @@ +#include "foobar2000.h" + +#ifdef WIN32 + +static void fix_ampersand(const char * src,pfc::string_base & out) +{ + out.reset(); + unsigned ptr = 0; + while(src[ptr]) + { + if (src[ptr]=='&') + { + out.add_string("&&"); + ptr++; + while(src[ptr]=='&') + { + out.add_string("&&"); + ptr++; + } + } + else out.add_byte(src[ptr++]); + } +} + +static unsigned flags_to_win32(unsigned flags) +{ + unsigned ret = 0; + if (flags & contextmenu_item_node::FLAG_RADIOCHECKED) {/* dealt with elsewhere */} + else if (flags & contextmenu_item_node::FLAG_CHECKED) ret |= MF_CHECKED; + if (flags & contextmenu_item_node::FLAG_DISABLED) ret |= MF_DISABLED; + if (flags & contextmenu_item_node::FLAG_GRAYED) ret |= MF_GRAYED; + return ret; +} + +void contextmenu_manager::win32_build_menu(HMENU menu,contextmenu_node * parent,int base_id,int max_id)//menu item identifiers are base_id<=Nget_type()==contextmenu_item_node::TYPE_POPUP) + { + pfc::string8_fastalloc temp; + t_size child_idx,child_num = parent->get_num_children(); + for(child_idx=0;child_idxget_child(child_idx); + if (child) + { + const char * name = child->get_name(); + if (strchr(name,'&')) {fix_ampersand(name,temp);name=temp;} + contextmenu_item_node::t_type type = child->get_type(); + if (type==contextmenu_item_node::TYPE_POPUP) + { + HMENU new_menu = CreatePopupMenu(); + uAppendMenu(menu,MF_STRING|MF_POPUP | flags_to_win32(child->get_display_flags()),(UINT_PTR)new_menu,name); + win32_build_menu(new_menu,child,base_id,max_id); + } + else if (type==contextmenu_item_node::TYPE_SEPARATOR) + { + uAppendMenu(menu,MF_SEPARATOR,0,0); + } + else if (type==contextmenu_item_node::TYPE_COMMAND) + { + int id = child->get_id(); + if (id>=0 && (max_id<0 || idget_display_flags(); + const UINT ID = base_id+id; + uAppendMenu(menu,MF_STRING | flags_to_win32(flags),ID,name); + if (flags & contextmenu_item_node::FLAG_RADIOCHECKED) CheckMenuRadioItem(menu,ID,ID,ID,MF_BYCOMMAND); + } + } + } + } + } +} + +#endif + +bool contextmenu_manager::get_description_by_id(unsigned id,pfc::string_base & out) { + contextmenu_node * ptr = find_by_id(id); + if (ptr == NULL) return false; + return ptr->get_description(out); +} +bool contextmenu_manager::execute_by_id(unsigned id) { + contextmenu_node * ptr = find_by_id(id); + if (ptr == NULL) return false; + ptr->execute(); + return true; +} + +#ifdef WIN32 + +void contextmenu_manager::win32_run_menu_popup(HWND parent,const POINT * pt) +{ + enum {ID_CUSTOM_BASE = 1}; + + int cmd; + + { + POINT p; + if (pt) p = *pt; + else GetCursorPos(&p); + + HMENU hmenu = CreatePopupMenu(); + try { + + win32_build_menu(hmenu,ID_CUSTOM_BASE,-1); + menu_helpers::win32_auto_mnemonics(hmenu); + + cmd = TrackPopupMenu(hmenu,TPM_RIGHTBUTTON|TPM_NONOTIFY|TPM_RETURNCMD,p.x,p.y,0,parent,0); + } catch(...) {DestroyMenu(hmenu); throw;} + + DestroyMenu(hmenu); + } + + if (cmd>0) + { + if (cmd>=ID_CUSTOM_BASE) + { + execute_by_id(cmd - ID_CUSTOM_BASE); + } + } +} + +void contextmenu_manager::win32_run_menu_context(HWND parent,const pfc::list_base_const_t & data,const POINT * pt,unsigned flags) +{ + service_ptr_t manager; + contextmenu_manager::g_create(manager); + manager->init_context(data,flags); + manager->win32_run_menu_popup(parent,pt); +} + +void contextmenu_manager::win32_run_menu_context_playlist(HWND parent,const POINT * pt,unsigned flags) +{ + service_ptr_t manager; + contextmenu_manager::g_create(manager); + manager->init_context_playlist(flags); + manager->win32_run_menu_popup(parent,pt); +} + + +namespace { + class mnemonic_manager + { + pfc::string8_fastalloc used; + bool is_used(unsigned c) + { + char temp[8]; + temp[pfc::utf8_encode_char(uCharLower(c),temp)]=0; + return !!strstr(used,temp); + } + + static bool is_alphanumeric(char c) + { + return (c>='a' && c<='z') || (c>='A' && c<='Z') || (c>='0' && c<='9'); + } + + + + + void insert(const char * src,unsigned idx,pfc::string_base & out) + { + out.reset(); + out.add_string(src,idx); + out.add_string("&"); + out.add_string(src+idx); + used.add_char(uCharLower(src[idx])); + } + public: + bool check_string(const char * src) + {//check for existing mnemonics + const char * ptr = src; + while(ptr = strchr(ptr,'&')) + { + if (ptr[1]=='&') ptr+=2; + else + { + unsigned c = 0; + if (pfc::utf8_decode_char(ptr+1,c)>0) + { + if (!is_used(c)) used.add_char(uCharLower(c)); + } + return true; + } + } + return false; + } + bool process_string(const char * src,pfc::string_base & out)//returns if changed + { + if (check_string(src)) {out=src;return false;} + unsigned idx=0; + while(src[idx]==' ') idx++; + while(src[idx]) + { + if (is_alphanumeric(src[idx]) && !is_used(src[idx])) + { + insert(src,idx,out); + return true; + } + + while(src[idx] && src[idx]!=' ' && src[idx]!='\t') idx++; + if (src[idx]=='\t') break; + while(src[idx]==' ') idx++; + } + + //no success picking first letter of one of words + idx=0; + while(src[idx]) + { + if (src[idx]=='\t') break; + if (is_alphanumeric(src[idx]) && !is_used(src[idx])) + { + insert(src,idx,out); + return true; + } + idx++; + } + + //giving up + out = src; + return false; + } + }; +} + +void menu_helpers::win32_auto_mnemonics(HMENU menu) +{ + mnemonic_manager mgr; + unsigned n, m = GetMenuItemCount(menu); + pfc::string8_fastalloc temp,temp2; + for(n=0;n & data,WPARAM wp,const GUID & caller) +{ + if (data.get_count()==0) return false; + return process_keydown_ex(TYPE_CONTEXT,data,get_key_code(wp),caller); +} + +bool keyboard_shortcut_manager::on_keydown_auto(WPARAM wp) +{ + if (on_keydown(TYPE_MAIN,wp)) return true; + if (on_keydown(TYPE_CONTEXT_PLAYLIST,wp)) return true; + if (on_keydown(TYPE_CONTEXT_NOW_PLAYING,wp)) return true; + return false; +} + +bool keyboard_shortcut_manager::on_keydown_auto_playlist(WPARAM wp) +{ + metadb_handle_list data; + static_api_ptr_t api; + api->activeplaylist_get_selected_items(data); + return on_keydown_auto_context(data,wp,contextmenu_item::caller_playlist); +} + +bool keyboard_shortcut_manager::on_keydown_auto_context(const pfc::list_base_const_t & data,WPARAM wp,const GUID & caller) +{ + if (on_keydown_context(data,wp,caller)) return true; + else return on_keydown_auto(wp); +} + +static bool should_relay_key_restricted(UINT p_key) { + switch(p_key) { + case VK_LEFT: + case VK_RIGHT: + case VK_UP: + case VK_DOWN: + return false; + default: + return (p_key >= VK_F1 && p_key <= VK_F24) || IsKeyPressed(VK_CONTROL) || IsKeyPressed(VK_LWIN) || IsKeyPressed(VK_RWIN); + } +} + +bool keyboard_shortcut_manager::on_keydown_restricted_auto(WPARAM wp) { + if (!should_relay_key_restricted(wp)) return false; + return on_keydown_auto(wp); +} +bool keyboard_shortcut_manager::on_keydown_restricted_auto_playlist(WPARAM wp) { + if (!should_relay_key_restricted(wp)) return false; + return on_keydown_auto_playlist(wp); +} +bool keyboard_shortcut_manager::on_keydown_restricted_auto_context(const pfc::list_base_const_t & data,WPARAM wp,const GUID & caller) { + if (!should_relay_key_restricted(wp)) return false; + return on_keydown_auto_context(data,wp,caller); +} + +bool keyboard_shortcut_manager_v2::pretranslate_message(const MSG * msg, HWND thisPopupWnd) { + switch(msg->message) { + case WM_KEYDOWN: + case WM_SYSKEYDOWN: + if (thisPopupWnd != NULL && FindOwningPopup(msg->hwnd) == thisPopupWnd) { + const t_uint32 modifiers = GetHotkeyModifierFlags(); + /*if (filterTypableWindowMessage(msg, modifiers))*/ { + if (process_keydown_simple(get_key_code(msg->wParam,modifiers))) return true; + } + } + return false; + default: + return false; + } +} + +bool keyboard_shortcut_manager::is_text_key(t_uint32 vkCode) { + return vkCode == VK_SPACE + || (vkCode >= '0' && vkCode < 0x40) + || (vkCode > 0x40 && vkCode < VK_LWIN) + || (vkCode >= VK_NUMPAD0 && vkCode <= VK_DIVIDE) + || (vkCode >= VK_OEM_1 && vkCode <= VK_OEM_3) + || (vkCode >= VK_OEM_4 && vkCode <= VK_OEM_8) + ; +} + +bool keyboard_shortcut_manager::is_typing_key(t_uint32 vkCode) { + return is_text_key(vkCode) + || vkCode == VK_BACK + || vkCode == VK_RETURN + || vkCode == VK_INSERT + || (vkCode > VK_SPACE && vkCode < '0'); +} + +bool keyboard_shortcut_manager::is_typing_key_combo(t_uint32 vkCode, t_uint32 modifiers) { + if (!is_typing_modifier(modifiers)) return false; + return is_typing_key(vkCode); +} + +bool keyboard_shortcut_manager::is_typing_modifier(t_uint32 flags) { + flags &= ~MOD_SHIFT; + return flags == 0 || flags == (MOD_ALT | MOD_CONTROL); +} + +bool keyboard_shortcut_manager::is_typing_message(HWND editbox, const MSG * msg) { + if (msg->hwnd != editbox) return false; + return is_typing_message(msg); +} +bool keyboard_shortcut_manager::is_typing_message(const MSG * msg) { + if (msg->message != WM_KEYDOWN && msg->message != WM_SYSKEYDOWN) return false; + return is_typing_key_combo(msg->wParam, GetHotkeyModifierFlags()); +} diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/message_loop.h b/tools/vio2sf/src/foobar/foobar2000/SDK/message_loop.h new file mode 100644 index 000000000..19cacaf60 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/message_loop.h @@ -0,0 +1,80 @@ +class NOVTABLE message_filter +{ +public: + virtual bool pretranslate_message(MSG * p_msg) = 0; +}; + +class NOVTABLE idle_handler { +public: + virtual bool on_idle() = 0; +}; + +class NOVTABLE message_loop : public service_base +{ +public: + virtual void add_message_filter(message_filter * ptr) = 0; + virtual void remove_message_filter(message_filter * ptr) = 0; + + virtual void add_idle_handler(idle_handler * ptr) = 0; + virtual void remove_idle_handler(idle_handler * ptr) = 0; + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(message_loop); +}; + +class NOVTABLE message_loop_v2 : public message_loop { +public: + virtual void add_message_filter_ex(message_filter * ptr, t_uint32 lowest, t_uint32 highest) = 0; + + FB2K_MAKE_SERVICE_INTERFACE(message_loop_v2, message_loop); +}; + +class message_filter_impl_base : public message_filter { +public: + message_filter_impl_base() {static_api_ptr_t()->add_message_filter(this);} + message_filter_impl_base(t_uint32 lowest, t_uint32 highest) { + static_api_ptr_t api; + message_loop_v2::ptr apiV2; + if (api->service_query_t(apiV2)) { + apiV2->add_message_filter_ex(this, lowest, highest); + } else { + api->add_message_filter(this); + } + } + ~message_filter_impl_base() {static_api_ptr_t()->remove_message_filter(this);} + bool pretranslate_message(MSG * p_msg) {return false;} + + PFC_CLASS_NOT_COPYABLE(message_filter_impl_base,message_filter_impl_base); +}; + +class message_filter_impl_accel : public message_filter_impl_base { +protected: + bool pretranslate_message(MSG * p_msg) { + if (m_wnd != NULL) { + if (GetActiveWindow() == m_wnd) { + if (TranslateAccelerator(m_wnd,m_accel.get(),p_msg) != 0) { + return true; + } + } + } + return false; + } +public: + message_filter_impl_accel(HINSTANCE p_instance,const TCHAR * p_accel) : m_wnd(NULL) { + m_accel.load(p_instance,p_accel); + } + void set_wnd(HWND p_wnd) {m_wnd = p_wnd;} +private: + HWND m_wnd; + win32_accelerator m_accel; + + PFC_CLASS_NOT_COPYABLE(message_filter_impl_accel,message_filter_impl_accel); +}; + +class idle_handler_impl_base : public idle_handler { +public: + idle_handler_impl_base() {static_api_ptr_t()->add_idle_handler(this);} + ~idle_handler_impl_base() {static_api_ptr_t()->remove_idle_handler(this);} + bool on_idle() {return true;} + + PFC_CLASS_NOT_COPYABLE_EX(idle_handler_impl_base) +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/metadb.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/metadb.cpp new file mode 100644 index 000000000..3fc8689b2 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/metadb.cpp @@ -0,0 +1,76 @@ +#include "foobar2000.h" + + +void metadb::handle_create_replace_path_canonical(metadb_handle_ptr & p_out,const metadb_handle_ptr & p_source,const char * p_new_path) { + handle_create(p_out,make_playable_location(p_new_path,p_source->get_subsong_index())); +} + +void metadb::handle_create_replace_path(metadb_handle_ptr & p_out,const metadb_handle_ptr & p_source,const char * p_new_path) { + pfc::string8 path; + filesystem::g_get_canonical_path(p_new_path,path); + handle_create_replace_path_canonical(p_out,p_source,path); +} + +void metadb::handle_replace_path_canonical(metadb_handle_ptr & p_out,const char * p_new_path) { + metadb_handle_ptr temp; + handle_create_replace_path_canonical(temp,p_out,p_new_path); + p_out = temp; +} + + +metadb_io::t_load_info_state metadb_io::load_info(metadb_handle_ptr p_item,t_load_info_type p_type,HWND p_parent_window,bool p_show_errors) { + return load_info_multi(pfc::list_single_ref_t(p_item),p_type,p_parent_window,p_show_errors); +} + +metadb_io::t_update_info_state metadb_io::update_info(metadb_handle_ptr p_item,file_info & p_info,HWND p_parent_window,bool p_show_errors) +{ + file_info * blah = &p_info; + return update_info_multi(pfc::list_single_ref_t(p_item),pfc::list_single_ref_t(blah),p_parent_window,p_show_errors); +} + + +void metadb_io::hint_async(metadb_handle_ptr p_item,const file_info & p_info,const t_filestats & p_stats,bool p_fresh) +{ + const file_info * blargh = &p_info; + hint_multi_async(pfc::list_single_ref_t(p_item),pfc::list_single_ref_t(blargh),pfc::list_single_ref_t(p_stats),bit_array_val(p_fresh)); +} + + +bool metadb::g_get_random_handle(metadb_handle_ptr & p_out) { + if (static_api_ptr_t()->get_now_playing(p_out)) return true; + + { + static_api_ptr_t api; + + t_size playlist_count = api->get_playlist_count(); + t_size active_playlist = api->get_active_playlist(); + if (active_playlist != infinite) { + if (api->playlist_get_focus_item_handle(p_out,active_playlist)) return true; + } + + for(t_size n = 0; n < playlist_count; n++) { + if (api->playlist_get_focus_item_handle(p_out,n)) return true; + } + + if (active_playlist != infinite) { + t_size item_count = api->playlist_get_item_count(active_playlist); + if (item_count > 0) { + if (api->playlist_get_item_handle(p_out,active_playlist,0)) return true; + } + } + + for(t_size n = 0; n < playlist_count; n++) { + t_size item_count = api->playlist_get_item_count(n); + if (item_count > 0) { + if (api->playlist_get_item_handle(p_out,n,0)) return true; + } + } + } + + return false; +} + + +void metadb_io_v2::update_info_async_simple(const pfc::list_base_const_t & p_list,const pfc::list_base_const_t & p_new_info, HWND p_parent_window,t_uint32 p_op_flags,completion_notify_ptr p_notify) { + update_info_async(p_list,new service_impl_t(p_list,p_new_info),p_parent_window,p_op_flags,p_notify); +} \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/metadb.h b/tools/vio2sf/src/foobar/foobar2000/SDK/metadb.h new file mode 100644 index 000000000..7b1495f8a --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/metadb.h @@ -0,0 +1,312 @@ +//! API for tag read/write operations. Legal to call from main thread only, except for hint_multi_async() / hint_async() / hint_reader().\n +//! Implemented only by core, do not reimplement.\n +//! Use static_api_ptr_t template to access metadb_io methods.\n +//! WARNING: Methods that perform file access (tag reads/writes) run a modal message loop. They SHOULD NOT be called from global callbacks and such. +class NOVTABLE metadb_io : public service_base +{ +public: + enum t_load_info_type { + load_info_default, + load_info_force, + load_info_check_if_changed + }; + + enum t_update_info_state { + update_info_success, + update_info_aborted, + update_info_errors, + }; + + enum t_load_info_state { + load_info_success, + load_info_aborted, + load_info_errors, + }; + + //! No longer use - returns false always. + __declspec(deprecated) virtual bool is_busy() = 0; + //! No longer used - returns false always. + __declspec(deprecated) virtual bool is_updating_disabled() = 0; + //! No longer used - returns false always. + __declspec(deprecated) virtual bool is_file_updating_blocked() = 0; + //! No longer used. + __declspec(deprecated) virtual void highlight_running_process() = 0; + //! Loads tags from multiple items. Use the async version in metadb_io_v2 instead if possible. + __declspec(deprecated) virtual t_load_info_state load_info_multi(metadb_handle_list_cref p_list,t_load_info_type p_type,HWND p_parent_window,bool p_show_errors) = 0; + //! Updates tags on multiple items. Use the async version in metadb_io_v2 instead if possible. + __declspec(deprecated) virtual t_update_info_state update_info_multi(metadb_handle_list_cref p_list,const pfc::list_base_const_t & p_new_info,HWND p_parent_window,bool p_show_errors) = 0; + //! Rewrites tags on multiple items. Use the async version in metadb_io_v2 instead if possible. + __declspec(deprecated) virtual t_update_info_state rewrite_info_multi(metadb_handle_list_cref p_list,HWND p_parent_window,bool p_show_errors) = 0; + //! Removes tags from multiple items. Use the async version in metadb_io_v2 instead if possible. + __declspec(deprecated) virtual t_update_info_state remove_info_multi(metadb_handle_list_cref p_list,HWND p_parent_window,bool p_show_errors) = 0; + + virtual void hint_multi(metadb_handle_list_cref p_list,const pfc::list_base_const_t & p_infos,const pfc::list_base_const_t & p_stats,const bit_array & p_fresh_mask) = 0; + + virtual void hint_multi_async(metadb_handle_list_cref p_list,const pfc::list_base_const_t & p_infos,const pfc::list_base_const_t & p_stats,const bit_array & p_fresh_mask) = 0; + + virtual void hint_reader(service_ptr_t p_reader,const char * p_path,abort_callback & p_abort) = 0; + + //! For internal use only. + virtual void path_to_handles_simple(const char * p_path, metadb_handle_list_ref p_out) = 0; + + //! Dispatches metadb_io_callback calls with specified items. To be used with metadb_display_field_provider when your component needs specified items refreshed. + virtual void dispatch_refresh(metadb_handle_list_cref p_list) = 0; + + void dispatch_refresh(metadb_handle_ptr const & handle) {dispatch_refresh(pfc::list_single_ref_t(handle));} + + void hint_async(metadb_handle_ptr p_item,const file_info & p_info,const t_filestats & p_stats,bool p_fresh); + + __declspec(deprecated) t_load_info_state load_info(metadb_handle_ptr p_item,t_load_info_type p_type,HWND p_parent_window,bool p_show_errors); + __declspec(deprecated) t_update_info_state update_info(metadb_handle_ptr p_item,file_info & p_info,HWND p_parent_window,bool p_show_errors); + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(metadb_io); +}; + +//! Implementing this class gives you direct control over which part of file_info gets altered during a tag update uperation. To be used with metadb_io_v2::update_info_async(). +class NOVTABLE file_info_filter : public service_base { +public: + //! Alters specified file_info entry; called as a part of tag update process. Specified file_info has been read from a file, and will be written back.\n + //! WARNING: This will be typically called from another thread than main app thread (precisely, from thread created by tag updater). You should copy all relevant data to members of your file_info_filter instance in constructor and reference only member data in apply_filter() implementation. + //! @returns True when you have altered file_info and changes need to be written back to the file; false if no changes have been made. + virtual bool apply_filter(metadb_handle_ptr p_location,t_filestats p_stats,file_info & p_info) = 0; + + FB2K_MAKE_SERVICE_INTERFACE(file_info_filter,service_base); +}; + +//! Advanced interface for passing infos read from files to metadb backend. Use metadb_io_v2::create_hint_list() to instantiate. +class NOVTABLE metadb_hint_list : public service_base { +public: + //! Adds a hint to the list. + //! @param p_location Location of the item the hint applies to. + //! @param p_info file_info object describing the item. + //! @param p_stats Information about the file containing item the hint applies to. + //! @param p_freshflag Set to true if the info has been directly read from the file, false if it comes from another source such as a playlist file. + virtual void add_hint(metadb_handle_ptr const & p_location,const file_info & p_info,const t_filestats & p_stats,bool p_freshflag) = 0; + //! Reads info from specified info reader instance and adds hints. May throw an exception in case info read has failed. + virtual void add_hint_reader(const char * p_path,service_ptr_t const & p_reader,abort_callback & p_abort) = 0; + //! Call this when you're done working with this metadb_hint_list instance, to apply hints and dispatch callbacks. If you don't call this, all added hints will be ignored. + virtual void on_done() = 0; + + FB2K_MAKE_SERVICE_INTERFACE(metadb_hint_list,service_base); +}; + +//! New in 0.9.3. Extends metadb_io functionality with nonblocking versions of tag read/write functions, and some other utility features. +class NOVTABLE metadb_io_v2 : public metadb_io { +public: + enum { + //! By default, when some part of requested operation could not be performed for reasons other than user abort, a popup dialog with description of the problem is spawned.\n + //! Set this flag to disable error notification. + op_flag_no_errors = 1 << 0, + //! Set this flag to make the progress dialog not steal focus on creation. + op_flag_background = 1 << 1, + //! Set this flag to delay the progress dialog becoming visible, so it does not appear at all during short operations. Also implies op_flag_background effect. + op_flag_delay_ui = 1 << 2, + }; + + //! Preloads information from the specified tracks. + //! @param p_list List of items to process. + //! @param p_op_flags Can be null, or one or more of op_flag_* enum values combined, altering behaviors of the operation. + //! @param p_notify Called when the task is completed. Status code is one of t_load_info_state values. Can be null if caller doesn't care. + virtual void load_info_async(metadb_handle_list_cref p_list,t_load_info_type p_type,HWND p_parent_window,t_uint32 p_op_flags,completion_notify_ptr p_notify) = 0; + //! Updates tags of the specified tracks. + //! @param p_list List of items to process. + //! @param p_op_flags Can be null, or one or more of op_flag_* enum values combined, altering behaviors of the operation. + //! @param p_notify Called when the task is completed. Status code is one of t_update_info values. Can be null if caller doesn't care. + //! @param p_filter Callback handling actual file_info alterations. Typically used to replace entire meta part of file_info, or to alter something else such as ReplayGain while leaving meta intact. + virtual void update_info_async(metadb_handle_list_cref p_list,service_ptr_t p_filter,HWND p_parent_window,t_uint32 p_op_flags,completion_notify_ptr p_notify) = 0; + //! Rewrites tags of the specified tracks; similar to update_info_async() but using last known/cached file_info values rather than values passed by caller. + //! @param p_list List of items to process. + //! @param p_op_flags Can be null, or one or more of op_flag_* enum values combined, altering behaviors of the operation. + //! @param p_notify Called when the task is completed. Status code is one of t_update_info values. Can be null if caller doesn't care. + virtual void rewrite_info_async(metadb_handle_list_cref p_list,HWND p_parent_window,t_uint32 p_op_flags,completion_notify_ptr p_notify) = 0; + //! Strips all tags / metadata fields from the specified tracks. + //! @param p_list List of items to process. + //! @param p_op_flags Can be null, or one or more of op_flag_* enum values combined, altering behaviors of the operation. + //! @param p_notify Called when the task is completed. Status code is one of t_update_info values. Can be null if caller doesn't care. + virtual void remove_info_async(metadb_handle_list_cref p_list,HWND p_parent_window,t_uint32 p_op_flags,completion_notify_ptr p_notify) = 0; + + //! Creates a metadb_hint_list object. + virtual metadb_hint_list::ptr create_hint_list() = 0; + + //! Updates tags of the specified tracks. Helper; uses update_info_async internally. + //! @param p_list List of items to process. + //! @param p_op_flags Can be null, or one or more of op_flag_* enum values combined, altering behaviors of the operation. + //! @param p_notify Called when the task is completed. Status code is one of t_update_info values. Can be null if caller doesn't care. + //! @param p_new_info New infos to write to specified items. + void update_info_async_simple(metadb_handle_list_cref p_list,const pfc::list_base_const_t & p_new_info, HWND p_parent_window,t_uint32 p_op_flags,completion_notify_ptr p_notify); + + FB2K_MAKE_SERVICE_INTERFACE(metadb_io_v2,metadb_io); +}; + + +//! Dynamically-registered version of metadb_io_callback. See metadb_io_callback for documentation, register instances using metadb_io_v3::register_callback(). It's recommended that you use the metadb_io_callback_dynamic_impl_base helper class to manage registration/unregistration. +class NOVTABLE metadb_io_callback_dynamic { +public: + virtual void on_changed_sorted(metadb_handle_list_cref p_items_sorted, bool p_fromhook) = 0; +}; + +//! New (0.9.5) +class NOVTABLE metadb_io_v3 : public metadb_io_v2 { +public: + virtual void register_callback(metadb_io_callback_dynamic * p_callback) = 0; + virtual void unregister_callback(metadb_io_callback_dynamic * p_callback) = 0; + + FB2K_MAKE_SERVICE_INTERFACE(metadb_io_v3,metadb_io_v2); +}; + +//! metadb_io_callback_dynamic implementation helper. +class metadb_io_callback_dynamic_impl_base : public metadb_io_callback_dynamic { +public: + void on_changed_sorted(metadb_handle_list_cref p_items_sorted, bool p_fromhook) {} + + metadb_io_callback_dynamic_impl_base() {static_api_ptr_t()->register_callback(this);} + ~metadb_io_callback_dynamic_impl_base() {static_api_ptr_t()->unregister_callback(this);} + + PFC_CLASS_NOT_COPYABLE_EX(metadb_io_callback_dynamic_impl_base) +}; +//! Callback service receiving notifications about metadb contents changes. +class NOVTABLE metadb_io_callback : public service_base { +public: + //! Called when metadb contents change. (Or, one of display hook component requests display update). + //! @param p_items_sorted List of items that have been updated. The list is always sorted by pointer value, to allow fast bsearch to test whether specific item has changed. + //! @param p_fromhook Set to true when actual file contents haven't changed but one of metadb_display_field_provider implementations requested an update so output of metadb_handle::format_title() etc has changed. + virtual void on_changed_sorted(metadb_handle_list_cref p_items_sorted, bool p_fromhook) = 0; + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(metadb_io_callback); +}; + +//! Entrypoint service for metadb_handle related operations.\n +//! Implemented only by core, do not reimplement.\n +//! Use static_api_ptr_t template to access it, e.g. static_api_ptr_t()->handle_create(myhandle,mylocation); +class NOVTABLE metadb : public service_base +{ +public: + //! Locks metadb to prevent other threads from modifying it while you're working with some of its contents. Some functions (metadb_handle::get_info_locked(), metadb_handle::get_info_async_locked()) can be called only from inside metadb lock section. + virtual void database_lock()=0; + //! Unlocks metadb after database_lock(). Some functions (metadb_handle::get_info_locked(), metadb_handle::get_info_async_locked()) can be called only from inside metadb lock section. + virtual void database_unlock()=0; + + //! Returns a metadb_handle object referencing the specified location. If one doesn't exist yet a new one is created. There can be only one metadb_handle object referencing specific location. \n + //! This function should never fail unless there's something critically wrong (can't allocate memory for the new object, etc). \n + //! Speed: O(log(n)) to total number of metadb_handles present. It's recommended to pass metadb_handles around whenever possible rather than pass playable_locations then retrieve metadb_handles on demand when needed. + //! @param p_out Receives the metadb_handle pointer. + //! @param p_location Location to create a metadb_handle for. + virtual void handle_create(metadb_handle_ptr & p_out,const playable_location & p_location)=0; + + void handle_create_replace_path_canonical(metadb_handle_ptr & p_out,const metadb_handle_ptr & p_source,const char * p_new_path); + void handle_replace_path_canonical(metadb_handle_ptr & p_out,const char * p_new_path); + void handle_create_replace_path(metadb_handle_ptr & p_out,const metadb_handle_ptr & p_source,const char * p_new_path); + + //! Helper function; attempts to retrieve a handle to any known playable location to be used for e.g. titleformatting script preview.\n + //! @returns True on success; false on failure (no known playable locations). + static bool g_get_random_handle(metadb_handle_ptr & p_out); + + enum {case_sensitive = true}; + typedef pfc::comparator_strcmp path_comparator; + + inline static int path_compare_ex(const char * p1,t_size len1,const char * p2,t_size len2) {return case_sensitive ? pfc::strcmp_ex(p1,len1,p2,len2) : stricmp_utf8_ex(p1,len1,p2,len2);} + inline static int path_compare(const char * p1,const char * p2) {return case_sensitive ? strcmp(p1,p2) : stricmp_utf8(p1,p2);} + inline static int path_compare_metadb_handle(const metadb_handle_ptr & p1,const metadb_handle_ptr & p2) {return path_compare(p1->get_path(),p2->get_path());} + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(metadb); +}; + +//! Metadb lock sync helper. For use around metadb_handle "locked" methods. +class in_metadb_sync { +public: + in_metadb_sync() { + m_api->database_lock(); + } + ~in_metadb_sync() { + m_api->database_unlock(); + } +private: + static_api_ptr_t m_api; +}; + +//! Metadb lock sync helper. For use around metadb_handle "locked" methods. +class in_metadb_sync_fromptr { +public: + in_metadb_sync_fromptr(const service_ptr_t & p_api) : m_api(p_api) {m_api->database_lock();} + ~in_metadb_sync_fromptr() {m_api->database_unlock();} +private: + service_ptr_t m_api; +}; + +//! Metadb lock sync helper. For use around metadb_handle "locked" methods. +class in_metadb_sync_fromhandle { +public: + in_metadb_sync_fromhandle(const service_ptr_t & p_api) : m_api(p_api) {m_api->metadb_lock();} + ~in_metadb_sync_fromhandle() {m_api->metadb_unlock();} +private: + service_ptr_t m_api; +}; + +class titleformat_text_out; +class titleformat_hook_function_params; + + +/*! + Implementing this service lets you provide your own title-formatting fields that are parsed globally with each call to metadb_handle::format_title methods. \n + This should be implemented only where absolutely necessary, for safety and performance reasons. Any expensive operations inside the process_field() method may severely damage performance of affected title-formatting calls. \n + You must NEVER make any other foobar2000 API calls from inside process_field, other than possibly querying information from the passed metadb_handle pointer; you should read your own implementation-specific private data and return as soon as possible. You must not make any assumptions about calling context (threading etc). \n + It is guaranteed that process_field() is called only inside a metadb lock scope so you can safely call "locked" metadb_handle methods on the metadb_handle pointer you get. You must not lock metadb by yourself inside process_field() - while it is always called from inside a metadb lock scope, it may be called from another thread than the one maintaining the lock because of multi-CPU optimizations active. \n + If there are multiple metadb_display_field_provider services registered providing fields of the same name, which one gets called is undefined. \n + IMPORTANT: Any components implementing metadb_display_field_provider MUST call metadb_io::dispatch_refresh() with affected metadb_handles whenever info that they present changes. Otherwise, anything rendering title-formatting strings that reference your data will not update properly, resulting in unreliable/broken output, repaint glitches, etc. \n + Do not expect a process_field() call each time somebody uses title formatting, calling code might perform its own caching of strings that you return, getting new ones only after metadb_io::dispatch_refresh() with relevant items. \n + If you can't reliably notify other components about changes of content of fields that you provide (such as when your fields provide some kind of global information and not information specific to item identified by passed metadb_handle), you should not be providing those fields in first place. You must not change returned values of your fields without dispatching appropriate notifications. \n + Use static service_factory_single_t to register your metadb_display_field_provider implementations. Do not call other people's metadb_display_field_provider services directly, they're meant to be called by backend only. \n + List of fields that you provide is expected to be fixed at run-time. The backend will enumerate your fields only once and refer to them by indexes later. \n +*/ + +class NOVTABLE metadb_display_field_provider : public service_base { +public: + //! Returns number of fields provided by this metadb_display_field_provider implementation. + virtual t_uint32 get_field_count() = 0; + //! Returns name of specified field provided by this metadb_display_field_provider implementation. Names are not case sensitive. It's strongly recommended that you keep your field names plain English / ASCII only. + virtual void get_field_name(t_uint32 index, pfc::string_base & out) = 0; + //! Evaluates the specified field. + //! @param index Index of field being processed : 0 <= index < get_field_count(). + //! @param handle Handle to item being processed. You can safely call "locked" methods on this handle to retrieve track information and such. + //! @param out Interface receiving your text output. + //! @returns Return true to indicate that the field is present so if it's enclosed in square brackets, contents of those brackets should not be skipped, false otherwise. + virtual bool process_field(t_uint32 index, metadb_handle * handle, titleformat_text_out * out) = 0; + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(metadb_display_field_provider); +}; + + + + + +//! Helper implementation of file_info_filter_impl. +class file_info_filter_impl : public file_info_filter { +public: + file_info_filter_impl(const pfc::list_base_const_t & p_list,const pfc::list_base_const_t & p_new_info) { + pfc::dynamic_assert(p_list.get_count() == p_new_info.get_count()); + pfc::array_t order; + order.set_size(p_list.get_count()); + order_helper::g_fill(order.get_ptr(),order.get_size()); + p_list.sort_get_permutation_t(pfc::compare_t,order.get_ptr()); + m_handles.set_count(order.get_size()); + m_infos.set_size(order.get_size()); + for(t_size n = 0; n < order.get_size(); n++) { + m_handles[n] = p_list[order[n]]; + m_infos[n] = *p_new_info[order[n]]; + } + } + + bool apply_filter(metadb_handle_ptr p_location,t_filestats p_stats,file_info & p_info) { + t_size index; + if (m_handles.bsearch_t(pfc::compare_t,p_location,index)) { + p_info = m_infos[index]; + return true; + } else { + return false; + } + } +private: + metadb_handle_list m_handles; + pfc::array_t m_infos; +}; + diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/metadb_handle.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/metadb_handle.cpp new file mode 100644 index 000000000..71fd8ae05 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/metadb_handle.cpp @@ -0,0 +1,48 @@ +#include "foobar2000.h" + + +double metadb_handle::get_length() +{ + double rv = 0; + in_metadb_sync_fromhandle l_sync(this); + const file_info * info; + if (get_info_locked(info)) + rv = info->get_length(); + return rv; +} + +t_filetimestamp metadb_handle::get_filetimestamp() +{ + return get_filestats().m_timestamp; +} + +t_filesize metadb_handle::get_filesize() +{ + return get_filestats().m_size; +} + +bool metadb_handle::format_title_legacy(titleformat_hook * p_hook,pfc::string_base & p_out,const char * p_spec,titleformat_text_filter * p_filter) +{ + service_ptr_t script; + if (static_api_ptr_t()->compile(script,p_spec)) { + return format_title(p_hook,p_out,script,p_filter); + } else { + p_out.reset(); + return false; + } +} + + + +bool metadb_handle::g_should_reload(const t_filestats & p_old_stats,const t_filestats & p_new_stats,bool p_fresh) +{ + if (p_new_stats.m_timestamp == filetimestamp_invalid) return p_fresh; + else if (p_fresh) return p_old_stats!= p_new_stats; + else return p_old_stats.m_timestamp < p_new_stats.m_timestamp; +} + +bool metadb_handle::should_reload(const t_filestats & p_new_stats, bool p_fresh) const +{ + if (!is_info_loaded_async()) return true; + else return g_should_reload(get_filestats(),p_new_stats,p_fresh); +} \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/metadb_handle.h b/tools/vio2sf/src/foobar/foobar2000/SDK/metadb_handle.h new file mode 100644 index 000000000..35d6363d9 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/metadb_handle.h @@ -0,0 +1,207 @@ +class titleformat_hook; +class titleformat_text_filter; + +//! A metadb_handle object represents interface to reference-counted file_info cache entry for the specified location.\n +//! To obtain a metadb_handle to specific location, use metadb::handle_create(). To obtain a list of metadb_handle objects corresponding to specific path (directory, playlist, multitrack file, etc), use relevant playlist_incoming_item_filter methods (recommended), or call playlist_loader methods directly.\n +//! A metadb_handle is also the most efficient way of passing playable object locations around because it provides fast access to both location and infos, and is reference counted so duplicating it is as fast as possible.\n +//! To retrieve a path of a file from a metadb_handle, use metadb_handle::get_path() function. Note that metadb_handle is NOT just file path, some formats support multiple subsongs per physical file, which are signaled using subsong indexes. + +class NOVTABLE metadb_handle : public service_base +{ +public: + //! Retrieves location represented by this metadb_handle object. Returned reference is valid until calling context releases metadb_handle that returned it (metadb_handle_ptr is deallocated etc). + virtual const playable_location & get_location() const = 0;//never fails, returned pointer valid till the object is released + + + //! Renders information about item referenced by this metadb_handle object. + //! @param p_hook Optional callback object overriding fields and functions; set to NULL if not used. + //! @param p_out String receiving the output on success. + //! @param p_script Titleformat script to use. Use titleformat_compiler service to create one. + //! @param p_filter Optional callback object allowing input to be filtered according to context (i.e. removal of linebreak characters present in tags when rendering playlist lines). Set to NULL when not used. + //! @returns true on success, false when dummy file_info instance was used because actual info is was not (yet) known. + virtual bool format_title(titleformat_hook * p_hook,pfc::string_base & p_out,const service_ptr_t & p_script,titleformat_text_filter * p_filter) = 0; + + //! Locks metadb to prevent other threads from modifying it while you're working with some of its contents. Some functions (metadb_handle::get_info_locked(), metadb_handle::get_info_async_locked()) can be called only from inside metadb lock section. + //! Same as metadb::database_lock(). + virtual void metadb_lock() = 0; + //! Unlocks metadb after metadb_lock(). Some functions (metadb_handle::get_info_locked(), metadb_handle::get_info_async_locked()) can be called only from inside metadb lock section. + //! Same as metadb::database_unlock(). + virtual void metadb_unlock() = 0; + + //! Returns last seen file stats, filestats_invalid if unknown. + virtual t_filestats get_filestats() const = 0; + + //! Queries whether cached info about item referenced by this metadb_handle object is already available.\n + //! Note that state of cached info changes only inside main thread, so you can safely assume that it doesn't change while some block of your code inside main thread is being executed. + virtual bool is_info_loaded() const = 0; + //! Queries cached info about item referenced by this metadb_handle object. Returns true on success, false when info is not yet known.\n + //! Note that state of cached info changes only inside main thread, so you can safely assume that it doesn't change while some block of your code inside main thread is being executed. + virtual bool get_info(file_info & p_info) const = 0; + //! Queries cached info about item referenced by this metadb_handle object. Returns true on success, false when info is not yet known. This is more efficient than get_info() since no data is copied.\n + //! You must lock the metadb before calling this function, and unlock it after you are done working with the returned pointer, to ensure multithread safety.\n + //! Note that state of cached info changes only inside main thread, so you can safely assume that it doesn't change while some block of your code inside main thread is being executed. + //! @param p_info On success, receives a pointer to metadb's file_info object. The pointer is for temporary use only, and becomes invalid when metadb is unlocked. + virtual bool get_info_locked(const file_info * & p_info) const = 0; + + //! Queries whether cached info about item referenced by this metadb_handle object is already available.\n + //! This is intended for use in special cases when you need to immediately retrieve info sent by metadb_io hint from another thread; state of returned data can be altered by any thread, as opposed to non-async methods. + virtual bool is_info_loaded_async() const = 0; + //! Queries cached info about item referenced by this metadb_handle object. Returns true on success, false when info is not yet known.\n + //! This is intended for use in special cases when you need to immediately retrieve info sent by metadb_io hint from another thread; state of returned data can be altered by any thread, as opposed to non-async methods. + virtual bool get_info_async(file_info & p_info) const = 0; + //! Queries cached info about item referenced by this metadb_handle object. Returns true on success, false when info is not yet known. This is more efficient than get_info() since no data is copied.\n + //! You must lock the metadb before calling this function, and unlock it after you are done working with the returned pointer, to ensure multithread safety.\n + //! This is intended for use in special cases when you need to immediately retrieve info sent by metadb_io hint from another thread; state of returned data can be altered by any thread, as opposed to non-async methods. + //! @param p_info On success, receives a pointer to metadb's file_info object. The pointer is for temporary use only, and becomes invalid when metadb is unlocked. + virtual bool get_info_async_locked(const file_info * & p_info) const = 0; + + + //! Renders information about item referenced by this metadb_handle object, using external file_info data. + virtual void format_title_from_external_info(const file_info & p_info,titleformat_hook * p_hook,pfc::string_base & p_out,const service_ptr_t & p_script,titleformat_text_filter * p_filter) = 0; + + + //! New in 0.9.5. + virtual bool format_title_nonlocking(titleformat_hook * p_hook,pfc::string_base & p_out,const service_ptr_t & p_script,titleformat_text_filter * p_filter) = 0; + + //! New in 0.9.5. + virtual void format_title_from_external_info_nonlocking(const file_info & p_info,titleformat_hook * p_hook,pfc::string_base & p_out,const service_ptr_t & p_script,titleformat_text_filter * p_filter) = 0; + + static bool g_should_reload(const t_filestats & p_old_stats,const t_filestats & p_new_stats,bool p_fresh); + bool should_reload(const t_filestats & p_new_stats,bool p_fresh) const; + + + //! Helper provided for backwards compatibility; takes formatting script as text string and calls relevant titleformat_compiler methods; returns false when the script could not be compiled.\n + //! See format_title() for descriptions of parameters.\n + //! Bottleneck warning: you should consider using precompiled titleformat script object and calling regular format_title() instead when processing large numbers of items. + bool format_title_legacy(titleformat_hook * p_hook,pfc::string_base & out,const char * p_spec,titleformat_text_filter * p_filter); + + //! Retrieves path of item described by this metadb_handle instance. Returned string is valid until calling context releases metadb_handle that returned it (metadb_handle_ptr is deallocated etc). + inline const char * get_path() const {return get_location().get_path();} + //! Retrieves subsong index of item described by this metadb_handle instance (used for multiple playable tracks within single physical file). + inline t_uint32 get_subsong_index() const {return get_location().get_subsong_index();} + + double get_length();//helper + + t_filetimestamp get_filetimestamp(); + t_filesize get_filesize(); + + FB2K_MAKE_SERVICE_INTERFACE(metadb_handle,service_base); +}; + +typedef service_ptr_t metadb_handle_ptr; + +typedef pfc::list_base_t & metadb_handle_list_ref; +typedef pfc::list_base_const_t const & metadb_handle_list_cref; + +namespace metadb_handle_list_helper { + void sort_by_format(metadb_handle_list_ref p_list,const char * spec,titleformat_hook * p_hook); + void sort_by_format_get_order(metadb_handle_list_cref p_list,t_size* order,const char * spec,titleformat_hook * p_hook); + void sort_by_format(metadb_handle_list_ref p_list,const service_ptr_t & p_script,titleformat_hook * p_hook, int direction = 1); + void sort_by_format_get_order(metadb_handle_list_cref p_list,t_size* order,const service_ptr_t & p_script,titleformat_hook * p_hook,int p_direction = 1); + + void sort_by_relative_path(metadb_handle_list_ref p_list); + void sort_by_relative_path_get_order(metadb_handle_list_cref p_list,t_size* order); + + void remove_duplicates(pfc::list_base_t & p_list); + void sort_by_pointer_remove_duplicates(pfc::list_base_t & p_list); + void sort_by_path_quick(pfc::list_base_t & p_list); + + void sort_by_pointer(pfc::list_base_t & p_list); + t_size bsearch_by_pointer(const pfc::list_base_const_t & p_list,const metadb_handle_ptr & val); + + double calc_total_duration(const pfc::list_base_const_t & p_list); + + void sort_by_path(pfc::list_base_t & p_list); + + t_filesize calc_total_size(metadb_handle_list_cref list, bool skipUnknown = false); + t_filesize calc_total_size_ex(metadb_handle_list_cref list, bool & foundUnknown); +}; + +template class t_alloc = pfc::alloc_fast > +class metadb_handle_list_t : public service_list_t { +private: + typedef metadb_handle_list_t t_self; + typedef list_base_const_t t_interface; +public: + inline void sort_by_format(const char * spec,titleformat_hook * p_hook) { + return metadb_handle_list_helper::sort_by_format(*this, spec, p_hook); + } + inline void sort_by_format_get_order(t_size* order,const char * spec,titleformat_hook * p_hook) const { + metadb_handle_list_helper::sort_by_format_get_order(*this, order, spec, p_hook); + } + + inline void sort_by_format(const service_ptr_t & p_script,titleformat_hook * p_hook, int direction = 1) { + metadb_handle_list_helper::sort_by_format(*this, p_script, p_hook, direction); + } + inline void sort_by_format_get_order(t_size* order,const service_ptr_t & p_script,titleformat_hook * p_hook) const { + metadb_handle_list_helper::sort_by_format_get_order(*this, order, p_script, p_hook); + } + + inline void sort_by_relative_path() { + metadb_handle_list_helper::sort_by_relative_path(*this); + } + inline void sort_by_relative_path_get_order(t_size* order) const { + metadb_handle_list_helper::sort_by_relative_path_get_order(*this,order); + } + + inline void remove_duplicates() {metadb_handle_list_helper::remove_duplicates(*this);} + inline void sort_by_pointer_remove_duplicates() {metadb_handle_list_helper::sort_by_pointer_remove_duplicates(*this);} + inline void sort_by_path_quick() {metadb_handle_list_helper::sort_by_path_quick(*this);} + + inline void sort_by_pointer() {metadb_handle_list_helper::sort_by_pointer(*this);} + inline t_size bsearch_by_pointer(const metadb_handle_ptr & val) const {return metadb_handle_list_helper::bsearch_by_pointer(*this,val);} + + inline double calc_total_duration() const {return metadb_handle_list_helper::calc_total_duration(*this);} + + inline void sort_by_path() {metadb_handle_list_helper::sort_by_path(*this);} + + const t_self & operator=(const t_self & p_source) {remove_all(); add_items(p_source);return *this;} + const t_self & operator=(const t_interface & p_source) {remove_all(); add_items(p_source);return *this;} + metadb_handle_list_t(const t_self & p_source) {add_items(p_source);} + metadb_handle_list_t(const t_interface & p_source) {add_items(p_source);} + metadb_handle_list_t() {} + + t_self & operator+=(const t_interface & source) {add_items(source); return *this;} + t_self & operator+=(const metadb_handle_ptr & source) {add_item(source); return *this;} +}; + +typedef metadb_handle_list_t<> metadb_handle_list; + +namespace metadb_handle_list_helper { + void sorted_by_pointer_extract_difference(metadb_handle_list const & p_list_1,metadb_handle_list const & p_list_2,metadb_handle_list & p_list_1_specific,metadb_handle_list & p_list_2_specific); +}; + +class metadb_handle_lock +{ + metadb_handle_ptr m_ptr; +public: + inline metadb_handle_lock(const metadb_handle_ptr & param) + { + m_ptr = param; + m_ptr->metadb_lock(); + } + inline ~metadb_handle_lock() {m_ptr->metadb_unlock();} +}; + +inline pfc::string_base & operator<<(pfc::string_base & p_fmt,const metadb_handle_ptr & p_location) { + if (p_location.is_valid()) + return p_fmt << p_location->get_location(); + else + return p_fmt << "[invalid location]"; +} + + +class string_format_title { +public: + string_format_title(metadb_handle_ptr p_item,const char * p_script) { + p_item->format_title_legacy(NULL,m_data,p_script,NULL); + } + string_format_title(metadb_handle_ptr p_item,service_ptr_t p_script) { + p_item->format_title(NULL,m_data,p_script,NULL); + } + + const char * get_ptr() const {return m_data.get_ptr();} + operator const char * () const {return m_data.get_ptr();} +private: + pfc::string8_fastalloc m_data; +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/metadb_handle_list.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/metadb_handle_list.cpp new file mode 100644 index 000000000..dbf3be6ce --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/metadb_handle_list.cpp @@ -0,0 +1,386 @@ +#include "foobar2000.h" +#include + +namespace { + + wchar_t * makeSortString(const char * in) { + wchar_t * out = new wchar_t[pfc::stringcvt::estimate_utf8_to_wide(in) + 1]; + out[0] = ' ';//StrCmpLogicalW bug workaround. + pfc::stringcvt::convert_utf8_to_wide_unchecked(out + 1, in); + return out; + } + + struct custom_sort_data { + wchar_t * text; + t_size index; + }; +} + +template +static int custom_sort_compare(const custom_sort_data & elem1, const custom_sort_data & elem2 ) { + int ret = direction * StrCmpLogicalW(elem1.text,elem2.text); + if (ret == 0) ret = pfc::sgn_t((t_ssize)elem1.index - (t_ssize)elem2.index); + return ret; +} + + +template +static int _cdecl _custom_sort_compare(const void * v1, const void * v2) { + return custom_sort_compare(*reinterpret_cast(v1),*reinterpret_cast(v2)); +} +void metadb_handle_list_helper::sort_by_format(metadb_handle_list_ref p_list,const char * spec,titleformat_hook * p_hook) +{ + service_ptr_t script; + if (static_api_ptr_t()->compile(script,spec)) + sort_by_format(p_list,script,p_hook); +} + +void metadb_handle_list_helper::sort_by_format_get_order(metadb_handle_list_cref p_list,t_size* order,const char * spec,titleformat_hook * p_hook) +{ + service_ptr_t script; + if (static_api_ptr_t()->compile(script,spec)) + sort_by_format_get_order(p_list,order,script,p_hook); +} + +void metadb_handle_list_helper::sort_by_format(metadb_handle_list_ref p_list,const service_ptr_t & p_script,titleformat_hook * p_hook, int direction) +{ + const t_size count = p_list.get_count(); + pfc::array_t order; order.set_size(count); + sort_by_format_get_order(p_list,order.get_ptr(),p_script,p_hook,direction); + p_list.reorder(order.get_ptr()); +} + +namespace { + + class tfhook_sort : public titleformat_hook { + public: + tfhook_sort() { + m_API->seed((unsigned)__rdtsc()); + } + bool process_field(titleformat_text_out * p_out,const char * p_name,t_size p_name_length,bool & p_found_flag) { + return false; + } + bool process_function(titleformat_text_out * p_out,const char * p_name,t_size p_name_length,titleformat_hook_function_params * p_params,bool & p_found_flag) { + if (stricmp_utf8_ex(p_name, p_name_length, "rand", ~0) == 0) { + t_size param_count = p_params->get_param_count(); + t_uint32 val; + if (param_count == 1) { + t_uint32 mod = (t_uint32)p_params->get_param_uint(0); + if (mod > 0) { + val = m_API->genrand(mod); + } else { + val = 0; + } + } else { + val = m_API->genrand(0xFFFFFFFF); + } + p_out->write_int(titleformat_inputtypes::unknown, val); + p_found_flag = true; + return true; + } else { + return false; + } + } + private: + static_api_ptr_t m_API; + }; + + class tfthread : public pfc::thread { + public: + tfthread(pfc::counter * walk, metadb_handle_list_cref items,custom_sort_data * out,titleformat_object::ptr script,titleformat_hook * hook) : m_walk(walk), m_items(items), m_out(out), m_script(script), m_hook(hook) {} + ~tfthread() {waitTillDone();} + + + + void threadProc() { + TRACK_CALL_TEXT("metadb_handle sort helper thread"); + + tfhook_sort myHook; + titleformat_hook_impl_splitter hookSplitter(&myHook, m_hook); + titleformat_hook * const hookPtr = m_hook ? pfc::safe_cast(&hookSplitter) : &myHook; + + pfc::string8_fastalloc temp; temp.prealloc(512); + const t_size total = m_items.get_size(); + for(;;) { + const t_size index = (*m_walk)++; + if (index >= total) break; + m_out[index].index = index; + m_items[index]->format_title_nonlocking(hookPtr,temp,m_script,0); + m_out[index].text = makeSortString(temp); + } + } + private: + pfc::counter * const m_walk; + metadb_handle_list_cref m_items; + custom_sort_data * const m_out; + titleformat_object::ptr const m_script; + titleformat_hook * const m_hook; + }; +} + +void metadb_handle_list_helper::sort_by_format_get_order(metadb_handle_list_cref p_list,t_size* order,const service_ptr_t & p_script,titleformat_hook * p_hook,int p_direction) +{ +// pfc::hires_timer timer; timer.start(); + + const t_size count = p_list.get_count(); + pfc::array_t data; data.set_size(count); + + { + in_metadb_sync sync; + pfc::counter counter(0); + pfc::array_t > threads; threads.set_size(pfc::getOptimalWorkerThreadCountEx(p_list.get_count() / 128)); + PFC_ASSERT( threads.get_size() > 0 ); + for(t_size walk = 0; walk < threads.get_size(); ++walk) { + threads[walk].new_t(&counter,p_list,data.get_ptr(),p_script,p_hook); + } + for(t_size walk = 1; walk < threads.get_size(); ++walk) threads[walk]->start(); + threads[0]->threadProc(); + for(t_size walk = 1; walk < threads.get_size(); ++walk) threads[walk]->waitTillDone(); + } +// console::formatter() << "metadb_handle sort: prepared in " << pfc::format_time_ex(timer.query(),6); + + pfc::sort_t(data, p_direction > 0 ? custom_sort_compare<1> : custom_sort_compare<-1>,count); + //qsort(data.get_ptr(),count,sizeof(custom_sort_data),p_direction > 0 ? _custom_sort_compare<1> : _custom_sort_compare<-1>); + + +// console::formatter() << "metadb_handle sort: sorted in " << pfc::format_time_ex(timer.query(),6); + + for(t_size n=0;n order; order.set_size(count); + sort_by_relative_path_get_order(p_list,order.get_ptr()); + p_list.reorder(order.get_ptr()); +} + +void metadb_handle_list_helper::sort_by_relative_path_get_order(metadb_handle_list_cref p_list,t_size* order) +{ + const t_size count = p_list.get_count(); + t_size n; + pfc::array_t data; + data.set_size(count); + static_api_ptr_t api; + + pfc::string8_fastalloc temp; + temp.prealloc(512); + for(n=0;nget_relative_path(item,temp)) temp = ""; + data[n].index = n; + data[n].text = makeSortString(temp); + //data[n].subsong = item->get_subsong_index(); + } + + pfc::sort_t(data,custom_sort_compare<1>,count); + //qsort(data.get_ptr(),count,sizeof(custom_sort_data),(int (__cdecl *)(const void *elem1, const void *elem2 ))custom_sort_compare); + + for(n=0;n0) + { + bit_array_bittable mask(count); + pfc::array_t order; order.set_size(count); + order_helper::g_fill(order); + + p_list.sort_get_permutation_t(pfc::compare_t,order.get_ptr()); + + t_size n; + bool found = false; + for(n=0;n0) + { + sort_by_pointer(p_list); + bool b_found = false; + t_size n; + for(n=0;n); + p_list.sort(); +} + +t_size metadb_handle_list_helper::bsearch_by_pointer(metadb_handle_list_cref p_list,const metadb_handle_ptr & val) +{ + t_size blah; + if (p_list.bsearch_t(pfc::compare_t,val,blah)) return blah; + else return ~0; +} + + +void metadb_handle_list_helper::sorted_by_pointer_extract_difference(metadb_handle_list const & p_list_1,metadb_handle_list const & p_list_2,metadb_handle_list & p_list_1_specific,metadb_handle_list & p_list_2_specific) +{ + t_size found_1, found_2; + const t_size count_1 = p_list_1.get_count(), count_2 = p_list_2.get_count(); + t_size ptr_1, ptr_2; + + found_1 = found_2 = 0; + ptr_1 = ptr_2 = 0; + while(ptr_1 < count_1 || ptr_2 < count_2) + { + while(ptr_1 < count_1 && (ptr_2 == count_2 || p_list_1[ptr_1] < p_list_2[ptr_2])) + { + found_1++; + t_size ptr_1_new = ptr_1 + 1; + while(ptr_1_new < count_1 && p_list_1[ptr_1_new] == p_list_1[ptr_1]) ptr_1_new++; + ptr_1 = ptr_1_new; + } + while(ptr_2 < count_2 && (ptr_1 == count_1 || p_list_2[ptr_2] < p_list_1[ptr_1])) + { + found_2++; + t_size ptr_2_new = ptr_2 + 1; + while(ptr_2_new < count_2 && p_list_2[ptr_2_new] == p_list_2[ptr_2]) ptr_2_new++; + ptr_2 = ptr_2_new; + } + while(ptr_1 < count_1 && ptr_2 < count_2 && p_list_1[ptr_1] == p_list_2[ptr_2]) {ptr_1++; ptr_2++;} + } + + + + p_list_1_specific.set_count(found_1); + p_list_2_specific.set_count(found_2); + if (found_1 > 0 || found_2 > 0) + { + found_1 = found_2 = 0; + ptr_1 = ptr_2 = 0; + + while(ptr_1 < count_1 || ptr_2 < count_2) + { + while(ptr_1 < count_1 && (ptr_2 == count_2 || p_list_1[ptr_1] < p_list_2[ptr_2])) + { + p_list_1_specific[found_1++] = p_list_1[ptr_1]; + t_size ptr_1_new = ptr_1 + 1; + while(ptr_1_new < count_1 && p_list_1[ptr_1_new] == p_list_1[ptr_1]) ptr_1_new++; + ptr_1 = ptr_1_new; + } + while(ptr_2 < count_2 && (ptr_1 == count_1 || p_list_2[ptr_2] < p_list_1[ptr_1])) + { + p_list_2_specific[found_2++] = p_list_2[ptr_2]; + t_size ptr_2_new = ptr_2 + 1; + while(ptr_2_new < count_2 && p_list_2[ptr_2_new] == p_list_2[ptr_2]) ptr_2_new++; + ptr_2 = ptr_2_new; + } + while(ptr_1 < count_1 && ptr_2 < count_2 && p_list_1[ptr_1] == p_list_2[ptr_2]) {ptr_1++; ptr_2++;} + } + + } +} + +double metadb_handle_list_helper::calc_total_duration(metadb_handle_list_cref p_list) +{ + double ret = 0; + t_size n, m = p_list.get_count(); + for(n=0;nget_length(); + if (temp > 0) ret += temp; + } + return ret; +} + +void metadb_handle_list_helper::sort_by_path(metadb_handle_list_ref p_list) +{ + sort_by_format(p_list,"%path_sort%",NULL); +} + + +t_filesize metadb_handle_list_helper::calc_total_size(metadb_handle_list_cref p_list, bool skipUnknown) { + metadb_handle_list list(p_list); + list.sort_t(metadb::path_compare_metadb_handle); + + t_filesize ret = 0; + t_size n, m = list.get_count(); + for(n=0;nget_path(),list[n]->get_path())) { + t_filesize t = list[n]->get_filesize(); + if (t == filesize_invalid) { + if (!skipUnknown) return filesize_invalid; + } else { + ret += t; + } + } + } + return ret; +} + +t_filesize metadb_handle_list_helper::calc_total_size_ex(metadb_handle_list_cref p_list, bool & foundUnknown) { + foundUnknown = false; + metadb_handle_list list(p_list); + list.sort_t(metadb::path_compare_metadb_handle); + + t_filesize ret = 0; + t_size n, m = list.get_count(); + for(n=0;nget_path(),list[n]->get_path())) { + t_filesize t = list[n]->get_filesize(); + if (t == filesize_invalid) { + foundUnknown = true; + } else { + ret += t; + } + } + } + return ret; +} diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/modeless_dialog.h b/tools/vio2sf/src/foobar/foobar2000/SDK/modeless_dialog.h new file mode 100644 index 000000000..cc7d10d1f --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/modeless_dialog.h @@ -0,0 +1,17 @@ +//! Service for plugging your nonmodal dialog windows into main app loop to receive IsDialogMessage()-translated messages.\n +//! Note that all methods are valid from main app thread only.\n +//! Usage: static_api_ptr_t or modeless_dialog_manager::g_add / modeless_dialog_manager::g_remove. +class NOVTABLE modeless_dialog_manager : public service_base { + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(modeless_dialog_manager); +public: + //! Adds specified window to global list of windows to receive IsDialogMessage(). + virtual void add(HWND p_wnd) = 0; + //! Removes specified window from global list of windows to receive IsDialogMessage(). + virtual void remove(HWND p_wnd) = 0; + + //! Static helper; see add(). + static void g_add(HWND p_wnd) {static_api_ptr_t()->add(p_wnd);} + //! Static helper; see remove(). + static void g_remove(HWND p_wnd) {static_api_ptr_t()->remove(p_wnd);} + +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/ole_interaction.h b/tools/vio2sf/src/foobar/foobar2000/SDK/ole_interaction.h new file mode 100644 index 000000000..5159194bd --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/ole_interaction.h @@ -0,0 +1,149 @@ +class NOVTABLE playlist_dataobject_desc { +public: + virtual t_size get_entry_count() const = 0; + virtual void get_entry_name(t_size which, pfc::string_base & out) const = 0; + virtual void get_entry_content(t_size which, metadb_handle_list_ref out) const = 0; + + virtual void set_entry_count(t_size count) = 0; + virtual void set_entry_name(t_size which, const char * name) = 0; + virtual void set_entry_content(t_size which, metadb_handle_list_cref content) = 0; + + void copy(playlist_dataobject_desc const & source) { + const t_size count = source.get_entry_count(); set_entry_count(count); + metadb_handle_list content; pfc::string8 name; + for(t_size walk = 0; walk < count; ++walk) { + source.get_entry_name(walk,name); source.get_entry_content(walk,content); + set_entry_name(walk,name); set_entry_content(walk,content); + } + } +protected: + ~playlist_dataobject_desc() {} +private: + const playlist_dataobject_desc & operator=(const playlist_dataobject_desc &) {return *this;} +}; + +class NOVTABLE playlist_dataobject_desc_v2 : public playlist_dataobject_desc { +public: + virtual void get_side_data(t_size which, mem_block_container & out) const = 0; + virtual void set_side_data(t_size which, const void * data, t_size size) = 0; + + void copy(playlist_dataobject_desc_v2 const & source) { + const t_size count = source.get_entry_count(); set_entry_count(count); + metadb_handle_list content; pfc::string8 name; + mem_block_container_impl_t sideData; + for(t_size walk = 0; walk < count; ++walk) { + source.get_entry_name(walk,name); source.get_entry_content(walk,content); source.get_side_data(walk, sideData); + set_entry_name(walk,name); set_entry_content(walk,content); set_side_data(walk, sideData.get_ptr(), sideData.get_size()); + } + } + + void set_from_playlist_manager(bit_array const & mask) { + static_api_ptr_t api; + const t_size pltotal = api->get_playlist_count(); + const t_size total = mask.calc_count(true,0,pltotal); + set_entry_count(total); + t_size done = 0; + pfc::string8 name; metadb_handle_list content; + abort_callback_dummy abort; + for(t_size walk = 0; walk < pltotal; ++walk) if (mask[walk]) { + pfc::dynamic_assert( done < total ); + api->playlist_get_name(walk,name); api->playlist_get_all_items(walk,content); + set_entry_name(done,name); set_entry_content(done,content); + stream_writer_buffer_simple sideData; api->playlist_get_sideinfo(walk, &sideData, abort); + set_side_data(done,sideData.m_buffer.get_ptr(), sideData.m_buffer.get_size()); + ++done; + } + pfc::dynamic_assert( done == total ); + } + + const playlist_dataobject_desc_v2 & operator=(const playlist_dataobject_desc_v2& source) {copy(source); return *this;} +protected: + ~playlist_dataobject_desc_v2() {} +}; + +class playlist_dataobject_desc_impl : public playlist_dataobject_desc_v2 { +public: + playlist_dataobject_desc_impl() {} + playlist_dataobject_desc_impl(const playlist_dataobject_desc_v2 & source) {copy(source);} + + t_size get_entry_count() const {return m_entries.get_size();} + void get_entry_name(t_size which, pfc::string_base & out) const { + if (which < m_entries.get_size()) out = m_entries[which].m_name; + else throw pfc::exception_invalid_params(); + } + void get_entry_content(t_size which, metadb_handle_list_ref out) const { + if (which < m_entries.get_size()) out = m_entries[which].m_content; + else throw pfc::exception_invalid_params(); + } + void set_entry_count(t_size count) { + m_entries.set_size(count); + } + void set_entry_name(t_size which, const char * name) { + if (which < m_entries.get_size()) m_entries[which].m_name = name; + else throw pfc::exception_invalid_params(); + } + void set_entry_content(t_size which, metadb_handle_list_cref content) { + if (which < m_entries.get_size()) m_entries[which].m_content = content; + else throw pfc::exception_invalid_params(); + } + void get_side_data(t_size which, mem_block_container & out) const { + if (which < m_entries.get_size()) out.set(m_entries[which].m_sideData); + else throw pfc::exception_invalid_params(); + } + void set_side_data(t_size which, const void * data, t_size size) { + if (which < m_entries.get_size()) m_entries[which].m_sideData.set_data_fromptr(reinterpret_cast(data), size); + else throw pfc::exception_invalid_params(); + } +private: + struct entry { metadb_handle_list m_content; pfc::string8 m_name; pfc::array_t m_sideData; }; + pfc::array_t m_entries; +}; + +//! \since 0.9.5 +//! Provides various methods for interaction between foobar2000 and OLE IDataObjects, Windows Clipboard, drag&drop and such. +//! To instantiate, use static_api_ptr_t. +class NOVTABLE ole_interaction : public service_base { + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(ole_interaction) +public: + enum { + KClipboardFormatSimpleLocations, + KClipboardFormatFPL, + KClipboardFormatMultiFPL, + KClipboardFormatTotal + }; + //! Retrieves clipboard format ID for one of foobar2000's internal data formats. + //! @param which One of KClipboardFormat* constants. + virtual t_uint32 get_clipboard_format(t_uint32 which) = 0; + + //! Creates an IDataObject from a group of tracks. + virtual pfc::com_ptr_t create_dataobject(metadb_handle_list_cref source) = 0; + + //! Creates an IDataObject from one or more playlists, including playlist name info for re-creating those playlists later. + virtual pfc::com_ptr_t create_dataobject(const playlist_dataobject_desc & source) = 0; + + //! Attempts to parse an IDataObject as playlists. + virtual HRESULT parse_dataobject_playlists(pfc::com_ptr_t obj, playlist_dataobject_desc & out) = 0; + + //! For internal use only. Will succeed only if the metadb_handle list can be generated immediately, without performing potentially timeconsuming tasks such as parsing media files (for an example when the specified IDataObject contains data in one of our internal formats). + virtual HRESULT parse_dataobject_immediate(pfc::com_ptr_t obj, metadb_handle_list_ref out) = 0; + + //! Attempts to parse an IDataObject into a dropped_files_data object (list of metadb_handles if immediately available, list of file paths otherwise). + virtual HRESULT parse_dataobject(pfc::com_ptr_t obj, dropped_files_data & out) = 0; + + //! Checks whether the specified IDataObject appears to be parsable by our parse_dataobject methods. + virtual HRESULT check_dataobject(pfc::com_ptr_t obj, DWORD & dropEffect, bool & isNative) = 0; + + //! Checks whether the specified IDataObject appears to be parsable as playlists (parse_dataobject_playlists method). + virtual HRESULT check_dataobject_playlists(pfc::com_ptr_t obj) = 0; +}; + +//! \since 0.9.5.4 +class NOVTABLE ole_interaction_v2 : public ole_interaction { + FB2K_MAKE_SERVICE_INTERFACE(ole_interaction_v2, ole_interaction) +public: + //! Creates an IDataObject from one or more playlists, including playlist name info for re-creating those playlists later. + virtual pfc::com_ptr_t create_dataobject(const playlist_dataobject_desc_v2 & source) = 0; + + //! Attempts to parse an IDataObject as playlists. + virtual HRESULT parse_dataobject_playlists(pfc::com_ptr_t obj, playlist_dataobject_desc_v2 & out) = 0; +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/packet_decoder.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/packet_decoder.cpp new file mode 100644 index 000000000..abef1bc4d --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/packet_decoder.cpp @@ -0,0 +1,14 @@ +#include "foobar2000.h" + +void packet_decoder::g_open(service_ptr_t & p_out,bool p_decode,const GUID & p_owner,t_size p_param1,const void * p_param2,t_size p_param2size,abort_callback & p_abort) +{ + service_enum_t e; + service_ptr_t ptr; + while(e.next(ptr)) { + if (ptr->is_our_setup(p_owner,p_param1,p_param2,p_param2size)) { + ptr->open(p_out,p_decode,p_owner,p_param1,p_param2,p_param2size,p_abort); + return; + } + } + throw exception_io_data(); +} \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/packet_decoder.h b/tools/vio2sf/src/foobar/foobar2000/SDK/packet_decoder.h new file mode 100644 index 000000000..55f6a6968 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/packet_decoder.h @@ -0,0 +1,113 @@ +//! Provides interface to decode various audio data types to PCM. Use packet_decoder_factory_t template to register. + +class NOVTABLE packet_decoder : public service_base { +protected: + //! Prototype of function that must be implemented by packet_decoder implementation but is not accessible through packet_decoder interface itself. + //! Determines whether specific packet_decoder implementation supports specified decoder setup data. + static bool g_is_our_setup(const GUID & p_owner,t_size p_param1,const void * p_param2,t_size p_param2size) {return false;} + + //! Prototype of function that must be implemented by packet_decoder implementation but is not accessible through packet_decoder interface itself. + //! Initializes packet decoder instance with specified decoder setup data. This is called only once, before any other methods. + //! @param p_decode If set to true, decode() and reset_after_seek() calls can be expected later. If set to false, those methods will not be called on this packet_decoder instance - for an example when caller is only retrieving information about the file rather than preparing to decode it. + void open(const GUID & p_owner,bool p_decode,t_size p_param1,const void * p_param2,t_size p_param2size,abort_callback & p_abort) {throw exception_io_data();} +public: + + + //! Forwards additional information about stream being decoded. \n + //! Calling: this must be called immediately after packet_decoder object is created, before any other methods are called.\n + //! Implementation: this is called after open() (which is called by implementation framework immediately after creation), and before any other methods are called. + virtual t_size set_stream_property(const GUID & p_type,t_size p_param1,const void * p_param2,t_size p_param2size) = 0; + + + //! Retrieves additional user-readable tech infos that decoder can provide. + //! @param p_info Interface receiving information about the stream being decoded. Note that it already contains partial info about the file; existing info should not be erased, decoder-provided info should be merged with it. + virtual void get_info(file_info & p_info) = 0; + + //! Returns many frames back to start decoding when seeking. + virtual unsigned get_max_frame_dependency()=0; + //! Returns much time back to start decoding when seeking (for containers where going back by specified number of frames is not trivial). + virtual double get_max_frame_dependency_time()=0; + + //! Flushes decoder after seeking. + virtual void reset_after_seek()=0; + + //! Decodes a block of audio data.\n + //! It may return empty chunk even when successful (caused by encoder+decoder delay for an example), caller must check for it and handle it appropriately. + virtual void decode(const void * p_buffer,t_size p_bytes,audio_chunk & p_chunk,abort_callback & p_abort)=0; + + //! Returns whether this packet decoder supports analyze_first_frame() function. + virtual bool analyze_first_frame_supported() = 0; + //! Optional. Some codecs need to analyze first frame of the stream to return additional info about the stream, such as encoding setup. This can be only called immediately after instantiation (and set_stream_property() if present), before any actual decoding or get_info(). Caller can determine whether this method is supported or not by calling analyze_first_frame_supported(), to avoid reading first frame when decoder won't utiilize the extra info for an example. If particular decoder can't utilize first frame info in any way (and analyze_first_frame_supported() returns false), this function should do nothing and succeed. + virtual void analyze_first_frame(const void * p_buffer,t_size p_bytes,abort_callback & p_abort) = 0; + + //! Static helper, creates a packet_decoder instance and initializes it with specific decoder setup data. + static void g_open(service_ptr_t & p_out,bool p_decode,const GUID & p_owner,t_size p_param1,const void * p_param2,t_size p_param2size,abort_callback & p_abort); + + static const GUID owner_MP4,owner_matroska,owner_MP3,owner_MP2,owner_MP1,owner_MP4_ALAC,owner_ADTS,owner_ADIF, owner_Ogg, owner_MP4_AMR, owner_MP4_AMR_WB; + + struct matroska_setup + { + const char * codec_id; + unsigned sample_rate,sample_rate_output; + unsigned channels; + unsigned codec_private_size; + const void * codec_private; + }; + //owner_MP4: param1 - codec ID (MP4 audio type), param2 - MP4 codec initialization data + //owner_MP3: raw MP3/MP2 file, parameters ignored + //owner_matroska: param2 = matroska_setup struct, param2size size must be equal to sizeof(matroska_setup) + + + //these are used to initialize PCM decoder + static const GUID property_samplerate,property_bitspersample,property_channels,property_byteorder,property_signed,property_channelmask; + //property_samplerate : param1 == sample rate in hz + //property_bitspersample : param1 == bits per sample + //property_channels : param1 == channel count + //property_byteorder : if (param1) little_endian; else big_endian; + //property_signed : if (param1) signed; else unsigned; + + + //property_ogg_header : p_param1 = unused, p_param2 = ogg_packet structure, retval: 0 when more headers are wanted, 1 when done parsing headers + //property_ogg_query_sample_rate : returns sample rate, no parameters + //property_ogg_packet : p_param1 = unused, p_param2 = ogg_packet strucute + static const GUID property_ogg_header, property_ogg_query_sample_rate, property_ogg_packet; + + FB2K_MAKE_SERVICE_INTERFACE(packet_decoder,service_base); +}; + +class NOVTABLE packet_decoder_streamparse : public packet_decoder +{ +public: + virtual void decode_ex(const void * p_buffer,t_size p_bytes,t_size & p_bytes_processed,audio_chunk & p_chunk,abort_callback & p_abort) = 0; + virtual void analyze_first_frame_ex(const void * p_buffer,t_size p_bytes,t_size & p_bytes_processed,abort_callback & p_abort) = 0; + + FB2K_MAKE_SERVICE_INTERFACE(packet_decoder_streamparse,packet_decoder); +}; + +class NOVTABLE packet_decoder_entry : public service_base +{ +public: + virtual bool is_our_setup(const GUID & p_owner,t_size p_param1,const void * p_param2,t_size p_param2size) = 0; + virtual void open(service_ptr_t & p_out,bool p_decode,const GUID & p_owner,t_size p_param1,const void * p_param2,t_size p_param2size,abort_callback & p_abort) = 0; + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(packet_decoder_entry); +}; + + +template +class packet_decoder_entry_impl_t : public packet_decoder_entry +{ +public: + bool is_our_setup(const GUID & p_owner,t_size p_param1,const void * p_param2,t_size p_param2size) { + return T::g_is_our_setup(p_owner,p_param1,p_param2,p_param2size); + } + void open(service_ptr_t & p_out,bool p_decode,const GUID & p_owner,t_size p_param1,const void * p_param2,t_size p_param2size,abort_callback & p_abort) { + assert(is_our_setup(p_owner,p_param1,p_param2,p_param2size)); + service_ptr_t instance = new service_impl_t(); + instance->open(p_owner,p_decode,p_param1,p_param2,p_param2size,p_abort); + p_out = instance.get_ptr(); + } +}; + +template +class packet_decoder_factory_t : public service_factory_single_t > {}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/play_callback.h b/tools/vio2sf/src/foobar/foobar2000/SDK/play_callback.h new file mode 100644 index 000000000..d3d659ffe --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/play_callback.h @@ -0,0 +1,149 @@ +/*! +Class receiving notifications about playback events. Note that all methods are called only from app's main thread. +Use play_callback_manager to register your dynamically created instances. Statically registered version is available too - see play_callback_static. +*/ +class NOVTABLE play_callback { +public: + //! Playback process is being initialized. on_playback_new_track() should be called soon after this when first file is successfully opened for decoding. + virtual void FB2KAPI on_playback_starting(play_control::t_track_command p_command,bool p_paused) = 0; + //! Playback advanced to new track. + virtual void FB2KAPI on_playback_new_track(metadb_handle_ptr p_track) = 0; + //! Playback stopped. + virtual void FB2KAPI on_playback_stop(play_control::t_stop_reason p_reason) = 0; + //! User has seeked to specific time. + virtual void FB2KAPI on_playback_seek(double p_time) = 0; + //! Called on pause/unpause. + virtual void FB2KAPI on_playback_pause(bool p_state) = 0; + //! Called when currently played file gets edited. + virtual void FB2KAPI on_playback_edited(metadb_handle_ptr p_track) = 0; + //! Dynamic info (VBR bitrate etc) change. + virtual void FB2KAPI on_playback_dynamic_info(const file_info & p_info) = 0; + //! Per-track dynamic info (stream track titles etc) change. Happens less often than on_playback_dynamic_info(). + virtual void FB2KAPI on_playback_dynamic_info_track(const file_info & p_info) = 0; + //! Called every second, for time display + virtual void FB2KAPI on_playback_time(double p_time) = 0; + //! User changed volume settings. Possibly called when not playing. + //! @param p_new_val new volume level in dB; 0 for full volume. + virtual void FB2KAPI on_volume_change(float p_new_val) = 0; + + enum { + flag_on_playback_starting = 1 << 0, + flag_on_playback_new_track = 1 << 1, + flag_on_playback_stop = 1 << 2, + flag_on_playback_seek = 1 << 3, + flag_on_playback_pause = 1 << 4, + flag_on_playback_edited = 1 << 5, + flag_on_playback_dynamic_info = 1 << 6, + flag_on_playback_dynamic_info_track = 1 << 7, + flag_on_playback_time = 1 << 8, + flag_on_volume_change = 1 << 9, + + flag_on_playback_all = flag_on_playback_starting | flag_on_playback_new_track | + flag_on_playback_stop | flag_on_playback_seek | + flag_on_playback_pause | flag_on_playback_edited | + flag_on_playback_dynamic_info | flag_on_playback_dynamic_info_track | flag_on_playback_time, + }; +protected: + play_callback() {} + ~play_callback() {} +}; + +//! Standard API (always present); manages registrations of dynamic play_callbacks. +//! Usage: use static_api_ptr_t. +//! Do not reimplement. +class NOVTABLE play_callback_manager : public service_base +{ +public: + //! Registers a play_callback object. + //! @param p_callback Interface to register. + //! @param p_flags Indicates which notifications are requested. + //! @param p_forward_status_on_register Set to true to have the callback immediately receive current playback status as notifications if playback is active (eg. to receive info about playback process that started before our callback was registered). + virtual void FB2KAPI register_callback(play_callback * p_callback,unsigned p_flags,bool p_forward_status_on_register) = 0; + //! Unregisters a play_callback object. + //! @p_callback Previously registered interface to unregister. + virtual void FB2KAPI unregister_callback(play_callback * p_callback) = 0; + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(play_callback_manager); +}; + +//! Implementation helper. +class play_callback_impl_base : public play_callback { +public: + play_callback_impl_base(unsigned p_flags = ~0) { + static_api_ptr_t()->register_callback(this,p_flags,false); + } + ~play_callback_impl_base() { + static_api_ptr_t()->unregister_callback(this); + } + void play_callback_reregister(unsigned flags, bool refresh = false) { + static_api_ptr_t api; + api->unregister_callback(this); + api->register_callback(this,flags,refresh); + } + void on_playback_starting(play_control::t_track_command p_command,bool p_paused) {} + void on_playback_new_track(metadb_handle_ptr p_track) {} + void on_playback_stop(play_control::t_stop_reason p_reason) {} + void on_playback_seek(double p_time) {} + void on_playback_pause(bool p_state) {} + void on_playback_edited(metadb_handle_ptr p_track) {} + void on_playback_dynamic_info(const file_info & p_info) {} + void on_playback_dynamic_info_track(const file_info & p_info) {} + void on_playback_time(double p_time) {} + void on_volume_change(float p_new_val) {} + + PFC_CLASS_NOT_COPYABLE_EX(play_callback_impl_base) +}; + +//! Static (autoregistered) version of play_callback. Use play_callback_static_factory_t to register. +class play_callback_static : public service_base, public play_callback { +public: + //! Controls which methods your callback wants called; returned value should not change in run time, you should expect it to be queried only once (on startup). See play_callback::flag_* constants. + virtual unsigned get_flags() = 0; + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(play_callback_static); +}; + +template +class play_callback_static_factory_t : public service_factory_single_t {}; + + +//! Gets notified about tracks being played. Notification occurs when at least 60s of the track has been played, or the track has reached its end after at least 1/3 of it has been played through. +//! Use playback_statistics_collector_factory_t to register. +class NOVTABLE playback_statistics_collector : public service_base { +public: + virtual void on_item_played(metadb_handle_ptr p_item) = 0; + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(playback_statistics_collector); +}; + +template +class playback_statistics_collector_factory_t : public service_factory_single_t {}; + + + + +//! Helper providing a simplified interface for receiving playback events, in case your code does not care about the kind of playback event that has occured; useful typically for GUI/rendering code that just refreshes some control whenever a playback state change occurs. +class playback_event_notify : private play_callback_impl_base { +public: + playback_event_notify(playback_control::t_display_level level = playback_control::display_level_all) : play_callback_impl_base(GrabCBFlags(level)) {} + + static t_uint32 GrabCBFlags(playback_control::t_display_level level) { + t_uint32 flags = flag_on_playback_starting | flag_on_playback_new_track | flag_on_playback_stop | flag_on_playback_pause | flag_on_playback_edited | flag_on_volume_change; + if (level >= playback_control::display_level_titles) flags |= flag_on_playback_dynamic_info_track; + if (level >= playback_control::display_level_all) flags |= flag_on_playback_seek | flag_on_playback_dynamic_info | flag_on_playback_time; + return flags; + } +protected: + virtual void on_playback_event() {} +private: + void on_playback_starting(play_control::t_track_command p_command,bool p_paused) {on_playback_event();} + void on_playback_new_track(metadb_handle_ptr p_track) {on_playback_event();} + void on_playback_stop(play_control::t_stop_reason p_reason) {on_playback_event();} + void on_playback_seek(double p_time) {on_playback_event();} + void on_playback_pause(bool p_state) {on_playback_event();} + void on_playback_edited(metadb_handle_ptr p_track) {on_playback_event();} + void on_playback_dynamic_info(const file_info & p_info) {on_playback_event();} + void on_playback_dynamic_info_track(const file_info & p_info) {on_playback_event();} + void on_playback_time(double p_time) {on_playback_event();} + void on_volume_change(float p_new_val) {on_playback_event();} +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/playable_location.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/playable_location.cpp new file mode 100644 index 000000000..5ad6e0c0e --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/playable_location.cpp @@ -0,0 +1,23 @@ +#include "foobar2000.h" + +int playable_location::g_compare(const playable_location & p_item1,const playable_location & p_item2) { + int ret = metadb::path_compare(p_item1.get_path(),p_item2.get_path()); + if (ret != 0) return ret; + return pfc::compare_t(p_item1.get_subsong(),p_item2.get_subsong()); +} + +pfc::string_base & operator<<(pfc::string_base & p_fmt,const playable_location & p_location) +{ + p_fmt << "\"" << file_path_display(p_location.get_path()) << "\""; + t_uint32 index = p_location.get_subsong_index(); + if (index != 0) p_fmt << " / index: " << p_location.get_subsong_index(); + return p_fmt; +} + + +bool playable_location::operator==(const playable_location & p_other) const { + return metadb::path_compare(get_path(),p_other.get_path()) == 0 && get_subsong() == p_other.get_subsong(); +} +bool playable_location::operator!=(const playable_location & p_other) const { + return !(*this == p_other); +} diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/playable_location.h b/tools/vio2sf/src/foobar/foobar2000/SDK/playable_location.h new file mode 100644 index 000000000..0f1d1829b --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/playable_location.h @@ -0,0 +1,90 @@ +#ifndef _FOOBAR2000_PLAYABLE_LOCATION_H_ +#define _FOOBAR2000_PLAYABLE_LOCATION_H_ + +//playable_location stores location of a playable resource, currently implemented as file path and integer for indicating multiple playable "subsongs" per file +//also see: file_info.h +//for getting more info about resource referenced by a playable_location, see metadb.h + +//char* strings are all UTF-8 + +class NOVTABLE playable_location//interface (for passing around between DLLs) +{ +public: + virtual const char * get_path() const =0; + virtual void set_path(const char*)=0; + virtual t_uint32 get_subsong() const =0; + virtual void set_subsong(t_uint32)=0; + + void copy(const playable_location & p_other) { + set_path(p_other.get_path()); + set_subsong(p_other.get_subsong()); + } + + static int g_compare(const playable_location & p_item1,const playable_location & p_item2); + + const playable_location & operator=(const playable_location & src) {copy(src);return *this;} + + bool operator==(const playable_location & p_other) const; + bool operator!=(const playable_location & p_other) const; + + inline bool is_empty() {return get_path()[0]==0 && get_subsong()==0;} + inline void reset() {set_path("");set_subsong(0);} + inline t_uint32 get_subsong_index() const {return get_subsong();} + inline void set_subsong_index(t_uint32 v) {set_subsong(v);} + + class comparator { + public: + static int compare(const playable_location & v1, const playable_location & v2) {return g_compare(v1,v2);} + }; + +protected: + playable_location() {} + ~playable_location() {} +}; + +typedef playable_location * pplayable_location; +typedef playable_location const * pcplayable_location; +typedef playable_location & rplayable_location; +typedef playable_location const & rcplayable_location; + +class playable_location_impl : public playable_location//implementation +{ +public: + const char * get_path() const {return m_path;} + void set_path(const char* p_path) {m_path=p_path;} + t_uint32 get_subsong() const {return m_subsong;} + void set_subsong(t_uint32 p_subsong) {m_subsong=p_subsong;} + + const playable_location_impl & operator=(const playable_location & src) {copy(src);return *this;} + const playable_location_impl & operator=(const playable_location_impl & src) {copy(src);return *this;} + + playable_location_impl() : m_subsong(0) {} + playable_location_impl(const char * p_path,t_uint32 p_subsong) : m_path(p_path), m_subsong(p_subsong) {} + playable_location_impl(const playable_location & src) {copy(src);} + playable_location_impl(const playable_location_impl & src) {copy(src);} + +private: + pfc::string_simple m_path; + t_uint32 m_subsong; +}; + +// usage: something( make_playable_location("file://c:\blah.ogg",0) ); +// only for use as a parameter to a function taking const playable_location & +class make_playable_location : public playable_location +{ + const char * path; + t_uint32 num; + + void set_path(const char*) {throw pfc::exception_not_implemented();} + void set_subsong(t_uint32) {throw pfc::exception_not_implemented();} + +public: + const char * get_path() const {return path;} + t_uint32 get_subsong() const {return num;} + + make_playable_location(const char * p_path,t_uint32 p_num) : path(p_path), num(p_num) {} +}; + +pfc::string_base & operator<<(pfc::string_base & p_fmt,const playable_location & p_location); + +#endif //_FOOBAR2000_PLAYABLE_LOCATION_H_ diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/playback_control.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/playback_control.cpp new file mode 100644 index 000000000..bf9c47be7 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/playback_control.cpp @@ -0,0 +1,13 @@ +#include "foobar2000.h" + + +double playback_control::playback_get_length() +{ + double rv = 0; + metadb_handle_ptr ptr; + if (get_now_playing(ptr)) + { + rv = ptr->get_length(); + } + return rv; +} diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/playback_control.h b/tools/vio2sf/src/foobar/foobar2000/SDK/playback_control.h new file mode 100644 index 000000000..a756847e4 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/playback_control.h @@ -0,0 +1,135 @@ +//! Provides control for various playback-related operations. +//! All methods provided by this interface work from main app thread only. Calling from another thread will do nothing or trigger an exception. If you need to trigger one of playback_control methods from another thread, see main_thread_callback. +//! Do not call playback_control methods from inside any kind of global callback (e.g. playlist callback), otherwise race conditions may occur. +//! Use static_api_ptr_t to instantiate. See static_api_ptr_t documentation for more info. +class NOVTABLE playback_control : public service_base +{ +public: + + enum t_stop_reason { + stop_reason_user = 0, + stop_reason_eof, + stop_reason_starting_another, + stop_reason_shutting_down, + }; + + + enum t_track_command { + track_command_default = 0, + track_command_play, + track_command_next, + track_command_prev, + track_command_settrack, + track_command_rand, + track_command_resume, + }; + + //! Retrieves now playing item handle. + //! @returns true on success, false on failure (not playing). + virtual bool get_now_playing(metadb_handle_ptr & p_out) = 0; + //! Starts playback. If playback is already active, existing process is stopped first. + //! @param p_command Specifies what track to start playback from. See t_track_Command enum for more info. + //! @param p_paused Specifies whether playback should be started as paused. + virtual void start(t_track_command p_command = track_command_play,bool p_paused = false) = 0; + //! Stops playback. + virtual void stop() = 0; + //! Returns whether playback is active. + virtual bool is_playing() = 0; + //! Returns whether playback is active and in paused state. + virtual bool is_paused() = 0; + //! Toggles pause state if playback is active. + //! @param p_state set to true when pausing or to false when unpausing. + virtual void pause(bool p_state) = 0; + + //! Retrieves stop-after-current-track option state. + virtual bool get_stop_after_current() = 0; + //! Alters stop-after-current-track option state. + virtual void set_stop_after_current(bool p_state) = 0; + + //! Alters playback volume level. + //! @param p_value volume in dB; 0 for full volume. + virtual void set_volume(float p_value) = 0; + //! Retrieves playback volume level. + //! @returns current playback volume level, in dB; 0 for full volume. + virtual float get_volume() = 0; + //! Alters playback volume level one step up. + virtual void volume_up() = 0; + //! Alters playback volume level one step down. + virtual void volume_down() = 0; + //! Toggles playback mute state. + virtual void volume_mute_toggle() = 0; + //! Seeks in currenly played track to specified time. + //! @param p_time target time in seconds. + virtual void playback_seek(double p_time) = 0; + //! Seeks in currently played track by specified time forward or back. + //! @param p_delta time in seconds to seek by; can be positive to seek forward or negative to seek back. + virtual void playback_seek_delta(double p_delta) = 0; + //! Returns whether currently played track is seekable. If it's not, playback_seek/playback_seek_delta calls will be ignored. + virtual bool playback_can_seek() = 0; + //! Returns current playback position within currently played track, in seconds. + virtual double playback_get_position() = 0; + + //! Type used to indicate level of dynamic playback-related info displayed. Safe to use with <> opereators, e.g. level above N always includes information rendered by level N. + enum t_display_level { + //! No playback-related info + display_level_none, + //! Static info and is_playing/is_paused stats + display_level_basic, + //! display_level_basic + dynamic track titles on e.g. live streams + display_level_titles, + //! display_level_titles + timing + VBR bitrate display etc + display_level_all, + }; + + //! Renders information about currently playing item. + //! @param p_hook Optional callback object overriding fields and functions; set to NULL if not used. + //! @param p_out String receiving the output on success. + //! @param p_script Titleformat script to use. Use titleformat_compiler service to create one. + //! @param p_filter Optional callback object allowing input to be filtered according to context (i.e. removal of linebreak characters present in tags when rendering playlist lines). Set to NULL when not used. + //! @param p_level Indicates level of dynamic playback-related info displayed. See t_display_level enum for more details. + //! @returns true on success, false when no item is currently being played. + virtual bool playback_format_title(titleformat_hook * p_hook,pfc::string_base & p_out,const service_ptr_t & p_script,titleformat_text_filter * p_filter,t_display_level p_level) = 0; + + + + //! Helper; renders info about any item, including currently playing item info if the item is currently played. + bool playback_format_title_ex(metadb_handle_ptr p_item,titleformat_hook * p_hook,pfc::string_base & p_out,const service_ptr_t & p_script,titleformat_text_filter * p_filter,t_display_level p_level) { + if (p_item.is_empty()) return playback_format_title(p_hook,p_out,p_script,p_filter,p_level); + metadb_handle_ptr temp; + if (get_now_playing(temp)) { + if (temp == p_item) { + return playback_format_title(p_hook,p_out,p_script,p_filter,p_level); + } + } + p_item->format_title(p_hook,p_out,p_script,p_filter); + return true; + } + + //! Helper; retrieves length of currently playing item. + double playback_get_length(); + + //! Toggles stop-after-current state. + void toggle_stop_after_current() {set_stop_after_current(!get_stop_after_current());} + //! Toggles pause state. + void toggle_pause() {pause(!is_paused());} + + //! Starts playback if playback is inactive, otherwise toggles pause. + void play_or_pause() {if (is_playing()) toggle_pause(); else start();} + + //deprecated + inline void play_start(t_track_command p_command = track_command_play,bool p_paused = false) {start(p_command,p_paused);} + //deprecated + inline void play_stop() {stop();} + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(playback_control); +}; + +class playback_control_v2 : public playback_control { +public: + virtual float get_volume_step() = 0; + + FB2K_MAKE_SERVICE_INTERFACE(playback_control_v2,playback_control); +}; + +//for compatibility with old code +typedef playback_control play_control; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/playlist.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/playlist.cpp new file mode 100644 index 000000000..fe4456bd9 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/playlist.cpp @@ -0,0 +1,861 @@ +#include "foobar2000.h" + + +namespace { + class enum_items_callback_retrieve_item : public playlist_manager::enum_items_callback + { + metadb_handle_ptr m_item; + public: + enum_items_callback_retrieve_item() : m_item(0) {} + bool on_item(t_size p_index,const metadb_handle_ptr & p_location,bool b_selected) + { + assert(m_item.is_empty()); + m_item = p_location; + return false; + } + inline const metadb_handle_ptr & get_item() {return m_item;} + }; + + class enum_items_callback_retrieve_selection : public playlist_manager::enum_items_callback + { + bool m_state; + public: + enum_items_callback_retrieve_selection() : m_state(false) {} + bool on_item(t_size p_index,const metadb_handle_ptr & p_location,bool b_selected) + { + m_state = b_selected; + return false; + } + inline bool get_state() {return m_state;} + }; + + class enum_items_callback_retrieve_selection_mask : public playlist_manager::enum_items_callback + { + bit_array_var & m_out; + public: + enum_items_callback_retrieve_selection_mask(bit_array_var & p_out) : m_out(p_out) {} + bool on_item(t_size p_index,const metadb_handle_ptr & p_location,bool b_selected) + { + m_out.set(p_index,b_selected); + return true; + } + }; + + class enum_items_callback_retrieve_all_items : public playlist_manager::enum_items_callback + { + pfc::list_base_t & m_out; + public: + enum_items_callback_retrieve_all_items(pfc::list_base_t & p_out) : m_out(p_out) {m_out.remove_all();} + bool on_item(t_size p_index,const metadb_handle_ptr & p_location,bool b_selected) + { + m_out.add_item(p_location); + return true; + } + }; + + class enum_items_callback_retrieve_selected_items : public playlist_manager::enum_items_callback + { + pfc::list_base_t & m_out; + public: + enum_items_callback_retrieve_selected_items(pfc::list_base_t & p_out) : m_out(p_out) {m_out.remove_all();} + bool on_item(t_size p_index,const metadb_handle_ptr & p_location,bool b_selected) + { + if (b_selected) m_out.add_item(p_location); + return true; + } + }; + + class enum_items_callback_count_selection : public playlist_manager::enum_items_callback + { + t_size m_counter,m_max; + public: + enum_items_callback_count_selection(t_size p_max) : m_max(p_max), m_counter(0) {} + bool on_item(t_size p_index,const metadb_handle_ptr & p_location,bool b_selected) + { + if (b_selected) + { + if (++m_counter >= m_max) return false; + } + return true; + } + + inline t_size get_count() {return m_counter;} + }; + +} + +void playlist_manager::playlist_get_all_items(t_size p_playlist,pfc::list_base_t & out) +{ + playlist_get_items(p_playlist,out,bit_array_true()); +} + +void playlist_manager::playlist_get_selected_items(t_size p_playlist,pfc::list_base_t & out) +{ + playlist_enum_items(p_playlist,enum_items_callback_retrieve_selected_items(out),bit_array_true()); +} + +void playlist_manager::playlist_get_selection_mask(t_size p_playlist,bit_array_var & out) +{ + playlist_enum_items(p_playlist,enum_items_callback_retrieve_selection_mask(out),bit_array_true()); +} + +bool playlist_manager::playlist_is_item_selected(t_size p_playlist,t_size p_item) +{ + enum_items_callback_retrieve_selection callback; + playlist_enum_items(p_playlist,callback,bit_array_one(p_item)); + return callback.get_state(); +} + +metadb_handle_ptr playlist_manager::playlist_get_item_handle(t_size playlist, t_size item) { + metadb_handle_ptr temp; + if (!playlist_get_item_handle(temp, playlist, item)) throw pfc::exception_invalid_params(); + PFC_ASSERT( temp.is_valid() ); + return temp; + +} +bool playlist_manager::playlist_get_item_handle(metadb_handle_ptr & p_out,t_size p_playlist,t_size p_item) +{ + enum_items_callback_retrieve_item callback; + playlist_enum_items(p_playlist,callback,bit_array_one(p_item)); + p_out = callback.get_item(); + return p_out.is_valid(); +} + +void playlist_manager::g_make_selection_move_permutation(t_size * p_output,t_size p_count,const bit_array & p_selection,int p_delta) { + pfc::create_move_items_permutation(p_output,p_count,p_selection,p_delta); +} + +bool playlist_manager::playlist_move_selection(t_size p_playlist,int p_delta) { + if (p_delta==0) return true; + + t_size count = playlist_get_item_count(p_playlist); + + pfc::array_t order; order.set_size(count); + pfc::array_t selection; selection.set_size(count); + + playlist_get_selection_mask(p_playlist,bit_array_var_table(selection.get_ptr(),selection.get_size())); + g_make_selection_move_permutation(order.get_ptr(),count,bit_array_table(selection.get_ptr(),selection.get_size()),p_delta); + return playlist_reorder_items(p_playlist,order.get_ptr(),count); +} + +//retrieving status +t_size playlist_manager::activeplaylist_get_item_count() +{ + t_size playlist = get_active_playlist(); + if (playlist == infinite) return 0; + else return playlist_get_item_count(playlist); +} + +void playlist_manager::activeplaylist_enum_items(enum_items_callback & p_callback,const bit_array & p_mask) +{ + t_size playlist = get_active_playlist(); + if (playlist != infinite) playlist_enum_items(playlist,p_callback,p_mask); +} + +t_size playlist_manager::activeplaylist_get_focus_item() +{ + t_size playlist = get_active_playlist(); + if (playlist == infinite) return infinite; + else return playlist_get_focus_item(playlist); +} + +bool playlist_manager::activeplaylist_get_name(pfc::string_base & p_out) +{ + t_size playlist = get_active_playlist(); + if (playlist == infinite) return false; + else return playlist_get_name(playlist,p_out); +} + +//modifying playlist +bool playlist_manager::activeplaylist_reorder_items(const t_size * order,t_size count) +{ + t_size playlist = get_active_playlist(); + if (playlist != infinite) return playlist_reorder_items(playlist,order,count); + else return false; +} + +void playlist_manager::activeplaylist_set_selection(const bit_array & affected,const bit_array & status) +{ + t_size playlist = get_active_playlist(); + if (playlist != infinite) playlist_set_selection(playlist,affected,status); +} + +bool playlist_manager::activeplaylist_remove_items(const bit_array & mask) +{ + t_size playlist = get_active_playlist(); + if (playlist != infinite) return playlist_remove_items(playlist,mask); + else return false; +} + +bool playlist_manager::activeplaylist_replace_item(t_size p_item,const metadb_handle_ptr & p_new_item) +{ + t_size playlist = get_active_playlist(); + if (playlist != infinite) return playlist_replace_item(playlist,p_item,p_new_item); + else return false; +} + +void playlist_manager::activeplaylist_set_focus_item(t_size p_item) +{ + t_size playlist = get_active_playlist(); + if (playlist != infinite) playlist_set_focus_item(playlist,p_item); +} + +t_size playlist_manager::activeplaylist_insert_items(t_size p_base,const pfc::list_base_const_t & data,const bit_array & p_selection) +{ + t_size playlist = get_active_playlist(); + if (playlist != infinite) return playlist_insert_items(playlist,p_base,data,p_selection); + else return infinite; +} + +void playlist_manager::activeplaylist_ensure_visible(t_size p_item) +{ + t_size playlist = get_active_playlist(); + if (playlist != infinite) playlist_ensure_visible(playlist,p_item); +} + +bool playlist_manager::activeplaylist_rename(const char * p_name,t_size p_name_len) +{ + t_size playlist = get_active_playlist(); + if (playlist != infinite) return playlist_rename(playlist,p_name,p_name_len); + else return false; +} + +bool playlist_manager::activeplaylist_is_item_selected(t_size p_item) +{ + t_size playlist = get_active_playlist(); + if (playlist != infinite) return playlist_is_item_selected(playlist,p_item); + else return false; +} + +metadb_handle_ptr playlist_manager::activeplaylist_get_item_handle(t_size p_item) { + metadb_handle_ptr temp; + if (!activeplaylist_get_item_handle(temp, p_item)) throw pfc::exception_invalid_params(); + PFC_ASSERT( temp.is_valid() ); + return temp; +} +bool playlist_manager::activeplaylist_get_item_handle(metadb_handle_ptr & p_out,t_size p_item) +{ + t_size playlist = get_active_playlist(); + if (playlist != infinite) return playlist_get_item_handle(p_out,playlist,p_item); + else return false; +} + +void playlist_manager::activeplaylist_move_selection(int p_delta) +{ + t_size playlist = get_active_playlist(); + if (playlist != infinite) playlist_move_selection(playlist,p_delta); +} + +void playlist_manager::activeplaylist_get_selection_mask(bit_array_var & out) +{ + t_size playlist = get_active_playlist(); + if (playlist != infinite) playlist_get_selection_mask(playlist,out); +} + +void playlist_manager::activeplaylist_get_all_items(pfc::list_base_t & out) +{ + t_size playlist = get_active_playlist(); + if (playlist != infinite) playlist_get_all_items(playlist,out); +} + +void playlist_manager::activeplaylist_get_selected_items(pfc::list_base_t & out) +{ + t_size playlist = get_active_playlist(); + if (playlist != infinite) playlist_get_selected_items(playlist,out); +} + +bool playlist_manager::remove_playlist(t_size idx) +{ + return remove_playlists(bit_array_one(idx)); +} + +bool playlist_incoming_item_filter::process_location(const char * url,pfc::list_base_t & out,bool filter,const char * p_mask,const char * p_exclude,HWND p_parentwnd) +{ + return process_locations(pfc::list_single_ref_t(url),out,filter,p_mask,p_exclude,p_parentwnd); +} + +void playlist_manager::playlist_clear(t_size p_playlist) +{ + playlist_remove_items(p_playlist,bit_array_true()); +} + +void playlist_manager::activeplaylist_clear() +{ + t_size playlist = get_active_playlist(); + if (playlist != infinite) playlist_clear(playlist); +} + +bool playlist_manager::playlist_update_content(t_size playlist, metadb_handle_list_cref content, bool bUndoBackup) { + metadb_handle_list old; + playlist_get_all_items(playlist, old); + if (old.get_size() == 0) { + if (content.get_size() == 0) return false; + if (bUndoBackup) playlist_undo_backup(playlist); + playlist_add_items(playlist, content, bit_array_false()); + return true; + } + pfc::avltree_t itemsOld, itemsNew; + + for(t_size walk = 0; walk < old.get_size(); ++walk) itemsOld += old[walk]; + for(t_size walk = 0; walk < content.get_size(); ++walk) itemsNew += content[walk]; + bit_array_bittable removeMask(old.get_size()); + bit_array_bittable filterMask(content.get_size()); + bool gotNew = false, filterNew = false, gotRemove = false; + for(t_size walk = 0; walk < content.get_size(); ++walk) { + const bool state = !itemsOld.have_item(content[walk]); + if (state) gotNew = true; + else filterNew = true; + filterMask.set(walk, state); + } + for(t_size walk = 0; walk < old.get_size(); ++walk) { + const bool state = !itemsNew.have_item(old[walk]); + if (state) gotRemove = true; + removeMask.set(walk, state); + } + if (!gotNew && !gotRemove) return false; + if (bUndoBackup) playlist_undo_backup(playlist); + if (gotRemove) { + playlist_remove_items(playlist, removeMask); + } + if (gotNew) { + if (filterNew) { + metadb_handle_list temp(content); + temp.filter_mask(filterMask); + playlist_add_items(playlist, temp, bit_array_false()); + } else { + playlist_add_items(playlist, content, bit_array_false()); + } + } + return true; +} +bool playlist_manager::playlist_add_items(t_size playlist,const pfc::list_base_const_t & data,const bit_array & p_selection) +{ + return playlist_insert_items(playlist,infinite,data,p_selection) != infinite; +} + +bool playlist_manager::activeplaylist_add_items(const pfc::list_base_const_t & data,const bit_array & p_selection) +{ + t_size playlist = get_active_playlist(); + if (playlist != infinite) return playlist_add_items(playlist,data,p_selection); + else return false; +} + +bool playlist_manager::playlist_insert_items_filter(t_size p_playlist,t_size p_base,const pfc::list_base_const_t & p_data,bool p_select) +{ + metadb_handle_list temp; + static_api_ptr_t api; + if (!api->filter_items(p_data,temp)) + return false; + return playlist_insert_items(p_playlist,p_base,temp,bit_array_val(p_select)) != infinite; +} + +bool playlist_manager::activeplaylist_insert_items_filter(t_size p_base,const pfc::list_base_const_t & p_data,bool p_select) +{ + t_size playlist = get_active_playlist(); + if (playlist != infinite) return playlist_insert_items_filter(playlist,p_base,p_data,p_select); + else return false; +} + +bool playlist_manager::playlist_insert_locations(t_size p_playlist,t_size p_base,const pfc::list_base_const_t & p_urls,bool p_select,HWND p_parentwnd) +{ + metadb_handle_list temp; + static_api_ptr_t api; + if (!api->process_locations(p_urls,temp,true,0,0,p_parentwnd)) return false; + return playlist_insert_items(p_playlist,p_base,temp,bit_array_val(p_select)) != infinite; +} + +bool playlist_manager::activeplaylist_insert_locations(t_size p_base,const pfc::list_base_const_t & p_urls,bool p_select,HWND p_parentwnd) +{ + t_size playlist = get_active_playlist(); + if (playlist != infinite) return playlist_insert_locations(playlist,p_base,p_urls,p_select,p_parentwnd); + else return false; +} + +bool playlist_manager::playlist_add_items_filter(t_size p_playlist,const pfc::list_base_const_t & p_data,bool p_select) +{ + return playlist_insert_items_filter(p_playlist,infinite,p_data,p_select); +} + +bool playlist_manager::activeplaylist_add_items_filter(const pfc::list_base_const_t & p_data,bool p_select) +{ + return activeplaylist_insert_items_filter(infinite,p_data,p_select); +} + +bool playlist_manager::playlist_add_locations(t_size p_playlist,const pfc::list_base_const_t & p_urls,bool p_select,HWND p_parentwnd) +{ + return playlist_insert_locations(p_playlist,infinite,p_urls,p_select,p_parentwnd); +} +bool playlist_manager::activeplaylist_add_locations(const pfc::list_base_const_t & p_urls,bool p_select,HWND p_parentwnd) +{ + return activeplaylist_insert_locations(infinite,p_urls,p_select,p_parentwnd); +} + +void playlist_manager::reset_playing_playlist() +{ + set_playing_playlist(get_active_playlist()); +} + +void playlist_manager::playlist_clear_selection(t_size p_playlist) +{ + playlist_set_selection(p_playlist,bit_array_true(),bit_array_false()); +} + +void playlist_manager::activeplaylist_clear_selection() +{ + t_size playlist = get_active_playlist(); + if (playlist != infinite) playlist_clear_selection(playlist); +} + +void playlist_manager::activeplaylist_undo_backup() +{ + t_size playlist = get_active_playlist(); + if (playlist != infinite) playlist_undo_backup(playlist); +} + +bool playlist_manager::activeplaylist_undo_restore() +{ + t_size playlist = get_active_playlist(); + if (playlist != infinite) return playlist_undo_restore(playlist); + else return false; +} + +bool playlist_manager::activeplaylist_redo_restore() +{ + t_size playlist = get_active_playlist(); + if (playlist != infinite) return playlist_redo_restore(playlist); + else return false; +} + +void playlist_manager::playlist_remove_selection(t_size p_playlist,bool p_crop) +{ + bit_array_bittable table(playlist_get_item_count(p_playlist)); + playlist_get_selection_mask(p_playlist,table); + if (p_crop) playlist_remove_items(p_playlist,bit_array_not(table)); + else playlist_remove_items(p_playlist,table); +} + +void playlist_manager::activeplaylist_remove_selection(bool p_crop) +{ + t_size playlist = get_active_playlist(); + if (playlist != infinite) playlist_remove_selection(playlist,p_crop); +} + +void playlist_manager::activeplaylist_item_format_title(t_size p_item,titleformat_hook * p_hook,pfc::string_base & out,const service_ptr_t & p_script,titleformat_text_filter * p_filter,play_control::t_display_level p_playback_info_level) +{ + t_size playlist = get_active_playlist(); + if (playlist == infinite) out = "NJET"; + else playlist_item_format_title(playlist,p_item,p_hook,out,p_script,p_filter,p_playback_info_level); +} + +void playlist_manager::playlist_set_selection_single(t_size p_playlist,t_size p_item,bool p_state) +{ + playlist_set_selection(p_playlist,bit_array_one(p_item),bit_array_val(p_state)); +} + +void playlist_manager::activeplaylist_set_selection_single(t_size p_item,bool p_state) +{ + t_size playlist = get_active_playlist(); + if (playlist != infinite) playlist_set_selection_single(playlist,p_item,p_state); +} + +t_size playlist_manager::playlist_get_selection_count(t_size p_playlist,t_size p_max) +{ + enum_items_callback_count_selection callback(p_max); + playlist_enum_items(p_playlist,callback,bit_array_true()); + return callback.get_count(); +} + +t_size playlist_manager::activeplaylist_get_selection_count(t_size p_max) +{ + t_size playlist = get_active_playlist(); + if (playlist != infinite) return playlist_get_selection_count(playlist,p_max); + else return 0; +} + +bool playlist_manager::playlist_get_focus_item_handle(metadb_handle_ptr & p_out,t_size p_playlist) +{ + t_size index = playlist_get_focus_item(p_playlist); + if (index == infinite) return false; + return playlist_get_item_handle(p_out,p_playlist,index); +} + +bool playlist_manager::activeplaylist_get_focus_item_handle(metadb_handle_ptr & p_out) +{ + t_size playlist = get_active_playlist(); + if (playlist != infinite) return playlist_get_focus_item_handle(p_out,playlist); + else return false; +} + +t_size playlist_manager::find_playlist(const char * p_name,t_size p_name_length) +{ + t_size n, m = get_playlist_count(); + pfc::string_formatter temp; + for(n=0;n namebuffer; + namebuffer << new_playlist_text << " (" << walk << ")"; + if (find_playlist(namebuffer,infinite) == infinite) return create_playlist(namebuffer,infinite,p_index); + } +} + +bool playlist_manager::activeplaylist_sort_by_format(const char * spec,bool p_sel_only) +{ + t_size playlist = get_active_playlist(); + if (playlist != infinite) return playlist_sort_by_format(playlist,spec,p_sel_only); + else return false; +} + +bool playlist_manager::highlight_playing_item() +{ + t_size playlist,item; + if (!get_playing_item_location(&playlist,&item)) return false; + set_active_playlist(playlist); + playlist_set_focus_item(playlist,item); + playlist_set_selection(playlist,bit_array_true(),bit_array_one(item)); + playlist_ensure_visible(playlist,item); + return true; +} + +void playlist_manager::playlist_get_items(t_size p_playlist,pfc::list_base_t & out,const bit_array & p_mask) +{ + playlist_enum_items(p_playlist,enum_items_callback_retrieve_all_items(out),p_mask); +} + +void playlist_manager::activeplaylist_get_items(pfc::list_base_t & out,const bit_array & p_mask) +{ + t_size playlist = get_active_playlist(); + if (playlist != infinite) playlist_get_items(playlist,out,p_mask); +} + +void playlist_manager::active_playlist_fix() +{ + t_size playlist = get_active_playlist(); + if (playlist == infinite) + { + t_size max = get_playlist_count(); + if (max == 0) + { + create_playlist_autoname(); + } + set_active_playlist(0); + } +} + +namespace { + class enum_items_callback_remove_list : public playlist_manager::enum_items_callback + { + const metadb_handle_list & m_data; + bit_array_var & m_table; + t_size m_found; + public: + enum_items_callback_remove_list(const metadb_handle_list & p_data,bit_array_var & p_table) : m_data(p_data), m_table(p_table), m_found(0) {} + bool on_item(t_size p_index,const metadb_handle_ptr & p_location,bool b_selected) + { + bool found = m_data.bsearch_by_pointer(p_location) != infinite; + m_table.set(p_index,found); + if (found) m_found++; + return true; + } + + inline t_size get_found() const {return m_found;} + }; +} + +void playlist_manager::remove_items_from_all_playlists(const pfc::list_base_const_t & p_data) +{ + t_size playlist_num, playlist_max = get_playlist_count(); + if (playlist_max != infinite) + { + metadb_handle_list temp; + temp.add_items(p_data); + temp.sort_by_pointer(); + for(playlist_num = 0; playlist_num < playlist_max; playlist_num++ ) + { + t_size playlist_item_count = playlist_get_item_count(playlist_num); + if (playlist_item_count == infinite) break; + bit_array_bittable table(playlist_item_count); + enum_items_callback_remove_list callback(temp,table); + playlist_enum_items(playlist_num,callback,bit_array_true()); + if (callback.get_found()>0) + playlist_remove_items(playlist_num,table); + } + } +} + +bool playlist_manager::get_all_items(pfc::list_base_t & out) +{ + t_size n, m = get_playlist_count(); + if (m == infinite) return false; + enum_items_callback_retrieve_all_items callback(out); + for(n=0;n 0) + { + if (idx >= total) idx = total-1; + set_active_playlist(idx); + } + } + return true; + } + else return false; +} + + + +bool t_playback_queue_item::operator==(const t_playback_queue_item & p_item) const +{ + return m_handle == p_item.m_handle && m_playlist == p_item.m_playlist && m_item == p_item.m_item; +} + +bool t_playback_queue_item::operator!=(const t_playback_queue_item & p_item) const +{ + return m_handle != p_item.m_handle || m_playlist != p_item.m_playlist || m_item != p_item.m_item; +} + + + +bool playlist_manager::activeplaylist_execute_default_action(t_size p_item) { + t_size idx = get_active_playlist(); + if (idx == infinite) return false; + else return playlist_execute_default_action(idx,p_item); +} + +namespace { + class completion_notify_dfd : public completion_notify { + public: + completion_notify_dfd(const pfc::list_base_const_t & p_data,service_ptr_t p_notify) : m_data(p_data), m_notify(p_notify) {} + void on_completion(unsigned p_code) { + switch(p_code) { + case metadb_io::load_info_aborted: + m_notify->on_aborted(); + break; + default: + m_notify->on_completion(m_data); + break; + } + } + private: + metadb_handle_list m_data; + service_ptr_t m_notify; + }; +}; + +void dropped_files_data_impl::to_handles_async_ex(t_uint32 p_op_flags,HWND p_parentwnd,service_ptr_t p_notify) { + if (m_is_paths) { + static_api_ptr_t()->process_locations_async( + m_paths, + p_op_flags, + NULL, + NULL, + p_parentwnd, + p_notify); + } else { + t_uint32 flags = 0; + if (p_op_flags & playlist_incoming_item_filter_v2::op_flag_background) flags |= metadb_io_v2::op_flag_background; + if (p_op_flags & playlist_incoming_item_filter_v2::op_flag_delay_ui) flags |= metadb_io_v2::op_flag_delay_ui; + static_api_ptr_t()->load_info_async(m_handles,metadb_io::load_info_default,p_parentwnd,flags,new service_impl_t(m_handles,p_notify)); + } +} +void dropped_files_data_impl::to_handles_async(bool p_filter,HWND p_parentwnd,service_ptr_t p_notify) { + to_handles_async_ex(p_filter ? 0 : playlist_incoming_item_filter_v2::op_flag_no_filter,p_parentwnd,p_notify); +} + +bool dropped_files_data_impl::to_handles(pfc::list_base_t & p_out,bool p_filter,HWND p_parentwnd) { + if (m_is_paths) { + return static_api_ptr_t()->process_locations(m_paths,p_out,p_filter,NULL,NULL,p_parentwnd); + } else { + if (static_api_ptr_t()->load_info_multi(m_handles,metadb_io::load_info_default,p_parentwnd,true) == metadb_io::load_info_aborted) return false; + p_out = m_handles; + return true; + } +} + +void playlist_manager::playlist_activate_delta(int p_delta) { + const t_size total = get_playlist_count(); + if (total > 0) { + t_size active = get_active_playlist(); + + //clip p_delta to -(total-1)...(total-1) range + if (p_delta < 0) { + p_delta = - ( (-p_delta) % (t_ssize)total ); + } else { + p_delta = p_delta % total; + } + if (p_delta != 0) { + if (active == infinite) { + //special case when no playlist is active + if (p_delta > 0) { + active = (t_size)(p_delta - 1); + } else { + active = (total + p_delta);//p_delta is negative + } + } else { + active = (t_size) (active + total + p_delta) % total; + } + set_active_playlist(active % total); + } + } +} +namespace { + class enum_items_callback_get_selected_count : public playlist_manager::enum_items_callback { + public: + enum_items_callback_get_selected_count() : m_found() {} + t_size get_count() const {return m_found;} + bool on_item(t_size p_index,const metadb_handle_ptr & p_location,bool b_selected) { + if (b_selected) m_found++; + return true; + } + private: + t_size m_found; + }; +} +t_size playlist_manager::playlist_get_selected_count(t_size p_playlist,bit_array const & p_mask) { + enum_items_callback_get_selected_count callback; + playlist_enum_items(p_playlist,callback,p_mask); + return callback.get_count(); +} + +namespace { + class enum_items_callback_find_item : public playlist_manager::enum_items_callback { + public: + enum_items_callback_find_item(metadb_handle_ptr p_lookingFor) : m_result(infinite), m_lookingFor(p_lookingFor) {} + t_size result() const {return m_result;} + bool on_item(t_size p_index,const metadb_handle_ptr & p_location,bool b_selected) { + if (p_location == m_lookingFor) { + m_result = p_index; + return false; + } else { + return true; + } + } + private: + metadb_handle_ptr m_lookingFor; + t_size m_result; + }; + class enum_items_callback_find_item_selected : public playlist_manager::enum_items_callback { + public: + enum_items_callback_find_item_selected(metadb_handle_ptr p_lookingFor) : m_result(infinite), m_lookingFor(p_lookingFor) {} + t_size result() const {return m_result;} + bool on_item(t_size p_index,const metadb_handle_ptr & p_location,bool b_selected) { + if (b_selected && p_location == m_lookingFor) { + m_result = p_index; + return false; + } else { + return true; + } + } + private: + metadb_handle_ptr m_lookingFor; + t_size m_result; + }; +} + +bool playlist_manager::playlist_find_item(t_size p_playlist,metadb_handle_ptr p_item,t_size & p_result) { + enum_items_callback_find_item callback(p_item); + playlist_enum_items(p_playlist,callback,bit_array_true()); + t_size result = callback.result(); + if (result == infinite) return false; + p_result = result; + return true; +} +bool playlist_manager::playlist_find_item_selected(t_size p_playlist,metadb_handle_ptr p_item,t_size & p_result) { + enum_items_callback_find_item_selected callback(p_item); + playlist_enum_items(p_playlist,callback,bit_array_true()); + t_size result = callback.result(); + if (result == infinite) return false; + p_result = result; + return true; +} +t_size playlist_manager::playlist_set_focus_by_handle(t_size p_playlist,metadb_handle_ptr p_item) { + t_size index; + if (!playlist_find_item(p_playlist,p_item,index)) index = infinite; + playlist_set_focus_item(p_playlist,index); + return index; +} +bool playlist_manager::activeplaylist_find_item(metadb_handle_ptr p_item,t_size & p_result) { + t_size playlist = get_active_playlist(); + if (playlist == infinite) return false; + return playlist_find_item(playlist,p_item,p_result); +} +t_size playlist_manager::activeplaylist_set_focus_by_handle(metadb_handle_ptr p_item) { + t_size playlist = get_active_playlist(); + if (playlist == infinite) return infinite; + return playlist_set_focus_by_handle(playlist,p_item); +} + +pfc::com_ptr_t playlist_incoming_item_filter::create_dataobject_ex(metadb_handle_list_cref data) { + pfc::com_ptr_t temp; temp.attach( create_dataobject(data) ); PFC_ASSERT( temp.is_valid() ); return temp; +} + +void playlist_manager_v3::recycler_restore_by_id(t_uint32 id) { + t_size which = recycler_find_by_id(id); + if (which != ~0) recycler_restore(which); +} + +t_size playlist_manager_v3::recycler_find_by_id(t_uint32 id) { + const t_size total = recycler_get_count(); + for(t_size walk = 0; walk < total; ++walk) { + if (id == recycler_get_id(walk)) return walk; + } + return ~0; +} diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/playlist.h b/tools/vio2sf/src/foobar/foobar2000/SDK/playlist.h new file mode 100644 index 000000000..1dc9a9e4c --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/playlist.h @@ -0,0 +1,873 @@ +//! This interface allows filtering of playlist modification operations.\n +//! Implemented by components "locking" playlists; use playlist_manager::playlist_lock_install() etc to takeover specific playlist with your instance of playlist_lock. +class NOVTABLE playlist_lock : public service_base { +public: + enum { + filter_add = 1 << 0, + filter_remove = 1 << 1, + filter_reorder = 1 << 2, + filter_replace = 1 << 3, + filter_rename = 1 << 4, + filter_remove_playlist = 1 << 5, + filter_default_action = 1 << 6, + }; + + //! Queries whether specified item insertiion operation is allowed in the locked playlist. + //! @param p_base Index from which the items are being inserted. + //! @param p_data Items being inserted. + //! @param p_selection Caller-requested selection state of items being inserted. + //! @returns True to allow the operation, false to block it. + virtual bool query_items_add(t_size p_base, const pfc::list_base_const_t & p_data,const bit_array & p_selection) = 0; + //! Queries whether specified item reorder operation is allowed in the locked playlist. + //! @param p_order Pointer to array containing permutation defining requested reorder operation. + //! @param p_count Number of items in array pointed to by p_order. This should always be equal to number of items on the locked playlist. + //! @returns True to allow the operation, false to block it. + virtual bool query_items_reorder(const t_size * p_order,t_size p_count) = 0; + //! Queries whether specified item removal operation is allowed in the locked playlist. + //! @param p_mask Specifies which items from locked playlist are being removed. + //! @param p_force If set to true, the call is made only for notification purpose and items are getting removed regardless (after e.g. they have been physically removed). + //! @returns True to allow the operation, false to block it. Note that return value is ignored if p_force is set to true. + virtual bool query_items_remove(const bit_array & p_mask,bool p_force) = 0; + //! Queries whether specified item replacement operation is allowed in the locked playlist. + //! @param p_index Index of the item being replaced. + //! @param p_old Old value of the item being replaced. + //! @param p_new New value of the item being replaced. + //! @returns True to allow the operation, false to block it. + virtual bool query_item_replace(t_size p_index,const metadb_handle_ptr & p_old,const metadb_handle_ptr & p_new)=0; + //! Queries whether renaming the locked playlist is allowed. + //! @param p_new_name Requested new name of the playlist; a UTF-8 encoded string. + //! @param p_new_name_len Length limit of the name string, in bytes (actual string may be shorter if null terminator is encountered before). Set this to infinite to use plain null-terminated strings. + //! @returns True to allow the operation, false to block it. + virtual bool query_playlist_rename(const char * p_new_name,t_size p_new_name_len) = 0; + //! Queries whether removal of the locked playlist is allowed. Note that the lock will be released when the playlist is removed. + //! @returns True to allow the operation, false to block it. + virtual bool query_playlist_remove() = 0; + //! Executes "default action" (doubleclick etc) for specified playlist item. When the playlist is not locked, default action starts playback of the item. + //! @returns True if custom default action was executed, false to fall-through to default one for non-locked playlists (start playback). + virtual bool execute_default_action(t_size p_item) = 0; + //! Notifies lock about changed index of the playlist, in result of user reordering playlists or removing other playlists. + virtual void on_playlist_index_change(t_size p_new_index) = 0; + //! Notifies lock about the locked playlist getting removed. + virtual void on_playlist_remove() = 0; + //! Retrieves human-readable name of playlist lock to display. + virtual void get_lock_name(pfc::string_base & p_out) = 0; + //! Requests user interface of component controlling the playlist lock to be shown. + virtual void show_ui() = 0; + //! Queries which actions the lock filters. The return value must not change while the lock is registered with playlist_manager. The return value is a combination of one or more filter_* constants. + virtual t_uint32 get_filter_mask() = 0; + + FB2K_MAKE_SERVICE_INTERFACE(playlist_lock,service_base); +}; + +struct t_playback_queue_item { + metadb_handle_ptr m_handle; + t_size m_playlist,m_item; + + bool operator==(const t_playback_queue_item & p_item) const; + bool operator!=(const t_playback_queue_item & p_item) const; +}; + + +//! This service provides methods for all sorts of playlist interaction.\n +//! All playlist_manager methods are valid only from main app thread.\n +//! Usage: static_api_ptr_t. +class NOVTABLE playlist_manager : public service_base +{ +public: + + //! Callback interface for playlist enumeration methods. + class NOVTABLE enum_items_callback { + public: + //! @returns True to continue enumeration, false to abort. + virtual bool on_item(t_size p_index,const metadb_handle_ptr & p_location,bool b_selected) = 0;//return false to stop + }; + + //! Retrieves number of playlists. + virtual t_size get_playlist_count() = 0; + //! Retrieves index of active playlist; infinite if no playlist is active. + virtual t_size get_active_playlist() = 0; + //! Sets active playlist (infinite to set no active playlist). + virtual void set_active_playlist(t_size p_index) = 0; + //! Retrieves playlist from which items to be played are taken from. + virtual t_size get_playing_playlist() = 0; + //! Sets playlist from which items to be played are taken from. + virtual void set_playing_playlist(t_size p_index) = 0; + //! Removes playlists according to specified mask. See also: bit_array. + virtual bool remove_playlists(const bit_array & p_mask) = 0; + //! Creates a new playlist. + //! @param p_name Name of playlist to create; a UTF-8 encoded string. + //! @param p_name_length Length limit of playlist name string, in bytes (actual string may be shorter if null terminator is encountered before). Set this to infinite to use plain null-terminated strings. + //! @param p_index Index at which to insert new playlist; set to infinite to put it at the end of playlist list. + //! @returns Actual index of newly inserted playlist, infinite on failure (call from invalid context). + virtual t_size create_playlist(const char * p_name,t_size p_name_length,t_size p_index) = 0; + //! Reorders the playlist list according to specified permutation. + //! @returns True on success, false on failure (call from invalid context). + virtual bool reorder(const t_size * p_order,t_size p_count) = 0; + + + //! Retrieves number of items on specified playlist. + virtual t_size playlist_get_item_count(t_size p_playlist) = 0; + //! Enumerates contents of specified playlist. + virtual void playlist_enum_items(t_size p_playlist,enum_items_callback & p_callback,const bit_array & p_mask) = 0; + //! Retrieves index of focus item on specified playlist; returns infinite when no item has focus. + virtual t_size playlist_get_focus_item(t_size p_playlist) = 0; + //! Retrieves name of specified playlist. Should never fail unless the parameters are invalid. + virtual bool playlist_get_name(t_size p_playlist,pfc::string_base & p_out) = 0; + + //! Reorders items in specified playlist according to specified permutation. + virtual bool playlist_reorder_items(t_size p_playlist,const t_size * p_order,t_size p_count) = 0; + //! Selects/deselects items on specified playlist. + //! @param p_playlist Index of playlist to alter. + //! @param p_affected Mask of items to alter. + //! @param p_status Mask of selected/deselected state to apply to items specified by p_affected. + virtual void playlist_set_selection(t_size p_playlist,const bit_array & p_affected,const bit_array & p_status) = 0; + //! Removes specified items from specified playlist. Returns true on success or false on failure (playlist locked). + virtual bool playlist_remove_items(t_size p_playlist,const bit_array & mask)=0; + //! Replaces specified item on specified playlist. Returns true on success or false on failure (playlist locked). + virtual bool playlist_replace_item(t_size p_playlist,t_size p_item,const metadb_handle_ptr & p_new_item) = 0; + //! Sets index of focus item on specified playlist; use infinite to set no focus item. + virtual void playlist_set_focus_item(t_size p_playlist,t_size p_item) = 0; + //! Inserts new items into specified playlist, at specified position. + virtual t_size playlist_insert_items(t_size p_playlist,t_size p_base,const pfc::list_base_const_t & data,const bit_array & p_selection) = 0; + //! Tells playlist renderers to make sure that specified item is visible. + virtual void playlist_ensure_visible(t_size p_playlist,t_size p_item) = 0; + //! Renames specified playlist. + //! @param p_name New name of playlist; a UTF-8 encoded string. + //! @param p_name_length Length limit of playlist name string, in bytes (actual string may be shorter if null terminator is encountered before). Set this to infinite to use plain null-terminated strings. + //! @returns True on success, false on failure (playlist locked). + virtual bool playlist_rename(t_size p_index,const char * p_name,t_size p_name_length) = 0; + + + //! Creates an undo restore point for specified playlist. + virtual void playlist_undo_backup(t_size p_playlist) = 0; + //! Reverts specified playlist to last undo restore point and generates a redo restore point. + //! @returns True on success, false on failure (playlist locked or no restore point available). + virtual bool playlist_undo_restore(t_size p_playlist) = 0; + //! Reverts specified playlist to next redo restore point and generates an undo restore point. + //! @returns True on success, false on failure (playlist locked or no restore point available). + virtual bool playlist_redo_restore(t_size p_playlist) = 0; + //! Returns whether an undo restore point is available for specified playlist. + virtual bool playlist_is_undo_available(t_size p_playlist) = 0; + //! Returns whether a redo restore point is available for specified playlist. + virtual bool playlist_is_redo_available(t_size p_playlist) = 0; + + //! Renders information about specified playlist item, using specified titleformatting script parameters. + //! @param p_playlist Index of playlist containing item being processed. + //! @param p_item Index of item being processed in the playlist containing it. + //! @param p_hook Titleformatting script hook to use; see titleformat_hook documentation for more info. Set to NULL when hook functionality is not needed. + //! @param p_out String object receiving results. + //! @param p_script Compiled titleformatting script to use; see titleformat_object cocumentation for more info. + //! @param p_filter Text filter to use; see titleformat_text_filter documentation for more info. Set to NULL when text filter functionality is not needed. + //! @param p_playback_info_level Level of playback related information requested. See playback_control::t_display_level documentation for more info. + virtual void playlist_item_format_title(t_size p_playlist,t_size p_item,titleformat_hook * p_hook,pfc::string_base & p_out,const service_ptr_t & p_script,titleformat_text_filter * p_filter,playback_control::t_display_level p_playback_info_level)=0; + + + //! Retrieves playlist position of currently playing item. + //! @param p_playlist Receives index of playlist containing currently playing item on success. + //! @param p_index Receives index of currently playing item in the playlist that contains it on success. + //! @returns True on success, false on failure (not playing or currently played item has been removed from the playlist it was on when starting). + virtual bool get_playing_item_location(t_size * p_playlist,t_size * p_index) = 0; + + //! Sorts specified playlist - entire playlist or selection only - by specified title formatting pattern, or randomizes the order. + //! @param p_playlist Index of playlist to alter. + //! @param p_pattern Title formatting pattern to sort by (an UTF-8 encoded null-termindated string). Set to NULL to randomize the order of items. + //! @param p_sel_only Set to false to sort/randomize whole playlist, or to true to sort/randomize only selection on the playlist. + //! @returns True on success, false on failure (playlist locked etc). + virtual bool playlist_sort_by_format(t_size p_playlist,const char * p_pattern,bool p_sel_only) = 0; + + //! For internal use only; p_items must be sorted by metadb::path_compare; use file_operation_callback static methods instead of calling this directly. + virtual void on_files_deleted_sorted(const pfc::list_base_const_t & p_items) = 0; + //! For internal use only; p_from must be sorted by metadb::path_compare; use file_operation_callback static methods instead of calling this directly. + virtual void on_files_moved_sorted(const pfc::list_base_const_t & p_from,const pfc::list_base_const_t & p_to) = 0; + + virtual bool playlist_lock_install(t_size p_playlist,const service_ptr_t & p_lock) = 0;//returns false when invalid playlist or already locked + virtual bool playlist_lock_uninstall(t_size p_playlist,const service_ptr_t & p_lock) = 0; + virtual bool playlist_lock_is_present(t_size p_playlist) = 0; + virtual bool playlist_lock_query_name(t_size p_playlist,pfc::string_base & p_out) = 0; + virtual bool playlist_lock_show_ui(t_size p_playlist) = 0; + virtual t_uint32 playlist_lock_get_filter_mask(t_size p_playlist) = 0; + + + //! Retrieves number of available playback order modes. + virtual t_size playback_order_get_count() = 0; + //! Retrieves name of specified playback order move. + //! @param p_index Index of playback order mode to query, from 0 to playback_order_get_count() return value - 1. + //! @returns Null-terminated UTF-8 encoded string containing name of the playback order mode. Returned pointer points to statically allocated string and can be safely stored without having to free it later. + virtual const char * playback_order_get_name(t_size p_index) = 0; + //! Retrieves GUID of specified playback order mode. Used for managing playback modes without relying on names. + //! @param p_index Index of playback order mode to query, from 0 to playback_order_get_count() return value - 1. + virtual GUID playback_order_get_guid(t_size p_index) = 0; + //! Retrieves index of active playback order mode. + virtual t_size playback_order_get_active() = 0; + //! Sets index of active playback order mode. + virtual void playback_order_set_active(t_size p_index) = 0; + + virtual void queue_remove_mask(bit_array const & p_mask) = 0; + virtual void queue_add_item_playlist(t_size p_playlist,t_size p_item) = 0; + virtual void queue_add_item(metadb_handle_ptr p_item) = 0; + virtual t_size queue_get_count() = 0; + virtual void queue_get_contents(pfc::list_base_t & p_out) = 0; + //! Returns index (0-based) on success, infinite on failure (item not in queue). + virtual t_size queue_find_index(t_playback_queue_item const & p_item) = 0; + + //! Registers a playlist callback; registered object receives notifications about any modifications of any of loaded playlists. + //! @param p_callback Callback interface to register. + //! @param p_flags Flags indicating which callback methods are requested. See playlist_callback::flag_* constants for more info. The main purpose of flags parameter is working set optimization by not calling methods that do nothing. + virtual void register_callback(class playlist_callback * p_callback,unsigned p_flags) = 0; + //! Registers a playlist callback; registered object receives notifications about any modifications of active playlist. + //! @param p_callback Callback interface to register. + //! @param p_flags Flags indicating which callback methods are requested. See playlist_callback_single::flag_* constants for more info. The main purpose of flags parameter is working set optimization by not calling methods that do nothing. + virtual void register_callback(class playlist_callback_single * p_callback,unsigned p_flags) = 0; + //! Unregisters a playlist callback (playlist_callback version). + virtual void unregister_callback(class playlist_callback * p_callback) = 0; + //! Unregisters a playlist callback (playlist_callback_single version). + virtual void unregister_callback(class playlist_callback_single * p_callback) = 0; + //! Modifies flags indicating which calback methods are requested (playlist_callback version). + virtual void modify_callback(class playlist_callback * p_callback,unsigned p_flags) = 0; + //! Modifies flags indicating which calback methods are requested (playlist_callback_single version). + virtual void modify_callback(class playlist_callback_single * p_callback,unsigned p_flags) = 0; + + //! Executes default doubleclick/enter action for specified item on specified playlist (starts playing the item unless overridden by a lock to do something else). + virtual bool playlist_execute_default_action(t_size p_playlist,t_size p_item) = 0; + + + //! Helper; removes all items from the playback queue. + void queue_flush() {queue_remove_mask(bit_array_true());} + //! Helper; returns whether there are items in the playback queue. + bool queue_is_active() {return queue_get_count() > 0;} + + //! Helper; highlights currently playing item; returns true on success or false on failure (not playing or currently played item has been removed from playlist since playback started). + bool highlight_playing_item(); + //! Helper; removes single playlist of specified index. + bool remove_playlist(t_size p_playlist); + //! Helper; removes single playlist of specified index, and switches to another playlist when possible. + bool remove_playlist_switch(t_size p_playlist); + + //! Helper; returns whether specified item on specified playlist is selected or not. + bool playlist_is_item_selected(t_size p_playlist,t_size p_item); + //! Helper; retrieves metadb_handle of the specified playlist item. Returns true on success, false on failure (invalid parameters). + bool playlist_get_item_handle(metadb_handle_ptr & p_out,t_size p_playlist,t_size p_item); + //! Helper; retrieves metadb_handle of the specified playlist item; throws pfc::exception_invalid_params() on failure. + metadb_handle_ptr playlist_get_item_handle(t_size playlist, t_size item); + + //! Moves selected items up/down in the playlist by specified offset. + //! @param p_playlist Index of playlist to alter. + //! @param p_delta Offset to move items by. Set it to a negative valuye to move up, or to a positive value to move down. + //! @returns True on success, false on failure (e.g. playlist locked). + bool playlist_move_selection(t_size p_playlist,int p_delta); + //! Retrieves selection map of specific playlist, using bit_array_var interface. + void playlist_get_selection_mask(t_size p_playlist,bit_array_var & out); + void playlist_get_items(t_size p_playlist,pfc::list_base_t & out,const bit_array & p_mask); + void playlist_get_all_items(t_size p_playlist,pfc::list_base_t & out); + void playlist_get_selected_items(t_size p_playlist,pfc::list_base_t & out); + + //! Clears contents of specified playlist (removes all items from it). + void playlist_clear(t_size p_playlist); + bool playlist_add_items(t_size playlist,const pfc::list_base_const_t & data,const bit_array & p_selection); + void playlist_clear_selection(t_size p_playlist); + void playlist_remove_selection(t_size p_playlist,bool p_crop = false); + + + //! Changes contents of the specified playlist to the specified items, trying to reuse existing playlist content as much as possible (preserving selection/focus/etc). Order of items in playlist not guaranteed to be the same as in the specified item list. + //! @returns true if the playlist has been altered, false if there was nothing to update. + bool playlist_update_content(t_size playlist, metadb_handle_list_cref content, bool bUndoBackup); + + //retrieving status + t_size activeplaylist_get_item_count(); + void activeplaylist_enum_items(enum_items_callback & p_callback,const bit_array & p_mask); + t_size activeplaylist_get_focus_item();//focus may be infinite if no item is focused + bool activeplaylist_get_name(pfc::string_base & p_out); + + //modifying playlist + bool activeplaylist_reorder_items(const t_size * order,t_size count); + void activeplaylist_set_selection(const bit_array & affected,const bit_array & status); + bool activeplaylist_remove_items(const bit_array & mask); + bool activeplaylist_replace_item(t_size p_item,const metadb_handle_ptr & p_new_item); + void activeplaylist_set_focus_item(t_size p_item); + t_size activeplaylist_insert_items(t_size p_base,const pfc::list_base_const_t & data,const bit_array & p_selection); + void activeplaylist_ensure_visible(t_size p_item); + bool activeplaylist_rename(const char * p_name,t_size p_name_len); + + void activeplaylist_undo_backup(); + bool activeplaylist_undo_restore(); + bool activeplaylist_redo_restore(); + + bool activeplaylist_is_item_selected(t_size p_item); + bool activeplaylist_get_item_handle(metadb_handle_ptr & item,t_size p_item); + metadb_handle_ptr activeplaylist_get_item_handle(t_size p_item); + void activeplaylist_move_selection(int p_delta); + void activeplaylist_get_selection_mask(bit_array_var & out); + void activeplaylist_get_items(pfc::list_base_t & out,const bit_array & p_mask); + void activeplaylist_get_all_items(pfc::list_base_t & out); + void activeplaylist_get_selected_items(pfc::list_base_t & out); + void activeplaylist_clear(); + + bool activeplaylist_add_items(const pfc::list_base_const_t & data,const bit_array & p_selection); + + bool playlist_insert_items_filter(t_size p_playlist,t_size p_base,const pfc::list_base_const_t & p_data,bool p_select); + bool activeplaylist_insert_items_filter(t_size p_base,const pfc::list_base_const_t & p_data,bool p_select); + + //! \deprecated (since 0.9.3) Use playlist_incoming_item_filter_v2::process_locations_async whenever possible + bool playlist_insert_locations(t_size p_playlist,t_size p_base,const pfc::list_base_const_t & p_urls,bool p_select,HWND p_parentwnd); + //! \deprecated (since 0.9.3) Use playlist_incoming_item_filter_v2::process_locations_async whenever possible + bool activeplaylist_insert_locations(t_size p_base,const pfc::list_base_const_t & p_urls,bool p_select,HWND p_parentwnd); + + bool playlist_add_items_filter(t_size p_playlist,const pfc::list_base_const_t & p_data,bool p_select); + bool activeplaylist_add_items_filter(const pfc::list_base_const_t & p_data,bool p_select); + + bool playlist_add_locations(t_size p_playlist,const pfc::list_base_const_t & p_urls,bool p_select,HWND p_parentwnd); + bool activeplaylist_add_locations(const pfc::list_base_const_t & p_urls,bool p_select,HWND p_parentwnd); + + void reset_playing_playlist(); + + void activeplaylist_clear_selection(); + void activeplaylist_remove_selection(bool p_crop = false); + + void activeplaylist_item_format_title(t_size p_item,titleformat_hook * p_hook,pfc::string_base & out,const service_ptr_t & p_script,titleformat_text_filter * p_filter,play_control::t_display_level p_playback_info_level); + + void playlist_set_selection_single(t_size p_playlist,t_size p_item,bool p_state); + void activeplaylist_set_selection_single(t_size p_item,bool p_state); + + t_size playlist_get_selection_count(t_size p_playlist,t_size p_max); + t_size activeplaylist_get_selection_count(t_size p_max); + + bool playlist_get_focus_item_handle(metadb_handle_ptr & p_item,t_size p_playlist); + bool activeplaylist_get_focus_item_handle(metadb_handle_ptr & item); + + t_size find_playlist(const char * p_name,t_size p_name_length = ~0); + t_size find_or_create_playlist(const char * p_name,t_size p_name_length = ~0); + t_size find_or_create_playlist_unlocked(const char * p_name,t_size p_name_length = ~0); + + t_size create_playlist_autoname(t_size p_index = infinite); + + bool activeplaylist_sort_by_format(const char * spec,bool p_sel_only); + + t_uint32 activeplaylist_lock_get_filter_mask(); + bool activeplaylist_is_undo_available(); + bool activeplaylist_is_redo_available(); + + bool activeplaylist_execute_default_action(t_size p_item); + + void remove_items_from_all_playlists(const pfc::list_base_const_t & p_data); + + void active_playlist_fix(); + + bool get_all_items(pfc::list_base_t & out); + + void playlist_activate_delta(int p_delta); + void playlist_activate_next() {playlist_activate_delta(1);} + void playlist_activate_previous() {playlist_activate_delta(-1);} + + + t_size playlist_get_selected_count(t_size p_playlist,bit_array const & p_mask); + t_size activeplaylist_get_selected_count(bit_array const & p_mask) {return playlist_get_selected_count(get_active_playlist(),p_mask);} + + bool playlist_find_item(t_size p_playlist,metadb_handle_ptr p_item,t_size & p_result);//inefficient, walks entire playlist + bool playlist_find_item_selected(t_size p_playlist,metadb_handle_ptr p_item,t_size & p_result);//inefficient, walks entire playlist + t_size playlist_set_focus_by_handle(t_size p_playlist,metadb_handle_ptr p_item); + bool activeplaylist_find_item(metadb_handle_ptr p_item,t_size & p_result);//inefficient, walks entire playlist + t_size activeplaylist_set_focus_by_handle(metadb_handle_ptr p_item); + + static void g_make_selection_move_permutation(t_size * p_output,t_size p_count,const bit_array & p_selection,int p_delta); + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(playlist_manager); +}; + +//! Extension of the playlist_manager service that manages playlist properties. +//! Playlist properties come in two flavors: persistent and runtime. +//! Persistent properties are blocks of binary that that will be preserved when the application is exited and restarted. +//! Runtime properties are service pointers that will be lost when the application exits. +//! \since 0.9.5 +class NOVTABLE playlist_manager_v2 : public playlist_manager { +public: + //! Write a persistent playlist property. + //! \param p_playlist Index of the playlist + //! \param p_property GUID that identifies the property + //! \param p_stream stream that contains the data that will be associated with the property + //! \param p_abort abort_callback that will be used when reading from p_stream + virtual void playlist_set_property(t_size p_playlist,const GUID & p_property,stream_reader * p_stream,t_size p_size_hint,abort_callback & p_abort) = 0; + //! Read a persistent playlist property. + //! \param p_playlist Index of the playlist + //! \param p_property GUID that identifies the property + //! \param p_stream stream that will receive the stored data + //! \param p_abort abort_callback that will be used when writing to p_stream + //! \return true if the property exists, false otherwise + virtual bool playlist_get_property(t_size p_playlist,const GUID & p_property,stream_writer * p_stream,abort_callback & p_abort) = 0; + //! Test existence of a persistent playlist property. + //! \param p_playlist Index of the playlist + //! \param p_property GUID that identifies the property + //! \return true if the property exists, false otherwise + virtual bool playlist_have_property(t_size p_playlist,const GUID & p_property) = 0; + //! Remove a persistent playlist property. + //! \param p_playlist Index of the playlist + //! \param p_property GUID that identifies the property + //! \return true if the property existed, false otherwise + virtual bool playlist_remove_property(t_size p_playlist,const GUID & p_property) = 0; + + //! Write a runtime playlist property. + //! \param p_playlist Index of the playlist + //! \param p_property GUID that identifies the property + //! \param p_data service pointer that will be associated with the property + virtual void playlist_set_runtime_property(t_size p_playlist,const GUID & p_property,service_ptr_t p_data) = 0; + //! Read a runtime playlist property. + //! \param p_playlist Index of the playlist + //! \param p_property GUID that identifies the property + //! \param p_data base service pointer reference that will receive the stored servive pointer + //! \return true if the property exists, false otherwise + virtual bool playlist_get_runtime_property(t_size p_playlist,const GUID & p_property,service_ptr_t & p_data) = 0; + //! Test existence of a runtime playlist property. + //! \param p_playlist Index of the playlist + //! \param p_property GUID that identifies the property + //! \return true if the property exists, false otherwise + virtual bool playlist_have_runtime_property(t_size p_playlist,const GUID & p_property) = 0; + //! Remove a runtime playlist property. + //! \param p_playlist Index of the playlist + //! \param p_property GUID that identifies the property + //! \return true if the property existed, false otherwise + virtual bool playlist_remove_runtime_property(t_size p_playlist,const GUID & p_property) = 0; + + //! Write a persistent playlist property. + //! \param p_playlist Index of the playlist + //! \param p_property GUID that identifies the property + //! \param p_data array that contains the data that will be associated with the property + template void playlist_set_property(t_size p_playlist,const GUID & p_property,const t_array & p_data) { + pfc::static_assert(); + playlist_set_property(p_playlist,p_property,&stream_reader_memblock_ref(p_data),p_data.get_size(),abort_callback_impl()); + } + //! Read a persistent playlist property. + //! \param p_playlist Index of the playlist + //! \param p_property GUID that identifies the property + //! \param p_data array that will receive the stored data + //! \return true if the property exists, false otherwise + template bool playlist_get_property(t_size p_playlist,const GUID & p_property,t_array & p_data) { + pfc::static_assert(); + typedef pfc::array_t t_temp; + t_temp temp; + if (!playlist_get_property(p_playlist,p_property,&stream_writer_buffer_append_ref_t(temp),abort_callback_impl())) return false; + p_data = temp; + return true; + } + //! Read a runtime playlist property. + //! \param p_playlist Index of the playlist + //! \param p_property GUID that identifies the property + //! \param p_data specific service pointer reference that will receive the stored servive pointer + //! \return true if the property exists and can be converted to the type of p_data, false otherwise + template bool playlist_get_runtime_property(t_size p_playlist,const GUID & p_property,service_ptr_t<_t_interface> & p_data) { + service_ptr_t ptr; + if (!playlist_get_runtime_property(p_playlist,p_property,ptr)) return false; + return ptr->service_query_t(p_data); + } + + //! Write a persistent playlist property. + //! \param p_playlist Index of the playlist + //! \param p_property GUID that identifies the property + //! \param p_value integer that will be associated with the property + template + void playlist_set_property_int(t_size p_playlist,const GUID & p_property,_t_int p_value) { + pfc::array_t temp; temp.set_size(sizeof(_t_int)); + pfc::encode_little_endian(temp.get_ptr(),p_value); + playlist_set_property(p_playlist,p_property,temp); + } + //! Read a persistent playlist property. + //! \param p_playlist Index of the playlist + //! \param p_property GUID that identifies the property + //! \param p_value integer reference that will receive the stored data + //! \return true if the property exists and if the data is compatible with p_value, false otherwise + template + bool playlist_get_property_int(t_size p_playlist,const GUID & p_property,_t_int & p_value) { + pfc::array_t temp; + if (!playlist_get_property(p_playlist,p_property,temp)) return false; + if (temp.get_size() != sizeof(_t_int)) return false; + pfc::decode_little_endian(p_value,temp.get_ptr()); + return true; + } + + FB2K_MAKE_SERVICE_INTERFACE(playlist_manager_v2,playlist_manager) +}; + +//! \since 0.9.5 +class NOVTABLE playlist_manager_v3 : public playlist_manager_v2 { + FB2K_MAKE_SERVICE_INTERFACE(playlist_manager_v3,playlist_manager_v2) +public: + virtual t_size recycler_get_count() = 0; + virtual void recycler_get_content(t_size which, metadb_handle_list_ref out) = 0; + virtual void recycler_get_name(t_size which, pfc::string_base & out) = 0; + virtual t_uint32 recycler_get_id(t_size which) = 0; + virtual void recycler_purge(const bit_array & mask) = 0; + virtual void recycler_restore(t_size which) = 0; + + void recycler_restore_by_id(t_uint32 id); + t_size recycler_find_by_id(t_uint32 id); +}; + +//! \since 0.9.5.4 +class NOVTABLE playlist_manager_v4 : public playlist_manager_v3 { + FB2K_MAKE_SERVICE_INTERFACE(playlist_manager_v4, playlist_manager_v3) +public: + virtual void playlist_get_sideinfo(t_size which, stream_writer * stream, abort_callback & abort) = 0; + virtual t_size create_playlist_ex(const char * p_name,t_size p_name_length,t_size p_index, metadb_handle_list_cref content, stream_reader * sideInfo, abort_callback & abort) = 0; +}; + +class NOVTABLE playlist_callback +{ +public: + virtual void on_items_added(t_size p_playlist,t_size p_start, const pfc::list_base_const_t & p_data,const bit_array & p_selection)=0;//inside any of these methods, you can call playlist APIs to get exact info about what happened (but only methods that read playlist state, not those that modify it) + virtual void on_items_reordered(t_size p_playlist,const t_size * p_order,t_size p_count)=0;//changes selection too; doesnt actually change set of items that are selected or item having focus, just changes their order + virtual void on_items_removing(t_size p_playlist,const bit_array & p_mask,t_size p_old_count,t_size p_new_count)=0;//called before actually removing them + virtual void on_items_removed(t_size p_playlist,const bit_array & p_mask,t_size p_old_count,t_size p_new_count)=0; + virtual void on_items_selection_change(t_size p_playlist,const bit_array & p_affected,const bit_array & p_state) = 0; + virtual void on_item_focus_change(t_size p_playlist,t_size p_from,t_size p_to)=0;//focus may be -1 when no item has focus; reminder: focus may also change on other callbacks + + virtual void on_items_modified(t_size p_playlist,const bit_array & p_mask)=0; + virtual void on_items_modified_fromplayback(t_size p_playlist,const bit_array & p_mask,play_control::t_display_level p_level)=0; + + struct t_on_items_replaced_entry + { + t_size m_index; + metadb_handle_ptr m_old,m_new; + }; + + virtual void on_items_replaced(t_size p_playlist,const bit_array & p_mask,const pfc::list_base_const_t & p_data)=0; + + virtual void on_item_ensure_visible(t_size p_playlist,t_size p_idx)=0; + + virtual void on_playlist_activate(t_size p_old,t_size p_new) = 0; + virtual void on_playlist_created(t_size p_index,const char * p_name,t_size p_name_len) = 0; + virtual void on_playlists_reorder(const t_size * p_order,t_size p_count) = 0; + virtual void on_playlists_removing(const bit_array & p_mask,t_size p_old_count,t_size p_new_count) = 0; + virtual void on_playlists_removed(const bit_array & p_mask,t_size p_old_count,t_size p_new_count) = 0; + virtual void on_playlist_renamed(t_size p_index,const char * p_new_name,t_size p_new_name_len) = 0; + + virtual void on_default_format_changed() = 0; + virtual void on_playback_order_changed(t_size p_new_index) = 0; + virtual void on_playlist_locked(t_size p_playlist,bool p_locked) = 0; + + enum { + flag_on_items_added = 1 << 0, + flag_on_items_reordered = 1 << 1, + flag_on_items_removing = 1 << 2, + flag_on_items_removed = 1 << 3, + flag_on_items_selection_change = 1 << 4, + flag_on_item_focus_change = 1 << 5, + flag_on_items_modified = 1 << 6, + flag_on_items_modified_fromplayback = 1 << 7, + flag_on_items_replaced = 1 << 8, + flag_on_item_ensure_visible = 1 << 9, + flag_on_playlist_activate = 1 << 10, + flag_on_playlist_created = 1 << 11, + flag_on_playlists_reorder = 1 << 12, + flag_on_playlists_removing = 1 << 13, + flag_on_playlists_removed = 1 << 14, + flag_on_playlist_renamed = 1 << 15, + flag_on_default_format_changed = 1 << 16, + flag_on_playback_order_changed = 1 << 17, + flag_on_playlist_locked = 1 << 18, + + flag_all = ~0, + flag_item_ops = flag_on_items_added | flag_on_items_reordered | flag_on_items_removing | flag_on_items_removed | flag_on_items_selection_change | flag_on_item_focus_change | flag_on_items_modified | flag_on_items_modified_fromplayback | flag_on_items_replaced | flag_on_item_ensure_visible, + flag_playlist_ops = flag_on_playlist_activate | flag_on_playlist_created | flag_on_playlists_reorder | flag_on_playlists_removing | flag_on_playlists_removed | flag_on_playlist_renamed | flag_on_playlist_locked, + }; +protected: + playlist_callback() {} + ~playlist_callback() {} +}; + +class NOVTABLE playlist_callback_static : public service_base, public playlist_callback +{ +public: + virtual unsigned get_flags() = 0; + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(playlist_callback_static); +}; + +class NOVTABLE playlist_callback_single +{ +public: + virtual void on_items_added(t_size p_base, const pfc::list_base_const_t & p_data,const bit_array & p_selection)=0;//inside any of these methods, you can call playlist APIs to get exact info about what happened (but only methods that read playlist state, not those that modify it) + virtual void on_items_reordered(const t_size * p_order,t_size p_count)=0;//changes selection too; doesnt actually change set of items that are selected or item having focus, just changes their order + virtual void on_items_removing(const bit_array & p_mask,t_size p_old_count,t_size p_new_count)=0;//called before actually removing them + virtual void on_items_removed(const bit_array & p_mask,t_size p_old_count,t_size p_new_count)=0; + virtual void on_items_selection_change(const bit_array & p_affected,const bit_array & p_state) = 0; + virtual void on_item_focus_change(t_size p_from,t_size p_to)=0;//focus may be -1 when no item has focus; reminder: focus may also change on other callbacks + virtual void on_items_modified(const bit_array & p_mask)=0; + virtual void on_items_modified_fromplayback(const bit_array & p_mask,play_control::t_display_level p_level)=0; + virtual void on_items_replaced(const bit_array & p_mask,const pfc::list_base_const_t & p_data)=0; + virtual void on_item_ensure_visible(t_size p_idx)=0; + + virtual void on_playlist_switch() = 0; + virtual void on_playlist_renamed(const char * p_new_name,t_size p_new_name_len) = 0; + virtual void on_playlist_locked(bool p_locked) = 0; + + virtual void on_default_format_changed() = 0; + virtual void on_playback_order_changed(t_size p_new_index) = 0; + + enum { + flag_on_items_added = 1 << 0, + flag_on_items_reordered = 1 << 1, + flag_on_items_removing = 1 << 2, + flag_on_items_removed = 1 << 3, + flag_on_items_selection_change = 1 << 4, + flag_on_item_focus_change = 1 << 5, + flag_on_items_modified = 1 << 6, + flag_on_items_modified_fromplayback = 1 << 7, + flag_on_items_replaced = 1 << 8, + flag_on_item_ensure_visible = 1 << 9, + flag_on_playlist_switch = 1 << 10, + flag_on_playlist_renamed = 1 << 11, + flag_on_playlist_locked = 1 << 12, + flag_on_default_format_changed = 1 << 13, + flag_on_playback_order_changed = 1 << 14, + flag_all = ~0, + }; +protected: + playlist_callback_single() {} + ~playlist_callback_single() {} +}; + +//! playlist_callback implementation helper - registers itself on creation / unregisters on destruction. Must not be instantiated statically! +class playlist_callback_impl_base : public playlist_callback { +public: + playlist_callback_impl_base(t_uint32 p_flags = 0) { + static_api_ptr_t()->register_callback(this,p_flags); + } + ~playlist_callback_impl_base() { + static_api_ptr_t()->unregister_callback(this); + } + void set_callback_flags(t_uint32 p_flags) { + static_api_ptr_t()->modify_callback(this,p_flags); + } + //dummy implementations - avoid possible pure virtual function calls! + void on_items_added(t_size p_playlist,t_size p_start, const pfc::list_base_const_t & p_data,const bit_array & p_selection) {} + void on_items_reordered(t_size p_playlist,const t_size * p_order,t_size p_count) {} + void on_items_removing(t_size p_playlist,const bit_array & p_mask,t_size p_old_count,t_size p_new_count) {} + void on_items_removed(t_size p_playlist,const bit_array & p_mask,t_size p_old_count,t_size p_new_count) {} + void on_items_selection_change(t_size p_playlist,const bit_array & p_affected,const bit_array & p_state) {} + void on_item_focus_change(t_size p_playlist,t_size p_from,t_size p_to) {} + + void on_items_modified(t_size p_playlist,const bit_array & p_mask) {} + void on_items_modified_fromplayback(t_size p_playlist,const bit_array & p_mask,play_control::t_display_level p_level) {} + + void on_items_replaced(t_size p_playlist,const bit_array & p_mask,const pfc::list_base_const_t & p_data) {} + + void on_item_ensure_visible(t_size p_playlist,t_size p_idx) {} + + void on_playlist_activate(t_size p_old,t_size p_new) {} + void on_playlist_created(t_size p_index,const char * p_name,t_size p_name_len) {} + void on_playlists_reorder(const t_size * p_order,t_size p_count) {} + void on_playlists_removing(const bit_array & p_mask,t_size p_old_count,t_size p_new_count) {} + void on_playlists_removed(const bit_array & p_mask,t_size p_old_count,t_size p_new_count) {} + void on_playlist_renamed(t_size p_index,const char * p_new_name,t_size p_new_name_len) {} + + void on_default_format_changed() {} + void on_playback_order_changed(t_size p_new_index) {} + void on_playlist_locked(t_size p_playlist,bool p_locked) {} +}; + +//! playlist_callback_single implementation helper - registers itself on creation / unregisters on destruction. Must not be instantiated statically! +class playlist_callback_single_impl_base : public playlist_callback_single { +protected: + playlist_callback_single_impl_base(t_uint32 p_flags = 0) { + static_api_ptr_t()->register_callback(this,p_flags); + } + void set_callback_flags(t_uint32 p_flags) { + static_api_ptr_t()->modify_callback(this,p_flags); + } + ~playlist_callback_single_impl_base() { + static_api_ptr_t()->unregister_callback(this); + } + + //dummy implementations - avoid possible pure virtual function calls! + void on_items_added(t_size p_base, const pfc::list_base_const_t & p_data,const bit_array & p_selection) {} + void on_items_reordered(const t_size * p_order,t_size p_count) {} + void on_items_removing(const bit_array & p_mask,t_size p_old_count,t_size p_new_count) {} + void on_items_removed(const bit_array & p_mask,t_size p_old_count,t_size p_new_count) {} + void on_items_selection_change(const bit_array & p_affected,const bit_array & p_state) {} + void on_item_focus_change(t_size p_from,t_size p_to) {} + void on_items_modified(const bit_array & p_mask) {} + void on_items_modified_fromplayback(const bit_array & p_mask,play_control::t_display_level p_level) {} + void on_items_replaced(const bit_array & p_mask,const pfc::list_base_const_t & p_data) {} + void on_item_ensure_visible(t_size p_idx) {} + + void on_playlist_switch() {} + void on_playlist_renamed(const char * p_new_name,t_size p_new_name_len) {} + void on_playlist_locked(bool p_locked) {} + + void on_default_format_changed() {} + void on_playback_order_changed(t_size p_new_index) {} + + PFC_CLASS_NOT_COPYABLE(playlist_callback_single_impl_base,playlist_callback_single_impl_base); +}; + +class playlist_callback_single_static : public service_base, public playlist_callback_single +{ +public: + virtual unsigned get_flags() = 0; + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(playlist_callback_single_static); +}; + + +//! Class used for async processing of IDataObject. Content of IDataObject can be dumped into dropped_files_data without any time-consuming operations - won't block calling app when used inside drag&drop handler - and actual time-consuming processing (listing directories and reading infos) can be done later.\n +//! \deprecated In 0.9.3 and up, instead of going thru dropped_files_data, you can use playlist_incoming_item_filter_v2::process_dropped_files_async(). +class NOVTABLE dropped_files_data { +public: + virtual void set_paths(pfc::string_list_const const & p_paths) = 0; + virtual void set_handles(const pfc::list_base_const_t & p_handles) = 0; +protected: + dropped_files_data() {} + ~dropped_files_data() {} +}; + + +class NOVTABLE playlist_incoming_item_filter : public service_base { +public: + //! Pre-sorts incoming items according to user-configured settings, removes duplicates. \n + //! @param in Items to process. + //! @param out Receives processed item list. \n + //! NOTE: because of an implementation bug in pre-0.9.5, the output list should be emptied before calling filter_items(), otherwise the results will be inconsistent/unpredictable. + //! @returns True when there's one or more item in the output list, false when the output list is empty. + virtual bool filter_items(metadb_handle_list_cref in,metadb_handle_list_ref out) = 0; + + //! Converts one or more paths to a list of metadb_handles; displays a progress dialog.\n + //! Note that this function creates modal dialog and does not return until the operation has completed. + //! @returns True on success, false on user abort. + //! \deprecated Use playlist_incoming_item_filter_v2::process_locations_async() when possible. + virtual bool process_locations(const pfc::list_base_const_t & p_urls,pfc::list_base_t & p_out,bool p_filter,const char * p_restrict_mask_override, const char * p_exclude_mask_override,HWND p_parentwnd) = 0; + + //! Converts an IDataObject to a list of metadb_handles. + //! Using this function is strongly disrecommended as it implies blocking the drag&drop source app (as well as our app).\n + //! @returns True on success, false on user abort or unknown data format. + //! \deprecated Use playlist_incoming_item_filter_v2::process_dropped_files_async() when possible. + virtual bool process_dropped_files(interface IDataObject * pDataObject,pfc::list_base_t & p_out,bool p_filter,HWND p_parentwnd) = 0; + + //! Checks whether IDataObject contains one of known data formats that can be translated to a list of metadb_handles. + virtual bool process_dropped_files_check(interface IDataObject * pDataObject) = 0; + + //! Checks whether IDataObject contains our own private data format (drag&drop within the app etc). + virtual bool process_dropped_files_check_if_native(interface IDataObject * pDataObject) = 0; + + //! Creates an IDataObject from specified metadb_handle list. The caller is responsible for releasing the returned object. It is recommended that you use create_dataobject_ex() to get an autopointer that ensures proper deletion. + virtual interface IDataObject * create_dataobject(const pfc::list_base_const_t & p_data) = 0; + + //! Checks whether IDataObject contains one of known data formats that can be translated to a list of metadb_handles.\n + //! This function also returns drop effects to use (see: IDropTarget::DragEnter(), IDropTarget::DragOver() ). In certain cases, drag effects are necessary for drag&drop to work at all (such as dragging links from IE).\n + virtual bool process_dropped_files_check_ex(interface IDataObject * pDataObject, DWORD * p_effect) = 0; + + //! Dumps IDataObject content to specified dropped_files_data object, without any time-consuming processing.\n + //! Using this function instead of process_dropped_files() and processing dropped_files_data outside drop handler allows you to avoid blocking drop source app when processing large directories etc.\n + //! Note: since 0.9.3, it is recommended to use playlist_incoming_item_filter_v2::process_dropped_files_async() instead. + //! @returns True on success, false when IDataObject does not contain any of known data formats. + virtual bool process_dropped_files_delayed(dropped_files_data & p_out,interface IDataObject * pDataObject) = 0; + + //! Helper - calls process_locations() with a single URL. See process_locations() for more info. + bool process_location(const char * url,pfc::list_base_t & out,bool filter,const char * p_mask,const char * p_exclude,HWND p_parentwnd); + //! Helper - returns a pfc::com_ptr_t<> rather than a raw pointer. + pfc::com_ptr_t create_dataobject_ex(metadb_handle_list_cref data); + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(playlist_incoming_item_filter); +}; + +//! For use with playlist_incoming_item_filter_v2::process_locations_async(). +//! \since 0.9.3 +class NOVTABLE process_locations_notify : public service_base { +public: + virtual void on_completion(const pfc::list_base_const_t & p_items) = 0; + virtual void on_aborted() = 0; + + FB2K_MAKE_SERVICE_INTERFACE(process_locations_notify,service_base); +}; + +typedef service_ptr_t process_locations_notify_ptr; + +//! \since 0.9.3 +class NOVTABLE playlist_incoming_item_filter_v2 : public playlist_incoming_item_filter { +public: + enum { + //! Set this to disable presorting (according to user settings) and duplicate removal in output list. Should be unset in most cases. + op_flag_no_filter = 1 << 0, + //! Set this flag to make the progress dialog not steal focus on creation. + op_flag_background = 1 << 1, + //! Set this flag to delay the progress dialog becoming visible, so it does not appear at all during short operations. Also implies op_flag_background effect. + op_flag_delay_ui = 1 << 2, + }; + + //! Converts one or more paths to a list of metadb_handles. The function returns immediately; specified callback object receives results when the operation has completed. + //! @param p_urls List of paths to process. + //! @param p_op_flags Can be null, or one or more of op_flag_* enum values combined, altering behaviors of the operation. + //! @param p_restrict_mask_override Override of "restrict incoming items to" setting. Pass NULL to use the value from preferences. + //! @param p_exclude_mask_override Override of "exclude file types" setting. Pass NULL to use value from preferences. + //! @param p_parentwnd Parent window for spawned progress dialogs. + //! @param p_notify Callback receiving notifications about success/abort of the operation as well as output item list. + virtual void process_locations_async(const pfc::list_base_const_t & p_urls,t_uint32 p_op_flags,const char * p_restrict_mask_override, const char * p_exclude_mask_override,HWND p_parentwnd,process_locations_notify_ptr p_notify) = 0; + + //! Converts an IDataObject to a list of metadb_handles. The function returns immediately; specified callback object receives results when the operation has completed. + //! @param p_dataobject IDataObject to process. + //! @param p_op_flags Can be null, or one or more of op_flag_* enum values combined, altering behaviors of the operation. + //! @param p_parentwnd Parent window for spawned progress dialogs. + //! @param p_notify Callback receiving notifications about success/abort of the operation as well as output item list. + virtual void process_dropped_files_async(interface IDataObject * p_dataobject,t_uint32 p_op_flags,HWND p_parentwnd,process_locations_notify_ptr p_notify) = 0; + + FB2K_MAKE_SERVICE_INTERFACE(playlist_incoming_item_filter_v2,playlist_incoming_item_filter); +}; + +//! \since 0.9.5 +class playlist_incoming_item_filter_v3 : public playlist_incoming_item_filter_v2 { +public: + virtual bool auto_playlist_name(metadb_handle_list_cref data,pfc::string_base & out) = 0; + + FB2K_MAKE_SERVICE_INTERFACE(playlist_incoming_item_filter_v3,playlist_incoming_item_filter_v2) +}; + +//! Implementation of dropped_files_data. +class dropped_files_data_impl : public dropped_files_data { +public: + dropped_files_data_impl() : m_is_paths(false) {} + void set_paths(pfc::string_list_const const & p_paths) { + m_is_paths = true; + m_paths = p_paths; + } + void set_handles(const pfc::list_base_const_t & p_handles) { + m_is_paths = false; + m_handles = p_handles; + } + + void to_handles_async(bool p_filter,HWND p_parentwnd,service_ptr_t p_notify); + //! @param p_op_flags Can be null, or one or more of playlist_incoming_item_filter_v2::op_flag_* enum values combined, altering behaviors of the operation. + void to_handles_async_ex(t_uint32 p_op_flags,HWND p_parentwnd,service_ptr_t p_notify); + bool to_handles(pfc::list_base_t & p_out,bool p_filter,HWND p_parentwnd); +private: + pfc::string_list_impl m_paths; + metadb_handle_list m_handles; + bool m_is_paths; +}; + + +class NOVTABLE playback_queue_callback : public service_base +{ +public: + enum t_change_origin { + changed_user_added, + changed_user_removed, + changed_playback_advance, + }; + virtual void on_changed(t_change_origin p_origin) = 0; + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(playback_queue_callback); +}; + + +class playlist_lock_change_notify : private playlist_callback_single_impl_base { +public: + playlist_lock_change_notify() : playlist_callback_single_impl_base(flag_on_playlist_switch|flag_on_playlist_locked) {} +protected: + virtual void on_lock_state_change() {} + bool is_playlist_command_available(t_uint32 what) const { + static_api_ptr_t api; + const t_size active = api->get_active_playlist(); + if (active == ~0) return false; + return (api->playlist_lock_get_filter_mask(active) & what) == 0; + } +private: + void on_playlist_switch() {on_lock_state_change();} + void on_playlist_locked(bool p_locked) {on_lock_state_change();} +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/playlist_loader.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/playlist_loader.cpp new file mode 100644 index 000000000..fe5f09d61 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/playlist_loader.cpp @@ -0,0 +1,270 @@ +#include "foobar2000.h" + +static void process_path_internal(const char * p_path,const service_ptr_t & p_reader,playlist_loader_callback_v2 & callback,playlist_loader_callback::t_entry_type type,const t_filestats & p_stats); + +namespace { + class archive_callback_impl : public archive_callback + { + public: + archive_callback_impl(playlist_loader_callback_v2 & p_callback) : m_callback(p_callback) {} + bool on_entry(archive * owner,const char * p_path,const t_filestats & p_stats,const service_ptr_t & p_reader) + { + process_path_internal(p_path,p_reader,m_callback,playlist_loader_callback::entry_directory_enumerated,p_stats); + return !m_callback.is_aborting(); + } + bool is_aborting() const {return m_callback.is_aborting();} + abort_callback_event get_abort_event() const {return m_callback.get_abort_event();} + private: + playlist_loader_callback_v2 & m_callback; + }; +} + +void playlist_loader::g_load_playlist_filehint(file::ptr fileHint,const char * p_path,playlist_loader_callback & p_callback) { + TRACK_CALL_TEXT("playlist_loader::g_load_playlist_filehint"); + pfc::string8 filepath; + + filesystem::g_get_canonical_path(p_path,filepath); + + pfc::string_extension extension(filepath); + + service_ptr_t l_file = fileHint; + + if (l_file.is_empty()) { + filesystem::ptr fs; + if (filesystem::g_get_interface(fs,filepath)) { + if (fs->supports_content_types()) { + fs->open(l_file,filepath,filesystem::open_mode_read,p_callback); + } + } + } + + { + service_enum_t e; + + if (l_file.is_valid()) { + pfc::string8 content_type; + if (l_file->get_content_type(content_type)) { + service_ptr_t l; + e.reset(); while(e.next(l)) { + if (l->is_our_content_type(content_type)) { + try { + TRACK_CODE("playlist_loader::open",l->open(filepath,l_file,p_callback)); + return; + } catch(exception_io_unsupported_format) { + l_file->reopen(p_callback); + } + } + } + } + } + + if (extension.length()>0) { + service_ptr_t l; + e.reset(); while(e.next(l)) { + if (stricmp_utf8(l->get_extension(),extension) == 0) { + if (l_file.is_empty()) filesystem::g_open_read(l_file,filepath,p_callback); + try { + TRACK_CODE("playlist_loader::open",l->open(filepath,l_file,p_callback)); + return; + } catch(exception_io_unsupported_format) { + l_file->reopen(p_callback); + } + } + } + } + } + + throw exception_io_unsupported_format(); +} +void playlist_loader::g_load_playlist(const char * p_path,playlist_loader_callback & callback) { + g_load_playlist_filehint(NULL,p_path,callback); +} + +static void index_tracks_helper(const char * p_path,const service_ptr_t & p_reader,const t_filestats & p_stats,playlist_loader_callback::t_entry_type p_type,playlist_loader_callback & p_callback,bool & p_got_input) +{ + TRACK_CALL_TEXT("index_tracks_helper"); + if (p_reader.is_empty() && filesystem::g_is_remote_safe(p_path)) + { + TRACK_CALL_TEXT("remote"); + metadb_handle_ptr handle; + p_callback.handle_create(handle,make_playable_location(p_path,0)); + p_got_input = true; + p_callback.on_entry(handle,p_type,p_stats,true); + } else { + TRACK_CALL_TEXT("hintable"); + service_ptr_t instance; + input_entry::g_open_for_info_read(instance,p_reader,p_path,p_callback); + + t_filestats stats = instance->get_file_stats(p_callback); + + t_uint32 subsong,subsong_count = instance->get_subsong_count(); + for(subsong=0;subsongget_subsong(subsong); + p_callback.handle_create(handle,make_playable_location(p_path,index)); + + p_got_input = true; + if (p_callback.want_info(handle,p_type,stats,true)) + { + file_info_impl info; + TRACK_CODE("get_info",instance->get_info(index,info,p_callback)); + p_callback.on_entry_info(handle,p_type,stats,info,true); + } + else + { + p_callback.on_entry(handle,p_type,stats,true); + } + } + } +} + + +static void track_indexer__g_get_tracks_wrap(const char * p_path,const service_ptr_t & p_reader,const t_filestats & p_stats,playlist_loader_callback::t_entry_type p_type,playlist_loader_callback & p_callback) { + bool got_input = false; + bool fail = false; + try { + index_tracks_helper(p_path,p_reader,p_stats,p_type,p_callback,got_input); + } catch(exception_aborted) { + throw; + } catch(exception_io_unsupported_format) { + fail = true; + } catch(std::exception const & e) { + fail = true; + console::formatter() << "could not enumerate tracks (" << e << ") on:\n" << file_path_display(p_path); + } + if (fail) { + if (!got_input && !p_callback.is_aborting()) { + if (p_type == playlist_loader_callback::entry_user_requested) + { + metadb_handle_ptr handle; + p_callback.handle_create(handle,make_playable_location(p_path,0)); + p_callback.on_entry(handle,p_type,p_stats,true); + } + } + } +} + + +static void process_path_internal(const char * p_path,const service_ptr_t & p_reader,playlist_loader_callback_v2 & p_callback,playlist_loader_callback::t_entry_type p_type,const t_filestats & p_stats) +{ + //p_path must be canonical + + p_callback.check(); + + p_callback.on_progress(p_path); + + + { + if (p_reader.is_empty()) { + directory_callback_impl directory_results(true); + try { + filesystem::g_list_directory(p_path,directory_results,p_callback); + for(t_size n=0;n e; + service_ptr_t f; + while(e.next(f)) { + p_callback.check(); + service_ptr_t arch; + if (f->service_query_t(arch)) { + if (p_reader.is_valid()) p_reader->reopen(p_callback); + + try { + TRACK_CODE("archive::archive_list",arch->archive_list(p_path,p_reader,archive_results,true)); + return; + } catch(exception_aborted) {throw;} + catch(...) {} + } + } + } + } + + + + { + service_ptr_t ptr; + if (link_resolver::g_find(ptr,p_path)) + { + if (p_reader.is_valid()) p_reader->reopen(p_callback); + + pfc::string8 temp; + try { + TRACK_CODE("link_resolver::resolve",ptr->resolve(p_reader,p_path,temp,p_callback)); + + track_indexer__g_get_tracks_wrap(temp,0,filestats_invalid,playlist_loader_callback::entry_from_playlist,p_callback); + return;//success + } catch(exception_aborted) {throw;} + catch(...) {} + } + } + + if (p_callback.is_path_wanted(p_path,p_type)) { + track_indexer__g_get_tracks_wrap(p_path,p_reader,p_stats,p_type,p_callback); + } +} + +void playlist_loader::g_process_path(const char * p_filename,playlist_loader_callback_v2 & callback,playlist_loader_callback::t_entry_type type) +{ + TRACK_CALL_TEXT("playlist_loader::g_process_path"); + + file_path_canonical filename(p_filename); + + process_path_internal(filename,0,callback,type,filestats_invalid); +} + +void playlist_loader::g_save_playlist(const char * p_filename,const pfc::list_base_const_t & data,abort_callback & p_abort) +{ + TRACK_CALL_TEXT("playlist_loader::g_save_playlist"); + pfc::string8 filename; + filesystem::g_get_canonical_path(p_filename,filename); + try { + service_ptr_t r; + filesystem::g_open(r,filename,filesystem::open_mode_write_new,p_abort); + + pfc::string_extension ext(filename); + + service_enum_t e; + service_ptr_t l; + if (e.first(l)) do { + if (l->can_write() && !stricmp_utf8(ext,l->get_extension())) { + try { + TRACK_CODE("playlist_loader::write",l->write(filename,r,data,p_abort)); + return; + } catch(exception_io_data) {} + } + } while(e.next(l)); + throw exception_io_data(); + } catch(...) { + try {filesystem::g_remove(filename,p_abort);} catch(...) {} + throw; + } +} + + +bool playlist_loader::g_process_path_ex(const char * filename,playlist_loader_callback_v2 & callback,playlist_loader_callback::t_entry_type type) +{ + try { + g_load_playlist(filename,callback); + return true; + } catch(exception_io_unsupported_format) {//not a playlist format + g_process_path(filename,callback,type); + return false; + } +} diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/playlist_loader.h b/tools/vio2sf/src/foobar/foobar2000/SDK/playlist_loader.h new file mode 100644 index 000000000..604b343e5 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/playlist_loader.h @@ -0,0 +1,151 @@ +//! Callback interface receiving item locations from playlist loader. Also inherits abort_callback methods and can be passed to functions that require an abort_callback. \n +//! See playlist_loader_callback_impl for a basic implementation of playlist_loader_callback. Typically, you call one of standard services such as playlist_incoming_item_filter instead of implementing this interface and calling playlist_loader methods directly. +class NOVTABLE playlist_loader_callback : public abort_callback { +public: + //! Enumeration type representing origin of item passed to playlist_loader_callback. + enum t_entry_type { + //! User-requested (such as directly dropped to window or picked in openfiledialog). + entry_user_requested, + //! From directory content enumeration. + entry_directory_enumerated, + //! Referenced by playlist file. + entry_from_playlist, + }; + //! Indicates specified path being processed; provided for updating GUI. Note that optimally GUI should not be updated every time this is called because that could introduce a bottleneck. + virtual void on_progress(const char * p_path) = 0; + + //! Receives an item from one of playlist_loader functions. + //! @param p_item Item location, in form of metadb_handle pointer. + //! @param p_type Origin of this item - see t_entry_type for more info. + //! @param p_stats File stats of this item; set to filestats_invalid if not available. + //! @param p_fresh Fresh flag; indicates whether stats are directly from filesystem (true) or as stored earlier in a playlist file (false). + virtual void on_entry(const metadb_handle_ptr & p_item,t_entry_type p_type,const t_filestats & p_stats,bool p_fresh) = 0; + //! Queries whether file_info for specified item is requested. In typical scenario, if want_info() returns false, on_entry() will be called with same parameters; otherwise caller will attempt to read info from the item and call on_entry_info() with same parameters and file_info read from the item. + //! @param p_item Item location, in form of metadb_handle pointer. + //! @param p_type Origin of this item - see t_entry_type for more info. + //! @param p_stats File stats of this item; set to filestats_invalid if not available. + //! @param p_fresh Fresh flag; indicates whether stats are directly from filesystem (true) or as stored earlier in a playlist file (false). + virtual bool want_info(const metadb_handle_ptr & p_item,t_entry_type p_type,const t_filestats & p_stats,bool p_fresh) = 0; + //! Receives an item from one of playlist_loader functions; including file_info data. Except for file_info to be typically used as hint for metadb backend, behavior of this method is same as on_entry(). + //! @param p_item Item location, in form of metadb_handle pointer. + //! @param p_type Origin of this item - see t_entry_type for more info. + //! @param p_stats File stats of this item; set to filestats_invalid if not available. + //! @param p_info Information about the item, read from the file directly (if p_fresh is set to true) or from e.g. playlist file (if p_fresh is set to false). + //! @param p_fresh Fresh flag; indicates whether stats are directly from filesystem (true) or as stored earlier in a playlist file (false). + virtual void on_entry_info(const metadb_handle_ptr & p_item,t_entry_type p_type,const t_filestats & p_stats,const file_info & p_info,bool p_fresh) = 0; + + //! Same as metadb::handle_create(); provided here to avoid repeated metadb instantiation bottleneck since calling code will need this function often. + virtual void handle_create(metadb_handle_ptr & p_out,const playable_location & p_location) = 0; + +protected: + playlist_loader_callback() {} + ~playlist_loader_callback() {} +}; + +class NOVTABLE playlist_loader_callback_v2 : public playlist_loader_callback { +public: + //! Returns whether further on_entry() calls for this file are wanted. Typically always returns true, can be used to optimize cases when directories are searched for files matching specific pattern only so unwanted files aren't parsed unnecessarily. + //! @param path Canonical path to the media file being processed. + virtual bool is_path_wanted(const char * path, t_entry_type type) = 0; + +protected: + playlist_loader_callback_v2() {} + ~playlist_loader_callback_v2() {} +}; + +//! Basic implementation of playlist_loader_callback. +class playlist_loader_callback_impl : public playlist_loader_callback_v2 { +public: + + playlist_loader_callback_impl(abort_callback & p_abort) : m_abort(p_abort) {} + + bool is_aborting() const {return m_abort.is_aborting();} + abort_callback_event get_abort_event() const {return m_abort.get_abort_event();} + + const metadb_handle_ptr & get_item(t_size idx) const {return m_data[idx];} + const metadb_handle_ptr & operator[](t_size idx) const {return m_data[idx];} + t_size get_count() const {return m_data.get_count();} + + const metadb_handle_list & get_data() const {return m_data;} + + void on_progress(const char * path) {} + + void on_entry(const metadb_handle_ptr & ptr,t_entry_type type,const t_filestats & p_stats,bool p_fresh) {m_data.add_item(ptr);} + bool want_info(const metadb_handle_ptr & ptr,t_entry_type type,const t_filestats & p_stats,bool p_fresh) {return false;} + void on_entry_info(const metadb_handle_ptr & ptr,t_entry_type type,const t_filestats & p_stats,const file_info & p_info,bool p_fresh) {m_data.add_item(ptr);} + + void handle_create(metadb_handle_ptr & p_out,const playable_location & p_location) {m_api->handle_create(p_out,p_location);} + + bool is_path_wanted(const char * path,t_entry_type type) {return true;} + +private: + metadb_handle_list m_data; + abort_callback & m_abort; + static_api_ptr_t m_api; +}; + +//! Service handling playlist file operations. There are multiple implementations handling different playlist formats; you can add new implementations to allow new custom playlist file formats to be read or written.\n +//! Also provides static helper functions for turning a filesystem path into a list of playable item locations. \n +//! Note that you should typically call playlist_incoming_item_filter methods instead of calling playlist_loader methods directly to get a list of playable items from a specified path; this way you get a core-implemented threading and abortable dialog displaying progress.\n +//! To register your own implementation, use playlist_loader_factory_t template.\n +//! To call existing implementations, use static helper methods of playlist_loader class. +class NOVTABLE playlist_loader : public service_base { +public: + //! Parses specified playlist file into list of playable locations. Throws exception_io or derivatives on failure, exception_aborted on abort. If specified file is not a recognized playlist file, exception_io_unsupported_format is thrown. + //! @param p_path Path of playlist file to parse. Used for relative path handling purposes (p_file parameter is used for actual file access). + //! @param p_file File interface to use for reading. Read/write pointer must be set to beginning by caller before calling. + //! @param p_callback Callback object receiving enumerated playable item locations as well as signaling user aborting the operation. + virtual void open(const char * p_path, const service_ptr_t & p_file,playlist_loader_callback & p_callback) = 0; + //! Writes a playlist file containing specific item list to specified file. Will fail (pfc::exception_not_implemented) if specified playlist_loader is read-only (can_write() returns false). + //! @param p_path Path of playlist file to write. Used for relative path handling purposes (p_file parameter is used for actual file access). + //! @param p_file File interface to use for writing. Caller should ensure that the file is empty (0 bytes long) before calling. + //! @param p_data List of items to save to playlist file. + //! @param p_abort abort_callback object signaling user aborting the operation. Note that aborting a save playlist operation will most likely leave user with corrupted/incomplete file. + virtual void write(const char * p_path, const service_ptr_t & p_file,const pfc::list_base_const_t & p_data,abort_callback & p_abort) = 0; + //! Returns extension of file format handled by this playlist_loader implementation (a UTF-8 encoded null-terminated string). + virtual const char * get_extension() = 0; + //! Returns whether this playlist_loader implementation supports writing. If can_write() returns false, all write() calls will fail. + virtual bool can_write() = 0; + //! Returns whether specified content type is one of playlist types supported by this playlist_loader implementation or not. + //! @param p_content_type Content type to query, a UTF-8 encoded null-terminated string. + virtual bool is_our_content_type(const char* p_content_type) = 0; + //! Returns whether playlist format extension supported by this implementation should be listed on file types associations page. + virtual bool is_associatable() = 0; + + //! Attempts to load a playlist file from specified filesystem path. Throws exception_io or derivatives on failure, exception_aborted on abort. If specified file is not a recognized playlist file, exception_io_unsupported_format is thrown. \n + //! Equivalent to g_load_playlist_filehint(NULL,p_path,p_callback). + //! @param p_path Filesystem path to load playlist from, a UTF-8 encoded null-terminated string. + //! @param p_callback Callback object receiving enumerated playable item locations as well as signaling user aborting the operation. + static void g_load_playlist(const char * p_path,playlist_loader_callback & p_callback); + + //! Attempts to load a playlist file from specified filesystem path. Throws exception_io or derivatives on failure, exception_aborted on abort. If specified file is not a recognized playlist file, exception_io_unsupported_format is thrown. + //! @param p_path Filesystem path to load playlist from, a UTF-8 encoded null-terminated string. + //! @param p_callback Callback object receiving enumerated playable item locations as well as signaling user aborting the operation. + //! @param fileHint File object to read from, can be NULL if not available. + static void g_load_playlist_filehint(file::ptr fileHint,const char * p_path,playlist_loader_callback & p_callback); + + //! Saves specified list of locations into a playlist file. Throws exception_io or derivatives on failure, exception_aborted on abort. + //! @param p_path Filesystem path to save playlist to, a UTF-8 encoded null-terminated string. + //! @param p_data List of items to save to playlist file. + //! @param p_abort abort_callback object signaling user aborting the operation. Note that aborting a save playlist operation will most likely leave user with corrupted/incomplete file. + static void g_save_playlist(const char * p_path,const pfc::list_base_const_t & p_data,abort_callback & p_abort); + + //! Processes specified path to generate list of playable items. Includes recursive directory/archive enumeration. \n + //! Does not touch playlist files encountered - use g_process_path_ex() if specified path is possibly a playlist file; playlist files found inside directories or archives are ignored regardless.\n + //! Warning: caller must handle exceptions which will occur in case of I/O failure. + //! @param p_path Filesystem path to process; a UTF-8 encoded null-terminated string. + //! @param p_callback Callback object receiving enumerated playable item locations as well as signaling user aborting the operation. + //! @param p_type Origin of p_path string. Reserved for internal use in recursive calls, should be left at default value; it controls various internal behaviors. + static void g_process_path(const char * p_path,playlist_loader_callback_v2 & p_callback,playlist_loader_callback::t_entry_type p_type = playlist_loader_callback::entry_user_requested); + + //! Calls attempts to process specified path as a playlist; if that fails (i.e. not a playlist), calls g_process_path with same parameters. See g_process_path for parameter descriptions. \n + //! Warning: caller must handle exceptions which will occur in case of I/O failure or playlist parsing failure. + //! @returns True if specified path was processed as a playlist file, false otherwise (relevant in some scenarios where output is sorted after loading, playlist file contents should not be sorted). + static bool g_process_path_ex(const char * p_path,playlist_loader_callback_v2 & p_callback,playlist_loader_callback::t_entry_type p_type = playlist_loader_callback::entry_user_requested); + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(playlist_loader); +}; + +template +class playlist_loader_factory_t : public service_factory_single_t {}; + diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/popup_message.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/popup_message.cpp new file mode 100644 index 000000000..7c62cb986 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/popup_message.cpp @@ -0,0 +1,6 @@ +#include "foobar2000.h" + +void popup_message::g_show_ex(const char * p_msg,unsigned p_msg_length,const char * p_title,unsigned p_title_length,t_icon p_icon) +{ + static_api_ptr_t()->show_ex(p_msg,p_msg_length,p_title,p_title_length,p_icon); +} diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/popup_message.h b/tools/vio2sf/src/foobar/foobar2000/SDK/popup_message.h new file mode 100644 index 000000000..f62aef6f9 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/popup_message.h @@ -0,0 +1,42 @@ + +//! This interface allows you to show generic nonmodal noninteractive dialog with a text message. This should be used instead of MessageBox where possible.\n +//! Usage: use popup_message::g_show / popup_message::g_show_ex static helpers, or static_api_ptr_t.\n +//! Note that all strings are UTF-8. + +class NOVTABLE popup_message : public service_base { +public: + enum t_icon {icon_information, icon_error, icon_query}; + //! Activates the popup dialog; returns immediately (the dialog remains visible). + //! @param p_msg Message to show (UTF-8 encoded string). + //! @param p_msg_length Length limit of message string to show, in bytes (actual string may be shorter if null terminator is encountered before). Set this to infinite to use plain null-terminated strings. + //! @param p_title Title of dialog to show (UTF-8 encoded string). + //! @param p_title_length Length limit of the title string, in bytes (actual string may be shorter if null terminator is encountered before). Set this to infinite to use plain null-terminated strings. + //! @param p_icon Icon of the dialog - can be set to icon_information, icon_error or icon_query. + virtual void show_ex(const char * p_msg,unsigned p_msg_length,const char * p_title,unsigned p_title_length,t_icon p_icon = icon_information) = 0; + + //! Activates the popup dialog; returns immediately (the dialog remains visible); helper function built around show_ex(), takes null terminated strings with no length limit parameters. + //! @param p_msg Message to show (UTF-8 encoded string). + //! @param p_title Title of dialog to show (UTF-8 encoded string). + //! @param p_icon Icon of the dialog - can be set to icon_information, icon_error or icon_query. + inline void show(const char * p_msg,const char * p_title,t_icon p_icon = icon_information) {show_ex(p_msg,infinite,p_title,infinite,p_icon);} + + //! Static helper function instantiating the service and activating the message dialog. See show_ex() for description of parameters. + static void g_show_ex(const char * p_msg,unsigned p_msg_length,const char * p_title,unsigned p_title_length,t_icon p_icon = icon_information); + //! Static helper function instantiating the service and activating the message dialog. See show() for description of parameters. + static inline void g_show(const char * p_msg,const char * p_title,t_icon p_icon = icon_information) {g_show_ex(p_msg,infinite,p_title,infinite,p_icon);} + + static void g_complain(const char * what) { + g_show(what, "Information", icon_error); + } + + static void g_complain(const char * p_whatFailed, const std::exception & p_exception) { + g_complain(p_whatFailed,p_exception.what()); + } + static void g_complain(const char * p_whatFailed, const char * msg) { + g_complain(pfc::string_formatter() << p_whatFailed << ": " << msg); + } + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(popup_message); +}; + +#define EXCEPTION_TO_POPUP_MESSAGE(CODE,LABEL) try { CODE; } catch(std::exception const & e) {popup_message::g_complain(LABEL,e);} diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/preferences_page.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/preferences_page.cpp new file mode 100644 index 000000000..037d6a819 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/preferences_page.cpp @@ -0,0 +1,10 @@ +#include "foobar2000.h" + +void preferences_page::get_help_url_helper(pfc::string_base & out, const char * category, const GUID & id, const char * name) { + out.reset(); + out << "http://help.foobar2000.org/" << core_version_info::g_get_version_string() << "/" << category << "/" << pfc::print_guid(id) << "/" << name; +} +bool preferences_page::get_help_url(pfc::string_base & p_out) { + get_help_url_helper(p_out,"preferences",get_guid(), get_name()); + return true; +} diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/preferences_page.h b/tools/vio2sf/src/foobar/foobar2000/SDK/preferences_page.h new file mode 100644 index 000000000..c184c66e8 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/preferences_page.h @@ -0,0 +1,84 @@ +#ifndef _FOOBAR2000_SDK_PREFERENCES_PAGE_H_ +#define _FOOBAR2000_SDK_PREFERENCES_PAGE_H_ + +//! Implementing this service will generate a page in preferences dialog. Use preferences_page_factory_t template to register. +class NOVTABLE preferences_page : public service_base { +public: + //! Creates preferences page dialog window. It is safe to assume that two dialog instances will never coexist. Caller is responsible for embedding it into preferences dialog itself. + virtual HWND create(HWND p_parent) = 0; + //! Retrieves name of the prefernces page to be displayed in preferences tree (static string). + virtual const char * get_name() = 0; + //! Retrieves GUID of the page. + virtual GUID get_guid() = 0; + //! Retrieves GUID of parent page/branch of this page. See preferences_page::guid_* constants for list of standard parent GUIDs. Can also be a GUID of another page or a branch (see: preferences_branch). + virtual GUID get_parent_guid() = 0; + //! Queries whether this page supports "reset page" feature. + virtual bool reset_query() = 0; + //! Activates "reset page" feature. It is safe to assume that the preferences page dialog does not exist at the point this is called (caller destroys it before calling reset and creates it again afterwards). + virtual void reset() = 0; + //! Retrieves help URL. Without overriding it, it will redirect to foobar2000 wiki. + virtual bool get_help_url(pfc::string_base & p_out); + + static void get_help_url_helper(pfc::string_base & out, const char * category, const GUID & id, const char * name); + + static const GUID guid_root, guid_hidden, guid_tools,guid_core,guid_display,guid_playback,guid_visualisations,guid_input,guid_tag_writing,guid_media_library, guid_tagging; + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(preferences_page); +}; + +class NOVTABLE preferences_page_v2 : public preferences_page { +public: + //! Allows custom sorting order of preferences pages. Return lower value for higher priority (lower resulting index in the list). When sorting priority of two items matches, alphabetic sorting is used. Return 0 to use default alphabetic sorting without overriding priority. + virtual double get_sort_priority() = 0; + + FB2K_MAKE_SERVICE_INTERFACE(preferences_page_v2,preferences_page); +}; + +template +class preferences_page_factory_t : public service_factory_single_t {}; + +//! Creates a preferences branch - an empty page that only serves as a parent for other pages and is hidden when no child pages exist. Instead of implementing this, simply use preferences_branch_factory class to declare a preferences branch with specified parameters. +class NOVTABLE preferences_branch : public service_base { +public: + //! Retrieves name of the preferences branch. + virtual const char * get_name() = 0; + //! Retrieves GUID of the preferences branch. Use this GUID as parent GUID for pages/branches nested in this branch. + virtual GUID get_guid() = 0; + //! Retrieves GUID of parent page/branch of this branch. See preferences_page::guid_* constants for list of standard parent GUIDs. Can also be a GUID of another branch or a page. + virtual GUID get_parent_guid() = 0; + + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(preferences_branch); +}; + +class preferences_branch_v2 : public preferences_branch { +public: + //! Allows custom sorting order of preferences pages. Return lower value for higher priority (lower resulting index in the list). When sorting priority of two items matches, alphabetic sorting is used. Return 0 to use default alphabetic sorting without overriding priority. + virtual double get_sort_priority() = 0; + + FB2K_MAKE_SERVICE_INTERFACE(preferences_branch_v2,preferences_branch); +}; + +class preferences_branch_impl : public preferences_branch_v2 { +public: + preferences_branch_impl(const GUID & p_guid,const GUID & p_parent,const char * p_name,double p_sort_priority = 0) : m_guid(p_guid), m_parent(p_parent), m_name(p_name), m_sort_priority(p_sort_priority) {} + const char * get_name() {return m_name;} + GUID get_guid() {return m_guid;} + GUID get_parent_guid() {return m_parent;} + double get_sort_priority() {return m_sort_priority;} +private: + const GUID m_guid,m_parent; + const pfc::string8 m_name; + const double m_sort_priority; +}; + +typedef service_factory_single_t __preferences_branch_factory; + +//! Instantiating this class declares a preferences branch with specified parameters.\n +//! Usage: static preferences_branch_factory g_mybranch(mybranchguid,parentbranchguid,"name of my preferences branch goes here"); +class preferences_branch_factory : public __preferences_branch_factory { +public: + preferences_branch_factory(const GUID & p_guid,const GUID & p_parent,const char * p_name,double p_sort_priority = 0) : __preferences_branch_factory(p_guid,p_parent,p_name,p_sort_priority) {} +}; + +#endif //_FOOBAR2000_SDK_PREFERENCES_PAGE_H_ diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/replaygain.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/replaygain.cpp new file mode 100644 index 000000000..caa22e623 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/replaygain.cpp @@ -0,0 +1,223 @@ +#include "foobar2000.h" + +void t_replaygain_config::reset() +{ + m_source_mode = source_mode_none; + m_processing_mode = processing_mode_none; + m_preamp_without_rg = 0; + m_preamp_with_rg = 0; +} + +audio_sample t_replaygain_config::query_scale(const file_info & p_info) const +{ + const audio_sample peak_margin = 1.0;//used to be 0.999 but it must not trigger on lossless + + audio_sample peak = peak_margin; + audio_sample gain = 0; + + bool have_rg_gain = false, have_rg_peak = false; + + if (m_source_mode == source_mode_track || m_source_mode == source_mode_album) + { + replaygain_info info = p_info.get_replaygain(); + float gain_select = replaygain_info::gain_invalid, peak_select = replaygain_info::peak_invalid; + if (m_source_mode == source_mode_track) + { + if (info.is_track_gain_present()) {gain = info.m_track_gain; have_rg_gain = true; } + else if (info.is_album_gain_present()) {gain = info.m_album_gain; have_rg_gain = true; } + if (info.is_track_peak_present()) {peak = info.m_track_peak; have_rg_peak = true; } + else if (info.is_album_peak_present()) {peak = info.m_album_peak; have_rg_peak = true; } + } + else + { + if (info.is_album_gain_present()) {gain = info.m_album_gain; have_rg_gain = true; } + else if (info.is_track_gain_present()) {gain = info.m_track_gain; have_rg_gain = true; } + if (info.is_album_peak_present()) {peak = info.m_album_peak; have_rg_peak = true; } + else if (info.is_track_peak_present()) {peak = info.m_track_peak; have_rg_peak = true; } + } + } + + gain += have_rg_gain ? m_preamp_with_rg : m_preamp_without_rg; + + audio_sample scale = 1.0; + + if (m_processing_mode == processing_mode_gain || m_processing_mode == processing_mode_gain_and_peak) + { + scale *= audio_math::gain_to_scale(gain); + } + + if (m_processing_mode == processing_mode_peak || m_processing_mode == processing_mode_gain_and_peak) + { + if (scale * peak > peak_margin) + scale = (audio_sample)(peak_margin / peak); + } + + return scale; +} + +audio_sample t_replaygain_config::query_scale(const metadb_handle_ptr & p_object) const +{ + audio_sample rv = 1.0; + p_object->metadb_lock(); + const file_info * info; + if (p_object->get_info_async_locked(info)) + rv = query_scale(*info); + p_object->metadb_unlock(); + return rv; +} + +audio_sample replaygain_manager::core_settings_query_scale(const file_info & p_info) +{ + t_replaygain_config temp; + get_core_settings(temp); + return temp.query_scale(p_info); +} + +audio_sample replaygain_manager::core_settings_query_scale(const metadb_handle_ptr & info) +{ + t_replaygain_config temp; + get_core_settings(temp); + return temp.query_scale(info); +} + +//enum t_source_mode {source_mode_none,source_mode_track,source_mode_album}; +//enum t_processing_mode {processing_mode_none,processing_mode_gain,processing_mode_gain_and_peak,processing_mode_peak}; +namespace { +class format_dbdelta +{ +public: + format_dbdelta(double p_val); + operator const char*() const {return m_buffer;} +private: + pfc::string_fixed_t<128> m_buffer; +}; +static const char * querysign(int val) { + return val<0 ? "-" : val>0 ? "+" : "\xc2\xb1"; +} + +format_dbdelta::format_dbdelta(double p_val) { + int val = (int)(p_val * 10); + m_buffer << querysign(val) << (abs(val)/10) << "." << (abs(val)%10) << "dB"; +} +} +void t_replaygain_config::format_name(pfc::string_base & p_out) const +{ + switch(m_processing_mode) + { + case processing_mode_none: + p_out = "None."; + break; + case processing_mode_gain: + switch(m_source_mode) + { + case source_mode_none: + if (m_preamp_without_rg == 0) p_out = "None."; + else p_out = pfc::string_formatter() << "Preamp : " << format_dbdelta(m_preamp_without_rg); + break; + case source_mode_track: + { + pfc::string_formatter fmt; + fmt << "Apply track gain"; + if (m_preamp_without_rg != 0 || m_preamp_with_rg != 0) fmt << ", with preamp"; + fmt << "."; + p_out = fmt; + } + break; + case source_mode_album: + { + pfc::string_formatter fmt; + fmt << "Apply album gain"; + if (m_preamp_without_rg != 0 || m_preamp_with_rg != 0) fmt << ", with preamp"; + fmt << "."; + p_out = fmt; + } + break; + }; + break; + case processing_mode_gain_and_peak: + switch(m_source_mode) + { + case source_mode_none: + if (m_preamp_without_rg >= 0) p_out = "None."; + else p_out = pfc::string_formatter() << "Preamp : " << format_dbdelta(m_preamp_without_rg); + break; + case source_mode_track: + { + pfc::string_formatter fmt; + fmt << "Apply track gain"; + if (m_preamp_without_rg != 0 || m_preamp_with_rg != 0) fmt << ", with preamp"; + fmt << ", prevent clipping according to track peak."; + p_out = fmt; + } + break; + case source_mode_album: + { + pfc::string_formatter fmt; + fmt << "Apply album gain"; + if (m_preamp_without_rg != 0 || m_preamp_with_rg != 0) fmt << ", with preamp"; + fmt << ", prevent clipping according to album peak."; + p_out = fmt; + } + break; + }; + break; + case processing_mode_peak: + switch(m_source_mode) + { + case source_mode_none: + p_out = "None."; + break; + case source_mode_track: + p_out = "Prevent clipping according to track peak."; + break; + case source_mode_album: + p_out = "Prevent clipping according to album peak."; + break; + }; + break; + } +} + +bool t_replaygain_config::is_active() const +{ + switch(m_processing_mode) + { + case processing_mode_none: + return false; + case processing_mode_gain: + switch(m_source_mode) + { + case source_mode_none: + return m_preamp_without_rg != 0; + case source_mode_track: + return true; + case source_mode_album: + return true; + }; + return false; + case processing_mode_gain_and_peak: + switch(m_source_mode) + { + case source_mode_none: + return m_preamp_without_rg < 0; + case source_mode_track: + return true; + case source_mode_album: + return true; + }; + return false; + case processing_mode_peak: + switch(m_source_mode) + { + case source_mode_none: + return false; + case source_mode_track: + return true; + case source_mode_album: + return true; + }; + return false; + default: + return false; + } +} diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/replaygain.h b/tools/vio2sf/src/foobar/foobar2000/SDK/replaygain.h new file mode 100644 index 000000000..5e4c840ce --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/replaygain.h @@ -0,0 +1,56 @@ +//! Structure storing ReplayGain configuration: album/track source data modes, gain/peak processing modes and preamp values. +struct t_replaygain_config +{ + enum /*t_source_mode*/ {source_mode_none,source_mode_track,source_mode_album}; + enum /*t_processing_mode*/ {processing_mode_none,processing_mode_gain,processing_mode_gain_and_peak,processing_mode_peak}; + typedef t_uint32 t_source_mode; typedef t_uint32 t_processing_mode; + + t_replaygain_config() {reset();} + t_replaygain_config(const t_replaygain_config & p_source) {*this = p_source;} + t_replaygain_config(t_source_mode p_source_mode,t_processing_mode p_processing_mode,float p_preamp_without_rg, float p_preamp_with_rg) + : m_source_mode(p_source_mode), m_processing_mode(p_processing_mode), m_preamp_without_rg(p_preamp_without_rg), m_preamp_with_rg(p_preamp_with_rg) {} + + + t_source_mode m_source_mode; + t_processing_mode m_processing_mode; + float m_preamp_without_rg, m_preamp_with_rg;//preamp values in dB + + void reset(); + audio_sample query_scale(const file_info & info) const; + audio_sample query_scale(const metadb_handle_ptr & info) const; + + void format_name(pfc::string_base & p_out) const; + bool is_active() const; +}; + +FB2K_STREAM_READER_OVERLOAD(t_replaygain_config) { + return stream >> value.m_source_mode >> value.m_processing_mode >> value.m_preamp_with_rg >> value.m_preamp_with_rg; +} +FB2K_STREAM_WRITER_OVERLOAD(t_replaygain_config) { + return stream << value.m_source_mode << value.m_processing_mode << value.m_preamp_with_rg << value.m_preamp_with_rg; +} + +//! Core service providing methods to retrieve/alter playback ReplayGain settings, as well as use ReplayGain configuration dialog. +class NOVTABLE replaygain_manager : public service_base { +public: + //! Retrieves playback ReplayGain settings. + virtual void get_core_settings(t_replaygain_config & p_out) = 0; + + //! Creates embedded version of ReplayGain settings dialog. Note that embedded dialog sends WM_COMMAND with id/BN_CLICKED to parent window when user makes changes to settings. + virtual HWND configure_embedded(const t_replaygain_config & p_initdata,HWND p_parent,unsigned p_id,bool p_from_modal) = 0; + //! Retrieves settings from embedded version of ReplayGain settings dialog. + virtual void configure_embedded_retrieve(HWND wnd,t_replaygain_config & p_data) = 0; + + //! Shows popup/modal version of ReplayGain settings dialog. Returns true when user changed the settings, false when user cancelled the operation. Title parameter can be null to use default one. + virtual bool configure_popup(t_replaygain_config & p_data,HWND p_parent,const char * p_title) = 0; + + //! Alters playback ReplayGain settings. + virtual void set_core_settings(const t_replaygain_config & p_config) = 0; + + //! Helper; queries scale value for specified item according to core playback settings. + audio_sample core_settings_query_scale(const file_info & p_info); + //! Helper; queries scale value for specified item according to core playback settings. + audio_sample core_settings_query_scale(const metadb_handle_ptr & info); + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(replaygain_manager); +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/replaygain_info.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/replaygain_info.cpp new file mode 100644 index 000000000..e1c5640fb --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/replaygain_info.cpp @@ -0,0 +1,136 @@ +#include "foobar2000.h" + +bool replaygain_info::g_format_gain(float p_value,char p_buffer[text_buffer_size]) +{ + fpu_control_roundnearest bah; + if (p_value == gain_invalid) + { + p_buffer[0] = 0; + return false; + } + else + { + pfc::float_to_string(p_buffer,text_buffer_size - 4,p_value,2,true); + strcat(p_buffer," dB"); + return true; + } +} + +bool replaygain_info::g_format_peak(float p_value,char p_buffer[text_buffer_size]) +{ + fpu_control_roundnearest bah; + if (p_value == peak_invalid) + { + p_buffer[0] = 0; + return false; + } + else + { + pfc::float_to_string(p_buffer,text_buffer_size,p_value,6,false); + return true; + } +} + +void replaygain_info::reset() +{ + m_album_gain = gain_invalid; + m_track_gain = gain_invalid; + m_album_peak = peak_invalid; + m_track_peak = peak_invalid; +} + +static const char meta_album_gain[] = "replaygain_album_gain", meta_album_peak[] = "replaygain_album_peak", meta_track_gain[] = "replaygain_track_gain", meta_track_peak[] = "replaygain_track_peak"; + +bool replaygain_info::g_is_meta_replaygain(const char * p_name,t_size p_name_len) +{ + return + stricmp_utf8_ex(p_name,p_name_len,meta_album_gain,infinite) == 0 || + stricmp_utf8_ex(p_name,p_name_len,meta_album_peak,infinite) == 0 || + stricmp_utf8_ex(p_name,p_name_len,meta_track_gain,infinite) == 0 || + stricmp_utf8_ex(p_name,p_name_len,meta_track_peak,infinite) == 0; +} + +bool replaygain_info::set_from_meta_ex(const char * p_name,t_size p_name_len,const char * p_value,t_size p_value_len) +{ + fpu_control_roundnearest bah; + if (stricmp_utf8_ex(p_name,p_name_len,meta_album_gain,infinite) == 0) + { + m_album_gain = (float)pfc::string_to_float(p_value,p_value_len); + return true; + } + else if (stricmp_utf8_ex(p_name,p_name_len,meta_album_peak,infinite) == 0) + { + m_album_peak = (float)pfc::string_to_float(p_value,p_value_len); + if (m_album_peak < 0) m_album_peak = 0; + return true; + } + else if (stricmp_utf8_ex(p_name,p_name_len,meta_track_gain,infinite) == 0) + { + m_track_gain = (float)pfc::string_to_float(p_value,p_value_len); + return true; + } + else if (stricmp_utf8_ex(p_name,p_name_len,meta_track_peak,infinite) == 0) + { + m_track_peak = (float)pfc::string_to_float(p_value,p_value_len); + if (m_track_peak < 0) m_track_peak = 0; + return true; + } + else return false; +} + + +t_size replaygain_info::get_value_count() +{ + t_size ret = 0; + if (is_album_gain_present()) ret++; + if (is_album_peak_present()) ret++; + if (is_track_gain_present()) ret++; + if (is_track_peak_present()) ret++; + return ret; +} + +void replaygain_info::set_album_gain_text(const char * p_text,t_size p_text_len) +{ + fpu_control_roundnearest bah; + if (p_text != 0 && p_text_len > 0 && *p_text != 0) + m_album_gain = (float)pfc::string_to_float(p_text,p_text_len); + else + remove_album_gain(); +} + +void replaygain_info::set_track_gain_text(const char * p_text,t_size p_text_len) +{ + fpu_control_roundnearest bah; + if (p_text != 0 && p_text_len > 0 && *p_text != 0) + m_track_gain = (float)pfc::string_to_float(p_text,p_text_len); + else + remove_track_gain(); +} + +void replaygain_info::set_album_peak_text(const char * p_text,t_size p_text_len) +{ + fpu_control_roundnearest bah; + if (p_text != 0 && p_text_len > 0 && *p_text != 0) + m_album_peak = (float)pfc::string_to_float(p_text,p_text_len); + else + remove_album_peak(); +} + +void replaygain_info::set_track_peak_text(const char * p_text,t_size p_text_len) +{ + fpu_control_roundnearest bah; + if (p_text != 0 && p_text_len > 0 && *p_text != 0) + m_track_peak = (float)pfc::string_to_float(p_text,p_text_len); + else + remove_track_peak(); +} + +replaygain_info replaygain_info::g_merge(replaygain_info r1,replaygain_info r2) +{ + replaygain_info ret = r1; + if (!ret.is_album_gain_present()) ret.m_album_gain = r2.m_album_gain; + if (!ret.is_album_peak_present()) ret.m_album_peak = r2.m_album_peak; + if (!ret.is_track_gain_present()) ret.m_track_gain = r2.m_track_gain; + if (!ret.is_track_peak_present()) ret.m_track_peak = r2.m_track_peak; + return ret; +} diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/replaygain_scanner.h b/tools/vio2sf/src/foobar/foobar2000/SDK/replaygain_scanner.h new file mode 100644 index 000000000..0224d8a9f --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/replaygain_scanner.h @@ -0,0 +1,37 @@ +//! Container of ReplayGain scan results from one or more tracks. +class replaygain_result : public service_base { + FB2K_MAKE_SERVICE_INTERFACE(replaygain_result, service_base); +public: + //! Retrieves the gain value, in dB. + virtual float get_gain() = 0; + //! Retrieves the peak value, normalized to 0..1 range (audio_sample value). + virtual float get_peak() = 0; + //! Merges ReplayGain scan results from different tracks. Merge results from all tracks in an album to get album gain/peak values. \n + //! This function returns a newly created replaygain_result object. Existing replaygain_result objects remain unaltered. + virtual replaygain_result::ptr merge(replaygain_result::ptr other) = 0; +}; + +//! Instance of a ReplayGain scanner. \n +//! Use static_api_ptr_t()->instantiate() to create a replaygain_scanner object; see replaygain_scanner_entry for more info. \n +//! Typical use: call process_chunk() with each chunk read from your track, call finalize() to obtain results for this track and reset replaygain_scanner's state for scanning another track; to obtain album gain/peak values, merge results (replaygain_result::merge) from all tracks. \n +class replaygain_scanner : public service_base { + FB2K_MAKE_SERVICE_INTERFACE(replaygain_scanner, service_base); +public: + //! Processes a PCM chunk. \n + //! May throw exception_io_data if the chunk contains something that can't be processed properly. + virtual void process_chunk(const audio_chunk & chunk) = 0; + //! Finalizes the scanning process; resets scanner's internal state and returns results for the track we've just scanned. \n + //! After calling finalize(), scanner's state becomes the same as after instantiation; you can continue with processing another track without creating a new scanner object. + virtual replaygain_result::ptr finalize() = 0; +}; + + +//! Entrypoint class for instantiating replaygain_scanner objects. Use static_api_ptr_t()->instantiate() to create replaygain_scanner instances. \n +//! This service is OPTIONAL; it's available from foobar2000 0.9.5.3 up but only if the ReplayGain Scanner component is installed. \n +//! It is recommended that you use replaygain_scanner like this: try { myInstance = static_api_ptr_t()->instantiate(); } catch(exception_service_not_found) { /* too old foobar2000 version or no foo_rgscan installed - complain/fail/etc */ } +class replaygain_scanner_entry : public service_base { + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(replaygain_scanner_entry); +public: + //! Instantiates a replaygain_scanner object. + virtual replaygain_scanner::ptr instantiate() = 0; +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/resampler.h b/tools/vio2sf/src/foobar/foobar2000/SDK/resampler.h new file mode 100644 index 000000000..de4626960 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/resampler.h @@ -0,0 +1,25 @@ +class NOVTABLE resampler_entry : public dsp_entry +{ +public: + virtual bool is_conversion_supported(unsigned p_srate_from,unsigned p_srate_to) = 0; + virtual bool create_preset(dsp_preset & p_out,unsigned p_target_srate,float p_qualityscale) = 0;//p_qualityscale is 0...1 + virtual float get_priority() = 0;//value is 0...1, where high-quality (SSRC etc) has 1 + + static bool g_get_interface(service_ptr_t & p_out,unsigned p_srate_from,unsigned p_srate_to); + static bool g_create(service_ptr_t & p_out,unsigned p_srate_from,unsigned p_srate_to,float p_qualityscale); + static bool g_create_preset(dsp_preset & p_out,unsigned p_srate_from,unsigned p_srate_to,float p_qualityscale); + + FB2K_MAKE_SERVICE_INTERFACE(resampler_entry,dsp_entry); +}; + +template +class resampler_entry_impl_t : public dsp_entry_impl_t +{ +public: + bool is_conversion_supported(unsigned p_srate_from,unsigned p_srate_to) {return T::g_is_conversion_supported(p_srate_from,p_srate_to);} + bool create_preset(dsp_preset & p_out,unsigned p_target_srate,float p_qualityscale) {return T::g_create_preset(p_out,p_target_srate,p_qualityscale);} + float get_priority() {return T::g_get_priority();} +}; + +template +class resampler_factory_t : public service_factory_single_t > {}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/search_tools.h b/tools/vio2sf/src/foobar/foobar2000/SDK/search_tools.h new file mode 100644 index 000000000..91c4fadbf --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/search_tools.h @@ -0,0 +1,68 @@ +//! Instance of a search filter object. New in 0.9.5. \n +//! This object contains a preprocessed search query; used to perform filtering similar to Media Library Search or Album List's "filter" box. \n +//! Use search_filter_manager API to instantiate search_filter objects. +class search_filter : public service_base { +public: + //! For backwards compatibility with older (0.9.5 alpha) revisions of this API. Do not call. + virtual bool test_locked(const metadb_handle_ptr & p_item,const file_info * p_info) = 0; + + //! Use this to run this filter on a group of items. + //! @param data Items to test. + //! @param out Pointer to a buffer (size at least equal to number of items in the source list) receiving the results. + virtual void test_multi(metadb_handle_list_cref data, bool * out) = 0; + + FB2K_MAKE_SERVICE_INTERFACE(search_filter,service_base); +}; + +//! New in 0.9.5.3. You can obtain a search_filter_v2 pointer by using service_query() on a search_filter pointer, or from search_filter_manager_v2::create_ex(). +class search_filter_v2 : public search_filter { +public: + virtual bool get_sort_pattern(titleformat_object::ptr & out, int & direction) = 0; + + //! Abortable version of test_multi(). If the abort_callback object becomes signaled while the operation is being performed, contents of the output buffer are undefined and the operation will fail with exception_aborted. + virtual void test_multi_ex(metadb_handle_list_cref data, bool * out, abort_callback & abort) = 0; + + FB2K_MAKE_SERVICE_INTERFACE(search_filter_v2, search_filter) +}; + +//! New in 0.9.5.4. You can obtain a search_filter_v2 pointer by using service_query() on a search_filter/search_filter_v2 pointer. +class search_filter_v3 : public search_filter_v2 { +public: + //! Returns whether the sort pattern returned by get_sort_pattern() was set by the user explicitly using "SORT BY" syntax or whether it was determined implicitly from some other part of the query. It's recommended to use this to determine whether to create a force-sorted autoplaylist or not. + virtual bool is_sort_explicit() = 0; + + FB2K_MAKE_SERVICE_INTERFACE(search_filter_v3, search_filter_v2) +}; + +//! Entrypoint class to instantiate search_filter objects. New in 0.9.5. +class search_filter_manager : public service_base { +public: + //! Creates a search_filter object. Throws an exception on failure (such as an error in the query). It's recommended that you relay the exception message to the user if this function fails. + virtual search_filter::ptr create(const char * p_query) = 0; + + //! Retrieves the search expression manual string. See also: show_manual(). + virtual void get_manual(pfc::string_base & p_out) = 0; + + void show_manual() { + pfc::string8 temp; + get_manual(temp); + popup_message::g_show(temp,"Search Expression Reference"); + } + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(search_filter_manager); +}; + +//! New in 0.9.5.3. +class search_filter_manager_v2 : public search_filter_manager { +public: + enum { + KFlagAllowSort = 1 << 0, + }; + //! Creates a search_filter object. Throws an exception on failure (such as an error in the query). It's recommended that you relay the exception message to the user if this function fails. + //! @param changeNotify A completion_notify callback object that will get called each time the query's behavior changes as a result of some external event (such as system time change). The caller must refresh query results each time this callback is triggered. The status parameter of it's on_completion() parameter is unused and always set to zero. + virtual search_filter_v2::ptr create_ex(const char * query, completion_notify::ptr changeNotify, t_uint32 flags) = 0; + + //! Opens the search query syntax reference document, typically an external HTML in user's default web browser. + virtual void show_manual() = 0; + + FB2K_MAKE_SERVICE_INTERFACE(search_filter_manager_v2, search_filter_manager); +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/service.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/service.cpp new file mode 100644 index 000000000..996117140 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/service.cpp @@ -0,0 +1,59 @@ +#include "foobar2000.h" +#include "component.h" + +foobar2000_api * g_api; + +service_class_ref service_factory_base::enum_find_class(const GUID & p_guid) +{ + PFC_ASSERT(core_api::are_services_available() && g_api); + return g_api->service_enum_find_class(p_guid); +} + +bool service_factory_base::enum_create(service_ptr_t & p_out,service_class_ref p_class,t_size p_index) +{ + PFC_ASSERT(core_api::are_services_available() && g_api); + return g_api->service_enum_create(p_out,p_class,p_index); +} + +t_size service_factory_base::enum_get_count(service_class_ref p_class) +{ + PFC_ASSERT(core_api::are_services_available() && g_api); + return g_api->service_enum_get_count(p_class); +} + +service_factory_base * service_factory_base::__internal__list = NULL; + + + + + +namespace { + class main_thread_callback_release_object : public main_thread_callback { + public: + main_thread_callback_release_object(service_ptr obj) : m_object(obj) {} + void callback_run() { + try { m_object.release(); } catch(...) {} + } + private: + service_ptr m_object; + }; +} +namespace service_impl_helper { + void release_object_delayed(service_ptr obj) { + static_api_ptr_t()->add_callback(new service_impl_t(obj)); + } +}; + + +void _standard_api_create_internal(service_ptr & out, const GUID & classID) { + service_class_ref c = service_factory_base::enum_find_class(classID); + switch(service_factory_base::enum_get_count(c)) { + case 0: + throw exception_service_not_found(); + case 1: + PFC_ASSERT_SUCCESS( service_factory_base::enum_create(out, c, 0) ); + break; + default: + throw exception_service_duplicated(); + } +} diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/service.h b/tools/vio2sf/src/foobar/foobar2000/SDK/service.h new file mode 100644 index 000000000..a2d64651d --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/service.h @@ -0,0 +1,605 @@ +#ifndef _foobar2000_sdk_service_h_included_ +#define _foobar2000_sdk_service_h_included_ + +typedef const void* service_class_ref; + +PFC_DECLARE_EXCEPTION(exception_service_not_found,pfc::exception,"Service not found"); +PFC_DECLARE_EXCEPTION(exception_service_extension_not_found,pfc::exception,"Service extension not found"); +PFC_DECLARE_EXCEPTION(exception_service_duplicated,pfc::exception,"Service duplicated"); + +#ifdef _MSC_VER +#define FOOGUIDDECL __declspec(selectany) +#else +#define FOOGUIDDECL +#endif + + +#define DECLARE_GUID(NAME,A,S,D,F,G,H,J,K,L,Z,X) FOOGUIDDECL const GUID NAME = {A,S,D,{F,G,H,J,K,L,Z,X}}; +#define DECLARE_CLASS_GUID(NAME,A,S,D,F,G,H,J,K,L,Z,X) FOOGUIDDECL const GUID NAME::class_guid = {A,S,D,{F,G,H,J,K,L,Z,X}}; + +//! Special hack to ensure errors when someone tries to ->service_add_ref()/->service_release() on a service_ptr_t +template class service_obscure_refcounting : public T { +private: + int service_add_ref() throw(); + int service_release() throw(); +}; + +//! Converts a service interface pointer to a pointer that obscures service counter functionality. +template static inline service_obscure_refcounting* service_obscure_refcounting_cast(T * p_source) throw() {return static_cast*>(p_source);} + +//Must be templated instead of taking service_base* because of multiple inheritance issues. +template static void service_release_safe(T * p_ptr) throw() { + if (p_ptr != NULL) PFC_ASSERT_NO_EXCEPTION( p_ptr->service_release() ); +} + +//Must be templated instead of taking service_base* because of multiple inheritance issues. +template static void service_add_ref_safe(T * p_ptr) throw() { + if (p_ptr != NULL) PFC_ASSERT_NO_EXCEPTION( p_ptr->service_add_ref() ); +} + +class service_base; + +//! Autopointer class to be used with all services. Manages reference counter calls behind-the-scenes. +template +class service_ptr_t { +private: + typedef service_ptr_t t_self; +public: + inline service_ptr_t() throw() : m_ptr(NULL) {} + inline service_ptr_t(T* p_ptr) throw() : m_ptr(NULL) {copy(p_ptr);} + inline service_ptr_t(const t_self & p_source) throw() : m_ptr(NULL) {copy(p_source);} + + template + inline service_ptr_t(t_source * p_ptr) throw() : m_ptr(NULL) {copy(p_ptr);} + + template + inline service_ptr_t(const service_ptr_t & p_source) throw() : m_ptr(NULL) {copy(p_source);} + + inline ~service_ptr_t() throw() {service_release_safe(m_ptr);} + + template + void copy(t_source * p_ptr) throw() { + service_add_ref_safe(p_ptr); + service_release_safe(m_ptr); + m_ptr = pfc::safe_ptr_cast(p_ptr); + + } + + template + inline void copy(const service_ptr_t & p_source) throw() {copy(p_source.get_ptr());} + + + inline const t_self & operator=(const t_self & p_source) throw() {copy(p_source); return *this;} + inline const t_self & operator=(T * p_ptr) throw() {copy(p_ptr); return *this;} + + template inline t_self & operator=(const service_ptr_t & p_source) throw() {copy(p_source); return *this;} + template inline t_self & operator=(t_source * p_ptr) throw() {copy(p_ptr); return *this;} + + inline void release() throw() { + service_release_safe(m_ptr); + m_ptr = NULL; + } + + + inline service_obscure_refcounting* operator->() const throw() {PFC_ASSERT(m_ptr != NULL);return service_obscure_refcounting_cast(m_ptr);} + + inline T* get_ptr() const throw() {return m_ptr;} + + inline bool is_valid() const throw() {return m_ptr != NULL;} + inline bool is_empty() const throw() {return m_ptr == NULL;} + + inline bool operator==(const t_self & p_item) const throw() {return m_ptr == p_item.get_ptr();} + inline bool operator!=(const t_self & p_item) const throw() {return m_ptr != p_item.get_ptr();} + inline bool operator>(const t_self & p_item) const throw() {return m_ptr > p_item.get_ptr();} + inline bool operator<(const t_self & p_item) const throw() {return m_ptr < p_item.get_ptr();} + + template + inline t_self & operator<<(service_ptr_t & p_source) throw() {attach(p_source.detach());return *this;} + template + inline t_self & operator>>(service_ptr_t & p_dest) throw() {p_dest.attach(detach());return *this;} + + + inline T* __unsafe_duplicate() const throw() {//should not be used ! temporary ! + service_add_ref_safe(m_ptr); + return m_ptr; + } + + inline T* detach() throw() { + return pfc::replace_null_t(m_ptr); + } + + template + inline void attach(t_source * p_ptr) throw() { + service_release_safe(m_ptr); + m_ptr = pfc::safe_ptr_cast(p_ptr); + } + + T & operator*() const throw() {return *m_ptr;} + + service_ptr_t & _as_base_ptr() { + PFC_ASSERT( _as_base_ptr_check() ); + return *reinterpret_cast*>(this); + } + static bool _as_base_ptr_check() { + return static_cast((T*)NULL) == reinterpret_cast((T*)NULL); + } +private: + T* m_ptr; +}; + +namespace pfc { + template + class traits_t > : public traits_default { + public: + enum { realloc_safe = true, constructor_may_fail = false}; + }; +} + + +template class t_alloc = pfc::alloc_fast> +class service_list_t : public pfc::list_t, t_alloc > +{ +}; + +//! Helper macro for use when defining a service class. Generates standard features of a service, without ability to register using service_factory / enumerate using service_enum_t. \n +//! This is used for declaring services that are meant to be instantiated by means other than service_enum_t (or non-entrypoint services), or extensions of services (including extension of entrypoint services). \n +//! Sample non-entrypoint declaration: class myclass : public service_base {...; FB2K_MAKE_SERVICE_INTERFACE(myclass, service_base); }; \n +//! Sample extension declaration: class myclass : public myotherclass {...; FB2K_MAKE_SERVICE_INTERFACE(myclass, myotherclass); }; \n +//! This macro is intended for use ONLY WITH INTERFACE CLASSES, not with implementation classes. +#define FB2K_MAKE_SERVICE_INTERFACE(THISCLASS,PARENTCLASS) \ + public: \ + typedef THISCLASS t_interface; \ + typedef PARENTCLASS t_interface_parent; \ + \ + static const GUID class_guid; \ + \ + virtual bool service_query(service_ptr_t & p_out,const GUID & p_guid) { \ + if (p_guid == class_guid) {p_out = this; return true;} \ + else return PARENTCLASS::service_query(p_out,p_guid); \ + } \ + typedef service_ptr_t ptr; \ + protected: \ + THISCLASS() {} \ + ~THISCLASS() {} \ + private: \ + const THISCLASS & operator=(const THISCLASS &) {throw pfc::exception_not_implemented();} \ + THISCLASS(const THISCLASS &) {throw pfc::exception_not_implemented();} \ + private: \ + void __private__service_declaration_selftest() { \ + pfc::assert_same_type(); /*parentclass must be an interface*/ \ + __validate_service_class_helper(); /*service_base must be reachable by walking t_interface_parent*/ \ + pfc::safe_cast(this); /*this class must derive from service_base, directly or indirectly, and be implictly castable to it*/ \ + } + +//! Helper macro for use when defining an entrypoint service class. Generates standard features of a service, including ability to register using service_factory and enumerate using service_enum. \n +//! Sample declaration: class myclass : public service_base {...; FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(myclass); }; \n +//! Note that entrypoint service classes must directly derive from service_base, and not from another service class. +//! This macro is intended for use ONLY WITH INTERFACE CLASSES, not with implementation classes. +#define FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(THISCLASS) \ + public: \ + typedef THISCLASS t_interface_entrypoint; \ + FB2K_MAKE_SERVICE_INTERFACE(THISCLASS,service_base) + + +#define FB2K_DECLARE_SERVICE_BEGIN(THISCLASS,BASECLASS) \ + class NOVTABLE THISCLASS : public BASECLASS { \ + FB2K_MAKE_SERVICE_INTERFACE(THISCLASS,BASECLASS); \ + public: + +#define FB2K_DECLARE_SERVICE_END() \ + }; + +#define FB2K_DECLARE_SERVICE_ENTRYPOINT_BEGIN(THISCLASS) \ + class NOVTABLE THISCLASS : public service_base { \ + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(THISCLASS) \ + public: + + +//! Base class for all service classes.\n +//! Provides interfaces for reference counter and querying for different interfaces supported by the object.\n +class NOVTABLE service_base +{ +public: + //! Decrements reference count; deletes the object if reference count reaches zero. This is normally not called directly but managed by service_ptr_t<> template. + //! @returns New reference count. For debug purposes only, in certain conditions return values may be unreliable. + virtual int service_release() throw() = 0; + //! Increments reference count. This is normally not called directly but managed by service_ptr_t<> template. + //! @returns New reference count. For debug purposes only, in certain conditions return values may be unreliable. + virtual int service_add_ref() throw() = 0; + //! Queries whether the object supports specific interface and retrieves a pointer to that interface. This is normally not called directly but managed by service_query_t<> function template. + //! Typical implementation checks the parameter against GUIDs of interfaces supported by this object, if the GUID is one of supported interfaces, p_out is set to service_base pointer that can be static_cast<>'ed to queried interface and the method returns true; otherwise the method returns false. + virtual bool service_query(service_ptr_t & p_out,const GUID & p_guid) {return false;} + + //! Queries whether the object supports specific interface and retrieves a pointer to that interface. + //! @param p_out Receives pointer to queried interface on success. + //! returns true on success, false on failure (interface not supported by the object). + template + bool service_query_t(service_ptr_t & p_out) + { + pfc::assert_same_type(); + return service_query( *reinterpret_cast*>(&p_out),T::class_guid); + } + + typedef service_base t_interface; + +protected: + service_base() {} + ~service_base() {} +private: + service_base(const service_base&) {throw pfc::exception_not_implemented();} + const service_base & operator=(const service_base&) {throw pfc::exception_not_implemented();} +}; + +typedef service_ptr_t service_ptr; + +template +static void __validate_service_class_helper() { + __validate_service_class_helper(); +} + +template<> +static void __validate_service_class_helper() {} + + +#include "service_impl.h" + +class NOVTABLE service_factory_base { +protected: + inline service_factory_base(const GUID & p_guid) : m_guid(p_guid) {PFC_ASSERT(!core_api::are_services_available());__internal__next=__internal__list;__internal__list=this;} + inline ~service_factory_base() {PFC_ASSERT(!core_api::are_services_available());} +public: + inline const GUID & get_class_guid() const {return m_guid;} + + static service_class_ref enum_find_class(const GUID & p_guid); + static bool enum_create(service_ptr_t & p_out,service_class_ref p_class,t_size p_index); + static t_size enum_get_count(service_class_ref p_class); + + inline static bool is_service_present(const GUID & g) {return enum_get_count(enum_find_class(g))>0;} + + //! Throws std::bad_alloc or another exception on failure. + virtual void instance_create(service_ptr_t & p_out) = 0; + + //! FOR INTERNAL USE ONLY + static service_factory_base *__internal__list; + //! FOR INTERNAL USE ONLY + service_factory_base * __internal__next; +private: + const GUID & m_guid; +}; + + +template +class service_factory_base_t : public service_factory_base { +public: + service_factory_base_t() : service_factory_base(B::class_guid) { + pfc::assert_same_type(); + } + +}; + + +template static void _validate_service_ptr(service_ptr_t const & ptr) { + PFC_ASSERT( ptr.is_valid() ); + service_ptr_t test; + PFC_ASSERT( ptr->service_query_t(test) ); +} + +#ifdef _DEBUG +#define FB2K_ASSERT_VALID_SERVICE_PTR(ptr) _validate_service_ptr(ptr) +#else +#define FB2K_ASSERT_VALID_SERVICE_PTR(ptr) +#endif + +template static bool service_enum_create_t(service_ptr_t & p_out,t_size p_index) { + pfc::assert_same_type(); + service_ptr_t ptr; + if (service_factory_base::enum_create(ptr,service_factory_base::enum_find_class(T::class_guid),p_index)) { + p_out = static_cast(ptr.get_ptr()); + return true; + } else { + p_out.release(); + return false; + } +} + +template static service_class_ref _service_find_class() { + pfc::assert_same_type(); + return service_factory_base::enum_find_class(T::class_guid); +} + +template +static bool _service_instantiate_helper(service_ptr_t & out, service_class_ref servClass, t_size index) { + /*if (out._as_base_ptr_check()) { + const bool state = service_factory_base::enum_create(out._as_base_ptr(), servClass, index); + if (state) { FB2K_ASSERT_VALID_SERVICE_PTR(out); } + return state; + } else */{ + service_ptr temp; + const bool state = service_factory_base::enum_create(temp, servClass, index); + if (state) { + out.attach( static_cast( temp.detach() ) ); + FB2K_ASSERT_VALID_SERVICE_PTR( out ); + } + return state; + } +} + +template class service_class_helper_t { +public: + service_class_helper_t() : m_class(service_factory_base::enum_find_class(T::class_guid)) { + pfc::assert_same_type(); + } + t_size get_count() const { + return service_factory_base::enum_get_count(m_class); + } + + bool create(service_ptr_t & p_out,t_size p_index) const { + return _service_instantiate_helper(p_out, m_class, p_index); + } + + service_ptr_t create(t_size p_index) const { + service_ptr_t temp; + if (!create(temp,p_index)) throw pfc::exception_bug_check_v2(); + return temp; + } + service_class_ref get_class() const {return m_class;} +private: + service_class_ref m_class; +}; + +void _standard_api_create_internal(service_ptr & out, const GUID & classID); + +template static void standard_api_create_t(service_ptr_t & p_out) { + if (pfc::is_same_type::value) { + _standard_api_create_internal(p_out._as_base_ptr(), T::class_guid); + FB2K_ASSERT_VALID_SERVICE_PTR(p_out); + } else { + service_ptr_t temp; + standard_api_create_t(temp); + if (!temp->service_query_t(p_out)) throw exception_service_extension_not_found(); + } +} + +template static service_ptr_t standard_api_create_t() { + service_ptr_t temp; + standard_api_create_t(temp); + return temp; +} + +template +static bool static_api_test_t() { + typedef T::t_interface_entrypoint EP; + service_class_helper_t helper; + if (helper.get_count() != 1) return false; + if (!pfc::is_same_type::value) { + service_ptr_t t; + if (!helper.create(0)->service_query_t(t)) return false; + } + return true; +} + +#define FB2K_API_AVAILABLE(API) static_api_test_t() + +//! Helper template used to easily access core services. \n +//! Usage: static_api_ptr_t api; api->dosomething(); +//! Can be used at any point of code, WITH EXCEPTION of static objects that are initialized during the DLL loading process before the service system is initialized; such as static static_api_ptr_t objects or having static_api_ptr_t instances as members of statically created objects. +//! Throws exception_service_not_found if service could not be reached (which can be ignored for core APIs that are always present unless there is some kind of bug in the code). +template +class static_api_ptr_t { +public: + static_api_ptr_t() { + standard_api_create_t(m_ptr); + } + service_obscure_refcounting* operator->() const {return service_obscure_refcounting_cast(m_ptr.get_ptr());} + t_interface* get_ptr() const {return m_ptr.get_ptr();} +private: + service_ptr_t m_ptr; +}; + +//! Helper; simulates array with instance of each available implementation of given service class. +template class service_instance_array_t { +public: + typedef service_ptr_t t_ptr; + service_instance_array_t() { + service_class_helper_t helper; + const t_size count = helper.get_count(); + m_data.set_size(count); + for(t_size n=0;n m_data; +}; + +template +class service_enum_t { +public: + service_enum_t() : m_index(0) { + pfc::assert_same_type(); + } + void reset() {m_index = 0;} + + template + bool first(service_ptr_t & p_out) { + reset(); + return next(p_out); + } + + template + bool next(service_ptr_t & p_out) { + pfc::assert_same_type(); + if (pfc::is_same_type::value) { + return __next(reinterpret_cast&>(p_out)); + } else { + service_ptr_t temp; + while(__next(temp)) { + if (temp->service_query_t(p_out)) return true; + } + return false; + } + } + +private: + bool __next(service_ptr_t & p_out) { + return m_helper.create(p_out,m_index++); + } + unsigned m_index; + service_class_helper_t m_helper; +}; + +template +class service_factory_t : public service_factory_base_t { +public: + void instance_create(service_ptr_t & p_out) { + p_out = pfc::safe_cast(pfc::safe_cast(pfc::safe_cast( new service_impl_t ))); + } +}; + +template +class service_factory_single_t : public service_factory_base_t { + service_impl_single_t g_instance; +public: + TEMPLATE_CONSTRUCTOR_FORWARD_FLOOD(service_factory_single_t,g_instance) + + void instance_create(service_ptr_t & p_out) { + p_out = pfc::safe_cast(pfc::safe_cast(pfc::safe_cast(&g_instance))); + } + + inline T& get_static_instance() {return g_instance;} + inline const T& get_static_instance() const {return g_instance;} +}; + +template +class service_factory_single_ref_t : public service_factory_base_t +{ +private: + T & instance; +public: + service_factory_single_ref_t(T& param) : instance(param) {} + + void instance_create(service_ptr_t & p_out) { + p_out = pfc::safe_cast(pfc::safe_cast(pfc::safe_cast(&instance))); + } + + inline T& get_static_instance() {return instance;} +}; + + +template +class service_factory_single_transparent_t : public service_factory_base_t, public service_impl_single_t +{ +public: + TEMPLATE_CONSTRUCTOR_FORWARD_FLOOD(service_factory_single_transparent_t,service_impl_single_t) + + void instance_create(service_ptr_t & p_out) { + p_out = pfc::safe_cast(pfc::safe_cast(pfc::safe_cast(this))); + } + + inline T& get_static_instance() {return *(T*)this;} +}; + + + + + + + + + + + + + + + +template +static bool service_by_guid_fallback(service_ptr_t & out, const GUID & id) { + service_enum_t e; + service_ptr_t ptr; + while(e.next(ptr)) { + if (ptr->get_guid() == id) {out = ptr; return true;} + } + return false; +} + +template +class service_by_guid_data { +public: + service_by_guid_data() : m_servClass(), m_inited() {} + + bool ready() const {return m_inited;} + + void initialize() { + if (m_inited) return; + pfc::assert_same_type< what, typename what::t_interface_entrypoint >(); + m_servClass = service_factory_base::enum_find_class(what::class_guid); + const t_size servCount = service_factory_base::enum_get_count(m_servClass); + for(t_size walk = 0; walk < servCount; ++walk) { + service_ptr_t temp; + if (_service_instantiate_helper(temp, m_servClass, walk)) { + m_order.set(temp->get_guid(), walk); + } + } + m_inited = true; + } + + bool create(service_ptr_t & out, const GUID & id) const { + PFC_ASSERT(m_inited); + t_size index; + if (!m_order.query(id,index)) return false; + return _service_instantiate_helper(out, m_servClass, index); + } + service_ptr_t create(const GUID & id) const { + service_ptr_t temp; if (!crete(temp,id)) throw exception_service_not_found(); return temp; + } + +private: + volatile bool m_inited; + pfc::map_t m_order; + service_class_ref m_servClass; +}; + +template +class _service_by_guid_data_container { +public: + static service_by_guid_data data; +}; +template service_by_guid_data _service_by_guid_data_container::data; + + +template +static void service_by_guid_init() { + service_by_guid_data & data = _service_by_guid_data_container::data; + data.initialize(); +} +template +static bool service_by_guid(service_ptr_t & out, const GUID & id) { + pfc::assert_same_type< what, typename what::t_interface_entrypoint >(); + service_by_guid_data & data = _service_by_guid_data_container::data; + if (data.ready()) { + //fall-thru + } else if (core_api::is_main_thread()) { + data.initialize(); + } else { +#ifdef _DEBUG + uDebugLog() << "Warning: service_by_guid() used in non-main thread without initialization, using fallback"; +#endif + return service_by_guid_fallback(out,id); + } + return data.create(out,id); +} +template +static service_ptr_t service_by_guid(const GUID & id) { + service_ptr_t temp; + if (!service_by_guid(temp,id)) throw exception_service_not_found(); + return temp; +} + +#define FB2K_FOR_EACH_SERVICE(type, call) {service_enum_t e; service_ptr_t ptr; while(e.next(ptr)) {ptr->call;} } + +#endif //_foobar2000_sdk_service_h_included_ diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/service_impl.h b/tools/vio2sf/src/foobar/foobar2000/SDK/service_impl.h new file mode 100644 index 000000000..1c31536bb --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/service_impl.h @@ -0,0 +1,37 @@ +//! Template implementing reference-counting features of service_base. Intended for dynamic instantiation: "new service_impl_t(param1,param2);"; should not be instantiated otherwise (no local/static/member objects) because it does a "delete this;" when reference count reaches zero.\n +//! Note that some constructor parameters such as NULL will need explicit typecasts to ensure correctly guessed types for constructor function template (null string needs to be (const char*)NULL rather than just NULL, etc). +template +class service_impl_t : public T +{ +public: + int FB2KAPI service_release() throw() { + int ret = --m_counter; + if (ret == 0) { + PFC_ASSERT_NO_EXCEPTION( delete this ); + } + return ret; + } + int FB2KAPI service_add_ref() throw() {return ++m_counter;} + + TEMPLATE_CONSTRUCTOR_FORWARD_FLOOD(service_impl_t,T) +private: + pfc::refcounter m_counter; +}; + +//! Template implementing dummy version of reference-counting features of service_base. Intended for static/local/member instantiation: "static service_impl_single_t myvar(params);". Because reference counting features are disabled (dummy reference counter), code instantiating it is responsible for deleting it as well as ensuring that no references are active when the object gets deleted.\n +//! Note that some constructor parameters such as NULL will need explicit typecasts to ensure correctly guessed types for constructor function template (null string needs to be (const char*)NULL rather than just NULL, etc). +template +class service_impl_single_t : public T +{ +public: + int FB2KAPI service_release() throw() {return 1;} + int FB2KAPI service_add_ref() throw() {return 1;} + + TEMPLATE_CONSTRUCTOR_FORWARD_FLOOD(service_impl_single_t,T) +}; + + +namespace service_impl_helper { + void release_object_delayed(service_ptr obj); +}; + diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/shortcut_actions.h b/tools/vio2sf/src/foobar/foobar2000/SDK/shortcut_actions.h new file mode 100644 index 000000000..cfc068aec --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/shortcut_actions.h @@ -0,0 +1 @@ +#error DEPRECATED diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/stdafx.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/stdafx.cpp new file mode 100644 index 000000000..ea4f0bdf1 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/stdafx.cpp @@ -0,0 +1,2 @@ +//cpp used to generate precompiled header +#include "foobar2000.h" \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/tag_processor.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/tag_processor.cpp new file mode 100644 index 000000000..6b6361a94 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/tag_processor.cpp @@ -0,0 +1,170 @@ +#include "foobar2000.h" + +void tag_processor_trailing::write_id3v1(const service_ptr_t & p_file,const file_info & p_info,abort_callback & p_abort) +{ + write(p_file,p_info,flag_id3v1,p_abort); +} + +void tag_processor_trailing::write_apev2(const service_ptr_t & p_file,const file_info & p_info,abort_callback & p_abort) +{ + write(p_file,p_info,flag_apev2,p_abort); +} + +void tag_processor_trailing::write_apev2_id3v1(const service_ptr_t & p_file,const file_info & p_info,abort_callback & p_abort) +{ + write(p_file,p_info,flag_id3v1|flag_apev2,p_abort); +} + + + + +enum { + g_flag_id3v1 = 1<<0, + g_flag_id3v2 = 1<<1, + g_flag_apev2 = 1<<2 +}; + +static void tagtype_list_append(pfc::string_base & p_out,const char * p_name) +{ + if (!p_out.is_empty()) p_out += "|"; + p_out += p_name; +} + +static void g_write_tags_ex(tag_write_callback & p_callback,unsigned p_flags,const service_ptr_t & p_file,const file_info * p_info,abort_callback & p_abort) { + PFC_ASSERT( p_flags == 0 || p_info != 0 ); + + + if (p_flags & (g_flag_id3v1 | g_flag_apev2)) { + switch(p_flags & (g_flag_id3v1 | g_flag_apev2)) { + case g_flag_id3v1 | g_flag_apev2: + static_api_ptr_t()->write_apev2_id3v1(p_file,*p_info,p_abort); + break; + case g_flag_id3v1: + static_api_ptr_t()->write_id3v1(p_file,*p_info,p_abort); + break; + case g_flag_apev2: + static_api_ptr_t()->write_apev2(p_file,*p_info,p_abort); + break; + default: + throw exception_io_data(); + } + } else { + static_api_ptr_t()->remove(p_file,p_abort); + } + + if (p_flags & g_flag_id3v2) + { + static_api_ptr_t()->write_ex(p_callback,p_file,*p_info,p_abort); + } + else + { + t_uint64 dummy; + tag_processor_id3v2::g_remove_ex(p_callback,p_file,dummy,p_abort); + } +} + +static void g_write_tags(unsigned p_flags,const service_ptr_t & p_file,const file_info * p_info,abort_callback & p_abort) { + g_write_tags_ex(tag_write_callback_dummy(),p_flags,p_file,p_info,p_abort); +} + + +void tag_processor::write_multi(const service_ptr_t & p_file,const file_info & p_info,abort_callback & p_abort,bool p_write_id3v1,bool p_write_id3v2,bool p_write_apev2) { + unsigned flags = 0; + if (p_write_id3v1) flags |= g_flag_id3v1; + if (p_write_id3v2) flags |= g_flag_id3v2; + if (p_write_apev2) flags |= g_flag_apev2; + g_write_tags(flags,p_file,&p_info,p_abort); +} + +void tag_processor::write_multi_ex(tag_write_callback & p_callback,const service_ptr_t & p_file,const file_info & p_info,abort_callback & p_abort,bool p_write_id3v1,bool p_write_id3v2,bool p_write_apev2) { + unsigned flags = 0; + if (p_write_id3v1) flags |= g_flag_id3v1; + if (p_write_id3v2) flags |= g_flag_id3v2; + if (p_write_apev2) flags |= g_flag_apev2; + g_write_tags_ex(p_callback,flags,p_file,&p_info,p_abort); +} + +void tag_processor::write_id3v1(const service_ptr_t & p_file,const file_info & p_info,abort_callback & p_abort) { + g_write_tags(g_flag_id3v1,p_file,&p_info,p_abort); +} + +void tag_processor::write_apev2(const service_ptr_t & p_file,const file_info & p_info,abort_callback & p_abort) { + g_write_tags(g_flag_apev2,p_file,&p_info,p_abort); +} + +void tag_processor::write_apev2_id3v1(const service_ptr_t & p_file,const file_info & p_info,abort_callback & p_abort) { + g_write_tags(g_flag_apev2|g_flag_id3v1,p_file,&p_info,p_abort); +} + +void tag_processor::write_id3v2(const service_ptr_t & p_file,const file_info & p_info,abort_callback & p_abort) { + g_write_tags(g_flag_id3v2,p_file,&p_info,p_abort); +} + +void tag_processor::write_id3v2_id3v1(const service_ptr_t & p_file,const file_info & p_info,abort_callback & p_abort) { + g_write_tags(g_flag_id3v2|g_flag_id3v1,p_file,&p_info,p_abort); +} + +void tag_processor::remove_trailing(const service_ptr_t & p_file,abort_callback & p_abort) { + return static_api_ptr_t()->remove(p_file,p_abort); +} + +bool tag_processor::remove_id3v2(const service_ptr_t & p_file,abort_callback & p_abort) { + t_uint64 dummy = 0; + tag_processor_id3v2::g_remove(p_file,dummy,p_abort); + return dummy > 0; +} + +void tag_processor::remove_id3v2_trailing(const service_ptr_t & p_file,abort_callback & p_abort) { + remove_id3v2(p_file,p_abort); + remove_trailing(p_file,p_abort); +} + +void tag_processor::read_trailing(const service_ptr_t & p_file,file_info & p_info,abort_callback & p_abort) { + static_api_ptr_t()->read(p_file,p_info,p_abort); +} + +void tag_processor::read_trailing_ex(const service_ptr_t & p_file,file_info & p_info,t_uint64 & p_tagoffset,abort_callback & p_abort) { + static_api_ptr_t()->read_ex(p_file,p_info,p_tagoffset,p_abort); +} + +void tag_processor::read_id3v2(const service_ptr_t & p_file,file_info & p_info,abort_callback & p_abort) { + static_api_ptr_t()->read(p_file,p_info,p_abort); +} + +void tag_processor::read_id3v2_trailing(const service_ptr_t & p_file,file_info & p_info,abort_callback & p_abort) +{ + file_info_impl temp_infos[2]; + bool have_id3v2 = true, have_trailing = true; + try { + read_id3v2(p_file,temp_infos[0],p_abort); + } catch(exception_io_data) { + have_id3v2 = false; + } + try { + read_trailing(p_file,temp_infos[1],p_abort); + } catch(exception_io_data) { + have_trailing = false; + } + + if (!have_id3v2 && !have_trailing) throw exception_tag_not_found(); + else { + pfc::ptr_list_t blargh; + if (have_id3v2) blargh.add_item(&temp_infos[0]); + if (have_trailing) blargh.add_item(&temp_infos[1]); + p_info.merge(blargh); + } +} + +void tag_processor::skip_id3v2(const service_ptr_t & p_file,t_uint64 & p_size_skipped,abort_callback & p_abort) { + tag_processor_id3v2::g_skip(p_file,p_size_skipped,p_abort); +} + +bool tag_processor::is_id3v1_sufficient(const file_info & p_info) +{ + return static_api_ptr_t()->is_id3v1_sufficient(p_info); +} + +void tag_processor::truncate_to_id3v1(file_info & p_info) +{ + static_api_ptr_t()->truncate_to_id3v1(p_info); +} \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/tag_processor.h b/tools/vio2sf/src/foobar/foobar2000/SDK/tag_processor.h new file mode 100644 index 000000000..8369d4f65 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/tag_processor.h @@ -0,0 +1,99 @@ +PFC_DECLARE_EXCEPTION(exception_tag_not_found,exception_io_data,"Tag not found"); + +//! Callback interface for write-tags-to-temp-file-and-swap scheme, used for ID3v2 tag updates and such where entire file needs to be rewritten. +//! As a speed optimization, file content can be copied to a temporary file in the same directory as the file being updated, and then source file can be swapped for the newly created file with updated tags. +//! This also gives better security against data loss on crash compared to rewriting the file in place and using memory or generic temporary file APIs to store content being rewritten. +class NOVTABLE tag_write_callback { +public: + //! Called only once per operation (or not called at all when operation being performed can be done in-place). + //! Requests a temporary file to be created in the same directory + virtual bool open_temp_file(service_ptr_t & p_out,abort_callback & p_abort) = 0; +protected: + tag_write_callback() {} + ~tag_write_callback() {} +private: + tag_write_callback(const tag_write_callback &) {throw pfc::exception_not_implemented();} + const tag_write_callback & operator=(const tag_write_callback &) {throw pfc::exception_not_implemented();} +}; + +class tag_write_callback_dummy : public tag_write_callback { +public: + bool open_temp_file(service_ptr_t & p_out,abort_callback & p_abort) {return false;} +}; + +//! For internal use - call tag_processor namespace methods instead. +class NOVTABLE tag_processor_id3v2 : public service_base +{ +public: + virtual void read(const service_ptr_t & p_file,file_info & p_info,abort_callback & p_abort) = 0; + virtual void write(const service_ptr_t & p_file,const file_info & p_info,abort_callback & p_abort) = 0; + virtual void write_ex(tag_write_callback & p_callback,const service_ptr_t & p_file,const file_info & p_info,abort_callback & p_abort) = 0; + + static bool g_get(service_ptr_t & p_out); + static void g_skip(const service_ptr_t & p_file,t_filesize & p_size_skipped,abort_callback & p_abort); + static void g_remove(const service_ptr_t & p_file,t_filesize & p_size_removed,abort_callback & p_abort); + static void g_remove_ex(tag_write_callback & p_callback,const service_ptr_t & p_file,t_filesize & p_size_removed,abort_callback & p_abort); + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(tag_processor_id3v2); +}; + +//! For internal use - call tag_processor namespace methods instead. +class NOVTABLE tag_processor_trailing : public service_base +{ +public: + enum { + flag_apev2 = 1, + flag_id3v1 = 2, + }; + + virtual void read(const service_ptr_t & p_file,file_info & p_info,abort_callback & p_abort) = 0; + virtual void write(const service_ptr_t & p_file,const file_info & p_info,unsigned p_flags,abort_callback & p_abort) = 0; + virtual void remove(const service_ptr_t & p_file,abort_callback & p_abort) = 0; + virtual bool is_id3v1_sufficient(const file_info & p_info) = 0; + virtual void truncate_to_id3v1(file_info & p_info) = 0; + virtual void read_ex(const service_ptr_t & p_file,file_info & p_info,t_filesize & p_tagoffset,abort_callback & p_abort) = 0; + + void write_id3v1(const service_ptr_t & p_file,const file_info & p_info,abort_callback & p_abort); + void write_apev2(const service_ptr_t & p_file,const file_info & p_info,abort_callback & p_abort); + void write_apev2_id3v1(const service_ptr_t & p_file,const file_info & p_info,abort_callback & p_abort); + + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(tag_processor_trailing); +}; + +namespace tag_processor { + //! Strips all recognized tags from the file and writes an ID3v1 tag with specified info. + void write_id3v1(const service_ptr_t & p_file,const file_info & p_info,abort_callback & p_abort); + //! Strips all recognized tags from the file and writes an APEv2 tag with specified info. + void write_apev2(const service_ptr_t & p_file,const file_info & p_info,abort_callback & p_abort); + //! Strips all recognized tags from the file and writes ID3v1+APEv2 tags with specified info. + void write_apev2_id3v1(const service_ptr_t & p_file,const file_info & p_info,abort_callback & p_abort); + //! Strips all recognized tags from the file and writes an ID3v2 tag with specified info. + void write_id3v2(const service_ptr_t & p_file,const file_info & p_info,abort_callback & p_abort); + //! Strips all recognized tags from the file and writes ID3v1+ID3v2 tags with specified info. + void write_id3v2_id3v1(const service_ptr_t & p_file,const file_info & p_info,abort_callback & p_abort); + //! Strips all recognized tags from the file and writes new tags with specified info according to parameters. + void write_multi(const service_ptr_t & p_file,const file_info & p_info,abort_callback & p_abort,bool p_write_id3v1,bool p_write_id3v2,bool p_write_apev2); + //! Strips all recognized tags from the file and writes new tags with specified info according to parameters. Extended to allow write-tags-to-temp-file-and-swap scheme. + void write_multi_ex(tag_write_callback & p_callback,const service_ptr_t & p_file,const file_info & p_info,abort_callback & p_abort,bool p_write_id3v1,bool p_write_id3v2,bool p_write_apev2); + //! Removes trailing tags from the file. + void remove_trailing(const service_ptr_t & p_file,abort_callback & p_abort); + //! Removes ID3v2 tags from the file. Returns true when a tag was removed, false when the file was not altered. + bool remove_id3v2(const service_ptr_t & p_file,abort_callback & p_abort); + //! Removes ID3v2 and trailing tags from specified file (not to be confused with trailing ID3v2 which are not yet supported). + void remove_id3v2_trailing(const service_ptr_t & p_file,abort_callback & p_abort); + //! Reads trailing tags from the file. + void read_trailing(const service_ptr_t & p_file,file_info & p_info,abort_callback & p_abort); + //! Reads trailing tags from the file. Extended version, returns offset at which parsed tags start. + void read_trailing_ex(const service_ptr_t & p_file,file_info & p_info,t_filesize & p_tagoffset,abort_callback & p_abort); + //! Reads ID3v2 tags from specified file. + void read_id3v2(const service_ptr_t & p_file,file_info & p_info,abort_callback & p_abort); + //! Reads ID3v2 and trailing tags from specified file (not to be confused with trailing ID3v2 which are not yet supported). + void read_id3v2_trailing(const service_ptr_t & p_file,file_info & p_info,abort_callback & p_abort); + + void skip_id3v2(const service_ptr_t & p_file,t_filesize & p_size_skipped,abort_callback & p_abort); + + bool is_id3v1_sufficient(const file_info & p_info); + void truncate_to_id3v1(file_info & p_info); + +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/tag_processor_id3v2.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/tag_processor_id3v2.cpp new file mode 100644 index 000000000..26e1577a9 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/tag_processor_id3v2.cpp @@ -0,0 +1,97 @@ +#include "foobar2000.h" + +bool tag_processor_id3v2::g_get(service_ptr_t & p_out) +{ + return service_enum_t().first(p_out); +} + +void tag_processor_id3v2::g_remove(const service_ptr_t & p_file,t_uint64 & p_size_removed,abort_callback & p_abort) { + g_remove_ex(tag_write_callback_dummy(),p_file,p_size_removed,p_abort); +} + +void tag_processor_id3v2::g_remove_ex(tag_write_callback & p_callback,const service_ptr_t & p_file,t_uint64 & p_size_removed,abort_callback & p_abort) +{ + p_file->ensure_seekable(); + + t_filesize len; + + len = p_file->get_size(p_abort); + + if (len == filesize_invalid) throw exception_io_no_length(); + + p_file->seek(0,p_abort); + + t_uint64 offset; + g_skip(p_file,offset,p_abort); + + if (offset>0 && offset temp; + if (p_callback.open_temp_file(temp,p_abort)) { + file::g_transfer_object(p_file,temp,len,p_abort); + } else { + if (len > 16*1024*1024) filesystem::g_open_temp(temp,p_abort); + else filesystem::g_open_tempmem(temp,p_abort); + file::g_transfer_object(p_file,temp,len,p_abort); + p_file->seek(0,p_abort); + p_file->set_eof(p_abort); + temp->seek(0,p_abort); + file::g_transfer_object(temp,p_file,len,p_abort); + } + } + p_size_removed = offset; +} + +void tag_processor_id3v2::g_skip(const service_ptr_t & p_file,t_uint64 & p_size_skipped,abort_callback & p_abort) +{ + + unsigned char tmp[10]; + + t_size io_bytes_done; + + p_file->seek ( 0, p_abort ); + + io_bytes_done = p_file->read( tmp, sizeof(tmp), p_abort); + if (io_bytes_done != sizeof(tmp)) { + p_file->seek ( 0, p_abort ); + p_size_skipped = 0; + return; + } + + if ( 0 != memcmp ( tmp, "ID3", 3) ) { + p_file->seek ( 0, p_abort ); + p_size_skipped = 0; + return; + } + + int Unsynchronisation = tmp[5] & 0x80; + int ExtHeaderPresent = tmp[5] & 0x40; + int ExperimentalFlag = tmp[5] & 0x20; + int FooterPresent = tmp[5] & 0x10; + + if ( tmp[5] & 0x0F ) { + p_file->seek ( 0, p_abort ); + p_size_skipped = 0; + return; + } + + if ( (tmp[6] | tmp[7] | tmp[8] | tmp[9]) & 0x80 ) { + p_file->seek ( 0, p_abort ); + p_size_skipped = 0; + return; + } + + t_uint32 ret; + ret = tmp[6] << 21; + ret += tmp[7] << 14; + ret += tmp[8] << 7; + ret += tmp[9] ; + ret += 10; + if ( FooterPresent ) ret += 10; + + p_file->seek ( ret, p_abort ); + + p_size_skipped = ret; + +} diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/threaded_process.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/threaded_process.cpp new file mode 100644 index 000000000..567bd304f --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/threaded_process.cpp @@ -0,0 +1,36 @@ +#include "foobar2000.h" + +void threaded_process_status::set_progress(t_size p_state,t_size p_max) +{ + set_progress( progress_min + MulDiv_Size(p_state,progress_max-progress_min,p_max) ); +} + +void threaded_process_status::set_progress_secondary(t_size p_state,t_size p_max) +{ + set_progress_secondary( progress_min + MulDiv_Size(p_state,progress_max-progress_min,p_max) ); +} + +void threaded_process_status::set_progress_float(double p_state) +{ + if (p_state < 0.0) set_progress(progress_min); + else if (p_state < 1.0) set_progress( progress_min + (t_size)(p_state * (progress_max - progress_min))); + else set_progress(progress_max); +} + +void threaded_process_status::set_progress_secondary_float(double p_state) +{ + if (p_state < 0.0) set_progress_secondary(progress_min); + else if (p_state < 1.0) set_progress_secondary( progress_min + (t_size)(p_state * (progress_max - progress_min))); + else set_progress_secondary(progress_max); +} + + +bool threaded_process::g_run_modal(service_ptr_t p_callback,unsigned p_flags,HWND p_parent,const char * p_title,t_size p_title_len) +{ + return static_api_ptr_t()->run_modal(p_callback,p_flags,p_parent,p_title,p_title_len); +} + +bool threaded_process::g_run_modeless(service_ptr_t p_callback,unsigned p_flags,HWND p_parent,const char * p_title,t_size p_title_len) +{ + return static_api_ptr_t()->run_modeless(p_callback,p_flags,p_parent,p_title,p_title_len); +} diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/threaded_process.h b/tools/vio2sf/src/foobar/foobar2000/SDK/threaded_process.h new file mode 100644 index 000000000..1f7dbc491 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/threaded_process.h @@ -0,0 +1,62 @@ +#ifndef _foobar2000_sdk_threaded_process_h_ +#define _foobar2000_sdk_threaded_process_h_ + +class NOVTABLE threaded_process_status +{ +public: + enum {progress_min = 0, progress_max = 5000}; + + virtual void set_progress(t_size p_state) = 0; + virtual void set_progress_secondary(t_size p_state) = 0; + virtual void set_item(const char * p_item,t_size p_item_len = ~0) = 0; + virtual void set_item_path(const char * p_item,t_size p_item_len = ~0) = 0; + virtual void set_title(const char * p_title,t_size p_title_len = ~0) = 0; + virtual void force_update() = 0; + virtual bool is_paused() = 0; + virtual bool process_pause() = 0;//checks if process is paused and sleeps if needed; returns false when process should be aborted, true on success + + void set_progress(t_size p_state,t_size p_max); + void set_progress_secondary(t_size p_state,t_size p_max); + void set_progress_float(double p_state); + void set_progress_secondary_float(double p_state); +protected: + threaded_process_status() {} + ~threaded_process_status() {} +}; + + +class NOVTABLE threaded_process_callback : public service_base +{ +public: + virtual void on_init(HWND p_wnd) {} + virtual void run(threaded_process_status & p_status,abort_callback & p_abort) = 0; + virtual void on_done(HWND p_wnd,bool p_was_aborted) {} + + FB2K_MAKE_SERVICE_INTERFACE(threaded_process_callback,service_base); +}; + +class NOVTABLE threaded_process : public service_base { +public: + enum { + flag_show_abort = 1, + flag_show_minimize = 1 << 1, + flag_show_progress = 1 << 2, + flag_show_progress_dual = 1 << 3,//implies flag_show_progress + flag_show_item = 1 << 4, + flag_show_pause = 1 << 5, + flag_high_priority = 1 << 6, + flag_show_delayed = 1 << 7,//modeless-only + flag_no_focus = 1 << 8,//new (0.9.3) + }; + + virtual bool run_modal(service_ptr_t p_callback,unsigned p_flags,HWND p_parent,const char * p_title,t_size p_title_len) = 0; + virtual bool run_modeless(service_ptr_t p_callback,unsigned p_flags,HWND p_parent,const char * p_title,t_size p_title_len) = 0; + + static bool g_run_modal(service_ptr_t p_callback,unsigned p_flags,HWND p_parent,const char * p_title,t_size p_title_len = infinite); + static bool g_run_modeless(service_ptr_t p_callback,unsigned p_flags,HWND p_parent,const char * p_title,t_size p_title_len = infinite); + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(threaded_process); +}; + + +#endif //_foobar2000_sdk_threaded_process_h_ diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/titleformat.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/titleformat.cpp new file mode 100644 index 000000000..251e15a1b --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/titleformat.cpp @@ -0,0 +1,190 @@ +#include "foobar2000.h" + + +#define tf_profiler(x) // profiler(x) + +void titleformat_compiler::remove_color_marks(const char * src,pfc::string_base & out)//helper +{ + out.reset(); + while(*src) + { + if (*src==3) + { + src++; + while(*src && *src!=3) src++; + if (*src==3) src++; + } + else out.add_byte(*src++); + } +} + +static bool test_for_bad_char(const char * source,t_size source_char_len,const char * reserved) +{ + return pfc::strstr_ex(reserved,(t_size)(-1),source,source_char_len) != (t_size)(-1); +} + +void titleformat_compiler::remove_forbidden_chars(titleformat_text_out * p_out,const GUID & p_inputtype,const char * p_source,t_size p_source_len,const char * p_reserved_chars) +{ + if (p_reserved_chars == 0 || *p_reserved_chars == 0) + { + p_out->write(p_inputtype,p_source,p_source_len); + } + else + { + p_source_len = pfc::strlen_max(p_source,p_source_len); + t_size index = 0; + t_size good_byte_count = 0; + while(index < p_source_len) + { + t_size delta = pfc::utf8_char_len(p_source + index,p_source_len - index); + if (delta == 0) break; + if (test_for_bad_char(p_source+index,delta,p_reserved_chars)) + { + if (good_byte_count > 0) {p_out->write(p_inputtype,p_source+index-good_byte_count,good_byte_count);good_byte_count=0;} + p_out->write(p_inputtype,"_",1); + } + else + { + good_byte_count += delta; + } + index += delta; + } + if (good_byte_count > 0) {p_out->write(p_inputtype,p_source+index-good_byte_count,good_byte_count);good_byte_count=0;} + } +} + +void titleformat_compiler::remove_forbidden_chars_string_append(pfc::string_receiver & p_out,const char * p_source,t_size p_source_len,const char * p_reserved_chars) +{ + remove_forbidden_chars(&titleformat_text_out_impl_string(p_out),pfc::guid_null,p_source,p_source_len,p_reserved_chars); +} + +void titleformat_compiler::remove_forbidden_chars_string(pfc::string_base & p_out,const char * p_source,t_size p_source_len,const char * p_reserved_chars) +{ + p_out.reset(); + remove_forbidden_chars_string_append(p_out,p_source,p_source_len,p_reserved_chars); +} + +bool titleformat_hook_impl_file_info::process_field(titleformat_text_out * p_out,const char * p_name,t_size p_name_length,bool & p_found_flag) { + return m_api->process_field(*m_info,m_location,p_out,p_name,p_name_length,p_found_flag); +} +bool titleformat_hook_impl_file_info::process_function(titleformat_text_out * p_out,const char * p_name,t_size p_name_length,titleformat_hook_function_params * p_params,bool & p_found_flag) { + return m_api->process_function(*m_info,m_location,p_out,p_name,p_name_length,p_params,p_found_flag); +} + +void titleformat_object::run_hook(const playable_location & p_location,const file_info * p_source,titleformat_hook * p_hook,pfc::string_base & p_out,titleformat_text_filter * p_filter) +{ + if (p_hook) + { + run( + &titleformat_hook_impl_splitter( + p_hook, + &titleformat_hook_impl_file_info(p_location,p_source) + ), + p_out,p_filter); + } + else + { + run( + &titleformat_hook_impl_file_info(p_location,p_source), + p_out,p_filter); + } +} + +void titleformat_object::run_simple(const playable_location & p_location,const file_info * p_source,pfc::string_base & p_out) +{ + run(&titleformat_hook_impl_file_info(p_location,p_source),p_out,NULL); +} + +t_size titleformat_hook_function_params::get_param_uint(t_size index) +{ + const char * str; + t_size str_len; + get_param(index,str,str_len); + return pfc::atoui_ex(str,str_len); +} + + +void titleformat_text_out_impl_filter_chars::write(const GUID & p_inputtype,const char * p_data,t_size p_data_length) +{ + titleformat_compiler::remove_forbidden_chars(m_chain,p_inputtype,p_data,p_data_length,m_restricted_chars); +} + +bool titleformat_hook_impl_splitter::process_field(titleformat_text_out * p_out,const char * p_name,t_size p_name_length,bool & p_found_flag) +{ + p_found_flag = false; + if (m_hook1 && m_hook1->process_field(p_out,p_name,p_name_length,p_found_flag)) return true; + p_found_flag = false; + if (m_hook2 && m_hook2->process_field(p_out,p_name,p_name_length,p_found_flag)) return true; + p_found_flag = false; + return false; +} + +bool titleformat_hook_impl_splitter::process_function(titleformat_text_out * p_out,const char * p_name,t_size p_name_length,titleformat_hook_function_params * p_params,bool & p_found_flag) +{ + p_found_flag = false; + if (m_hook1 && m_hook1->process_function(p_out,p_name,p_name_length,p_params,p_found_flag)) return true; + p_found_flag = false; + if (m_hook2 && m_hook2->process_function(p_out,p_name,p_name_length,p_params,p_found_flag)) return true; + p_found_flag = false; + return false; +} + +void titleformat_text_out::write_int_padded(const GUID & p_inputtype,t_int64 val,t_int64 maxval) +{ + unsigned width = 0; + while(maxval > 0) {maxval/=10;width++;} + write(p_inputtype,pfc::format_int(val,width)); +} + +void titleformat_text_out::write_int(const GUID & p_inputtype,t_int64 val) +{ + write(p_inputtype,pfc::format_int(val)); +} +void titleformat_text_filter_impl_reserved_chars::write(const GUID & p_inputtype,pfc::string_receiver & p_out,const char * p_data,t_size p_data_length) +{ + if (p_inputtype == titleformat_inputtypes::meta) titleformat_compiler::remove_forbidden_chars_string_append(p_out,p_data,p_data_length,m_reserved_chars); + else p_out.add_string(p_data,p_data_length); +} + +void titleformat_compiler::run(titleformat_hook * p_source,pfc::string_base & p_out,const char * p_spec) +{ + service_ptr_t ptr; + if (!compile(ptr,p_spec)) p_out = "[COMPILATION ERROR]"; + else ptr->run(p_source,p_out,NULL); +} + +void titleformat_compiler::compile_safe(service_ptr_t & p_out,const char * p_spec) +{ + if (!compile(p_out,p_spec)) { + if (!compile(p_out,"%filename%")) + throw pfc::exception_bug_check_v2(); + } +} + + +namespace titleformat_inputtypes { + const GUID meta = { 0xcd839c8e, 0x5c66, 0x4ae1, { 0x8d, 0xad, 0x71, 0x1f, 0x86, 0x0, 0xa, 0xe3 } }; + const GUID unknown = { 0x673aa1cd, 0xa7a8, 0x40c8, { 0xbf, 0x9b, 0x34, 0x37, 0x99, 0x29, 0x16, 0x3b } }; +}; + +void titleformat_text_filter_impl_filename_chars::write(const GUID & p_inputType,pfc::string_receiver & p_out,const char * p_data,t_size p_dataLength) { + if (p_inputType == titleformat_inputtypes::meta) { + //slightly inefficient... + p_out.add_string( pfc::io::path::replaceIllegalNameChars(pfc::string(p_data,p_dataLength)).ptr()); + } else p_out.add_string(p_data,p_dataLength); +} + +void titleformat_compiler::compile_safe_ex(titleformat_object::ptr & p_out,const char * p_spec,const char * p_fallback) { + if (!compile(p_out,p_spec)) compile_force(p_out,p_fallback); +} + + +void titleformat_text_filter_nontext_chars::write(const GUID & p_inputtype,pfc::string_receiver & p_out,const char * p_data,t_size p_data_length) { + for(t_size walk = 0;;) { + t_size base = walk; + while(walk < p_data_length && !isReserved(p_data[walk]) && p_data[walk] != 0) walk++; + p_out.add_string(p_data+base,walk-base); + if (walk >= p_data_length || p_data[walk] == 0) break; + p_out.add_byte('_'); walk++; + } +} diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/titleformat.h b/tools/vio2sf/src/foobar/foobar2000/SDK/titleformat.h new file mode 100644 index 000000000..6ed9bce65 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/titleformat.h @@ -0,0 +1,227 @@ +namespace titleformat_inputtypes { + extern const GUID meta, unknown; +}; + +class NOVTABLE titleformat_text_out { +public: + virtual void write(const GUID & p_inputtype,const char * p_data,t_size p_data_length = infinite) = 0; + void write_int(const GUID & p_inputtype,t_int64 val); + void write_int_padded(const GUID & p_inputtype,t_int64 val,t_int64 maxval); +protected: + titleformat_text_out() {} + ~titleformat_text_out() {} +}; + + +class NOVTABLE titleformat_text_filter { +public: + virtual void write(const GUID & p_inputtype,pfc::string_receiver & p_out,const char * p_data,t_size p_data_length) = 0; +protected: + titleformat_text_filter() {} + ~titleformat_text_filter() {} +}; + +class NOVTABLE titleformat_hook_function_params +{ +public: + virtual t_size get_param_count() = 0; + virtual void get_param(t_size index,const char * & p_string,t_size & p_string_len) = 0;//warning: not a null-terminated string + + //helper + t_size get_param_uint(t_size index); +}; + +class NOVTABLE titleformat_hook +{ +public: + virtual bool process_field(titleformat_text_out * p_out,const char * p_name,t_size p_name_length,bool & p_found_flag) = 0; + virtual bool process_function(titleformat_text_out * p_out,const char * p_name,t_size p_name_length,titleformat_hook_function_params * p_params,bool & p_found_flag) = 0; +}; +//! Represents precompiled executable title-formatting script. Use titleformat_compiler to instantiate; do not reimplement. +class NOVTABLE titleformat_object : public service_base +{ +public: + virtual void run(titleformat_hook * p_source,pfc::string_base & p_out,titleformat_text_filter * p_filter)=0; + + void run_hook(const playable_location & p_location,const file_info * p_source,titleformat_hook * p_hook,pfc::string_base & p_out,titleformat_text_filter * p_filter); + void run_simple(const playable_location & p_location,const file_info * p_source,pfc::string_base & p_out); + + FB2K_MAKE_SERVICE_INTERFACE(titleformat_object,service_base); +}; + +//! Standard service for instantiating titleformat_object. Implemented by the core; do not reimplement. +//! To instantiate, use static_api_ptr_t. +class NOVTABLE titleformat_compiler : public service_base +{ +public: + //! Returns false in case of a compilation error. + virtual bool compile(titleformat_object::ptr & p_out,const char * p_spec) = 0; + //! Helper; + void run(titleformat_hook * p_source,pfc::string_base & p_out,const char * p_spec); + //! Should never fail, falls back to %filename% in case of failure. + void compile_safe(titleformat_object::ptr & p_out,const char * p_spec); + + //! Falls back to p_fallback in case of failure. + void compile_safe_ex(titleformat_object::ptr & p_out,const char * p_spec,const char * p_fallback = ""); + + //! Throws a bug check exception when script can't be compiled. For use with hardcoded scripts only. + void compile_force(titleformat_object::ptr & p_out,const char * p_spec) {if (!compile(p_out,p_spec)) throw pfc::exception_bug_check_v2();} + + + static void remove_color_marks(const char * src,pfc::string_base & out);//helper + static void remove_forbidden_chars(titleformat_text_out * p_out,const GUID & p_inputtype,const char * p_source,t_size p_source_len,const char * p_forbidden_chars); + static void remove_forbidden_chars_string_append(pfc::string_receiver & p_out,const char * p_source,t_size p_source_len,const char * p_forbidden_chars); + static void remove_forbidden_chars_string(pfc::string_base & p_out,const char * p_source,t_size p_source_len,const char * p_forbidden_chars); + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(titleformat_compiler); +}; + + +class titleformat_object_wrapper { +public: + titleformat_object_wrapper(const char * p_script) { + static_api_ptr_t()->compile_force(m_script,p_script); + } + + operator const service_ptr_t &() const {return m_script;} + +private: + service_ptr_t m_script; +}; + + +//helpers + + +class titleformat_text_out_impl_filter_chars : public titleformat_text_out +{ +public: + inline titleformat_text_out_impl_filter_chars(titleformat_text_out * p_chain,const char * p_restricted_chars) + : m_chain(p_chain), m_restricted_chars(p_restricted_chars) {} + void write(const GUID & p_inputtype,const char * p_data,t_size p_data_length); +private: + titleformat_text_out * m_chain; + const char * m_restricted_chars; +}; + +class titleformat_text_out_impl_string : public titleformat_text_out { +public: + titleformat_text_out_impl_string(pfc::string_receiver & p_string) : m_string(p_string) {} + void write(const GUID & p_inputtype,const char * p_data,t_size p_data_length) {m_string.add_string(p_data,p_data_length);} +private: + pfc::string_receiver & m_string; +}; + +class titleformat_common_methods : public service_base { +public: + virtual bool process_field(const file_info & p_info,const playable_location & p_location,titleformat_text_out * p_out,const char * p_name,t_size p_name_length,bool & p_found_flag) = 0; + virtual bool process_function(const file_info & p_info,const playable_location & p_location,titleformat_text_out * p_out,const char * p_name,t_size p_name_length,titleformat_hook_function_params * p_params,bool & p_found_flag) = 0; + virtual bool remap_meta(const file_info & p_info,t_size & p_index, const char * p_name, t_size p_name_length) = 0; + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(titleformat_common_methods); +}; + +class titleformat_hook_impl_file_info : public titleformat_hook +{ +public: + titleformat_hook_impl_file_info(const playable_location & p_location,const file_info * p_info) : m_location(p_location), m_info(p_info) {}//caller must ensure that referenced file_info object is alive as long as the titleformat_hook_impl_file_info instance + bool process_field(titleformat_text_out * p_out,const char * p_name,t_size p_name_length,bool & p_found_flag); + bool process_function(titleformat_text_out * p_out,const char * p_name,t_size p_name_length,titleformat_hook_function_params * p_params,bool & p_found_flag); +protected: + bool remap_meta(t_size & p_index, const char * p_name, t_size p_name_length) {return m_api->remap_meta(*m_info,p_index,p_name,p_name_length);} + const file_info * m_info; +private: + const playable_location & m_location; + static_api_ptr_t m_api; +}; + +class titleformat_hook_impl_splitter : public titleformat_hook { +public: + inline titleformat_hook_impl_splitter(titleformat_hook * p_hook1,titleformat_hook * p_hook2) : m_hook1(p_hook1), m_hook2(p_hook2) {} + bool process_field(titleformat_text_out * p_out,const char * p_name,t_size p_name_length,bool & p_found_flag); + bool process_function(titleformat_text_out * p_out,const char * p_name,t_size p_name_length,titleformat_hook_function_params * p_params,bool & p_found_flag); +private: + titleformat_hook * m_hook1, * m_hook2; +}; + +class titleformat_text_filter_impl_reserved_chars : public titleformat_text_filter { +public: + titleformat_text_filter_impl_reserved_chars(const char * p_reserved_chars) : m_reserved_chars(p_reserved_chars) {} + virtual void write(const GUID & p_inputtype,pfc::string_receiver & p_out,const char * p_data,t_size p_data_length); +private: + const char * m_reserved_chars; +}; + +class titleformat_text_filter_impl_filename_chars : public titleformat_text_filter { +public: + void write(const GUID & p_inputType,pfc::string_receiver & p_out,const char * p_data,t_size p_dataLength); +}; + +class titleformat_text_filter_nontext_chars : public titleformat_text_filter { +public: + inline static bool isReserved(char c) { return c >= 0 && c < 0x20; } + void write(const GUID & p_inputtype,pfc::string_receiver & p_out,const char * p_data,t_size p_data_length); +}; + + + + + + + +class titleformat_hook_impl_list : public titleformat_hook { +public: + titleformat_hook_impl_list(t_size p_index /* zero-based! */,t_size p_total) : m_index(p_index), m_total(p_total) {} + + bool process_field(titleformat_text_out * p_out,const char * p_name,t_size p_name_length,bool & p_found_flag) { + if ( + stricmp_utf8_ex(p_name,p_name_length,"list_index",infinite) == 0 + ) { + p_out->write_int_padded(titleformat_inputtypes::unknown,m_index+1, m_total); + p_found_flag = true; return true; + } else if ( + stricmp_utf8_ex(p_name,p_name_length,"list_total",infinite) == 0 + ) { + p_out->write_int(titleformat_inputtypes::unknown,m_total); + p_found_flag = true; return true; + } else { + p_found_flag = false; return false; + } + } + + bool process_function(titleformat_text_out * p_out,const char * p_name,t_size p_name_length,titleformat_hook_function_params * p_params,bool & p_found_flag) {return false;} + +private: + t_size m_index, m_total; +}; + +class string_formatter_tf : public pfc::string_base { +public: + string_formatter_tf(titleformat_text_out * out, const GUID & inputType = titleformat_inputtypes::meta) : m_out(out), m_inputType(inputType) {} + + const char * get_ptr() const { + throw pfc::exception_not_implemented(); + } + void add_string(const char * p_string,t_size p_length) { + m_out->write(m_inputType,p_string,p_length); + } + void set_string(const char * p_string,t_size p_length) { + throw pfc::exception_not_implemented(); + } + void truncate(t_size len) { + throw pfc::exception_not_implemented(); + } + t_size get_length() const { + throw pfc::exception_not_implemented(); + } + char * lock_buffer(t_size p_requested_length) { + throw pfc::exception_not_implemented(); + } + void unlock_buffer() { + throw pfc::exception_not_implemented(); + } + +private: + titleformat_text_out * const m_out; + const GUID m_inputType; +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/track_property.h b/tools/vio2sf/src/foobar/foobar2000/SDK/track_property.h new file mode 100644 index 000000000..3f8aa605d --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/track_property.h @@ -0,0 +1,45 @@ +//! Callback interface for track_property_provider::enumerate_properties(). +class NOVTABLE track_property_callback { +public: + //! Sets a property list entry to display. Called by track_property_provider::enumerate_properties() implementation. + //! @param p_group Name of group to put the entry in, case-sensitive. Note that non-standard groups are sorted alphabetically. + //! @param p_sortpriority Sort priority of the property inside its group (smaller value means earlier in the list), pass 0 if you don't care (alphabetic order by name used when more than one item has same priority). + //! @param p_name Name of the property. + //! @param p_value Value of the property. + virtual void set_property(const char * p_group,double p_sortpriority,const char * p_name,const char * p_value) = 0; +protected: + track_property_callback const & operator=(track_property_callback const &) {return *this;} + ~track_property_callback() {} +}; + +class NOVTABLE track_property_callback_v2 : public track_property_callback { +public: + virtual bool is_group_wanted(const char * p_group) = 0; +protected: + ~track_property_callback_v2() {} +}; + +//! Service for adding custom entries in "Properties" tab of the properties dialog. +class NOVTABLE track_property_provider : public service_base { +public: + //! Enumerates properties of specified track list. + //! @param p_tracks List of tracks to enumerate properties on. + //! @param p_out Callback interface receiving enumerated properties. + virtual void enumerate_properties(metadb_handle_list_cref p_tracks, track_property_callback & p_out) = 0; + //! Returns whether specified tech info filed is processed by our service and should not be displayed among unknown fields. + //! @param p_name Name of tech info field being queried. + //! @returns True if the field is among fields processed by this track_property_provider implementation and should not be displayed among unknown fields, false otherwise. + virtual bool is_our_tech_info(const char * p_name) = 0; + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(track_property_provider); +}; + +class NOVTABLE track_property_provider_v2 : public track_property_provider { +public: + virtual void enumerate_properties_v2(metadb_handle_list_cref p_tracks, track_property_callback_v2 & p_out) = 0; + + FB2K_MAKE_SERVICE_INTERFACE(track_property_provider_v2,track_property_provider) +}; + +template +class track_property_provider_factory_t : public service_factory_single_t {}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/ui.cpp b/tools/vio2sf/src/foobar/foobar2000/SDK/ui.cpp new file mode 100644 index 000000000..7417e65e5 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/ui.cpp @@ -0,0 +1,35 @@ +#include "foobar2000.h" + +bool ui_drop_item_callback::g_on_drop(interface IDataObject * pDataObject) +{ + service_enum_t e; + service_ptr_t ptr; + if (e.first(ptr)) do { + if (ptr->on_drop(pDataObject)) return true; + } while(e.next(ptr)); + return false; +} + +bool ui_drop_item_callback::g_is_accepted_type(interface IDataObject * pDataObject, DWORD * p_effect) +{ + service_enum_t e; + service_ptr_t ptr; + if (e.first(ptr)) do { + if (ptr->is_accepted_type(pDataObject,p_effect)) return true; + } while(e.next(ptr)); + return false; +} + +bool user_interface::g_find(service_ptr_t & p_out,const GUID & p_guid) +{ + service_enum_t e; + service_ptr_t ptr; + if (e.first(ptr)) do { + if (ptr->get_guid() == p_guid) + { + p_out = ptr; + return true; + } + } while(e.next(ptr)); + return false; +} diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/ui.h b/tools/vio2sf/src/foobar/foobar2000/SDK/ui.h new file mode 100644 index 000000000..079a63e68 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/ui.h @@ -0,0 +1,190 @@ +#ifndef _WINDOWS +#error PORTME +#endif + +//! Entrypoint service for user interface modules. Implement when registering an UI module. Do not call existing implementations; only core enumerates / dispatches calls. To control UI behaviors from other components, use ui_control API. \n +//! Use user_interface_factory_t<> to register, e.g static user_interface_factory_t g_myclass_factory; +class NOVTABLE user_interface : public service_base { +public: + //!HookProc usage: \n + //! in your windowproc, call HookProc first, and if it returns true, return LRESULT value it passed to you + typedef BOOL (WINAPI * HookProc_t)(HWND wnd,UINT msg,WPARAM wp,LPARAM lp,LRESULT * ret); + + //! Retrieves name (UTF-8 null-terminated string) of the UI module. + virtual const char * get_name()=0; + //! Initializes the UI module - creates the main app window, etc. Failure should be signaled by appropriate exception (std::exception or a derivative). + virtual HWND init(HookProc_t hook)=0; + //! Deinitializes the UI module - destroys the main app window, etc. + virtual void shutdown()=0; + //! Activates main app window. + virtual void activate()=0; + //! Minimizes/hides main app window. + virtual void hide()=0; + //! Returns whether main window is visible / not minimized. Used for activate/hide command. + virtual bool is_visible() = 0; + //! Retrieves GUID of your implementation, to be stored in configuration file etc. + virtual GUID get_guid() = 0; + + //! Overrides statusbar text with specified string. The parameter is a null terminated UTF-8 string. The override is valid until another override_statusbar_text() call or revert_statusbar_text() call. + virtual void override_statusbar_text(const char * p_text) = 0; + //! Disables statusbar text override. + virtual void revert_statusbar_text() = 0; + + //! Shows now-playing item somehow (e.g. system notification area popup). + virtual void show_now_playing() = 0; + + static bool g_find(service_ptr_t & p_out,const GUID & p_guid); + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(user_interface); +}; + +template +class user_interface_factory : public service_factory_single_t {}; + +//! Interface class allowing you to override UI statusbar text. There may be multiple callers trying to override statusbar text; backend decides which one succeeds so you will not always get what you want. Statusbar text override is automatically cancelled when the object is released.\n +//! Use ui_control::override_status_text_create() to instantiate. +//! Implemented by core. Do not reimplement. +class NOVTABLE ui_status_text_override : public service_base +{ +public: + //! Sets statusbar text to specified UTF-8 null-terminated string. + virtual void override_text(const char * p_message) = 0; + //! Cancels statusbar text override. + virtual void revert_text() = 0; + + FB2K_MAKE_SERVICE_INTERFACE(ui_status_text_override,service_base); +}; + +//! Serivce providing various UI-related commands. Implemented by core; do not reimplement. +//! Instantiation: use static_api_ptr_t. +class NOVTABLE ui_control : public service_base { +public: + //! Returns whether primary UI is visible/unminimized. + virtual bool is_visible()=0; + //! Activates/unminimizes main UI. + virtual void activate()=0; + //! Hides/minimizese main UI. + virtual void hide()=0; + //! Retrieves main GUI icon, to use as window icon etc. Returned handle does not need to be freed. + virtual HICON get_main_icon()=0; + //! Loads main GUI icon, version with specified width/height. Returned handle needs to be freed with DestroyIcon when you are done using it. + virtual HICON load_main_icon(unsigned width,unsigned height) = 0; + + //! Activates preferences dialog and navigates to specified page. See also: preference_page API. + virtual void show_preferences(const GUID & p_page) = 0; + + //! Instantiates ui_status_text_override service, that can be used to display status messages. + //! @param p_out receives new ui_status_text_override instance. + //! @returns true on success, false on failure (out of memory / no GUI loaded / etc) + virtual bool override_status_text_create(service_ptr_t & p_out) = 0; + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(ui_control); +}; + +//! Service called from the UI when some object is dropped into the UI. Usable for modifying drag&drop behaviors such as adding custom handlers for object types other than supported media files.\n +//! Implement where needed; use ui_drop_item_callback_factory_t<> template to register, e.g. static ui_drop_item_callback_factory_t g_myclass_factory. +class NOVTABLE ui_drop_item_callback : public service_base { +public: + //! Called when an object was dropped; returns true if the object was processed and false if not. + virtual bool on_drop(interface IDataObject * pDataObject) = 0; + //! Tests whether specified object type is supported by this ui_drop_item_callback implementation. Returns true and sets p_effect when it's supported; returns false otherwise. \n + //! See IDropTarget::DragEnter() documentation for more information about p_effect values. + virtual bool is_accepted_type(interface IDataObject * pDataObject, DWORD * p_effect)=0; + + //! Static helper, calls all existing implementations appropriately. See on_drop(). + static bool g_on_drop(interface IDataObject * pDataObject); + //! Static helper, calls all existing implementations appropriately. See is_accepted_type(). + static bool g_is_accepted_type(interface IDataObject * pDataObject, DWORD * p_effect); + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(ui_drop_item_callback); +}; + +template +class ui_drop_item_callback_factory_t : public service_factory_single_t {}; + + +class ui_selection_callback; + +//! Write interface and reference counter for the shared selection. +//! The ui_selection_manager stores the selected items as a list. +//! The ui_selection_holder service allows components to modify this list. +//! It also serves as a reference count: the ui_selection_manager clears the stored +//! selection when no component holds a reference to a ui_selection_holder. +//! +//! When a window that uses the shared selection gets the focus, it should acquire +//! a ui_selection_holder from the ui_selection_manager. If it contains selectable items, +//! it should use the appropriate method to store its selected items as the shared selection. +//! If it just wants to preserve the selection - for example so it can display it - it should +//! merely store the acquired ui_selection_holder. +//! +//! When the window loses the focus, it should release its ui_selection_holder. +//! It should not use a set method to clear the selection +class NOVTABLE ui_selection_holder : public service_base { +public: + //! Sets selected items. + virtual void set_selection(metadb_handle_list_cref data) = 0; + //! Sets selected items to playlist selection and enables tracking. + //! When the playlist selection changes, the stored selection is automatically updated. + //! Tracking ends when a set method is called on any ui_selection_holder or when + //! the last reference to this ui_selection_holder is released. + virtual void set_playlist_selection_tracking() = 0; + //! Sets selected items to the contents of the active playlist and enables tracking. + //! When the active playlist or its contents changes, the stored selection is automatically updated. + //! Tracking ends when a set method is called on any ui_selection_holder or when + //! the last reference to this ui_selection_holder is released. + virtual void set_playlist_tracking() = 0; + + //! Sets selected items and type of selection holder. + //! @param type Specifies type of selection. Values same as contextmenu_item caller IDs. + virtual void set_selection_ex(metadb_handle_list_cref data, const GUID & type) = 0; + + FB2K_MAKE_SERVICE_INTERFACE(ui_selection_holder,service_base); +}; + +class NOVTABLE ui_selection_manager : public service_base { +public: + //! Retrieves current selection. + virtual void get_selection(pfc::list_base_t & p_selection) = 0; + //! Registers a callback. It is recommended to use ui_selection_callback_impl_base class instead of calling this directly. + virtual void register_callback(ui_selection_callback * p_callback) = 0; + //! Unregisters a callback. It is recommended to use ui_selection_callback_impl_base class instead of calling this directly. + virtual void unregister_callback(ui_selection_callback * p_callback) = 0; + + virtual ui_selection_holder::ptr acquire() = 0; + + //! Retrieves type of the active selection holder. Values same as contextmenu_item caller IDs. + virtual GUID get_selection_type() = 0; + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(ui_selection_manager); +}; + +class ui_selection_callback { +public: + virtual void on_selection_changed(const pfc::list_base_const_t & p_selection) = 0; +protected: + ui_selection_callback() {} + ~ui_selection_callback() {} +}; + +//! ui_selection_callback implementation helper with autoregistration - do not instantiate statically +class ui_selection_callback_impl_base : public ui_selection_callback { +protected: + ui_selection_callback_impl_base(bool activate = true) : m_active() {ui_selection_callback_activate(activate);} + ~ui_selection_callback_impl_base() {ui_selection_callback_activate(false);} + + void ui_selection_callback_activate(bool state = true) { + if (state != m_active) { + m_active = state; + static_api_ptr_t api; + if (state) api->register_callback(this); + else api->unregister_callback(this); + } + } + + //avoid pure virtual function calls in rare cases - provide a dummy implementation + void on_selection_changed(const pfc::list_base_const_t & p_selection) {} + + PFC_CLASS_NOT_COPYABLE_EX(ui_selection_callback_impl_base); +private: + bool m_active; +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/unpack.h b/tools/vio2sf/src/foobar/foobar2000/SDK/unpack.h new file mode 100644 index 000000000..7e2be58cb --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/unpack.h @@ -0,0 +1,22 @@ +//! Service providing "unpacker" functionality - processes "packed" file (such as a zip file containing a single media file inside) to allow its contents to be accessed transparently.\n +//! To access existing unpacker implementations, use unpacker::g_open helper function.\n +//! To register your own implementation, use unpacker_factory_t template. +class NOVTABLE unpacker : public service_base { +public: + //! Attempts to open specified file for unpacking, creates interface to virtual file with uncompressed data on success. When examined file doesn't appear to be one of formats supported by this unpacker implementation, throws exception_io_data. + //! @param p_out Receives interface to virtual file with uncompressed data on success. + //! @param p_source Source file to process. + //! @param p_abort abort_callback object signaling user aborting the operation. + virtual void open(service_ptr_t & p_out,const service_ptr_t & p_source,abort_callback & p_abort) = 0; + + //! Static helper querying existing unpacker implementations until one that successfully opens specified file is found. Attempts to open specified file for unpacking, creates interface to virtual file with uncompressed data on success. When examined file doesn't appear to be one of formats supported by registered unpacker implementations, throws exception_io_data. + //! @param p_out Receives interface to virtual file with uncompressed data on success. + //! @param p_source Source file to process. + //! @param p_abort abort_callback object signaling user aborting the operation. + static void g_open(service_ptr_t & p_out,const service_ptr_t & p_source,abort_callback & p_abort); + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(unpacker); +}; + +template +class unpacker_factory_t : public service_factory_single_t {}; diff --git a/tools/vio2sf/src/foobar/foobar2000/SDK/vis.h b/tools/vio2sf/src/foobar/foobar2000/SDK/vis.h new file mode 100644 index 000000000..803311386 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/SDK/vis.h @@ -0,0 +1,78 @@ +//! This class provides abstraction for retrieving visualisation data. Instances of visualisation_stream being created/released serve as an indication for visualisation backend to process currently played audio data or shut down when there are no visualisation clients active.\n +//! Use visualisation_manager::create_stream to instantiate. +class NOVTABLE visualisation_stream : public service_base { +public: + //! Retrieves absolute playback time since last playback start or seek. You typically pass value retrieved by this function - optionally with offset added - to other visualisation_stream methods. + virtual bool get_absolute_time(double & p_value) = 0; + + //! Retrieves an audio chunk starting at specified offset (see get_absolute_time()), of specified length. + //! @returns False when requested timestamp is out of available range, true on success. + virtual bool get_chunk_absolute(audio_chunk & p_chunk,double p_offset,double p_requested_length) = 0; + //! Retrieves spectrum for audio data at specified offset (see get_absolute_time()), with specified FFT size. + //! @param p_chunk Receives spectrum data. audio_chunk type is used for consistency (since required functionality is identical to provided by audio_chunk), the data is *not* PCM. Returned sample count is equal to half of FFT size; channels and sample rate are as in audio stream the spectrum was generated from. + //! @param p_offset Timestamp of spectrum to retrieve. See get_absolute_time(). + //! @param p_fft_size FFT size to use for spectrum generation. Must be a power of 2. + //! @returns False when requested timestamp is out of available range, true on success. + virtual bool get_spectrum_absolute(audio_chunk & p_chunk,double p_offset,unsigned p_fft_size) = 0; + + //! Generates fake audio chunk to display when get_chunk_absolute() fails - e.g. shortly after visualisation_stream creation data for currently played audio might not be available yet. + //! Throws std::exception derivatives on failure. + virtual void make_fake_chunk_absolute(audio_chunk & p_chunk,double p_offset,double p_requested_length) = 0; + //! Generates fake spectrum to display when get_spectrum_absolute() fails - e.g. shortly after visualisation_stream creation data for currently played audio might not be available yet. + //! Throws std::exception derivatives on failure. + virtual void make_fake_spectrum_absolute(audio_chunk & p_chunk,double p_offset,unsigned p_fft_size) = 0; + + FB2K_MAKE_SERVICE_INTERFACE(visualisation_stream,service_base); +}; + +//! New in 0.9.5. +class NOVTABLE visualisation_stream_v2 : public visualisation_stream { +public: + virtual void request_backlog(double p_time) = 0; + virtual void set_channel_mode(t_uint32 p_mode) = 0; + + enum { + channel_mode_default = 0, + channel_mode_mono, + channel_mode_frontonly, + channel_mode_backonly, + }; + + FB2K_MAKE_SERVICE_INTERFACE(visualisation_stream_v2,visualisation_stream); +}; + +//! New in 0.9.5.2. +class NOVTABLE visualisation_stream_v3 : public visualisation_stream_v2 { +public: + virtual void chunk_to_spectrum(audio_chunk const & chunk, audio_chunk & spectrum, double centerOffset) = 0; + + FB2K_MAKE_SERVICE_INTERFACE(visualisation_stream_v3,visualisation_stream_v2); +}; + +//! Entrypoint service for visualisation processing; use this to create visualisation_stream objects that can be used to retrieve properties of currently played audio. \n +//! Implemented by core; do not reimplement.\n +//! Use static_api_ptr_t to access it, e.g. static_api_ptr_t()->create_stream(mystream,0); +class NOVTABLE visualisation_manager : public service_base { +public: + //! Creates a visualisation_stream object. See visualisation_stream for more info. + //! @param p_out Receives newly created visualisation_stream instance. + //! @param p_flags Combination of one or more KStreamFlag* values. Currently only KStreamFlagNewFFT is defined. + //! It's recommended that you set p_flags to KStreamFlagNewFFT to get the new FFT behavior (better quality and result normalization), the old behavior for null flags is preserved for compatibility with old components that rely on it. + virtual void create_stream(service_ptr_t & p_out,unsigned p_flags) = 0; + + enum { + //! New FFT behavior for spectrum-generating methods, available in 0.9.5.2 and newer: output normalized to 0..1, Gauss window used instead of rectangluar (better quality / less aliasing). + //! It's recommended to always set this flag. The old behavior is preserved for backwards compatibility. + KStreamFlagNewFFT = 1 << 0, + }; + + + //! Wrapper around non-template create_stream(); retrieves one of newer visualisation_stream_* interfaces rather than base visualisation_stream interface. Throws exception_service_extension_not_found() when running too old foobar2000 version for the requested interface. + template + void create_stream(t_streamptr & out, unsigned flags) { + visualisation_stream::ptr temp; create_stream(temp, flags); + if (!temp->service_query_t(out)) throw exception_service_extension_not_found(); + } + + FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(visualisation_manager); +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/foobar2000_component_client/component_client.cpp b/tools/vio2sf/src/foobar/foobar2000/foobar2000_component_client/component_client.cpp new file mode 100644 index 000000000..1b1c919da --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/foobar2000_component_client/component_client.cpp @@ -0,0 +1,132 @@ +#include "../SDK/foobar2000.h" +#include "../SDK/component.h" + +static HINSTANCE g_hIns; + +static pfc::string_simple g_name,g_full_path; + +static bool g_services_available = false, g_initialized = false; + + + +namespace core_api +{ + + HINSTANCE get_my_instance() + { + return g_hIns; + } + + HWND get_main_window() + { + return g_api->get_main_window(); + } + pcchar get_my_file_name() + { + return g_name; + } + + pcchar get_my_full_path() + { + return g_full_path; + } + + bool are_services_available() + { + return g_services_available; + } + bool assert_main_thread() + { + return (g_services_available && g_api) ? g_api->assert_main_thread() : true; + } + + void ensure_main_thread() { + if (!assert_main_thread()) throw exception_wrong_thread(); + } + + bool is_main_thread() + { + return (g_services_available && g_api) ? g_api->is_main_thread() : true; + } + pcchar get_profile_path() + { + return (g_services_available && g_api) ? g_api->get_profile_path() : 0; + } + + bool is_shutting_down() + { + return (g_services_available && g_api) ? g_api->is_shutting_down() : g_initialized; + } + bool is_initializing() + { + return (g_services_available && g_api) ? g_api->is_initializing() : !g_initialized; + } +} + +namespace { + class foobar2000_client_impl : public foobar2000_client + { + public: + t_uint32 get_version() {return FOOBAR2000_CLIENT_VERSION;} + pservice_factory_base get_service_list() {return service_factory_base::__internal__list;} + + void get_config(stream_writer * p_stream,abort_callback & p_abort) { + cfg_var::config_write_file(p_stream,p_abort); + } + + void set_config(stream_reader * p_stream,abort_callback & p_abort) { + cfg_var::config_read_file(p_stream,p_abort); + } + + void set_library_path(const char * path,const char * name) { + g_full_path = path; + g_name = name; + } + + void services_init(bool val) { + if (val) g_initialized = true; + g_services_available = val; + } + + bool is_debug() { +#ifdef _DEBUG + return true; +#else + return false; +#endif + } + }; +} + +static foobar2000_client_impl g_client; + +extern "C" +{ + __declspec(dllexport) foobar2000_client * _cdecl foobar2000_get_interface(foobar2000_api * p_api,HINSTANCE hIns) + { + g_hIns = hIns; + g_api = p_api; + + return &g_client; + } +} + +#if 0 +BOOLEAN WINAPI DllMain(IN HINSTANCE hDllHandle, IN DWORD nReason, IN LPVOID Reserved ) +{ + BOOLEAN bSuccess = TRUE; + + switch ( nReason ) { + case DLL_PROCESS_ATTACH: + + DisableThreadLibraryCalls( hDllHandle ); + + break; + + case DLL_PROCESS_DETACH: + + break; + } + return TRUE; +} +#endif \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/foobar2000_component_client/foobar2000_component_client.vcproj b/tools/vio2sf/src/foobar/foobar2000/foobar2000_component_client/foobar2000_component_client.vcproj new file mode 100644 index 000000000..c5ccc4a16 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/foobar2000_component_client/foobar2000_component_client.vcproj @@ -0,0 +1,334 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/COM_utils.h b/tools/vio2sf/src/foobar/foobar2000/helpers/COM_utils.h new file mode 100644 index 000000000..b0704c6b4 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/COM_utils.h @@ -0,0 +1,7 @@ +#define FB2K_COM_CATCH catch(exception_com const & e) {return e.get_code();} catch(std::bad_alloc) {return E_OUTOFMEMORY;} catch(pfc::exception_invalid_params) {return E_INVALIDARG;} catch(...) {return E_UNEXPECTED;} + +#define COM_QI_BEGIN() HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid,void ** ppvObject) { if (ppvObject == NULL) return E_INVALIDARG; +#define COM_QI_ENTRY(IWhat) { if (iid == IID_##IWhat) {IWhat * temp = this; temp->AddRef(); * ppvObject = temp; return S_OK;} } +#define COM_QI_END() return E_NOINTERFACE; } + +#define COM_QI_CHAIN(Parent) { HRESULT status = Parent::QueryInterface(iid, ppvObject); if (SUCCEEDED(status)) return status; } diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/CallForwarder.h b/tools/vio2sf/src/foobar/foobar2000/helpers/CallForwarder.h new file mode 100644 index 000000000..53608d6c1 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/CallForwarder.h @@ -0,0 +1,32 @@ +namespace CF { + template class CallForwarder { + public: + CallForwarder(TWhat * ptr) { m_ptr.new_t(ptr); } + + void Orphan() {*m_ptr = NULL;} + bool IsValid() const { return *m_ptr != NULL; } + bool IsEmpty() const { return !IsValid(); } + + TWhat * operator->() const { + PFC_ASSERT( IsValid() ); + return *m_ptr; + } + + TWhat & operator*() const { + PFC_ASSERT( IsValid() ); + return **m_ptr; + } + + private: + pfc::rcptr_t m_ptr; + }; + + template class CallForwarderMaster : public CallForwarder { + public: + CallForwarderMaster(TWhat * ptr) : CallForwarder(ptr) {} + ~CallForwarderMaster() { Orphan(); } + + PFC_CLASS_NOT_COPYABLE(CallForwarderMaster, CallForwarderMaster); + }; + +} \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/IDataObjectUtils.cpp b/tools/vio2sf/src/foobar/foobar2000/helpers/IDataObjectUtils.cpp new file mode 100644 index 000000000..ed0bff6a7 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/IDataObjectUtils.cpp @@ -0,0 +1,183 @@ +#include "stdafx.h" + + +HRESULT IDataObjectUtils::DataBlockToSTGMEDIUM(const void * blockPtr, t_size blockSize, STGMEDIUM * medium, DWORD tymed, bool bHere) throw() { + try { + if (bHere) { + switch(tymed) { + case TYMED_ISTREAM: + { + if (medium->pstm == NULL) return E_INVALIDARG; + ULONG written = 0; + HRESULT state; + state = medium->pstm->Write(blockPtr, pfc::downcast_guarded(blockSize),&written); + if (FAILED(state)) return state; + if (written != blockSize) return STG_E_MEDIUMFULL; + return S_OK; + } + default: + return DV_E_TYMED; + } + } else { + if (tymed & TYMED_HGLOBAL) { + HGLOBAL hMem = HGlobalFromMemblock(blockPtr, blockSize); + if (hMem == NULL) return E_OUTOFMEMORY; + medium->tymed = TYMED_HGLOBAL; + medium->hGlobal = hMem; + medium->pUnkForRelease = NULL; + return S_OK; + } + if (tymed & TYMED_ISTREAM) { + HRESULT state; + HGLOBAL hMem = HGlobalFromMemblock(blockPtr, blockSize); + if (hMem == NULL) return E_OUTOFMEMORY; + medium->tymed = TYMED_ISTREAM; + pfc::com_ptr_t stream; + if (FAILED( state = CreateStreamOnHGlobal(hMem,TRUE,stream.receive_ptr()) ) ) { + GlobalFree(hMem); + return state; + } + { + LARGE_INTEGER wtf = {}; + if (FAILED( state = stream->Seek(wtf,STREAM_SEEK_END,NULL) ) ) { + return state; + } + } + medium->pstm = stream.get_ptr(); + medium->pUnkForRelease = stream.detach(); + return S_OK; + } + return DV_E_TYMED; + } + } catch(pfc::exception_not_implemented) { + return E_NOTIMPL; + } catch(std::bad_alloc) { + return E_OUTOFMEMORY; + } catch(...) { + return E_UNEXPECTED; + } +} + + +HGLOBAL IDataObjectUtils::HGlobalFromMemblock(const void * ptr,t_size size) { + HGLOBAL handle = GlobalAlloc(GMEM_MOVEABLE,size); + if (handle != NULL) { + void * destptr = GlobalLock(handle); + if (destptr == NULL) { + GlobalFree(handle); + handle = NULL; + } else { + memcpy(destptr,ptr,size); + GlobalUnlock(handle); + } + } + return handle; +} + +HRESULT IDataObjectUtils::ExtractDataObjectContent(pfc::com_ptr_t obj, UINT format, DWORD aspect, LONG index, pfc::array_t & out) { + FORMATETC fmt = {}; + fmt.cfFormat = format; fmt.dwAspect = aspect; fmt.lindex = index; + fmt.tymed = TYMED_HGLOBAL | TYMED_ISTREAM; + + STGMEDIUM med = {}; + HRESULT state; + if (FAILED( state = obj->GetData(&fmt,&med) ) ) return state; + ReleaseStgMediumScope relScope(&med); + return STGMEDIUMToDataBlock(med, out); +} + +HRESULT IDataObjectUtils::STGMEDIUMToDataBlock(const STGMEDIUM & med, pfc::array_t & out) { + switch(med.tymed) { + case TYMED_HGLOBAL: + { + CGlobalLockScope lock(med.hGlobal); + out.set_data_fromptr( (const t_uint8*) lock.GetPtr(), lock.GetSize() ); + } + return S_OK; + case TYMED_ISTREAM: + { + HRESULT state; + IStream * stream = med.pstm; + LARGE_INTEGER offset = {}; + STATSTG stats = {}; + if (FAILED( state = stream->Stat(&stats,STATFLAG_NONAME ) ) ) return state; + t_size toRead = pfc::downcast_guarded(stats.cbSize.QuadPart); + out.set_size(toRead); + if (FAILED( state = stream->Seek(offset,STREAM_SEEK_SET,NULL) ) ) return state; + ULONG cbRead = 0; + if (FAILED( state = stream->Read(out.get_ptr(), pfc::downcast_guarded(toRead), &cbRead) ) ) return state; + if (cbRead != toRead) return E_UNEXPECTED; + } + return S_OK; + default: + return DV_E_TYMED; + } +} + +HRESULT IDataObjectUtils::ExtractDataObjectContent(pfc::com_ptr_t obj, UINT format, pfc::array_t & out) { + return ExtractDataObjectContent(obj, format, DVASPECT_CONTENT, -1, out); +} + +HRESULT IDataObjectUtils::ExtractDataObjectContentTest(pfc::com_ptr_t obj, UINT format, DWORD aspect, LONG index) { + FORMATETC fmt = {}; + fmt.cfFormat = format; fmt.dwAspect = aspect; fmt.lindex = index; + for(t_uint32 walk = 0; walk < 32; ++walk) { + const DWORD tymed = 1 << walk; + if ((ExtractDataObjectContent_SupportedTymeds & tymed) != 0) { + fmt.tymed = tymed; + HRESULT state = obj->QueryGetData(&fmt); + if (SUCCEEDED(state)) return S_OK; + if (state != DV_E_TYMED) return state; + } + } + return E_FAIL; +} + +HRESULT IDataObjectUtils::ExtractDataObjectContentTest(pfc::com_ptr_t obj, UINT format) { + return ExtractDataObjectContentTest(obj,format,DVASPECT_CONTENT,-1); +} + +HRESULT IDataObjectUtils::ExtractDataObjectString(pfc::com_ptr_t obj, pfc::string_base & out) { + pfc::array_t data; + HRESULT state; + state = ExtractDataObjectContent(obj,CF_UNICODETEXT,data); + if (SUCCEEDED(state)) { + out = pfc::stringcvt::string_utf8_from_os_ex( (const wchar_t*) data.get_ptr(), data.get_size() / sizeof(wchar_t) ); + return S_OK; + } + state = ExtractDataObjectContent(obj,CF_TEXT,data); + if (SUCCEEDED(state)) { + out = pfc::stringcvt::string_utf8_from_os_ex( (const char*) data.get_ptr(), data.get_size() / sizeof(char) ); + return S_OK; + } + return E_FAIL; +} + +HRESULT IDataObjectUtils::SetDataObjectContent(pfc::com_ptr_t obj, UINT format, DWORD aspect, LONG index, const void * data, t_size dataSize) { + STGMEDIUM med = {}; + FORMATETC fmt = {}; + fmt.cfFormat = format; fmt.dwAspect = aspect; fmt.lindex = index; fmt.tymed = TYMED_HGLOBAL; + HRESULT state; + if (FAILED(state = DataBlockToSTGMEDIUM(data,dataSize,&med,TYMED_HGLOBAL,false))) return state; + return obj->SetData(&fmt,&med,TRUE); +} + +HRESULT IDataObjectUtils::SetDataObjectString(pfc::com_ptr_t obj, const char * str) { + pfc::stringcvt::string_wide_from_utf8 s(str); + return SetDataObjectContent(obj,CF_UNICODETEXT,DVASPECT_CONTENT,-1,s.get_ptr(), (s.length()+1) * sizeof(s[0])); +} + +HRESULT IDataObjectUtils::ExtractDataObjectDWORD(pfc::com_ptr_t obj, UINT format, DWORD & val) { + HRESULT state; + pfc::array_t buffer; + if (FAILED( state = ExtractDataObjectContent(obj, format, DVASPECT_CONTENT, -1, buffer) ) ) return state; + if (buffer.get_size() < sizeof(val)) return E_UNEXPECTED; + val = *(DWORD*) buffer.get_ptr(); + return S_OK; +} +HRESULT IDataObjectUtils::SetDataObjectDWORD(pfc::com_ptr_t obj, UINT format, DWORD val) { + return SetDataObjectContent(obj,format,DVASPECT_CONTENT,-1,&val,sizeof(val)); +} +HRESULT IDataObjectUtils::PasteSucceeded(pfc::com_ptr_t obj, DWORD effect) { + return SetDataObjectDWORD(obj, RegisterClipboardFormat(CFSTR_PASTESUCCEEDED), effect); +} diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/IDataObjectUtils.h b/tools/vio2sf/src/foobar/foobar2000/helpers/IDataObjectUtils.h new file mode 100644 index 000000000..fb69d9957 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/IDataObjectUtils.h @@ -0,0 +1,183 @@ +#include + +namespace IDataObjectUtils { + + class ReleaseStgMediumScope { + public: + ReleaseStgMediumScope(STGMEDIUM * medium) : m_medium(medium) {} + ~ReleaseStgMediumScope() {if (m_medium != NULL) ReleaseStgMedium(m_medium);} + private: + STGMEDIUM * m_medium; + + PFC_CLASS_NOT_COPYABLE_EX(ReleaseStgMediumScope) + }; + + static const DWORD DataBlockToSTGMEDIUM_SupportedTymeds = TYMED_ISTREAM | TYMED_HGLOBAL; + static const DWORD ExtractDataObjectContent_SupportedTymeds = TYMED_ISTREAM | TYMED_HGLOBAL; + + HRESULT DataBlockToSTGMEDIUM(const void * blockPtr, t_size blockSize, STGMEDIUM * medium, DWORD tymed, bool bHere) throw(); + + HGLOBAL HGlobalFromMemblock(const void * ptr,t_size size); + + HRESULT ExtractDataObjectContent(pfc::com_ptr_t obj, UINT format, DWORD aspect, LONG index, pfc::array_t & out); + HRESULT ExtractDataObjectContent(pfc::com_ptr_t obj, UINT format, pfc::array_t & out); + + HRESULT ExtractDataObjectContentTest(pfc::com_ptr_t obj, UINT format, DWORD aspect, LONG index); + HRESULT ExtractDataObjectContentTest(pfc::com_ptr_t obj, UINT format); + + HRESULT ExtractDataObjectString(pfc::com_ptr_t obj, pfc::string_base & out); + HRESULT SetDataObjectString(pfc::com_ptr_t obj, const char * str); + + HRESULT SetDataObjectContent(pfc::com_ptr_t obj, UINT format, DWORD aspect, LONG index, const void * data, t_size dataSize); + + HRESULT STGMEDIUMToDataBlock(const STGMEDIUM & med, pfc::array_t & out); + + HRESULT ExtractDataObjectDWORD(pfc::com_ptr_t obj, UINT format, DWORD & val); + HRESULT SetDataObjectDWORD(pfc::com_ptr_t obj, UINT format, DWORD val); + + HRESULT PasteSucceeded(pfc::com_ptr_t obj, DWORD effect); + + class comparator_FORMATETC { + public: + static int compare(const FORMATETC & v1, const FORMATETC & v2) { + int val; + val = pfc::compare_t(v1.cfFormat,v2.cfFormat); if (val != 0) return val; + val = pfc::compare_t(v1.dwAspect,v2.dwAspect); if (val != 0) return val; + val = pfc::compare_t(v1.lindex, v2.lindex ); if (val != 0) return val; + return 0; + } + }; + + class CDataObjectBase : public IDataObject { + public: + COM_QI_BEGIN() + COM_QI_ENTRY(IUnknown) + COM_QI_ENTRY(IDataObject) + COM_QI_END() + + HRESULT STDMETHODCALLTYPE GetData(FORMATETC * formatetc, STGMEDIUM * medium) { + return GetData_internal(formatetc,medium,false); + } + + HRESULT STDMETHODCALLTYPE GetDataHere(FORMATETC * formatetc, STGMEDIUM * medium) { + return GetData_internal(formatetc,medium,true); + } + + HRESULT STDMETHODCALLTYPE QueryGetData(FORMATETC * formatetc) { + if (formatetc == NULL) return E_INVALIDARG; + + if ((DataBlockToSTGMEDIUM_SupportedTymeds & formatetc->tymed) == 0) return DV_E_TYMED; + + try { + return RenderDataTest(formatetc->cfFormat,formatetc->dwAspect,formatetc->lindex); + } FB2K_COM_CATCH; + } + + + HRESULT STDMETHODCALLTYPE GetCanonicalFormatEtc(FORMATETC * in, FORMATETC * out) { + //check this again + if (in == NULL || out == NULL) + return E_INVALIDARG; + *out = *in; + return DATA_S_SAMEFORMATETC; + } + + HRESULT STDMETHODCALLTYPE EnumFormatEtc(DWORD dwDirection,IEnumFORMATETC ** ppenumFormatetc) { + if (dwDirection == DATADIR_GET) { + if (ppenumFormatetc == NULL) return E_INVALIDARG; + return CreateIEnumFORMATETC(ppenumFormatetc); + } else if (dwDirection == DATADIR_SET) { + return E_NOTIMPL; + } else { + return E_INVALIDARG; + } + } + + HRESULT STDMETHODCALLTYPE SetData(FORMATETC * pFormatetc, STGMEDIUM * pmedium, BOOL fRelease) { + try { + ReleaseStgMediumScope relScope(fRelease ? pmedium : NULL); + if (pFormatetc == NULL || pmedium == NULL) return E_INVALIDARG; + + /*TCHAR buf[256]; + if (GetClipboardFormatName(pFormatetc->cfFormat,buf,tabsize(buf)) > 0) { + buf[tabsize(buf)-1] = 0; + OutputDebugString(TEXT("SetData: ")); OutputDebugString(buf); OutputDebugString(TEXT("\n")); + } else { + OutputDebugString(TEXT("SetData: unknown clipboard format.\n")); + }*/ + + pfc::array_t temp; + HRESULT state = STGMEDIUMToDataBlock(*pmedium,temp); + if (FAILED(state)) return state; + m_entries.set(*pFormatetc,temp); + return S_OK; + } FB2K_COM_CATCH; + } + HRESULT STDMETHODCALLTYPE DAdvise(FORMATETC * pFormatetc, DWORD advf, IAdviseSink * pAdvSink, DWORD * pdwConnection) {return OLE_E_ADVISENOTSUPPORTED;} + HRESULT STDMETHODCALLTYPE DUnadvise(DWORD dwConnection) {return OLE_E_ADVISENOTSUPPORTED;} + HRESULT STDMETHODCALLTYPE EnumDAdvise(IEnumSTATDATA ** ppenumAdvise) {return OLE_E_ADVISENOTSUPPORTED;} + protected: + virtual HRESULT RenderData(UINT format,DWORD aspect,LONG dataIndex,stream_writer_formatter<> & out) const { + FORMATETC fmt = {}; + fmt.cfFormat = format; fmt.dwAspect = aspect; fmt.lindex = dataIndex; + const pfc::array_t * entry = m_entries.query_ptr(fmt); + if (entry != NULL) { + out.write_raw(entry->get_ptr(), entry->get_size()); + return S_OK; + } + return DV_E_FORMATETC; + } + virtual HRESULT RenderDataTest(UINT format,DWORD aspect, LONG dataIndex) const { + FORMATETC fmt = {}; + fmt.cfFormat = format; fmt.dwAspect = aspect; fmt.lindex = dataIndex; + if (m_entries.have_item(fmt)) return S_OK; + return DV_E_FORMATETC; + } + typedef pfc::list_base_t TFormatList; + + static void AddFormat(TFormatList & out,UINT code) { + FORMATETC fmt = {}; + fmt.dwAspect = DVASPECT_CONTENT; + fmt.lindex = -1; + fmt.cfFormat = code; + for(t_size medWalk = 0; medWalk < 32; ++medWalk) { + const DWORD med = 1 << medWalk; + if ((DataBlockToSTGMEDIUM_SupportedTymeds & med) != 0) { + fmt.tymed = med; + out.add_item(fmt); + } + } + } + + virtual void EnumFormats(TFormatList & out) const { + pfc::avltree_t formats; + for(t_entries::const_iterator walk = m_entries.first(); walk.is_valid(); ++walk) { + formats.add_item( walk->m_key.cfFormat ); + } + for(pfc::const_iterator walk = formats.first(); walk.is_valid(); ++walk) { + AddFormat(out, *walk); + } + } + HRESULT CreateIEnumFORMATETC(IEnumFORMATETC ** outptr) const throw() { + try { + pfc::list_t out; + EnumFormats(out); + return SHCreateStdEnumFmtEtc((UINT)out.get_count(), out.get_ptr(), outptr); + } FB2K_COM_CATCH; + } + private: + HRESULT GetData_internal(FORMATETC * formatetc, STGMEDIUM * medium,bool bHere) { + if (formatetc == NULL || medium == NULL) return E_INVALIDARG; + + try { + stream_writer_formatter_simple<> out; + HRESULT hr = RenderData(formatetc->cfFormat,formatetc->dwAspect,formatetc->lindex,out); + if (FAILED(hr)) return hr; + return DataBlockToSTGMEDIUM(out.m_buffer.get_ptr(),out.m_buffer.get_size(),medium,formatetc->tymed,bHere); + } FB2K_COM_CATCH; + } + + typedef pfc::map_t, comparator_FORMATETC> t_entries; + t_entries m_entries; + }; +} diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/StdAfx.cpp b/tools/vio2sf/src/foobar/foobar2000/helpers/StdAfx.cpp new file mode 100644 index 000000000..9dc5b543a --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/StdAfx.cpp @@ -0,0 +1,6 @@ +// stdafx.cpp : source file that includes just the standard includes +// foobar2000_sdk_helpers.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/StdAfx.h b/tools/vio2sf/src/foobar/foobar2000/helpers/StdAfx.h new file mode 100644 index 000000000..50a4e7bf8 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/StdAfx.h @@ -0,0 +1,22 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#if !defined(AFX_STDAFX_H__6356EC2B_6DD1_4BE8_935C_87ECBA8697E4__INCLUDED_) +#define AFX_STDAFX_H__6356EC2B_6DD1_4BE8_935C_87ECBA8697E4__INCLUDED_ + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + + +#include "../SDK/foobar2000.h" +#include "helpers.h" + +// TODO: reference additional headers your program requires here + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif // !defined(AFX_STDAFX_H__6356EC2B_6DD1_4BE8_935C_87ECBA8697E4__INCLUDED_) diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/ThreadUtils.h b/tools/vio2sf/src/foobar/foobar2000/helpers/ThreadUtils.h new file mode 100644 index 000000000..6495410a8 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/ThreadUtils.h @@ -0,0 +1,135 @@ +namespace ThreadUtils { + static void WaitAbortable(HANDLE ev, abort_callback & abort, DWORD timeout = INFINITE) { + const HANDLE handles[2] = {ev, abort.get_abort_event()}; + SetLastError(0); + const DWORD status = WaitForMultipleObjects(2, handles, FALSE, INFINITE); + switch(status) { + case WAIT_OBJECT_0: + break; + case WAIT_OBJECT_0 + 1: + throw exception_aborted(); + default: + throw exception_win32(GetLastError()); + } + } + + template + class CObjectQueue { + public: + CObjectQueue() { m_event.create(true,false); } + + template void Add(const TSource & source) { + insync(m_sync); + m_content.add_item(source); + if (m_content.get_count() == 1) m_event.set_state(true); + } + template void Get(TDestination & out, abort_callback & abort) { + WaitAbortable(m_event.get(), abort); + insync(m_sync); + pfc::const_iterator iter = m_content.first(); + pfc::dynamic_assert( iter.is_valid() ); + out = *iter; + m_content.remove(iter); + if (m_content.get_count() == 0) m_event.set_state(false); + } + + private: + win32_event m_event; + critical_section m_sync; + pfc::chain_list_v2_t m_content; + }; + + + template + class CSingleThreadWrapper : protected pfc::thread { + private: + enum status { + success, + fail, + fail_io, + fail_io_data, + fail_abort, + }; + protected: + class command { + protected: + command() : m_status(success), m_abort(), m_completionEvent() {} + virtual void executeImpl(TBase &) {} + virtual ~command() {} + public: + void execute(TBase & obj) { + try { + executeImpl(obj); + m_status = success; + } catch(exception_aborted const & e) { + m_status = fail_abort; m_statusMsg = e.what(); + } catch(exception_io_data const & e) { + m_status = fail_io_data; m_statusMsg = e.what(); + } catch(exception_io const & e) { + m_status = fail_io; m_statusMsg = e.what(); + } catch(std::exception const & e) { + m_status = fail; m_statusMsg = e.what(); + } + SetEvent(m_completionEvent); + } + void rethrow() const { + switch(m_status) { + case fail: + throw pfc::exception(m_statusMsg); + case fail_io: + throw exception_io(m_statusMsg); + case fail_io_data: + throw exception_io_data(m_statusMsg); + case fail_abort: + throw exception_aborted(); + case success: + break; + default: + throw pfc::exception_bug_check_v2(); + } + } + status m_status; + pfc::string8 m_statusMsg; + HANDLE m_completionEvent; + abort_callback * m_abort; + }; + + typedef pfc::rcptr_t command_ptr; + + CSingleThreadWrapper() { + m_completionEvent.create(true,false); + start(); + } + + ~CSingleThreadWrapper() { + m_threadAbort.abort(); + waitTillDone(); + } + + void invokeCommand(command_ptr cmd, abort_callback & abort) { + abort.check(); + m_completionEvent.set_state(false); + pfc::vartoggle_t abortToggle(cmd->m_abort, &abort); + pfc::vartoggle_t eventToggle(cmd->m_completionEvent, m_completionEvent.get() ); + m_commands.Add(cmd); + m_completionEvent.wait_for(-1); + //WaitAbortable(m_completionEvent.get(), abort); + cmd->rethrow(); + } + + private: + void threadProc() { + try { + TBase instance; + for(;;) { + command_ptr cmd; + m_commands.Get(cmd, m_threadAbort); + cmd->execute(instance); + } + } catch(...) {} + } + win32_event m_completionEvent; + CObjectQueue m_commands; + abort_callback_impl m_threadAbort; + }; +} diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/VisUtils.cpp b/tools/vio2sf/src/foobar/foobar2000/helpers/VisUtils.cpp new file mode 100644 index 000000000..069244d46 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/VisUtils.cpp @@ -0,0 +1,36 @@ +#include "stdafx.h" + +namespace VisUtils { + void PrepareFFTChunk(audio_chunk const & source, audio_chunk & out, double centerOffset) { + const t_size channels = source.get_channel_count(); + const t_uint32 sampleRate = source.get_sample_rate(); + pfc::dynamic_assert( sampleRate > 0 ); + out.set_channels(channels, source.get_channel_config()); + out.set_sample_rate(sampleRate); + const t_size inSize = source.get_sample_count(); + const t_size fftSize = MatchFFTSize(inSize); + out.set_sample_count(fftSize); + out.set_data_size(fftSize * channels); + if (fftSize >= inSize) { //rare case with *REALLY* small input + pfc::memcpy_t( out.get_data(), source.get_data(), inSize * channels ); + pfc::memset_null_t( out.get_data() + inSize * channels, (fftSize - inSize) * channels ); + } else { //inSize > fftSize, we're using a subset of source chunk for the job, pick a subset around centerOffset. + const double baseOffset = pfc::max_t(0, centerOffset - 0.5 * (double)fftSize / (double)sampleRate); + const t_size baseSample = pfc::min_t( (t_size) audio_math::time_to_samples(baseOffset, sampleRate), inSize - fftSize); + pfc::memcpy_t( out.get_data(), source.get_data() + baseSample * channels, fftSize * channels); + } + } + + bool IsValidFFTSize(t_size p_size) { + return p_size >= 2 && (p_size & (p_size - 1)) == 0; + } + + t_size MatchFFTSize(t_size samples) { + if (samples <= 2) return 2; + t_size mask = 1; + while(!IsValidFFTSize(samples)) { + samples &= ~mask; mask <<= 1; + } + return samples; + } +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/VisUtils.h b/tools/vio2sf/src/foobar/foobar2000/helpers/VisUtils.h new file mode 100644 index 000000000..973fb3fcb --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/VisUtils.h @@ -0,0 +1,8 @@ +namespace VisUtils { + //! Turns an arbitrary audio_chunk into a valid chunk to run FFT on, with proper sample count etc. + //! @param centerOffset Time offset (in seconds) inside the source chunk to center the output on, in case the FFT window is smaller than input data. + void PrepareFFTChunk(audio_chunk const & source, audio_chunk & out, double centerOffset); + + bool IsValidFFTSize(t_size size); + t_size MatchFFTSize(t_size samples); +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/album_art_helpers.h b/tools/vio2sf/src/foobar/foobar2000/helpers/album_art_helpers.h new file mode 100644 index 000000000..e1e669335 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/album_art_helpers.h @@ -0,0 +1,109 @@ +//! Helper class to load album art from a separate thread (without lagging GUI). In most scenarios you will want to use CAlbumArtLoader instead of deriving from CAlbumArtLoaderBase, unless you want to additionally process the images as they are loaded. +//! All methods meant to be called from the main thread. +//! IMPORTANT: derived classes must call Abort() in their own destructor rather than relying on CAlbumArtLoaderBase destructor, since the thread calls virtual functions! +class CAlbumArtLoaderBase : private CSimpleThread { +public: + CAlbumArtLoaderBase() : m_api(static_api_ptr_t()->instantiate()) {} + ~CAlbumArtLoaderBase() {Abort();} + + //! Requests the loader to process specific album art type. See album_art_ids namespace for defined types. + void AddType(const GUID & p_what) { + if (!HaveType(p_what)) { + Abort(); + m_requestIds.add_item(p_what); + m_api->close(); + } + } + bool HaveType(const GUID & p_what) const { + return m_requestIds.have_item(p_what); + } + + void ResetTypes() { + Abort(); + m_requestIds.remove_all(); + m_api->close(); + } + + void Abort() { + AbortThread(); + m_notify.release(); + } + + //! Completion notify code is 1 when content has changed, 0 when content is the same as before the request (like, advanced to another track with the same album art data). + void Request(const char * p_path,completion_notify_ptr p_notify = NULL) { + Abort(); + m_requestPath = p_path; + m_notify = p_notify; + StartThread(); + } + + bool IsReady() const {return !IsWorking();} + bool IsWorking() const {return IsThreadActive();} + +protected: + virtual void OnContent(const GUID & p_what,album_art_data_ptr p_data,abort_callback & p_abort) {} + virtual void OnContentReset() {} + +private: + unsigned ThreadProc(abort_callback & p_abort) { + try { + return ProcessRequest(p_abort); + } catch(exception_aborted) { + return 0; + } catch(std::exception const & e) { + console::complain("Album Art loading failure", e); + return 0; + } + } + + unsigned ProcessRequest(abort_callback & p_abort) { + if (m_api->open(m_requestPath,p_abort)) { + OnContentReset(); + for(pfc::chain_list_v2_t::const_iterator walk = m_requestIds.first(); walk.is_valid(); ++walk) { + album_art_data_ptr data; + try { + data = m_api->query(*walk,p_abort); + } catch(exception_io const & e) { + console::complain("Requested Album Art entry could not be retrieved", e); + continue; + } + pfc::dynamic_assert( data.is_valid() ); + OnContent(*walk,data,p_abort); + } + return 1; + } else { + return 0; + } + } + void ThreadDone(unsigned p_code) { + //release our notify ptr before triggering callbacks, they might fire another query from inside that + completion_notify_ptr temp; temp << m_notify; + if (temp.is_valid()) temp->on_completion(p_code); + } + + pfc::string8 m_requestPath; + pfc::chain_list_v2_t m_requestIds; + + completion_notify_ptr m_notify; + + const album_art_manager_instance_ptr m_api; + + PFC_CLASS_NOT_COPYABLE_EX(CAlbumArtLoaderBase); +}; + +class CAlbumArtLoader : public CAlbumArtLoaderBase { +public: + ~CAlbumArtLoader() {Abort();} + bool Query(const GUID & p_what, album_art_data_ptr & p_data) const { + pfc::dynamic_assert( IsReady() ); + return m_content.query(p_what,p_data); + } +protected: + void OnContentReset() { + m_content.remove_all(); + } + void OnContent(const GUID & p_what,album_art_data_ptr p_data,abort_callback & p_abort) { + m_content.set(p_what,p_data); + } + pfc::map_t m_content; +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/bitreader_helper.h b/tools/vio2sf/src/foobar/foobar2000/helpers/bitreader_helper.h new file mode 100644 index 000000000..4af87efd0 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/bitreader_helper.h @@ -0,0 +1,122 @@ +namespace bitreader_helper { + + inline static size_t extract_bit(const t_uint8 * p_stream,size_t p_offset) { + return (p_stream[p_offset>>3] >> (7-(p_offset&7)))&1; + } + + static size_t extract_int(const t_uint8 * p_stream,size_t p_base,size_t p_width) { + size_t ret = 0; + size_t offset = p_base; + for(size_t bit=0;bit + t_ret read_t(t_size p_bits) { + t_ret ret = 0; + for(t_size bit=0;bit>3] >> (7-(m_bitptr&7)))&1; + m_bitptr++; + } + return ret; + } + + t_size read(t_size p_bits) {return read_t(p_bits);} + + inline t_size get_bitptr() const {return m_bitptr;} + + inline bool read_bit() { + bool state = ( (m_ptr[m_bitptr>>3] >> (7-(m_bitptr&7)))&1 ) != 0; + m_bitptr++; + return state; + } + +private: + + const t_uint8 * m_ptr; + t_size m_bitptr; +}; + +class bitreader_fromfile +{ +public: + inline bitreader_fromfile(service_ptr_t const& p_file) : m_file(p_file), m_buffer_ptr(0) {} + + t_size read(t_size p_bits,abort_callback & p_abort) { + t_size ret = 0; + for(t_size bit=0;bitread_object(&m_buffer,1,p_abort); + + ret <<= 1; + ret |= (m_buffer >> (7-m_buffer_ptr))&1; + m_buffer_ptr = (m_buffer_ptr+1) & 7; + } + return ret; + } + + void skip(t_size p_bits,abort_callback & p_abort) { + for(t_size bit=0;bitread_object(&m_buffer,1,p_abort); + m_buffer_ptr = (m_buffer_ptr+1) & 7; + } + } + + inline void byte_align() {m_buffer_ptr = 0;} + +private: + service_ptr_t m_file; + t_size m_buffer_ptr; + t_uint8 m_buffer; +}; + +class bitreader_limited +{ +public: + inline bitreader_limited(const t_uint8 * p_ptr,t_size p_base,t_size p_remaining) : m_reader(p_ptr,p_base), m_remaining(p_remaining) {} + + inline t_size get_bitptr() const {return m_reader.get_bitptr();} + + inline t_size get_remaining() const {return m_remaining;} + + inline void skip(t_size p_bits) { + if (p_bits > m_remaining) throw exception_io_data_truncation(); + m_remaining -= p_bits; + m_reader.skip(p_bits); + } + + t_size read(t_size p_bits) + { + if (p_bits > m_remaining) throw exception_io_data_truncation(); + m_remaining -= p_bits; + return m_reader.read(p_bits); + } + +private: + bitreader m_reader; + t_size m_remaining; +}; + +inline static t_size extract_bits(const t_uint8 * p_buffer,t_size p_base,t_size p_count) { + return bitreader(p_buffer,p_base).read(p_count); +} + +} \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/cfg_guidlist.h b/tools/vio2sf/src/foobar/foobar2000/helpers/cfg_guidlist.h new file mode 100644 index 000000000..dfdbae14e --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/cfg_guidlist.h @@ -0,0 +1,29 @@ +class cfg_guidlist : public cfg_var, public pfc::list_t +{ +public: + void get_data_raw(stream_writer * p_stream,abort_callback & p_abort) { + t_uint32 n, m = pfc::downcast_guarded(get_count()); + p_stream->write_lendian_t(m,p_abort); + for(n=0;nwrite_lendian_t(get_item(n),p_abort); + } + void set_data_raw(stream_reader * p_stream,t_size p_sizehint,abort_callback & p_abort) { + t_uint32 n,count; + p_stream->read_lendian_t(count,p_abort); + m_buffer.set_size(count); + for(n=0;nread_lendian_t(m_buffer[n],p_abort); + } catch(...) {m_buffer.set_size(0); throw;} + } + } + + void sort() {sort_t(pfc::guid_compare);} + + bool have_item_bsearch(const GUID & p_item) { + t_size dummy; + return bsearch_t(pfc::guid_compare,p_item,dummy); + } + +public: + cfg_guidlist(const GUID & p_guid) : cfg_var(p_guid) {} +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/clipboard.cpp b/tools/vio2sf/src/foobar/foobar2000/helpers/clipboard.cpp new file mode 100644 index 000000000..928ce1e0a --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/clipboard.cpp @@ -0,0 +1,37 @@ +#include "stdafx.h" + +#ifdef UNICODE +#define CF_TCHAR CF_UNICODETEXT +#else +#define CF_TCHAR CF_TEXT +#endif + +namespace ClipboardHelper { + void SetRaw(UINT format,const void * data, t_size size) { + HANDLE buffer = GlobalAlloc(GMEM_DDESHARE,size); + if (buffer == NULL) throw std::bad_alloc(); + try { + CGlobalLockScope lock(buffer); + PFC_ASSERT(lock.GetSize() == size); + memcpy(lock.GetPtr(),data,size); + } catch(...) { + GlobalFree(buffer); throw; + } + + WIN32_OP(SetClipboardData(format,buffer) != NULL); + } + void SetString(const char * in) { + pfc::stringcvt::string_os_from_utf8 temp(in); + SetRaw(CF_TCHAR,temp.get_ptr(),(temp.length() + 1) * sizeof(TCHAR)); + } + + bool GetString(pfc::string_base & out) { + pfc::array_t temp; + if (!GetRaw(CF_TCHAR,temp)) return false; + out = pfc::stringcvt::string_utf8_from_os(reinterpret_cast(temp.get_ptr()),temp.get_size() / sizeof(TCHAR)); + return true; + } + bool IsTextAvailable() { + return IsClipboardFormatAvailable(CF_TCHAR) == TRUE; + } +} diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/clipboard.h b/tools/vio2sf/src/foobar/foobar2000/helpers/clipboard.h new file mode 100644 index 000000000..f456ab1c9 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/clipboard.h @@ -0,0 +1,40 @@ +namespace ClipboardHelper { + + class OpenScope { + public: + OpenScope() : m_open(false) {} + ~OpenScope() {Close();} + void Open(HWND p_owner) { + Close(); + WIN32_OP(OpenClipboard(p_owner)); + m_open = true; + } + void Close() { + if (m_open) { + m_open = false; + CloseClipboard(); + } + } + private: + bool m_open; + + PFC_CLASS_NOT_COPYABLE_EX(OpenScope) + }; + + void SetRaw(UINT format,const void * buffer, t_size size); + void SetString(const char * in); + + bool GetString(pfc::string_base & out); + + template + bool GetRaw(UINT format,TArray & out) { + pfc::assert_byte_type(); + HANDLE data = GetClipboardData(format); + if (data == NULL) return false; + CGlobalLockScope lock(data); + out.set_size( lock.GetSize() ); + memcpy(out.get_ptr(), lock.GetPtr(), lock.GetSize() ); + return true; + } + bool IsTextAvailable(); +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/create_directory_helper.cpp b/tools/vio2sf/src/foobar/foobar2000/helpers/create_directory_helper.cpp new file mode 100644 index 000000000..14d03c1b5 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/create_directory_helper.cpp @@ -0,0 +1,122 @@ +#include "stdafx.h" + +namespace create_directory_helper +{ + static void create_path_internal(const char * p_path,t_size p_base,abort_callback & p_abort) { + pfc::string8_fastalloc temp; + for(t_size walk = p_base; p_path[walk]; walk++) { + if (p_path[walk] == '\\') { + temp.set_string(p_path,walk); + try {filesystem::g_create_directory(temp.get_ptr(),p_abort);} catch(exception_io_already_exists) {} + } + } + } + + static bool is_valid_netpath_char(char p_char) { + return pfc::char_is_ascii_alphanumeric(p_char) || p_char == '_' || p_char == '-'; + } + + static bool test_localpath(const char * p_path) { + if (pfc::strcmp_partial(p_path,"file://") == 0) p_path += strlen("file://"); + return pfc::char_is_ascii_alpha(p_path[0]) && + p_path[1] == ':' && + p_path[2] == '\\'; + } + static bool test_netpath(const char * p_path) { + if (pfc::strcmp_partial(p_path,"file://") == 0) p_path += strlen("file://"); + if (*p_path != '\\') return false; + p_path++; + if (*p_path != '\\') return false; + p_path++; + if (!is_valid_netpath_char(*p_path)) return false; + p_path++; + while(is_valid_netpath_char(*p_path)) p_path++; + if (*p_path != '\\') return false; + return true; + } + + void create_path(const char * p_path,abort_callback & p_abort) { + if (test_localpath(p_path)) { + t_size walk = 0; + if (pfc::strcmp_partial(p_path,"file://") == 0) walk += strlen("file://"); + create_path_internal(p_path,walk + 3,p_abort); + } else if (test_netpath(p_path)) { + t_size walk = 0; + if (pfc::strcmp_partial(p_path,"file://") == 0) walk += strlen("file://"); + while(p_path[walk] == '\\') walk++; + while(p_path[walk] != 0 && p_path[walk] != '\\') walk++; + while(p_path[walk] == '\\') walk++; + create_path_internal(p_path,walk,p_abort); + } else { + throw exception_io("Could not create directory structure; unknown path format"); + } + } + + static bool is_bad_dirchar(char c) + { + return c==' ' || c=='.'; + } + + void make_path(const char * parent,const char * filename,const char * extension,bool allow_new_dirs,pfc::string8 & out,bool really_create_dirs,abort_callback & p_abort) + { + out.reset(); + if (parent && *parent) + { + out = parent; + out.fix_dir_separator('\\'); + } + bool last_char_is_dir_sep = true; + while(*filename) + { +#ifdef WIN32 + if (allow_new_dirs && is_bad_dirchar(*filename)) + { + const char * ptr = filename+1; + while(is_bad_dirchar(*ptr)) ptr++; + if (*ptr!='\\' && *ptr!='/') out.add_string(filename,ptr-filename); + filename = ptr; + if (*filename==0) break; + } +#endif + if (pfc::is_path_bad_char(*filename)) + { + if (allow_new_dirs && (*filename=='\\' || *filename=='/')) + { + if (!last_char_is_dir_sep) + { + if (really_create_dirs) try{filesystem::g_create_directory(out,p_abort);}catch(exception_io_already_exists){} + out.add_char('\\'); + last_char_is_dir_sep = true; + } + } + else + out.add_char('_'); + } + else + { + out.add_byte(*filename); + last_char_is_dir_sep = false; + } + filename++; + } + if (out.length()>0 && out[out.length()-1]=='\\') + { + out.add_string("noname"); + } + if (extension && *extension) + { + out.add_char('.'); + out.add_string(extension); + } + } +} + +void create_directory_helper::format_filename(const metadb_handle_ptr & handle,titleformat_hook * p_hook,const char * spec,pfc::string8 & out) +{ + titleformat_text_filter_impl_filename_chars filter; + pfc::string8 temp; + handle->format_title_legacy(p_hook,temp,spec,&filter); + temp.replace_char('/','\\'); + temp.fix_filename_chars('_','\\'); + out = temp; +} diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/create_directory_helper.h b/tools/vio2sf/src/foobar/foobar2000/helpers/create_directory_helper.h new file mode 100644 index 000000000..b15624196 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/create_directory_helper.h @@ -0,0 +1,10 @@ +#ifndef _CREATE_DIRECTORY_HELPER_H_ +#define _CREATE_DIRECTORY_HELPER_H_ + +namespace create_directory_helper { + void create_path(const char * p_path,abort_callback & p_abort); + void make_path(const char * parent,const char * filename,const char * extension,bool allow_new_dirs,pfc::string8 & out,bool b_really_create_dirs,abort_callback & p_dir_create_abort); + void format_filename(const metadb_handle_ptr & handle,titleformat_hook * p_hook,const char * spec,pfc::string8 & out); +}; + +#endif//_CREATE_DIRECTORY_HELPER_H_ \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/cue_creator.cpp b/tools/vio2sf/src/foobar/foobar2000/helpers/cue_creator.cpp new file mode 100644 index 000000000..6b261ceaf --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/cue_creator.cpp @@ -0,0 +1,171 @@ +#include "stdafx.h" + + +namespace { + + class format_meta + { + public: + format_meta(const file_info & p_source,const char * p_name,bool p_allow_space = true) + { + p_source.meta_format(p_name,m_buffer); + m_buffer.replace_byte('\"','\''); + uReplaceString(m_buffer,pfc::string8(m_buffer),infinite,"\x0d\x0a",2,"\\",1,false); + if (!p_allow_space) m_buffer.replace_byte(' ','_'); + m_buffer.replace_nontext_chars(); + } + inline operator const char*() const {return m_buffer;} + private: + pfc::string8_fastalloc m_buffer; + }; +} + +static bool is_meta_same_everywhere(const cue_creator::t_entry_list & p_list,const char * p_meta) +{ + pfc::string8_fastalloc reference,temp; + + cue_creator::t_entry_list::const_iterator iter; + iter = p_list.first(); + if (!iter.is_valid()) return false; + if (!iter->m_infos.meta_format(p_meta,reference)) return false; + for(;iter.is_valid();++iter) + { + if (!iter->m_infos.meta_format(p_meta,temp)) return false; + if (strcmp(temp,reference)!=0) return false; + } + return true; +} + +static const char g_eol[] = "\r\n"; + + +namespace cue_creator +{ + void create(pfc::string_formatter & p_out,const t_entry_list & p_data) + { + if (p_data.get_count() == 0) return; + bool album_artist_global = is_meta_same_everywhere(p_data,"album artist"), + artist_global = is_meta_same_everywhere(p_data,"artist"), + album_global = is_meta_same_everywhere(p_data,"album"), + genre_global = is_meta_same_everywhere(p_data,"genre"), + date_global = is_meta_same_everywhere(p_data,"date"), + discid_global = is_meta_same_everywhere(p_data,"discid"), + comment_global = is_meta_same_everywhere(p_data,"comment"), + catalog_global = is_meta_same_everywhere(p_data,"catalog"), + songwriter_global = is_meta_same_everywhere(p_data,"songwriter"); + + if (genre_global) { + p_out << "REM GENRE " << format_meta(p_data.first()->m_infos,"genre") << g_eol; + } + if (date_global) { + p_out << "REM DATE " << format_meta(p_data.first()->m_infos,"date") << g_eol; + } + if (discid_global) { + p_out << "REM DISCID " << format_meta(p_data.first()->m_infos,"discid") << g_eol; + } + if (comment_global) { + p_out << "REM COMMENT " << format_meta(p_data.first()->m_infos,"comment") << g_eol; + } + if (catalog_global) { + p_out << "CATALOG " << format_meta(p_data.first()->m_infos,"catalog") << g_eol; + } + if (songwriter_global) { + p_out << "SONGWRITER \"" << format_meta(p_data.first()->m_infos,"songwriter") << "\"" << g_eol; + } + + if (album_artist_global) + { + p_out << "PERFORMER \"" << format_meta(p_data.first()->m_infos,"album artist") << "\"" << g_eol; + artist_global = false; + } + else if (artist_global) + { + p_out << "PERFORMER \"" << format_meta(p_data.first()->m_infos,"artist") << "\"" << g_eol; + } + if (album_global) + { + p_out << "TITLE \"" << format_meta(p_data.first()->m_infos,"album") << "\"" << g_eol; + } + + { + replaygain_info::t_text_buffer rgbuffer; + replaygain_info rg = p_data.first()->m_infos.get_replaygain(); + if (rg.format_album_gain(rgbuffer)) + p_out << "REM REPLAYGAIN_ALBUM_GAIN " << rgbuffer << g_eol; + if (rg.format_album_peak(rgbuffer)) + p_out << "REM REPLAYGAIN_ALBUM_PEAK " << rgbuffer << g_eol; + } + + pfc::string8 last_file; + + for(t_entry_list::const_iterator iter = p_data.first();iter.is_valid();++iter) + { + if (strcmp(last_file,iter->m_file) != 0) + { + p_out << "FILE \"" << iter->m_file << "\" WAVE" << g_eol; + last_file = iter->m_file; + } + + p_out << " TRACK " << pfc::format_int(iter->m_track_number,2) << " AUDIO" << g_eol; + + if (iter->m_infos.meta_find("title") != infinite) + p_out << " TITLE \"" << format_meta(iter->m_infos,"title") << "\"" << g_eol; + + if (!artist_global && iter->m_infos.meta_find("artist") != infinite) + p_out << " PERFORMER \"" << format_meta(iter->m_infos,"artist") << "\"" << g_eol; + + if (!songwriter_global && iter->m_infos.meta_find("songwriter") != infinite) { + p_out << " SONGWRITER \"" << format_meta(iter->m_infos,"songwriter") << "\"" << g_eol; + } + + if (iter->m_infos.meta_find("isrc") != infinite) { + p_out << " ISRC " << format_meta(iter->m_infos,"isrc") << g_eol; + } + + if (!date_global && iter->m_infos.meta_find("date") != infinite) { + p_out << " REM DATE " << format_meta(iter->m_infos,"date") << g_eol; + } + + + + { + replaygain_info::t_text_buffer rgbuffer; + replaygain_info rg = iter->m_infos.get_replaygain(); + if (rg.format_track_gain(rgbuffer)) + p_out << " REM REPLAYGAIN_TRACK_GAIN " << rgbuffer << g_eol; + if (rg.format_track_peak(rgbuffer)) + p_out << " REM REPLAYGAIN_TRACK_PEAK " << rgbuffer << g_eol; + } + + if (!iter->m_flags.is_empty()) { + p_out << " FLAGS " << iter->m_flags << g_eol; + } + + if (iter->m_index_list.m_positions[0] < iter->m_index_list.m_positions[1]) + { + if (iter->m_index_list.m_positions[0] < 0) + p_out << " PREGAP " << cuesheet_format_index_time(iter->m_index_list.m_positions[1] - iter->m_index_list.m_positions[0]) << g_eol; + else + p_out << " INDEX 00 " << cuesheet_format_index_time(iter->m_index_list.m_positions[0]) << g_eol; + } + + p_out << " INDEX 01 " << cuesheet_format_index_time(iter->m_index_list.m_positions[1]) << g_eol; + + for(unsigned n=2;nm_index_list.m_positions[n] > 0;n++) + { + p_out << " INDEX " << pfc::format_uint(n,2) << " " << cuesheet_format_index_time(iter->m_index_list.m_positions[n]) << g_eol; + } + + // p_out << " INDEX 01 " << cuesheet_format_index_time(iter->m_offset) << g_eol; + } + } + + + void t_entry::set_simple_index(double p_time) + { + m_index_list.reset(); + m_index_list.m_positions[0] = m_index_list.m_positions[1] = p_time; + } + +} + diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/cue_creator.h b/tools/vio2sf/src/foobar/foobar2000/helpers/cue_creator.h new file mode 100644 index 000000000..cb62cbbf3 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/cue_creator.h @@ -0,0 +1,17 @@ +namespace cue_creator +{ + struct t_entry + { + file_info_impl m_infos; + pfc::string8 m_file,m_flags; + unsigned m_track_number; + + t_cuesheet_index_list m_index_list; + + void set_simple_index(double p_time); + }; + + typedef pfc::chain_list_v2_t t_entry_list; + + void create(pfc::string_formatter & p_out,const t_entry_list & p_list); +}; \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/cue_parser.cpp b/tools/vio2sf/src/foobar/foobar2000/helpers/cue_parser.cpp new file mode 100644 index 000000000..536e8326b --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/cue_parser.cpp @@ -0,0 +1,764 @@ +#include "stdafx.h" + +namespace { + PFC_DECLARE_EXCEPTION(exception_cue,pfc::exception,"Invalid cuesheet"); +} + +static bool is_numeric(char c) {return c>='0' && c<='9';} + + +static bool is_spacing(char c) +{ + return c == ' ' || c == '\t'; +} + +static bool is_linebreak(char c) +{ + return c == '\n' || c == '\r'; +} + +static void validate_file_type(const char * p_type,t_size p_type_length) { + if ( + //standard types + stricmp_utf8_ex(p_type,p_type_length,"WAVE",infinite) != 0 && + stricmp_utf8_ex(p_type,p_type_length,"MP3",infinite) != 0 && + stricmp_utf8_ex(p_type,p_type_length,"AIFF",infinite) != 0 && + //common user-entered types + stricmp_utf8_ex(p_type,p_type_length,"APE",infinite) != 0 && + stricmp_utf8_ex(p_type,p_type_length,"FLAC",infinite) != 0 && + stricmp_utf8_ex(p_type,p_type_length,"WV",infinite) != 0 && + stricmp_utf8_ex(p_type,p_type_length,"WAVPACK",infinite) != 0 + ) + throw exception_cue(pfc::string_formatter() << "expected WAVE, MP3 or AIFF, got : \"" << pfc::string8(p_type,p_type_length) << "\""); +} + +namespace { + + class NOVTABLE cue_parser_callback + { + public: + virtual void on_file(const char * p_file,t_size p_file_length,const char * p_type,t_size p_type_length) = 0; + virtual void on_track(unsigned p_index,const char * p_type,t_size p_type_length) = 0; + virtual void on_pregap(unsigned p_value) = 0; + virtual void on_index(unsigned p_index,unsigned p_value) = 0; + virtual void on_title(const char * p_title,t_size p_title_length) = 0; + virtual void on_performer(const char * p_performer,t_size p_performer_length) = 0; + virtual void on_songwriter(const char * p_songwriter,t_size p_songwriter_length) = 0; + virtual void on_isrc(const char * p_isrc,t_size p_isrc_length) = 0; + virtual void on_catalog(const char * p_catalog,t_size p_catalog_length) = 0; + virtual void on_comment(const char * p_comment,t_size p_comment_length) = 0; + virtual void on_flags(const char * p_flags,t_size p_flags_length) = 0; + }; + + class NOVTABLE cue_parser_callback_meta : public cue_parser_callback + { + public: + virtual void on_file(const char * p_file,t_size p_file_length,const char * p_type,t_size p_type_length) = 0; + virtual void on_track(unsigned p_index,const char * p_type,t_size p_type_length) = 0; + virtual void on_pregap(unsigned p_value) = 0; + virtual void on_index(unsigned p_index,unsigned p_value) = 0; + virtual void on_meta(const char * p_name,t_size p_name_length,const char * p_value,t_size p_value_length) = 0; + protected: + static bool is_known_meta(const char * p_name,t_size p_length) + { + static const char * metas[] = {"genre","date","discid","comment","replaygain_track_gain","replaygain_track_peak","replaygain_album_gain","replaygain_album_peak"}; + for(t_size n=0;n value_base) on_meta(p_comment,name_length,p_comment + value_base,ptr - value_base); + } + else + { + unsigned value_base = ptr; + while(ptr < p_comment_length /*&& !is_spacing(p_comment[ptr])*/) ptr++; + if (ptr > value_base) on_meta(p_comment,name_length,p_comment + value_base,ptr - value_base); + } + } + } + } + void on_title(const char * p_title,t_size p_title_length) + { + on_meta("title",infinite,p_title,p_title_length); + } + void on_songwriter(const char * p_songwriter,t_size p_songwriter_length) { + on_meta("songwriter",infinite,p_songwriter,p_songwriter_length); + } + void on_performer(const char * p_performer,t_size p_performer_length) + { + on_meta("artist",infinite,p_performer,p_performer_length); + } + + void on_isrc(const char * p_isrc,t_size p_isrc_length) + { + on_meta("isrc",infinite,p_isrc,p_isrc_length); + } + void on_catalog(const char * p_catalog,t_size p_catalog_length) + { + on_meta("catalog",infinite,p_catalog,p_catalog_length); + } + void on_flags(const char * p_flags,t_size p_flags_length) {} + }; + + + class cue_parser_callback_retrievelist : public cue_parser_callback + { + public: + cue_parser_callback_retrievelist(cue_parser::t_cue_entry_list & p_out) : m_out(p_out), m_track(0), m_pregap(0), m_index0_set(false), m_index1_set(false) + { + } + + void on_file(const char * p_file,t_size p_file_length,const char * p_type,t_size p_type_length) + { + validate_file_type(p_type,p_type_length); + m_file.set_string(p_file,p_file_length); + } + + void on_track(unsigned p_index,const char * p_type,t_size p_type_length) + { + if (stricmp_utf8_ex(p_type,p_type_length,"audio",infinite)) throw exception_cue("only tracks of type AUDIO supported",0); + //if (p_index != m_track + 1) throw exception_cue("cuesheet tracks out of order"); + if (m_track != 0) finalize_track(); + if (m_file.is_empty()) throw exception_cue("declaring a track with no file set",0); + m_trackfile = m_file; + m_track = p_index; + } + + void on_pregap(unsigned p_value) {m_pregap = (double) p_value / 75.0;} + + void on_index(unsigned p_index,unsigned p_value) + { + if (p_index < t_cuesheet_index_list::count) + { + switch(p_index) + { + case 0: m_index0_set = true; break; + case 1: m_index1_set = true; break; + } + m_index_list.m_positions[p_index] = (double) p_value / 75.0; + } + } + + void on_title(const char * p_title,t_size p_title_length) {} + void on_performer(const char * p_performer,t_size p_performer_length) {} + void on_songwriter(const char * p_songwriter,t_size p_songwriter_length) {} + void on_isrc(const char * p_isrc,t_size p_isrc_length) {} + void on_catalog(const char * p_catalog,t_size p_catalog_length) {} + void on_comment(const char * p_comment,t_size p_comment_length) {} + void on_flags(const char * p_flags,t_size p_flags_length) {} + + void finalize() + { + if (m_track != 0) + { + finalize_track(); + m_track = 0; + } + } + + private: + void finalize_track() + { + if (!m_index1_set) throw exception_cue("INDEX 01 not set",0); + if (!m_index0_set) m_index_list.m_positions[0] = m_index_list.m_positions[1] - m_pregap; + if (!m_index_list.is_valid()) throw exception_cue("invalid index list"); + + cue_parser::t_cue_entry_list::iterator iter; + iter = m_out.insert_last(); + if (m_trackfile.is_empty()) throw exception_cue("track has no file assigned",0); + iter->m_file = m_trackfile; + iter->m_track_number = m_track; + iter->m_indexes = m_index_list; + + m_index_list.reset(); + m_index0_set = false; + m_index1_set = false; + m_pregap = 0; + } + + bool m_index0_set,m_index1_set; + t_cuesheet_index_list m_index_list; + double m_pregap; + unsigned m_track; + pfc::string8 m_file,m_trackfile; + cue_parser::t_cue_entry_list & m_out; + }; + + class cue_parser_callback_retrieveinfo : public cue_parser_callback_meta + { + public: + cue_parser_callback_retrieveinfo(file_info & p_out,unsigned p_wanted_track) : m_out(p_out), m_wanted_track(p_wanted_track), m_track(0), m_is_va(false), m_index0_set(false), m_index1_set(false), m_pregap(0), m_totaltracks(0) {} + + void on_file(const char * p_file,t_size p_file_length,const char * p_type,t_size p_type_length) {} + + void on_track(unsigned p_index,const char * p_type,t_size p_type_length) + { + if (p_index == 0) throw exception_cue("invalid TRACK index",0); + if (p_index == m_wanted_track) + { + if (stricmp_utf8_ex(p_type,p_type_length,"audio",infinite)) throw exception_cue("only tracks of type AUDIO supported",0); + } + m_track = p_index; + m_totaltracks++; + } + + void on_pregap(unsigned p_value) {if (m_track == m_wanted_track) m_pregap = (double) p_value / 75.0;} + + void on_index(unsigned p_index,unsigned p_value) + { + if (m_track == m_wanted_track && p_index < t_cuesheet_index_list::count) + { + switch(p_index) + { + case 0: m_index0_set = true; break; + case 1: m_index1_set = true; break; + } + m_indexes.m_positions[p_index] = (double) p_value / 75.0; + } + } + + + void on_meta(const char * p_name,t_size p_name_length,const char * p_value,t_size p_value_length) + { + t_meta_list::iterator iter; + if (m_track == 0) //globals + { + //convert global title to album + if (!stricmp_utf8_ex(p_name,p_name_length,"title",infinite)) + { + p_name = "album"; + p_name_length = 5; + } + else if (!stricmp_utf8_ex(p_name,p_name_length,"artist",infinite)) + { + m_album_artist.set_string(p_value,p_value_length); + } + + iter = m_globals.insert_last(); + } + else + { + if (!m_is_va) + { + if (!stricmp_utf8_ex(p_name,p_name_length,"artist",infinite)) + { + if (!m_album_artist.is_empty()) + { + if (stricmp_utf8_ex(p_value,p_value_length,m_album_artist,m_album_artist.length())) m_is_va = true; + } + } + } + + if (m_track == m_wanted_track) //locals + { + iter = m_locals.insert_last(); + } + } + if (iter.is_valid()) + { + iter->m_name.set_string(p_name,p_name_length); + iter->m_value.set_string(p_value,p_value_length); + } + } + + void finalize() + { + if (!m_index1_set) throw exception_cue("INDEX 01 not set",0); + if (!m_index0_set) m_indexes.m_positions[0] = m_indexes.m_positions[1] - m_pregap; + m_indexes.to_infos(m_out); + + replaygain_info rg; + rg.reset(); + t_meta_list::const_iterator iter; + + if (m_is_va) + { + //clean up VA mess + + t_meta_list::const_iterator iter_global,iter_local; + + iter_global = find_first_field(m_globals,"artist"); + iter_local = find_first_field(m_locals,"artist"); + if (iter_global.is_valid()) + { + m_out.meta_set("album artist",iter_global->m_value); + if (iter_local.is_valid()) m_out.meta_set("artist",iter_local->m_value); + else m_out.meta_set("artist",iter_global->m_value); + } + else + { + if (iter_local.is_valid()) m_out.meta_set("artist",iter_local->m_value); + } + + + wipe_field(m_globals,"artist"); + wipe_field(m_locals,"artist"); + + } + + for(iter=m_globals.first();iter.is_valid();iter++) + { + if (!rg.set_from_meta(iter->m_name,iter->m_value)) + m_out.meta_set(iter->m_name,iter->m_value); + } + for(iter=m_locals.first();iter.is_valid();iter++) + { + if (!rg.set_from_meta(iter->m_name,iter->m_value)) + m_out.meta_set(iter->m_name,iter->m_value); + } + m_out.meta_set("tracknumber",pfc::string_formatter() << m_wanted_track); + m_out.meta_set("totaltracks", pfc::string_formatter() << m_totaltracks); + m_out.set_replaygain(rg); + + } + private: + struct t_meta_entry { + pfc::string8 m_name,m_value; + }; + typedef pfc::chain_list_v2_t t_meta_list; + + static t_meta_list::const_iterator find_first_field(t_meta_list const & p_list,const char * p_field) + { + t_meta_list::const_iterator iter; + for(iter=p_list.first();iter.is_valid();++iter) + { + if (!stricmp_utf8(p_field,iter->m_name)) return iter; + } + return t_meta_list::const_iterator();//null iterator + } + + static void wipe_field(t_meta_list & p_list,const char * p_field) + { + t_meta_list::iterator iter; + for(iter=p_list.first();iter.is_valid();) + { + if (!stricmp_utf8(p_field,iter->m_name)) + { + t_meta_list::iterator temp = iter; + ++temp; + p_list.remove_single(iter); + iter = temp; + } + else + { + ++iter; + } + } + } + + t_meta_list m_globals,m_locals; + file_info & m_out; + unsigned m_wanted_track, m_track,m_totaltracks; + pfc::string8 m_album_artist; + bool m_is_va; + t_cuesheet_index_list m_indexes; + bool m_index0_set,m_index1_set; + double m_pregap; + }; + +}; + + +static void g_parse_cue_line(const char * p_line,t_size p_line_length,cue_parser_callback & p_callback) +{ + t_size ptr = 0; + while(ptr < p_line_length && !is_spacing(p_line[ptr])) ptr++; + if (!stricmp_utf8_ex(p_line,ptr,"file",infinite)) + { + while(ptr < p_line_length && is_spacing(p_line[ptr])) ptr++; + t_size file_base,file_length, type_base,type_length; + + if (p_line[ptr] == '\"') + { + ptr++; + file_base = ptr; + while(ptr < p_line_length && p_line[ptr] != '\"') ptr++; + if (ptr == p_line_length) throw exception_cue("invalid FILE syntax",0); + file_length = ptr - file_base; + ptr++; + while(ptr < p_line_length && is_spacing(p_line[ptr])) ptr++; + } + else + { + file_base = ptr; + while(ptr < p_line_length && !is_spacing(p_line[ptr])) ptr++; + file_length = ptr - file_base; + while(ptr < p_line_length && is_spacing(p_line[ptr])) ptr++; + } + + type_base = ptr; + while(ptr < p_line_length && !is_spacing(p_line[ptr])) ptr++; + type_length = ptr - type_base; + while(ptr < p_line_length && is_spacing(p_line[ptr])) ptr++; + + if (ptr != p_line_length || file_length == 0 || type_length == 0) throw exception_cue("invalid FILE syntax",0); + + p_callback.on_file(p_line + file_base, file_length, p_line + type_base, type_length); + } + else if (!stricmp_utf8_ex(p_line,ptr,"track",infinite)) + { + while(ptr < p_line_length && is_spacing(p_line[ptr])) ptr++; + + t_size track_base = ptr, track_length; + while(ptr < p_line_length && !is_spacing(p_line[ptr])) + { + if (!is_numeric(p_line[ptr])) throw exception_cue("invalid TRACK syntax",0); + ptr++; + } + track_length = ptr - track_base; + while(ptr < p_line_length && is_spacing(p_line[ptr])) ptr++; + + t_size type_base = ptr, type_length; + while(ptr < p_line_length && !is_spacing(p_line[ptr])) ptr++; + type_length = ptr - type_base; + + while(ptr < p_line_length && is_spacing(p_line[ptr])) ptr++; + if (ptr != p_line_length || type_length == 0) throw exception_cue("invalid TRACK syntax",0); + unsigned track = pfc::atoui_ex(p_line+track_base,track_length); + if (track < 1 || track > 99) throw exception_cue("invalid track number",0); + + p_callback.on_track(track,p_line + type_base, type_length); + } + else if (!stricmp_utf8_ex(p_line,ptr,"index",infinite)) + { + while(ptr < p_line_length && is_spacing(p_line[ptr])) ptr++; + + t_size index_base,index_length, time_base,time_length; + index_base = ptr; + while(ptr < p_line_length && !is_spacing(p_line[ptr])) + { + if (!is_numeric(p_line[ptr])) throw exception_cue("invalid INDEX syntax",0); + ptr++; + } + index_length = ptr - index_base; + + while(ptr < p_line_length && is_spacing(p_line[ptr])) ptr++; + time_base = ptr; + while(ptr < p_line_length && !is_spacing(p_line[ptr])) + { + if (!is_numeric(p_line[ptr]) && p_line[ptr] != ':') + throw exception_cue("invalid INDEX syntax",0); + ptr++; + } + time_length = ptr - time_base; + + while(ptr < p_line_length && is_spacing(p_line[ptr])) ptr++; + + if (ptr != p_line_length || index_length == 0 || time_length == 0) + throw exception_cue("invalid INDEX syntax",0); + + unsigned index = pfc::atoui_ex(p_line+index_base,index_length); + if (index > 99) throw exception_cue("invalid INDEX syntax",0); + unsigned time = cuesheet_parse_index_time_ticks_e(p_line + time_base,time_length); + + p_callback.on_index(index,time); + } + else if (!stricmp_utf8_ex(p_line,ptr,"pregap",infinite)) + { + while(ptr < p_line_length && is_spacing(p_line[ptr])) ptr++; + + t_size time_base, time_length; + time_base = ptr; + while(ptr < p_line_length && !is_spacing(p_line[ptr])) + { + if (!is_numeric(p_line[ptr]) && p_line[ptr] != ':') + throw exception_cue("invalid PREGAP syntax",0); + ptr++; + } + time_length = ptr - time_base; + + while(ptr < p_line_length && is_spacing(p_line[ptr])) ptr++; + + if (ptr != p_line_length || time_length == 0) + throw exception_cue("invalid PREGAP syntax",0); + + unsigned time = cuesheet_parse_index_time_ticks_e(p_line + time_base,time_length); + + p_callback.on_pregap(time); + } + else if (!stricmp_utf8_ex(p_line,ptr,"title",infinite)) + { + while(ptr < p_line_length && is_spacing(p_line[ptr])) ptr++; + if (ptr == p_line_length) throw exception_cue("invalid TITLE syntax",0); + if (p_line[ptr] == '\"') + { + ptr++; + t_size base = ptr; + while(ptr < p_line_length && p_line[ptr] != '\"') ptr++; + if (ptr == p_line_length) throw exception_cue("invalid TITLE syntax",0); + t_size length = ptr-base; + ptr++; + while(ptr < p_line_length && is_spacing(p_line[ptr])) ptr++; + if (ptr != p_line_length) throw exception_cue("invalid TITLE syntax",0); + p_callback.on_title(p_line+base,length); + } + else + { + p_callback.on_title(p_line+ptr,p_line_length-ptr); + } + } + else if (!stricmp_utf8_ex(p_line,ptr,"performer",infinite)) + { + while(ptr < p_line_length && is_spacing(p_line[ptr])) ptr++; + if (ptr == p_line_length) throw exception_cue("invalid PERFORMER syntax",0); + if (p_line[ptr] == '\"') + { + ptr++; + t_size base = ptr; + while(ptr < p_line_length && p_line[ptr] != '\"') ptr++; + if (ptr == p_line_length) throw exception_cue("invalid PERFORMER syntax",0); + t_size length = ptr-base; + ptr++; + while(ptr < p_line_length && is_spacing(p_line[ptr])) ptr++; + if (ptr != p_line_length) throw exception_cue("invalid PERFORMER syntax",0); + p_callback.on_performer(p_line+base,length); + } + else + { + p_callback.on_performer(p_line+ptr,p_line_length-ptr); + } + } + else if (!stricmp_utf8_ex(p_line,ptr,"songwriter",infinite)) + { + while(ptr < p_line_length && is_spacing(p_line[ptr])) ptr++; + if (ptr == p_line_length) throw exception_cue("invalid SONGWRITER syntax",0); + if (p_line[ptr] == '\"') + { + ptr++; + t_size base = ptr; + while(ptr < p_line_length && p_line[ptr] != '\"') ptr++; + if (ptr == p_line_length) throw exception_cue("invalid SONGWRITER syntax",0); + t_size length = ptr-base; + ptr++; + while(ptr < p_line_length && is_spacing(p_line[ptr])) ptr++; + if (ptr != p_line_length) throw exception_cue("invalid SONGWRITER syntax",0); + p_callback.on_songwriter(p_line+base,length); + } + else + { + p_callback.on_songwriter(p_line+ptr,p_line_length-ptr); + } + } + else if (!stricmp_utf8_ex(p_line,ptr,"isrc",infinite)) + { + while(ptr < p_line_length && is_spacing(p_line[ptr])) ptr++; + t_size length = p_line_length - ptr; + if (length == 0) throw exception_cue("invalid ISRC syntax",0); + p_callback.on_isrc(p_line+ptr,length); + } + else if (!stricmp_utf8_ex(p_line,ptr,"catalog",infinite)) + { + while(ptr < p_line_length && is_spacing(p_line[ptr])) ptr++; + t_size length = p_line_length - ptr; + if (length == 0) throw exception_cue("invalid CATALOG syntax",0); + p_callback.on_catalog(p_line+ptr,length); + } + else if (!stricmp_utf8_ex(p_line,ptr,"flags",infinite)) + { + while(ptr < p_line_length && is_spacing(p_line[ptr])) ptr++; + if (ptr < p_line_length) + p_callback.on_flags(p_line + ptr, p_line_length - ptr); + } + else if (!stricmp_utf8_ex(p_line,ptr,"rem",infinite)) + { + while(ptr < p_line_length && is_spacing(p_line[ptr])) ptr++; + if (ptr < p_line_length) + p_callback.on_comment(p_line + ptr, p_line_length - ptr); + } + else if (!stricmp_utf8_ex(p_line,ptr,"postgap",infinite)) { + throw exception_cue("POSTGAP is not supported",0); + } else if (!stricmp_utf8_ex(p_line,ptr,"cdtextfile",infinite)) { + //do nothing + } + else throw exception_cue("unknown cuesheet item",0); +} + +static void g_parse_cue(const char * p_cuesheet,cue_parser_callback & p_callback) +{ + const char * parseptr = p_cuesheet; + t_size lineidx = 1; + while(*parseptr) + { + while(is_spacing(*parseptr)) *parseptr++; + if (*parseptr) + { + t_size length = 0; + while(parseptr[length] && !is_linebreak(parseptr[length])) length++; + if (length > 0) { + try { + g_parse_cue_line(parseptr,length,p_callback); + } catch(exception_cue const & e) {//rethrow with line info + throw exception_cue(pfc::string_formatter() << e.what() << " (line " << lineidx << ")"); + } + } + parseptr += length; + while(is_linebreak(*parseptr)) { + if (*parseptr == '\n') lineidx++; + parseptr++; + } + } + } +} + +void cue_parser::parse(const char *p_cuesheet,t_cue_entry_list & p_out) { + try { + cue_parser_callback_retrievelist callback(p_out); + g_parse_cue(p_cuesheet,callback); + callback.finalize(); + } catch(exception_cue const & e) { + throw exception_bad_cuesheet(pfc::string_formatter() << "Error parsing cuesheet: " << e.what()); + } +} +void cue_parser::parse_info(const char * p_cuesheet,file_info & p_info,unsigned p_index) { + try { + cue_parser_callback_retrieveinfo callback(p_info,p_index); + g_parse_cue(p_cuesheet,callback); + callback.finalize(); + } catch(exception_cue const & e) { + throw exception_bad_cuesheet(pfc::string_formatter() << "Error parsing cuesheet: " << e.what()); + } +} + +namespace { + + class cue_parser_callback_retrievecount : public cue_parser_callback + { + public: + cue_parser_callback_retrievecount() : m_count(0) {} + unsigned get_count() const {return m_count;} + void on_file(const char * p_file,t_size p_file_length,const char * p_type,t_size p_type_length) {} + void on_track(unsigned p_index,const char * p_type,t_size p_type_length) {m_count++;} + void on_pregap(unsigned p_value) {} + void on_index(unsigned p_index,unsigned p_value) {} + void on_title(const char * p_title,t_size p_title_length) {} + void on_performer(const char * p_performer,t_size p_performer_length) {} + void on_isrc(const char * p_isrc,t_size p_isrc_length) {} + void on_catalog(const char * p_catalog,t_size p_catalog_length) {} + void on_comment(const char * p_comment,t_size p_comment_length) {} + void on_flags(const char * p_flags,t_size p_flags_length) {} + private: + unsigned m_count; + }; + + class cue_parser_callback_retrievecreatorentries : public cue_parser_callback + { + public: + cue_parser_callback_retrievecreatorentries(cue_creator::t_entry_list & p_out) : m_out(p_out), m_track(0), m_pregap(0), m_index0_set(false), m_index1_set(false) {} + + void on_file(const char * p_file,t_size p_file_length,const char * p_type,t_size p_type_length) { + validate_file_type(p_type,p_type_length); + m_file.set_string(p_file,p_file_length); + } + + void on_track(unsigned p_index,const char * p_type,t_size p_type_length) + { + if (stricmp_utf8_ex(p_type,p_type_length,"audio",infinite)) throw exception_cue("only tracks of type AUDIO supported",0); + //if (p_index != m_track + 1) throw exception_cue("cuesheet tracks out of order",0); + if (m_track != 0) finalize_track(); + if (m_file.is_empty()) throw exception_cue("declaring a track with no file set",0); + m_trackfile = m_file; + m_track = p_index; + } + + void on_pregap(unsigned p_value) + { + m_pregap = (double) p_value / 75.0; + } + + void on_index(unsigned p_index,unsigned p_value) + { + if (p_index < t_cuesheet_index_list::count) + { + switch(p_index) + { + case 0: m_index0_set = true; break; + case 1: m_index1_set = true; break; + } + m_indexes.m_positions[p_index] = (double) p_value / 75.0; + } + } + void on_title(const char * p_title,t_size p_title_length) {} + void on_performer(const char * p_performer,t_size p_performer_length) {} + void on_songwriter(const char * p_performer,t_size p_performer_length) {} + void on_isrc(const char * p_isrc,t_size p_isrc_length) {} + void on_catalog(const char * p_catalog,t_size p_catalog_length) {} + void on_comment(const char * p_comment,t_size p_comment_length) {} + void finalize() + { + if (m_track != 0) + { + finalize_track(); + m_track = 0; + } + } + void on_flags(const char * p_flags,t_size p_flags_length) { + m_flags.set_string(p_flags,p_flags_length); + } + private: + void finalize_track() + { + if (m_track < 1 || m_track > 99) throw exception_cue("track number out of range",0); + if (!m_index1_set) throw exception_cue("INDEX 01 not set",0); + if (!m_index0_set) m_indexes.m_positions[0] = m_indexes.m_positions[1] - m_pregap; + if (!m_indexes.is_valid()) throw exception_cue("invalid index list"); + + cue_creator::t_entry_list::iterator iter; + iter = m_out.insert_last(); + iter->m_track_number = m_track; + iter->m_file = m_trackfile; + iter->m_index_list = m_indexes; + iter->m_flags = m_flags; + m_pregap = 0; + m_indexes.reset(); + m_index0_set = m_index1_set = false; + m_flags.reset(); + } + + bool m_index0_set,m_index1_set; + double m_pregap; + unsigned m_track; + cue_creator::t_entry_list & m_out; + pfc::string8 m_file,m_trackfile,m_flags; + t_cuesheet_index_list m_indexes; + }; +} + +void cue_parser::parse_full(const char * p_cuesheet,cue_creator::t_entry_list & p_out) { + try { + { + cue_parser_callback_retrievecreatorentries callback(p_out); + g_parse_cue(p_cuesheet,callback); + callback.finalize(); + } + + { + cue_creator::t_entry_list::iterator iter; + for(iter=p_out.first();iter.is_valid();++iter) + { + cue_parser_callback_retrieveinfo callback(iter->m_infos,iter->m_track_number); + g_parse_cue(p_cuesheet,callback); + callback.finalize(); + } + } + } catch(exception_cue const & e) { + throw exception_bad_cuesheet(pfc::string_formatter() << "Error parsing cuesheet: " << e.what()); + } +} diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/cue_parser.h b/tools/vio2sf/src/foobar/foobar2000/helpers/cue_parser.h new file mode 100644 index 000000000..92f546bbf --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/cue_parser.h @@ -0,0 +1,445 @@ +//HINT: for info on how to generate an embedded cuesheet enabled input, see the end of this header. + +//to be moved somewhere else later +namespace file_info_record_helper { + + class __file_info_record__info__enumerator { + public: + __file_info_record__info__enumerator(file_info & p_out) : m_out(p_out) {} + void operator() (const char * p_name,const char * p_value) {m_out.__info_add_unsafe(p_name,p_value);} + private: + file_info & m_out; + }; + + class __file_info_record__meta__enumerator { + public: + __file_info_record__meta__enumerator(file_info & p_out) : m_out(p_out) {} + template void operator() (const char * p_name,const t_value & p_value) { + t_size index = infinite; + for(typename t_value::const_iterator iter = p_value.first(); iter.is_valid(); ++iter) { + if (index == infinite) index = m_out.__meta_add_unsafe(p_name,*iter); + else m_out.meta_add_value(index,*iter); + } + } + private: + file_info & m_out; + }; + + class file_info_record { + public: + typedef pfc::chain_list_v2_t t_meta_value; + typedef pfc::map_t t_meta_map; + typedef pfc::map_t t_info_map; + + file_info_record() : m_replaygain(replaygain_info_invalid), m_length(0) {} + + replaygain_info get_replaygain() const {return m_replaygain;} + void set_replaygain(const replaygain_info & p_replaygain) {m_replaygain = p_replaygain;} + double get_length() const {return m_length;} + void set_length(double p_length) {m_length = p_length;} + + void reset() { + m_meta.remove_all(); m_info.remove_all(); + m_length = 0; + m_replaygain = replaygain_info_invalid; + } + + void from_info_overwrite_info(const file_info & p_info) { + for(t_size infowalk = 0, infocount = p_info.info_get_count(); infowalk < infocount; ++infowalk) { + m_info.set(p_info.info_enum_name(infowalk),p_info.info_enum_value(infowalk)); + } + } + void from_info_overwrite_meta(const file_info & p_info) { + for(t_size metawalk = 0, metacount = p_info.meta_get_count(); metawalk < metacount; ++metawalk) { + const t_size valuecount = p_info.meta_enum_value_count(metawalk); + if (valuecount > 0) { + t_meta_value & entry = m_meta.find_or_add(p_info.meta_enum_name(metawalk)); + entry.remove_all(); + for(t_size valuewalk = 0; valuewalk < valuecount; ++valuewalk) { + entry.add_item(p_info.meta_enum_value(metawalk,valuewalk)); + } + } + } + } + + void from_info_overwrite_rg(const file_info & p_info) { + m_replaygain = replaygain_info::g_merge(m_replaygain,p_info.get_replaygain()); + } + + template + void overwrite_meta(const t_source & p_meta) { + m_meta.overwrite(p_meta); + } + template + void overwrite_info(const t_source & p_info) { + m_info.overwrite(p_info); + } + + void merge_overwrite(const file_info & p_info) { + from_info_overwrite_info(p_info); + from_info_overwrite_meta(p_info); + from_info_overwrite_rg(p_info); + } + + void transfer_meta_entry(const char * p_name,const file_info & p_info,t_size p_index) { + const t_size count = p_info.meta_enum_value_count(p_index); + if (count == 0) { + m_meta.remove(p_name); + } else { + t_meta_value & val = m_meta.find_or_add(p_name); + val.remove_all(); + for(t_size walk = 0; walk < count; ++walk) { + val.add_item(p_info.meta_enum_value(p_index,walk)); + } + } + } + + void meta_set(const char * p_name,const char * p_value) { + m_meta.find_or_add(p_name).set_single(p_value); + } + + const t_meta_value * meta_query_ptr(const char * p_name) const { + return m_meta.query_ptr(p_name); + } + + + void from_info_set_meta(const file_info & p_info) { + m_meta.remove_all(); + from_info_overwrite_meta(p_info); + } + + void from_info(const file_info & p_info) { + reset(); + m_length = p_info.get_length(); + m_replaygain = p_info.get_replaygain(); + from_info_overwrite_meta(p_info); + from_info_overwrite_info(p_info); + } + void to_info(file_info & p_info) const { + p_info.reset(); + p_info.set_length(m_length); + p_info.set_replaygain(m_replaygain); + m_info.enumerate(__file_info_record__info__enumerator(p_info)); + m_meta.enumerate(__file_info_record__meta__enumerator(p_info)); + } + + template void enumerate_meta(t_callback & p_callback) const {m_meta.enumerate(p_callback);} + template void enumerate_meta(t_callback & p_callback) {m_meta.enumerate(p_callback);} + + //private: + t_meta_map m_meta; + t_info_map m_info; + replaygain_info m_replaygain; + double m_length; + }; + +}//namespace file_info_record_helper + + +namespace cue_parser +{ + struct cue_entry { + pfc::string8 m_file; + unsigned m_track_number; + t_cuesheet_index_list m_indexes; + }; + + typedef pfc::chain_list_v2_t t_cue_entry_list; + + + PFC_DECLARE_EXCEPTION(exception_bad_cuesheet,exception_io_data,"Invalid cuesheet"); + + //! Throws exception_bad_cuesheet on failure. + void parse(const char *p_cuesheet,t_cue_entry_list & p_out); + //! Throws exception_bad_cuesheet on failure. + void parse_info(const char *p_cuesheet,file_info & p_info,unsigned p_index); + //! Throws exception_bad_cuesheet on failure. + void parse_full(const char * p_cuesheet,cue_creator::t_entry_list & p_out); + + + + struct track_record { + file_info_record_helper::file_info_record m_info; + pfc::string8 m_file,m_flags; + t_cuesheet_index_list m_index_list; + }; + + typedef pfc::map_t track_record_list; + + class embeddedcue_metadata_manager { + public: + void get_tag(file_info & p_info) const; + void set_tag(file_info const & p_info); + + void get_track_info(unsigned p_track,file_info & p_info) const; + void set_track_info(unsigned p_track,file_info const & p_info); + void query_track_offsets(unsigned p_track,double & p_begin,double & p_length) const; + bool have_cuesheet() const; + unsigned remap_trackno(unsigned p_index) const; + t_size get_cue_track_count() const; + private: + track_record_list m_content; + }; + + + + + + + class _decoder_wrapper { + public: + virtual bool run(audio_chunk & p_chunk,abort_callback & p_abort) = 0; + virtual void seek(double p_seconds,abort_callback & p_abort) = 0; + virtual bool get_dynamic_info(file_info & p_out, double & p_timestamp_delta) = 0; + virtual bool get_dynamic_info_track(file_info & p_out, double & p_timestamp_delta) = 0; + virtual void on_idle(abort_callback & p_abort) = 0; + virtual bool run_raw(audio_chunk & p_chunk, mem_block_container & p_raw, abort_callback & p_abort) = 0; + virtual void set_logger(event_logger::ptr ptr) = 0; + virtual ~_decoder_wrapper() {} + }; + + template + class _decoder_wrapper_simple : public _decoder_wrapper { + public: + void initialize(service_ptr_t p_filehint,const char * p_path,unsigned p_flags,abort_callback & p_abort) { + m_input.open(p_filehint,p_path,input_open_decode,p_abort); + m_input.decode_initialize(p_flags,p_abort); + } + bool run(audio_chunk & p_chunk,abort_callback & p_abort) {return m_input.decode_run(p_chunk,p_abort);} + void seek(double p_seconds,abort_callback & p_abort) {m_input.decode_seek(p_seconds,p_abort);} + bool get_dynamic_info(file_info & p_out, double & p_timestamp_delta) {return m_input.decode_get_dynamic_info(p_out,p_timestamp_delta);} + bool get_dynamic_info_track(file_info & p_out, double & p_timestamp_delta) {return m_input.decode_get_dynamic_info_track(p_out,p_timestamp_delta);} + void on_idle(abort_callback & p_abort) {m_input.decode_on_idle(p_abort);} + bool run_raw(audio_chunk & p_chunk, mem_block_container & p_raw, abort_callback & p_abort) {return m_input.decode_run_raw(p_chunk, p_raw, p_abort);} + void set_logger(event_logger::ptr ptr) {m_input.set_logger(ptr);} + private: + t_input m_input; + }; + + class _decoder_wrapper_cue : public _decoder_wrapper { + public: + void open(service_ptr_t p_filehint,const playable_location & p_location,unsigned p_flags,abort_callback & p_abort,double p_start,double p_length) { + m_input.open(p_filehint,p_location,p_flags,p_abort,p_start,p_length); + } + bool run(audio_chunk & p_chunk,abort_callback & p_abort) {return m_input.run(p_chunk,p_abort);} + void seek(double p_seconds,abort_callback & p_abort) {m_input.seek(p_seconds,p_abort);} + bool get_dynamic_info(file_info & p_out, double & p_timestamp_delta) {return m_input.get_dynamic_info(p_out,p_timestamp_delta);} + bool get_dynamic_info_track(file_info & p_out, double & p_timestamp_delta) {return m_input.get_dynamic_info_track(p_out,p_timestamp_delta);} + void on_idle(abort_callback & p_abort) {m_input.on_idle(p_abort);} + bool run_raw(audio_chunk & p_chunk, mem_block_container & p_raw, abort_callback & p_abort) {return m_input.run_raw(p_chunk, p_raw, p_abort);} + void set_logger(event_logger::ptr ptr) {m_input.set_logger(ptr);} + private: + input_helper_cue m_input; + }; + + template + class input_wrapper_cue_t { + public: + input_wrapper_cue_t() {} + ~input_wrapper_cue_t() {} + + void open(service_ptr_t p_filehint,const char * p_path,t_input_open_reason p_reason,abort_callback & p_abort) { + m_path = p_path; + + m_file = p_filehint; + input_open_file_helper(m_file,p_path,p_reason,p_abort); + + { + file_info_impl info; + t_base instance; + instance.open(m_file,p_path,p_reason,p_abort); + instance.get_info(info,p_abort); + m_meta.set_tag(info); + } + } + + t_uint32 get_subsong_count() { + return m_meta.have_cuesheet() ? m_meta.get_cue_track_count() : 1; + } + + t_uint32 get_subsong(t_uint32 p_index) { + return m_meta.have_cuesheet() ? m_meta.remap_trackno(p_index) : 0; + } + + void get_info(t_uint32 p_subsong,file_info & p_info,abort_callback & p_abort) { + if (p_subsong == 0) { + m_meta.get_tag(p_info); + } else { + m_meta.get_track_info(p_subsong,p_info); + } + } + + t_filestats get_file_stats(abort_callback & p_abort) {return m_file->get_stats(p_abort);} + + void decode_initialize(t_uint32 p_subsong,unsigned p_flags,abort_callback & p_abort) { + m_decoder.release(); + if (p_subsong == 0) { + pfc::rcptr_t<_decoder_wrapper_simple > temp; + temp.new_t(); + m_file->reopen(p_abort); + temp->initialize(m_file,m_path,p_flags,p_abort); + m_decoder = temp; + } else { + double start,length; + m_meta.query_track_offsets(p_subsong,start,length); + + pfc::rcptr_t<_decoder_wrapper_cue> temp; + temp.new_t(); + m_file->reopen(p_abort); + temp->open(m_file,make_playable_location(m_path,0),p_flags & ~input_flag_no_seeking,p_abort,start,length); + m_decoder = temp; + } + if (m_logger.is_valid()) m_decoder->set_logger(m_logger); + } + + bool decode_run(audio_chunk & p_chunk,abort_callback & p_abort) { + return m_decoder->run(p_chunk,p_abort); + } + + void decode_seek(double p_seconds,abort_callback & p_abort) { + m_decoder->seek(p_seconds,p_abort); + } + + bool decode_can_seek() {return true;} + + bool decode_run_raw(audio_chunk & p_chunk, mem_block_container & p_raw, abort_callback & p_abort) { + return m_decoder->run_raw(p_chunk, p_raw, p_abort); + } + void set_logger(event_logger::ptr ptr) { + m_logger = ptr; + if (m_decoder.is_valid()) m_decoder->set_logger(ptr); + } + + bool decode_get_dynamic_info(file_info & p_out, double & p_timestamp_delta) { + return m_decoder->get_dynamic_info(p_out,p_timestamp_delta); + } + + bool decode_get_dynamic_info_track(file_info & p_out, double & p_timestamp_delta) { + return m_decoder->get_dynamic_info_track(p_out,p_timestamp_delta); + } + + void decode_on_idle(abort_callback & p_abort) { + m_decoder->on_idle(p_abort); + } + + void retag_set_info(t_uint32 p_subsong,const file_info & p_info,abort_callback & p_abort) { + pfc::dynamic_assert(m_decoder.is_empty()); + if (p_subsong == 0) { + m_meta.set_tag(p_info); + } else { + m_meta.set_track_info(p_subsong,p_info); + } + } + + void retag_commit(abort_callback & p_abort) { + pfc::dynamic_assert(m_decoder.is_empty()); + + file_info_impl info; + m_meta.get_tag(info); + + { + t_base instance; + m_file->reopen(p_abort); + instance.open(m_file,m_path,input_open_info_write,p_abort); + instance.retag(pfc::safe_cast(info),p_abort); + info.reset(); + instance.get_info(info,p_abort); + m_meta.set_tag(info); + } + } + + inline static bool g_is_our_content_type(const char * p_content_type) {return t_base::g_is_our_content_type(p_content_type);} + inline static bool g_is_our_path(const char * p_path,const char * p_extension) {return t_base::g_is_our_path(p_path,p_extension);} + + private: + pfc::rcptr_t<_decoder_wrapper> m_decoder; + + file_info_impl m_info; + pfc::string8 m_path; + service_ptr_t m_file; + + embeddedcue_metadata_manager m_meta; + event_logger::ptr m_logger; + }; + + template + class chapterizer_impl_t : public chapterizer + { + public: + bool is_our_file(const char * p_path,abort_callback & p_abort) + { + return I::g_is_our_path(p_path,pfc::string_extension(p_path)); + } + + void set_chapters(const char * p_path,chapter_list const & p_list,abort_callback & p_abort) { + + + input_wrapper_cue_t instance; + instance.open(0,p_path,input_open_info_write,p_abort); + + //stamp the cuesheet first + { + file_info_impl info; + instance.get_info(0,info,p_abort); + + pfc::string_formatter cuesheet; + + { + cue_creator::t_entry_list entries; + t_size n, m = p_list.get_chapter_count(); + + double offset_acc = 0; + for(n=0;nm_infos = p_list.get_info(n); + entry->m_file = "CDImage.wav"; + entry->m_track_number = (unsigned)(n+1); + entry->m_index_list.from_infos(entry->m_infos,offset_acc); + offset_acc += entry->m_infos.get_length(); + } + cue_creator::create(cuesheet,entries); + } + + info.meta_set("cuesheet",cuesheet); + + instance.retag_set_info(0,info,p_abort); + } + //stamp per-chapter infos + for(t_size walk = 0, total = p_list.get_chapter_count(); walk < total; ++walk) { + instance.retag_set_info(walk + 1, p_list.get_info(walk),p_abort); + } + + instance.retag_commit(p_abort); + } + + void get_chapters(const char * p_path,chapter_list & p_list,abort_callback & p_abort) { + + input_wrapper_cue_t instance; + + + instance.open(0,p_path,input_open_info_read,p_abort); + + const t_uint32 total = instance.get_subsong_count(); + + p_list.set_chapter_count(total); + for(t_uint32 walk = 0; walk < total; ++walk) { + file_info_impl info; + instance.get_info(instance.get_subsong(walk),info,p_abort); + p_list.set_info(walk,info); + } + } + }; + +}; + +//! Wrapper template for generating embedded cuesheet enabled inputs. +//! t_input_impl is a singletrack input implementation (see input_singletrack_impl for method declarations). +//! To declare an embedded cuesheet enabled input, change your input declaration from input_singletrack_factory_t to input_cuesheet_factory_t. +template +class input_cuesheet_factory_t { +public: + input_factory_ex_t,0,input_decoder_v2> m_input_factory; + service_factory_single_t > m_chapterizer_factory; +}; \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/cue_parser_embedding.cpp b/tools/vio2sf/src/foobar/foobar2000/helpers/cue_parser_embedding.cpp new file mode 100644 index 000000000..41719f2e3 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/cue_parser_embedding.cpp @@ -0,0 +1,358 @@ +#include "stdafx.h" + +using namespace cue_parser; +using namespace file_info_record_helper; +static void build_cue_meta_name(const char * p_name,unsigned p_tracknumber,pfc::string_base & p_out) { + p_out.reset(); + p_out << "cue_track" << pfc::format_uint(p_tracknumber % 100,2) << "_" << p_name; +} + +static bool is_reserved_meta_entry(const char * p_name) { + return file_info::field_name_comparator::compare(p_name,"cuesheet") == 0; +} + +static bool is_global_meta_entry(const char * p_name) { + static const char header[] = "cue_track"; + return pfc::stricmp_ascii_ex(p_name,strlen(header),header,infinite) != 0; +} +static bool is_allowed_field(const char * p_name) { + return !is_reserved_meta_entry(p_name) && is_global_meta_entry(p_name); +} +namespace { + class __get_tag_cue_track_list_builder { + public: + __get_tag_cue_track_list_builder(cue_creator::t_entry_list & p_entries) : m_entries(p_entries) {} + void operator() (unsigned p_trackno,const track_record & p_record) { + if (p_trackno > 0) { + cue_creator::t_entry_list::iterator iter = m_entries.insert_last(); + iter->m_file = p_record.m_file; + iter->m_flags = p_record.m_flags; + iter->m_index_list = p_record.m_index_list; + iter->m_track_number = p_trackno; + p_record.m_info.to_info(iter->m_infos); + } + } + private: + cue_creator::t_entry_list & m_entries; + }; + + typedef pfc::avltree_t field_name_list; + + class __get_tag__enum_fields_enumerator { + public: + __get_tag__enum_fields_enumerator(field_name_list & p_out) : m_out(p_out) {} + void operator() (unsigned p_trackno,const track_record & p_record) { + if (p_trackno > 0) p_record.m_info.enumerate_meta(*this); + } + template void operator() (const char * p_name,const t_value & p_value) { + m_out.add(p_name); + } + private: + field_name_list & m_out; + }; + + + class __get_tag__is_field_global_check { + private: + typedef file_info_record::t_meta_value t_value; + public: + __get_tag__is_field_global_check(const char * p_field) : m_field(p_field), m_value(NULL), m_state(true) {} + + void operator() (unsigned p_trackno,const track_record & p_record) { + if (p_trackno > 0 && m_state) { + const t_value * val = p_record.m_info.meta_query_ptr(m_field); + if (val == NULL) {m_state = false; return;} + if (m_value == NULL) { + m_value = val; + } else { + if (pfc::comparator_list::compare(*m_value,*val) != 0) { + m_state = false; return; + } + } + } + } + void finalize(file_info_record::t_meta_map & p_globals) { + if (m_state && m_value != NULL) { + p_globals.set(m_field,*m_value); + } + } + private: + const char * const m_field; + const t_value * m_value; + bool m_state; + }; + + class __get_tag__filter_globals { + public: + __get_tag__filter_globals(track_record_list const & p_tracks,file_info_record::t_meta_map & p_globals) : m_tracks(p_tracks), m_globals(p_globals) {} + + void operator() (const char * p_field) { + if (is_allowed_field(p_field)) { + __get_tag__is_field_global_check wrapper(p_field); + m_tracks.enumerate(wrapper); + wrapper.finalize(m_globals); + } + } + private: + const track_record_list & m_tracks; + file_info_record::t_meta_map & m_globals; + }; + + class __get_tag__local_field_filter { + public: + __get_tag__local_field_filter(const file_info_record::t_meta_map & p_globals,file_info_record::t_meta_map & p_output) : m_globals(p_globals), m_output(p_output), m_currenttrack(0) {} + void operator() (unsigned p_trackno,const track_record & p_track) { + if (p_trackno > 0) { + m_currenttrack = p_trackno; + p_track.m_info.enumerate_meta(*this); + } + } + void operator() (const char * p_name,const file_info_record::t_meta_value & p_value) { + PFC_ASSERT(m_currenttrack > 0); + if (!m_globals.have_item(p_name)) { + build_cue_meta_name(p_name,m_currenttrack,m_buffer); + m_output.set(m_buffer,p_value); + } + } + private: + unsigned m_currenttrack; + pfc::string8_fastalloc m_buffer; + const file_info_record::t_meta_map & m_globals; + file_info_record::t_meta_map & m_output; + }; +}; + +static void strip_redundant_track_meta(unsigned p_tracknumber,const file_info & p_cueinfo,file_info_record::t_meta_map & p_meta,const char * p_metaname) { + t_size metaindex = p_cueinfo.meta_find(p_metaname); + if (metaindex == infinite) return; + pfc::string_formatter namelocal; + build_cue_meta_name(p_metaname,p_tracknumber,namelocal); + { + const file_info_record::t_meta_value * val = p_meta.query_ptr(namelocal); + if (val == NULL) return; + file_info_record::t_meta_value::const_iterator iter = val->first(); + for(t_size valwalk = 0, valcount = p_cueinfo.meta_enum_value_count(metaindex); valwalk < valcount; ++valwalk) { + if (iter.is_empty()) return; + if (strcmp(*iter,p_cueinfo.meta_enum_value(metaindex,valwalk)) != 0) return; + ++iter; + } + if (!iter.is_empty()) return; + } + //success + p_meta.remove(namelocal); +} + +void embeddedcue_metadata_manager::get_tag(file_info & p_info) const { + if (!have_cuesheet()) { + m_content.query_ptr((unsigned)0)->m_info.to_info(p_info); + p_info.meta_remove_field("cuesheet"); + } else { + cue_creator::t_entry_list entries; + m_content.enumerate(__get_tag_cue_track_list_builder(entries)); + pfc::string_formatter cuesheet; + cue_creator::create(cuesheet,entries); + entries.remove_all(); + //parse it back to see what info got stored in the cuesheet and what needs to be stored outside cuesheet in the tags + cue_parser::parse_full(cuesheet,entries); + file_info_record output; + + + + + { + file_info_record::t_meta_map globals; + //1. find global infos and forward them + { + field_name_list fields; + m_content.enumerate(__get_tag__enum_fields_enumerator(fields)); + fields.enumerate(__get_tag__filter_globals(m_content,globals)); + } + + output.overwrite_meta(globals); + + //2. find local infos + m_content.enumerate(__get_tag__local_field_filter(globals,output.m_meta)); + } + + + //strip redundant titles and tracknumbers that the cuesheet already contains + for(cue_creator::t_entry_list::const_iterator iter = entries.first(); iter.is_valid(); ++iter) { + strip_redundant_track_meta(iter->m_track_number,iter->m_infos,output.m_meta,"tracknumber"); + strip_redundant_track_meta(iter->m_track_number,iter->m_infos,output.m_meta,"title"); + } + + + //add tech infos etc + + { + const track_record * rec = m_content.query_ptr((unsigned)0); + if (rec != NULL) { + output.set_length(rec->m_info.get_length()); + output.set_replaygain(rec->m_info.get_replaygain()); + output.overwrite_info(rec->m_info.m_info); + } + } + output.meta_set("cuesheet",cuesheet); + output.to_info(p_info); + } +} + +static bool resolve_cue_meta_name(const char * p_name,pfc::string_base & p_outname,unsigned & p_tracknumber) { + //"cue_trackNN_fieldname" + static const char header[] = "cue_track"; + if (pfc::stricmp_ascii_ex(p_name,strlen(header),header,infinite) != 0) return false; + p_name += strlen(header); + if (!pfc::char_is_numeric(p_name[0]) || !pfc::char_is_numeric(p_name[1]) || p_name[2] != '_') return false; + unsigned tracknumber = pfc::atoui_ex(p_name,2); + if (tracknumber == 0) return false; + p_name += 3; + p_tracknumber = tracknumber; + p_outname = p_name; + return true; +} + + +namespace { + class __set_tag_global_field_relay { + public: + __set_tag_global_field_relay(const file_info & p_info,t_size p_index) : m_info(p_info), m_index(p_index) {} + void operator() (unsigned p_trackno,track_record & p_record) { + if (p_trackno > 0) { + p_record.m_info.transfer_meta_entry(m_info.meta_enum_name(m_index),m_info,m_index); + } + } + private: + const file_info & m_info; + const t_size m_index; + }; +} + +void embeddedcue_metadata_manager::set_tag(file_info const & p_info) { + m_content.remove_all(); + + { + track_record & track0 = m_content.find_or_add((unsigned)0); + track0.m_info.from_info(p_info); + track0.m_info.m_info.set("cue_embedded","no"); + } + + + + const char * cuesheet = p_info.meta_get("cuesheet",0); + if (cuesheet == NULL) { + return; + } + + //processing order + //1. cuesheet content + //2. overwrite with global metadata from the tag + //2. overwrite with local metadata from the tag + + { + cue_creator::t_entry_list entries; + try { + cue_parser::parse_full(cuesheet,entries); + } catch(exception_io_data const & e) { + console::print(e.what()); + return; + } + + for(cue_creator::t_entry_list::const_iterator iter = entries.first(); iter.is_valid(); ) { + cue_creator::t_entry_list::const_iterator next = iter; + ++next; + track_record & entry = m_content.find_or_add(iter->m_track_number); + entry.m_file = iter->m_file; + entry.m_flags = iter->m_flags; + entry.m_index_list = iter->m_index_list; + entry.m_info.from_info(iter->m_infos); + entry.m_info.from_info_overwrite_info(p_info); + entry.m_info.m_info.set("cue_embedded","yes"); + double begin = entry.m_index_list.start(), end = next.is_valid() ? next->m_index_list.start() : p_info.get_length(); + if (end <= begin) throw exception_io_data(); + entry.m_info.set_length(end - begin); + iter = next; + } + } + + for(t_size metawalk = 0, metacount = p_info.meta_get_count(); metawalk < metacount; ++metawalk) { + const char * name = p_info.meta_enum_name(metawalk); + const t_size valuecount = p_info.meta_enum_value_count(metawalk); + if (valuecount > 0 && !is_reserved_meta_entry(name) && is_global_meta_entry(name)) { + __set_tag_global_field_relay relay(p_info,metawalk); + m_content.enumerate(relay); + } + } + + { + pfc::string8_fastalloc namebuffer; + for(t_size metawalk = 0, metacount = p_info.meta_get_count(); metawalk < metacount; ++metawalk) { + const char * name = p_info.meta_enum_name(metawalk); + const t_size valuecount = p_info.meta_enum_value_count(metawalk); + unsigned trackno; + if (valuecount > 0 && !is_reserved_meta_entry(name) && resolve_cue_meta_name(name,namebuffer,trackno)) { + track_record * rec = m_content.query_ptr(trackno); + if (rec != NULL) { + rec->m_info.transfer_meta_entry(namebuffer,p_info,metawalk); + } + } + } + } +} + +void embeddedcue_metadata_manager::get_track_info(unsigned p_track,file_info & p_info) const { + const track_record * rec = m_content.query_ptr(p_track); + if (rec == NULL) throw exception_io_data(); + rec->m_info.to_info(p_info); +} + +void embeddedcue_metadata_manager::set_track_info(unsigned p_track,file_info const & p_info) { + track_record * rec = m_content.query_ptr(p_track); + if (rec == NULL) throw exception_io_data(); + rec->m_info.from_info_set_meta(p_info); + rec->m_info.set_replaygain(p_info.get_replaygain()); +} + +void embeddedcue_metadata_manager::query_track_offsets(unsigned p_track,double & p_begin,double & p_length) const { + const track_record * rec = m_content.query_ptr(p_track); + if (rec == NULL) throw exception_io_data(); + p_begin = rec->m_index_list.start(); + p_length = rec->m_info.get_length(); +} + +bool embeddedcue_metadata_manager::have_cuesheet() const { + return m_content.get_count() > 1; +} + +namespace { + class __remap_trackno_enumerator { + public: + __remap_trackno_enumerator(unsigned p_index) : m_countdown(p_index), m_result(0) {} + template void operator() (unsigned p_trackno,const t_blah&) { + if (p_trackno > 0 && m_result == 0) { + if (m_countdown == 0) { + m_result = p_trackno; + } else { + --m_countdown; + } + } + } + unsigned result() const {return m_result;} + private: + unsigned m_countdown; + unsigned m_result; + }; +}; + +unsigned embeddedcue_metadata_manager::remap_trackno(unsigned p_index) const { + if (have_cuesheet()) { + __remap_trackno_enumerator wrapper(p_index); + m_content.enumerate(wrapper); + return wrapper.result(); + } else { + return 0; + } +} + +t_size embeddedcue_metadata_manager::get_cue_track_count() const { + return m_content.get_count() - 1; +} \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/cuesheet_index_list.cpp b/tools/vio2sf/src/foobar/foobar2000/helpers/cuesheet_index_list.cpp new file mode 100644 index 000000000..5f9700876 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/cuesheet_index_list.cpp @@ -0,0 +1,139 @@ +#include "stdafx.h" + +static bool is_numeric(char c) {return c>='0' && c<='9';} + + +bool t_cuesheet_index_list::is_valid() const { + if (m_positions[1] < m_positions[0]) return false; + for(t_size n = 2; n < count && m_positions[n] > 0; n++) { + if (m_positions[n] < m_positions[n-1]) return false; + } + return true; +} + +void t_cuesheet_index_list::to_infos(file_info & p_out) const +{ + double base = m_positions[1]; + + if (base > 0) { + p_out.info_set("referenced_offset",cuesheet_format_index_time(base)); + } + + if (m_positions[0] < base) + p_out.info_set("pregap",cuesheet_format_index_time(base - m_positions[0])); + else + p_out.info_remove("pregap"); + + p_out.info_remove("index 00"); + p_out.info_remove("index 01"); + + for(unsigned n=2;n 0) + p_out.info_set(namebuffer,cuesheet_format_index_time(position)); + else + p_out.info_remove(namebuffer); + } +} + +static bool parse_value(const char * p_name,double & p_out) +{ + if (p_name == NULL) return false; + try { + p_out = cuesheet_parse_index_time_e(p_name,strlen(p_name)); + } catch(std::exception const &) {return false;} + return true; +} + +bool t_cuesheet_index_list::from_infos(file_info const & p_in,double p_base) +{ + double pregap; + bool found = false; + if (!parse_value(p_in.info_get("pregap"),pregap)) pregap = 0; + else found = true; + m_positions[0] = p_base - pregap; + m_positions[1] = p_base; + for(unsigned n=2;n= 2) throw std::exception("invalid INDEX time syntax",0); + splitmarks[splitptr++] = ptr; + } + else if (!is_numeric(p_string[ptr])) throw std::exception("invalid INDEX time syntax",0); + } + + t_size minutes_base = 0, minutes_length = 0, seconds_base = 0, seconds_length = 0, frames_base = 0, frames_length = 0; + + switch(splitptr) + { + case 0: + frames_base = 0; + frames_length = p_length; + break; + case 1: + seconds_base = 0; + seconds_length = splitmarks[0]; + frames_base = splitmarks[0] + 1; + frames_length = p_length - frames_base; + break; + case 2: + minutes_base = 0; + minutes_length = splitmarks[0]; + seconds_base = splitmarks[0] + 1; + seconds_length = splitmarks[1] - seconds_base; + frames_base = splitmarks[1] + 1; + frames_length = p_length - frames_base; + break; + } + + unsigned ret = 0; + + if (frames_length > 0) ret += pfc::atoui_ex(p_string + frames_base,frames_length); + if (seconds_length > 0) ret += 75 * pfc::atoui_ex(p_string + seconds_base,seconds_length); + if (minutes_length > 0) ret += 60 * 75 * pfc::atoui_ex(p_string + minutes_base,minutes_length); + + return ret; +} + + +bool t_cuesheet_index_list::is_empty() const { + for(unsigned n=0;nptMaxTrackSize.x = r.right - r.left; + info->ptMaxTrackSize.y = r.bottom - r.top; + } + if (min_x && min_y) + { + r.left = 0; r.right = min_x; + r.top = 0; r.bottom = min_y; + MapDialogRect(hWnd,&r); + AdjustWindowRectEx(&r, dwStyle, FALSE, dwExStyle); + info->ptMinTrackSize.x = r.right - r.left; + info->ptMinTrackSize.y = r.bottom - r.top; + } + } + lResult = 0; + return TRUE; + case WM_INITDIALOG: + set_parent(hWnd); + { + t_size n; + for(n=0;n rects; + RECT orig_client; + HWND parent; + HWND sizegrip; + unsigned min_x,min_y,max_x,max_y; + +public: + struct param { + unsigned short id; + unsigned short flags; + }; +private: + pfc::array_t m_table; + + void set_parent(HWND wnd); + void reset(); + void on_wm_size(); +public: + inline void set_min_size(unsigned x,unsigned y) {min_x = x; min_y = y;} + inline void set_max_size(unsigned x,unsigned y) {max_x = x; max_y = y;} + void add_sizegrip(); + + enum { + X_MOVE = 1, X_SIZE = 2, Y_MOVE = 4, Y_SIZE = 8, + XY_MOVE = X_MOVE|Y_MOVE, XY_SIZE = X_SIZE|Y_SIZE, + X_MOVE_Y_SIZE = X_MOVE|Y_SIZE, X_SIZE_Y_MOVE = X_SIZE|Y_MOVE, + }; + //the old way + bool process_message(HWND wnd,UINT msg,WPARAM wp,LPARAM lp); + + //ATL-compatible + BOOL ProcessWindowMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& lResult); + + dialog_resize_helper(const param * src,unsigned count,unsigned p_min_x,unsigned p_min_y,unsigned p_max_x,unsigned p_max_y); + + ~dialog_resize_helper(); + + PFC_CLASS_NOT_COPYABLE_EX(dialog_resize_helper); +}; + +#endif diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/dropdown_helper.cpp b/tools/vio2sf/src/foobar/foobar2000/helpers/dropdown_helper.cpp new file mode 100644 index 000000000..f75427e90 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/dropdown_helper.cpp @@ -0,0 +1,153 @@ +#include "stdafx.h" +#include "dropdown_helper.h" + + +void cfg_dropdown_history::build_list(pfc::ptr_list_t & out) +{ + const char * src = data; + while(*src) + { + int ptr = 0; + while(src[ptr] && src[ptr]!=separator) ptr++; + if (ptr>0) + { + out.add_item(pfc::strdup_n(src,ptr)); + src += ptr; + } + while(*src==separator) src++; + } +} + +void cfg_dropdown_history::parse_list(const pfc::ptr_list_t & src) +{ + t_size n; + pfc::string8_fastalloc temp; + for(n=0;n & list) +{ + t_size n, m = list.get_count(); + uSendMessage(wnd,CB_RESETCONTENT,0,0); + for(n=0;n list; + build_list(list); + g_setup_dropdown_fromlist(wnd,list); + list.free_all(); +} + +void cfg_dropdown_history::add_item(const char * item) +{ + if (!item || !*item) return; + pfc::string8 meh; + if (strchr(item,separator)) + { + uReplaceChar(meh,item,-1,separator,'|',false); + item = meh; + } + pfc::ptr_list_t list; + build_list(list); + unsigned n; + bool found = false; + for(n=0;n max) list.delete_by_idx(list.get_count()-1); + list.insert_item(_strdup(item),0); + } + parse_list(list); + list.free_all(); +} + +bool cfg_dropdown_history::is_empty() +{ + const char * src = data; + while(*src) + { + if (*src!=separator) return false; + src++; + } + return true; +} + +void cfg_dropdown_history::on_context(HWND wnd,LPARAM coords) { + try { + int coords_x = (short)LOWORD(coords), coords_y = (short)HIWORD(coords); + if (coords_x == -1 && coords_y == -1) + { + RECT asdf; + GetWindowRect(wnd,&asdf); + coords_x = (asdf.left + asdf.right) / 2; + coords_y = (asdf.top + asdf.bottom) / 2; + } + enum {ID_ERASE_ALL = 1, ID_ERASE_ONE }; + HMENU menu = CreatePopupMenu(); + uAppendMenu(menu,MF_STRING,ID_ERASE_ALL,"Wipe history"); + { + pfc::string8 tempvalue; + uGetWindowText(wnd,tempvalue); + if (!tempvalue.is_empty()) + uAppendMenu(menu,MF_STRING,ID_ERASE_ONE,"Remove this history item"); + } + int cmd = TrackPopupMenu(menu,TPM_RIGHTBUTTON|TPM_NONOTIFY|TPM_RETURNCMD,coords_x,coords_y,0,wnd,0); + DestroyMenu(menu); + switch(cmd) + { + case ID_ERASE_ALL: + { + data = ""; + pfc::string8 value;//preserve old value while wiping dropdown list + uGetWindowText(wnd,value); + uSendMessage(wnd,CB_RESETCONTENT,0,0); + uSetWindowText(wnd,value); + } + break; + case ID_ERASE_ONE: + { + pfc::string8 value; + uGetWindowText(wnd,value); + + pfc::ptr_list_t list; + t_size n,m; + bool found; + build_list(list); + m = list.get_count(); + found = false; + for(n=0;n & out); + void parse_list(const pfc::ptr_list_t & src); +public: + cfg_dropdown_history(const GUID & p_guid,unsigned p_max = 10,const char * init_vals = "") : data(p_guid,init_vals) {max = p_max;} + void setup_dropdown(HWND wnd); + void setup_dropdown(HWND wnd,UINT id) {setup_dropdown(GetDlgItem(wnd,id));} + void add_item(const char * item); + bool is_empty(); + void on_context(HWND wnd,LPARAM coords); +}; + +// ATL-compatible message map entry macro for installing dropdown list context menus. +#define DROPDOWN_HISTORY_HANDLER(ctrlID,var) \ + if(uMsg == WM_CONTEXTMENU) { \ + const HWND source = (HWND) wParam; \ + if (source != NULL && source == GetDlgItem(ctrlID)) { \ + var.on_context(source,lParam); \ + lResult = 0; \ + return TRUE; \ + } \ + } + +#endif //_DROPDOWN_HELPER_H_ diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/dynamic_bitrate_helper.cpp b/tools/vio2sf/src/foobar/foobar2000/helpers/dynamic_bitrate_helper.cpp new file mode 100644 index 000000000..2be9380be --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/dynamic_bitrate_helper.cpp @@ -0,0 +1,74 @@ +#include "stdafx.h" + +static unsigned g_query_settings() +{ + t_int32 temp; + try { + config_object::g_get_data_int32(standard_config_objects::int32_dynamic_bitrate_display_rate,temp); + } catch(std::exception const &) {return 9;} + if (temp < 0) return 0; + return (unsigned) temp; +} + +dynamic_bitrate_helper::dynamic_bitrate_helper() +{ + reset(); +} + +void dynamic_bitrate_helper::init() +{ + if (!m_inited) + { + m_inited = true; + unsigned temp = g_query_settings(); + if (temp > 0) {m_enabled = true; m_update_interval = 1.0 / (double) temp; } + else {m_enabled = false; m_update_interval = 0; } + m_last_duration = 0; + m_update_bits = 0; + m_update_time = 0; + + } +} + +void dynamic_bitrate_helper::on_frame(double p_duration,t_size p_bits) +{ + init(); + m_last_duration = p_duration; + m_update_time += p_duration; + m_update_bits += p_bits; +} + +bool dynamic_bitrate_helper::on_update(file_info & p_out, double & p_timestamp_delta) +{ + init(); + + bool ret = false; + if (m_enabled) + { + if (m_update_time > m_update_interval) + { + int val = (int) ( ((double)m_update_bits / m_update_time + 500.0) / 1000.0 ); + if (val != p_out.info_get_bitrate_vbr()) + { + p_timestamp_delta = - (m_update_time - m_last_duration); //relative to last frame beginning; + p_out.info_set_bitrate_vbr(val); + ret = true; + } + m_update_bits = 0; + m_update_time = 0; + } + } + else + { + m_update_bits = 0; + m_update_time = 0; + } + + return ret; + +} + +void dynamic_bitrate_helper::reset() +{ + m_inited = false; +} diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/dynamic_bitrate_helper.h b/tools/vio2sf/src/foobar/foobar2000/helpers/dynamic_bitrate_helper.h new file mode 100644 index 000000000..6480c679e --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/dynamic_bitrate_helper.h @@ -0,0 +1,15 @@ +class dynamic_bitrate_helper +{ +public: + dynamic_bitrate_helper(); + void on_frame(double p_duration,t_size p_bits); + bool on_update(file_info & p_out, double & p_timestamp_delta); + void reset(); +private: + void init(); + double m_last_duration; + t_size m_update_bits; + double m_update_time; + double m_update_interval; + bool m_inited, m_enabled; +}; \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/file_cached.h b/tools/vio2sf/src/foobar/foobar2000/helpers/file_cached.h new file mode 100644 index 000000000..b31be524b --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/file_cached.h @@ -0,0 +1,116 @@ +class file_cached : public file { +public: + static void g_create(service_ptr_t & p_out,service_ptr_t p_base,abort_callback & p_abort, t_size blockSize) { + service_ptr_t temp = new service_impl_t(blockSize); + temp->initialize(p_base,p_abort); + p_out = temp.get_ptr(); + } +protected: + file_cached(t_size blocksize) { + m_buffer.set_size(blocksize); + } + void initialize(service_ptr_t p_base,abort_callback & p_abort) { + m_base = p_base; + m_position = 0; + m_can_seek = m_base->can_seek(); + if (m_can_seek) { + m_position_base = m_base->get_position(p_abort); + } else { + m_position_base = 0; + } + + m_size = m_base->get_size(p_abort); + + flush_buffer(); + } +public: + + t_size read(void * p_buffer,t_size p_bytes,abort_callback & p_abort) { + t_uint8 * outptr = (t_uint8*)p_buffer; + t_size done = 0; + while(done < p_bytes && m_position < m_size) { + p_abort.check(); + + if (m_position >= m_buffer_position && m_position < m_buffer_position + m_buffer_status) { + t_size delta = pfc::min_t((t_size)(m_buffer_position + m_buffer_status - m_position),p_bytes - done); + t_size bufptr = (t_size)(m_position - m_buffer_position); + memcpy(outptr+done,m_buffer.get_ptr()+bufptr,delta); + done += delta; + m_position += delta; + if (m_buffer_status != m_buffer.get_size() && done < p_bytes) break;//EOF before m_size is hit + } else { + m_buffer_position = m_position - m_position % m_buffer.get_size(); + adjust_position(m_buffer_position,p_abort); + + m_buffer_status = m_base->read(m_buffer.get_ptr(),m_buffer.get_size(),p_abort); + m_position_base += m_buffer_status; + + if (m_buffer_status <= (t_size)(m_position - m_buffer_position)) break; + } + } + + return done; + } + + void write(const void * p_buffer,t_size p_bytes,abort_callback & p_abort) { + p_abort.check(); + adjust_position(m_position,p_abort); + m_base->write(p_buffer,p_bytes,p_abort); + m_position_base = m_position = m_position + p_bytes; + if (m_size < m_position) m_size = m_position; + flush_buffer(); + } + + t_filesize get_size(abort_callback & p_abort) { + p_abort.check(); + return m_size; + } + t_filesize get_position(abort_callback & p_abort) { + p_abort.check(); + return m_position; + } + void set_eof(abort_callback & p_abort) { + p_abort.check(); + adjust_position(m_position,p_abort); + m_base->set_eof(p_abort); + flush_buffer(); + } + void seek(t_filesize p_position,abort_callback & p_abort) { + p_abort.check(); + if (!m_can_seek) throw exception_io_object_not_seekable(); + if (p_position > m_size) throw exception_io_seek_out_of_range(); + m_position = p_position; + } + void reopen(abort_callback & p_abort) {seek(0,p_abort);} + bool can_seek() {return m_can_seek;} + bool get_content_type(pfc::string_base & out) {return m_base->get_content_type(out);} + void on_idle(abort_callback & p_abort) {p_abort.check();m_base->on_idle(p_abort);} + t_filetimestamp get_timestamp(abort_callback & p_abort) {p_abort.check(); return m_base->get_timestamp(p_abort);} + bool is_remote() {return m_base->is_remote();} + void resize(t_filesize p_size,abort_callback & p_abort) { + flush_buffer(); + m_base->resize(p_size,p_abort); + m_size = p_size; + if (m_position > m_size) m_position = m_size; + if (m_position_base > m_size) m_position_base = m_size; + } +private: + void adjust_position(t_filesize p_target,abort_callback & p_abort) { + if (p_target != m_position_base) { + m_base->seek(p_target,p_abort); + m_position_base = p_target; + } + } + + void flush_buffer() { + m_buffer_status = 0; + m_buffer_position = 0; + } + + service_ptr_t m_base; + t_filesize m_position,m_position_base,m_size; + bool m_can_seek; + t_filesize m_buffer_position; + t_size m_buffer_status; + pfc::array_t m_buffer; +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/file_info_const_impl.cpp b/tools/vio2sf/src/foobar/foobar2000/helpers/file_info_const_impl.cpp new file mode 100644 index 000000000..1851fac3b --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/file_info_const_impl.cpp @@ -0,0 +1,269 @@ +#include "stdafx.h" + +// presorted - do not change without a proper strcmp resort +static const char * const standard_fieldnames[] = { + "ALBUM","ALBUM ARTIST","ARTIST","Album","Album Artist","Artist","COMMENT","Comment","DATE","DISCNUMBER","Date", + "Discnumber","GENRE","Genre","TITLE","TOTALTRACKS","TRACKNUMBER","Title","TotalTracks","Totaltracks","TrackNumber", + "Tracknumber","album","album artist","artist","comment","date","discnumber","genre","title","totaltracks","tracknumber", +}; + +// presorted - do not change without a proper strcmp resort +static const char * const standard_infonames[] = { + "bitrate","bitspersample","channels","codec","codec_profile","encoding","samplerate","tagtype","tool", +}; + +static const char * optimize_fieldname(const char * p_string) { + t_size index; + if (!pfc::binarySearch::run(standard_fieldnames,0,tabsize(standard_fieldnames),p_string,index)) return NULL; + return standard_fieldnames[index]; +} + +static const char * optimize_infoname(const char * p_string) { + t_size index; + if (!pfc::binarySearch::run(standard_infonames,0,tabsize(standard_infonames),p_string,index)) return NULL; + return standard_infonames[index]; +} + +/* +order of things + + meta entries + meta value map + info entries + string buffer + +*/ + +inline static char* stringbuffer_append(char * & buffer,const char * value) +{ + char * ret = buffer; + while(*value) *(buffer++) = *(value++); + *(buffer++) = 0; + return ret; +} + +#ifdef __file_info_const_impl_have_hintmap__ + +namespace { + class sort_callback_hintmap_impl : public pfc::sort_callback + { + public: + sort_callback_hintmap_impl(const file_info_const_impl::meta_entry * p_meta,file_info_const_impl::t_index * p_hintmap) + : m_meta(p_meta), m_hintmap(p_hintmap) + { + } + + int compare(t_size p_index1, t_size p_index2) const + { +// profiler(sort_callback_hintmap_impl_compare); + return pfc::stricmp_ascii(m_meta[m_hintmap[p_index1]].m_name,m_meta[m_hintmap[p_index2]].m_name); + } + + void swap(t_size p_index1, t_size p_index2) + { + pfc::swap_t(m_hintmap[p_index1],m_hintmap[p_index2]); + } + private: + const file_info_const_impl::meta_entry * m_meta; + file_info_const_impl::t_index * m_hintmap; + }; + + class bsearch_callback_hintmap_impl// : public pfc::bsearch_callback + { + public: + bsearch_callback_hintmap_impl( + const file_info_const_impl::meta_entry * p_meta, + const file_info_const_impl::t_index * p_hintmap, + const char * p_name, + t_size p_name_length) + : m_meta(p_meta), m_hintmap(p_hintmap), m_name(p_name), m_name_length(p_name_length) + { + } + + inline int test(t_size p_index) const + { + return pfc::stricmp_ascii_ex(m_meta[m_hintmap[p_index]].m_name,infinite,m_name,m_name_length); + } + + private: + const file_info_const_impl::meta_entry * m_meta; + const file_info_const_impl::t_index * m_hintmap; + const char * m_name; + t_size m_name_length; + }; +} + +#endif//__file_info_const_impl_have_hintmap__ + +void file_info_const_impl::copy(const file_info & p_source) +{ +// profiler(file_info_const_impl__copy); + t_size meta_size = 0; + t_size info_size = 0; + t_size valuemap_size = 0; + t_size stringbuffer_size = 0; +#ifdef __file_info_const_impl_have_hintmap__ + t_size hintmap_size = 0; +#endif + + { +// profiler(file_info_const_impl__copy__pass1); + t_size index; + m_meta_count = pfc::downcast_guarded(p_source.meta_get_count()); + meta_size = m_meta_count * sizeof(meta_entry); +#ifdef __file_info_const_impl_have_hintmap__ + hintmap_size = (m_meta_count > hintmap_cutoff) ? m_meta_count * sizeof(t_index) : 0; +#endif//__file_info_const_impl_have_hintmap__ + for(index = 0; index < m_meta_count; index++ ) + { + { + const char * name = p_source.meta_enum_name(index); + if (optimize_fieldname(name) == 0) + stringbuffer_size += strlen(name) + 1; + } + + t_size val; const t_size val_max = p_source.meta_enum_value_count(index); + + if (val_max == 1) + { + stringbuffer_size += strlen(p_source.meta_enum_value(index,0)) + 1; + } + else + { + valuemap_size += val_max * sizeof(char*); + + for(val = 0; val < val_max; val++ ) + { + stringbuffer_size += strlen(p_source.meta_enum_value(index,val)) + 1; + } + } + } + + m_info_count = pfc::downcast_guarded(p_source.info_get_count()); + info_size = m_info_count * sizeof(info_entry); + for(index = 0; index < m_info_count; index++ ) + { + const char * name = p_source.info_enum_name(index); + if (optimize_infoname(name) == NULL) stringbuffer_size += strlen(name) + 1; + stringbuffer_size += strlen(p_source.info_enum_value(index)) + 1; + } + } + + + { +// profiler(file_info_const_impl__copy__alloc); + m_buffer.set_size( +#ifdef __file_info_const_impl_have_hintmap__ + hintmap_size + +#endif + meta_size + info_size + valuemap_size + stringbuffer_size); + } + + char * walk = m_buffer.get_ptr(); + +#ifdef __file_info_const_impl_have_hintmap__ + t_index* hintmap = (hintmap_size > 0) ? (t_index*) walk : NULL; + walk += hintmap_size; +#endif + meta_entry * meta = (meta_entry*) walk; + walk += meta_size; + char ** valuemap = (char**) walk; + walk += valuemap_size; + info_entry * info = (info_entry*) walk; + walk += info_size; + char * stringbuffer = walk; + + m_meta = meta; + m_info = info; +#ifdef __file_info_const_impl_have_hintmap__ + m_hintmap = hintmap; +#endif + + { +// profiler(file_info_const_impl__copy__pass2); + t_size index; + for( index = 0; index < m_meta_count; index ++ ) + { + t_size val; const t_size val_max = p_source.meta_enum_value_count(index); + + { + const char * name = p_source.meta_enum_name(index); + const char * name_opt = optimize_fieldname(name); + if (name_opt == NULL) + meta[index].m_name = stringbuffer_append(stringbuffer, name ); + else + meta[index].m_name = name_opt; + } + + meta[index].m_valuecount = val_max; + + if (val_max == 1) + { + meta[index].m_valuemap = reinterpret_cast(stringbuffer_append(stringbuffer, p_source.meta_enum_value(index,0) )); + } + else + { + meta[index].m_valuemap = valuemap; + for( val = 0; val < val_max ; val ++ ) + *(valuemap ++ ) = stringbuffer_append(stringbuffer, p_source.meta_enum_value(index,val) ); + } + } + + for( index = 0; index < m_info_count; index ++ ) + { + const char * name = p_source.info_enum_name(index); + const char * name_opt = optimize_infoname(name); + if (name_opt == NULL) + info[index].m_name = stringbuffer_append(stringbuffer, name ); + else + info[index].m_name = name_opt; + info[index].m_value = stringbuffer_append(stringbuffer, p_source.info_enum_value(index) ); + } + } + + m_length = p_source.get_length(); + m_replaygain = p_source.get_replaygain(); +#ifdef __file_info_const_impl_have_hintmap__ + if (hintmap != NULL) { +// profiler(file_info_const_impl__copy__hintmap); + for(t_size n=0;n(entry.m_valuemap); + else + return entry.m_valuemap[p_value_number]; +} diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/file_info_const_impl.h b/tools/vio2sf/src/foobar/foobar2000/helpers/file_info_const_impl.h new file mode 100644 index 000000000..05cd5e595 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/file_info_const_impl.h @@ -0,0 +1,78 @@ +#define __file_info_const_impl_have_hintmap__ + +//! Special implementation of file_info that implements only const and copy methods. The difference between this and regular file_info_impl is amount of resources used and speed of the copy operation. +class file_info_const_impl : public file_info +{ +public: + file_info_const_impl(const file_info & p_source) {copy(p_source);} + file_info_const_impl(const file_info_const_impl & p_source) {copy(p_source);} + file_info_const_impl() {m_meta_count = m_info_count = 0; m_length = 0; m_replaygain.reset();} + + double get_length() const {return m_length;} + + t_size meta_get_count() const {return m_meta_count;} + const char* meta_enum_name(t_size p_index) const {return m_meta[p_index].m_name;} + t_size meta_enum_value_count(t_size p_index) const; + const char* meta_enum_value(t_size p_index,t_size p_value_number) const; + t_size meta_find_ex(const char * p_name,t_size p_name_length) const; + + t_size info_get_count() const {return m_info_count;} + const char* info_enum_name(t_size p_index) const {return m_info[p_index].m_name;} + const char* info_enum_value(t_size p_index) const {return m_info[p_index].m_value;} + + + const file_info_const_impl & operator=(const file_info & p_source) {copy(p_source); return *this;} + const file_info_const_impl & operator=(const file_info_const_impl & p_source) {copy(p_source); return *this;} + void copy(const file_info & p_source); + void reset(); + + replaygain_info get_replaygain() const {return m_replaygain;} + +private: + void set_length(double p_length) {throw pfc::exception_bug_check_v2();} + + t_size meta_set_ex(const char * p_name,t_size p_name_length,const char * p_value,t_size p_value_length) {throw pfc::exception_bug_check_v2();} + void meta_insert_value_ex(t_size p_index,t_size p_value_index,const char * p_value,t_size p_value_length) {throw pfc::exception_bug_check_v2();} + void meta_remove_mask(const bit_array & p_mask) {throw pfc::exception_bug_check_v2();} + void meta_reorder(const t_size * p_order) {throw pfc::exception_bug_check_v2();} + void meta_remove_values(t_size p_index,const bit_array & p_mask) {throw pfc::exception_bug_check_v2();} + void meta_modify_value_ex(t_size p_index,t_size p_value_index,const char * p_value,t_size p_value_length) {throw pfc::exception_bug_check_v2();} + + t_size info_set_ex(const char * p_name,t_size p_name_length,const char * p_value,t_size p_value_length) {throw pfc::exception_bug_check_v2();} + void info_remove_mask(const bit_array & p_mask) {throw pfc::exception_bug_check_v2();} + + void set_replaygain(const replaygain_info & p_info) {throw pfc::exception_bug_check_v2();} + + t_size meta_set_nocheck_ex(const char * p_name,t_size p_name_length,const char * p_value,t_size p_value_length) {throw pfc::exception_bug_check_v2();} + t_size info_set_nocheck_ex(const char * p_name,t_size p_name_length,const char * p_value,t_size p_value_length) {throw pfc::exception_bug_check_v2();} +public: + struct meta_entry { + const char * m_name; + t_size m_valuecount; + const char * const * m_valuemap; + }; + + struct info_entry { + const char * m_name; + const char * m_value; + }; + +#ifdef __file_info_const_impl_have_hintmap__ + typedef t_uint32 t_index; + enum {hintmap_cutoff = 20}; +#endif//__file_info_const_impl_have_hintmap__ +private: + pfc::array_t m_buffer; + t_index m_meta_count; + t_index m_info_count; + + const meta_entry * m_meta; + const info_entry * m_info; + +#ifdef __file_info_const_impl_have_hintmap__ + const t_index * m_hintmap; +#endif + + double m_length; + replaygain_info m_replaygain; +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/file_info_update_helper.cpp b/tools/vio2sf/src/foobar/foobar2000/helpers/file_info_update_helper.cpp new file mode 100644 index 000000000..618797247 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/file_info_update_helper.cpp @@ -0,0 +1,101 @@ +#include "stdafx.h" + +file_info_update_helper::file_info_update_helper(metadb_handle_ptr p_item) +{ + const t_size count = 1; + m_data.add_item(p_item); + + m_infos.set_size(count); + m_mask.set_size(count); + for(t_size n=0;n & p_data) +{ + const t_size count = p_data.get_count(); + m_data.add_items(p_data); + + m_infos.set_size(count); + m_mask.set_size(count); + for(t_size n=0;n api; + if (api->load_info_multi(m_data,metadb_io::load_info_default,p_parent,p_show_errors) != metadb_io::load_info_success) return false; + t_size n; const t_size m = m_data.get_count(); + t_size loaded_count = 0; + for(n=0;nget_info(m_infos[n]); + if (val) loaded_count++; + m_mask[n] = val; + } + return loaded_count == m; +} + +file_info_update_helper::t_write_result file_info_update_helper::write_infos(HWND p_parent,bool p_show_errors) +{ + t_size n, outptr = 0; const t_size count = m_data.get_count(); + pfc::array_t items_to_update; + pfc::array_t infos_to_write; + items_to_update.set_size(count); + infos_to_write.set_size(count); + + for(n=0;n api; + switch(api->update_info_multi( + pfc::list_const_array_t&>(items_to_update,outptr), + pfc::list_const_array_t&>(infos_to_write,outptr), + p_parent, + true + )) + { + case metadb_io::update_info_success: + return write_ok; + case metadb_io::update_info_aborted: + return write_aborted; + default: + case metadb_io::update_info_errors: + return write_error; + } + } +} + +t_size file_info_update_helper::get_item_count() const +{ + return m_data.get_count(); +} + +bool file_info_update_helper::is_item_valid(t_size p_index) const +{ + return m_mask[p_index]; +} + +file_info & file_info_update_helper::get_item(t_size p_index) +{ + return m_infos[p_index]; +} + +metadb_handle_ptr file_info_update_helper::get_item_handle(t_size p_index) const +{ + return m_data[p_index]; +} + +void file_info_update_helper::invalidate_item(t_size p_index) +{ + m_mask[p_index] = false; +} diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/file_info_update_helper.h b/tools/vio2sf/src/foobar/foobar2000/helpers/file_info_update_helper.h new file mode 100644 index 000000000..831446481 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/file_info_update_helper.h @@ -0,0 +1,29 @@ +//! Deprecated - relies on old blocking metadb_io methods - use metadb_io_v2::update_info_async w/ file_info_filter whenever possible. +class __declspec(deprecated("Use metadb_io_v2::update_info_async instead whenever possible.")) file_info_update_helper { +public: + file_info_update_helper(const pfc::list_base_const_t & p_data); + file_info_update_helper(metadb_handle_ptr p_item); + + bool read_infos(HWND p_parent,bool p_show_errors); + + enum t_write_result + { + write_ok, + write_aborted, + write_error + }; + t_write_result write_infos(HWND p_parent,bool p_show_errors); + + t_size get_item_count() const; + bool is_item_valid(t_size p_index) const;//returns false where info reading failed + + file_info & get_item(t_size p_index); + metadb_handle_ptr get_item_handle(t_size p_index) const; + + void invalidate_item(t_size p_index); + +private: + metadb_handle_list m_data; + pfc::array_t m_infos; + pfc::array_t m_mask; +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/file_list_helper.cpp b/tools/vio2sf/src/foobar/foobar2000/helpers/file_list_helper.cpp new file mode 100644 index 000000000..4053e73a0 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/file_list_helper.cpp @@ -0,0 +1,70 @@ +#include "stdafx.h" + +static void file_list_remove_duplicates(pfc::ptr_list_t & out) +{ + t_size n, m = out.get_count(); + out.sort_t(metadb::path_compare); + bit_array_bittable mask(m); + t_size duplicates = 0; + for(n=1;n0) { + out.free_mask(mask); + } +} + + +namespace file_list_helper +{ + t_size file_list_from_metadb_handle_list::g_get_count(metadb_handle_list_cref data, t_size max) { + pfc::avltree_t content; + const t_size inCount = data.get_size(); + for(t_size walk = 0; walk < inCount && content.get_count() < max; ++walk) { + content += data[walk]->get_path(); + } + return content.get_count(); + } + void file_list_from_metadb_handle_list::__add(const char * p_what) { + char * temp = _strdup(p_what); + if (temp == NULL) throw std::bad_alloc(); + try {m_data.add_item(temp); } catch(...) {free(temp); throw;} + } + + void file_list_from_metadb_handle_list::init_from_list(const list_base_const_t & p_list) + { + m_data.free_all(); + + t_size n, m = p_list.get_count(); + for(n=0;nget_path() ); + } + file_list_remove_duplicates(m_data); + } + + void file_list_from_metadb_handle_list::init_from_list_display(const list_base_const_t & p_list) + { + m_data.free_all(); + + pfc::string8_fastalloc temp; + + t_size n, m = p_list.get_count(); + for(n=0;nget_path(),temp); + __add(temp); + } + file_list_remove_duplicates(m_data); + + + } + + t_size file_list_from_metadb_handle_list::get_count() const {return m_data.get_count();} + void file_list_from_metadb_handle_list::get_item_ex(const char * & p_out,t_size n) const {p_out = m_data.get_item(n);} + + file_list_from_metadb_handle_list::~file_list_from_metadb_handle_list() + { + m_data.free_all(); + } + +} \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/file_list_helper.h b/tools/vio2sf/src/foobar/foobar2000/helpers/file_list_helper.h new file mode 100644 index 000000000..3cf03831c --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/file_list_helper.h @@ -0,0 +1,30 @@ +#ifndef _foobar2000_helpers_file_list_helper_ +#define _foobar2000_helpers_file_list_helper_ + + +namespace file_list_helper +{ + //list guaranteed to be sorted by metadb::path_compare + class file_list_from_metadb_handle_list : public pfc::list_base_const_t { + public: + + static t_size g_get_count(const list_base_const_t & p_list, t_size max = ~0); + + void init_from_list(const list_base_const_t & p_list); + void init_from_list_display(const list_base_const_t & p_list); + + t_size get_count() const; + void get_item_ex(const char * & p_out,t_size n) const; + + ~file_list_from_metadb_handle_list(); + + private: + void __add(const char * p_what); + pfc::ptr_list_t m_data; + }; + + +}; + + +#endif //_foobar2000_helpers_file_list_helper_ \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/file_move_helper.cpp b/tools/vio2sf/src/foobar/foobar2000/helpers/file_move_helper.cpp new file mode 100644 index 000000000..b54c99e76 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/file_move_helper.cpp @@ -0,0 +1,278 @@ +#include "stdafx.h" + +static bool grab_items_by_path(pfc::list_base_t & p_out,const char * p_path,abort_callback & p_abort) +{ + try { + pfc::string8 path; + filesystem::g_get_canonical_path(p_path,path); + p_out.remove_all(); + service_ptr_t reader; + input_entry::g_open_for_info_read(reader,0,path,p_abort); + + static_api_ptr_t l_metadb; + + const t_uint32 count = reader->get_subsong_count(); + for(t_uint32 n=0;nhandle_create(ptr,make_playable_location(path,reader->get_subsong(n))); + p_out.add_item(ptr); + } + + return p_out.get_count() > 0; + } catch(std::exception const &) {return false;} +} + +file_move_helper::file_move_helper() {} +file_move_helper::~file_move_helper() {} +file_move_helper::file_move_helper(const file_move_helper & p_src) {*this = p_src;} + +bool file_move_helper::take_snapshot(const char * p_path,abort_callback & p_abort) +{ + in_metadb_sync blah; + + m_source_handles.remove_all(); + m_data.set_size(0); + if (!grab_items_by_path(m_source_handles,p_path,p_abort)) return false; + t_size n, m = m_source_handles.get_count(); + m_data.set_size(m); + for(n=0;nget_location(); + m_data[n].m_have_info = m_source_handles[n]->get_info(m_data[n].m_info); + m_data[n].m_stats = m_source_handles[n]->get_filestats(); + + } + return true; +} + +bool file_move_helper::on_moved(const char * p_path,abort_callback & p_abort) +{ + bool ret; + file_move_callback_manager cb; + ret = on_moved(p_path,p_abort,cb); + cb.run_callback(); + return ret; +} + +bool file_move_helper::on_copied(const char * p_path,abort_callback & p_abort) +{ + bool ret; + file_move_callback_manager cb; + ret = on_copied(p_path,p_abort,cb); + cb.run_callback(); + return ret; +} + +bool file_move_helper::on_moved(const char * p_path,abort_callback & p_abort,file_move_callback_manager & p_cb) +{ + file_path_canonical path(p_path); + if (m_data.get_size() == 0) return false; + if (!metadb::path_compare(path,get_source_path())) return true; + + metadb_handle_list items; + make_new_item_list(items,path,p_cb); + + + /*if (p_update_db)*/ + p_cb.on_library_add_items(items); + p_cb.on_library_remove_items(m_source_handles); + + p_cb.on_moved(pfc::list_single_ref_t(get_source_path()),pfc::list_single_ref_t(path)); + + return true; +} + +bool file_move_helper::on_copied(const char * p_path,abort_callback & p_abort,file_move_callback_manager & p_cb) +{ + file_path_canonical path(p_path); + if (m_data.get_size() == 0) return false; + if (!metadb::path_compare(path,get_source_path())) return true; + metadb_handle_list items; + make_new_item_list(items,path,p_cb); + /*if (p_update_db)*/ p_cb.on_library_add_items(items); + p_cb.on_copied(pfc::list_single_ref_t(get_source_path()),pfc::list_single_ref_t(path)); + return true; +} + +bool file_move_helper::g_on_deleted(const pfc::list_base_const_t & p_files) +{ + file_operation_callback::g_on_files_deleted(p_files); + return true; +} + +void file_move_helper::make_new_item_list(pfc::list_base_t & p_out,const char * p_new_path,file_move_callback_manager & p_cb) +{ + pfc::string8 new_path; + filesystem::g_get_canonical_path(p_new_path,new_path); + + t_size n; const t_size m = m_data.get_size(); + static_api_ptr_t api; + pfc::array_t hint_handles; + pfc::array_t hint_infos; + pfc::array_t hint_stats; + hint_handles.set_size(m); hint_infos.set_size(m); hint_stats.set_size(m); + t_size hintptr = 0; + for(n=0;nhandle_create(temp,make_playable_location(new_path,m_data[n].m_location.get_subsong())); + if (m_data[n].m_have_info) + { + hint_handles[hintptr] = temp; + hint_infos[hintptr] = &m_data[n].m_info; + hint_stats[hintptr] = m_data[n].m_stats; + + hintptr++; + } + p_out.add_item(temp); + } + + if (hintptr > 0) + { + p_cb.on_hint( + pfc::list_const_array_t &>(hint_handles,hintptr), + pfc::list_const_array_t &>(hint_infos,hintptr), + pfc::list_const_array_t &>(hint_stats,hintptr) + ); +/* + static_api_ptr_t()->hint_multi( + list_const_array_t &>(hint_handles,hintptr), + list_const_array_t &>(hint_infos,hintptr), + list_const_array_t &>(hint_stats,hintptr), + bit_array_false());*/ + } + +} + +const char * file_move_helper::get_source_path() const +{ + return m_data.get_size() > 0 ? m_data[0].m_location.get_path() : 0; +} + +t_size file_move_helper::g_filter_dead_files_sorted_make_mask(pfc::list_base_t & p_data,const pfc::list_base_const_t & p_dead,bit_array_var & p_mask) +{ + t_size n, m = p_data.get_count(); + t_size found = 0; + for(n=0;nget_path(),dummy); + if (dead) found++; + p_mask.set(n,dead); + } + return found; +} + +t_size file_move_helper::g_filter_dead_files_sorted(pfc::list_base_t & p_data,const pfc::list_base_const_t & p_dead) +{ + bit_array_bittable mask(p_data.get_count()); + t_size found = g_filter_dead_files_sorted_make_mask(p_data,p_dead,mask); + if (found > 0) p_data.remove_mask(mask); + return found; +} + +t_size file_move_helper::g_filter_dead_files(pfc::list_base_t & p_data,const pfc::list_base_const_t & p_dead) +{ + pfc::ptr_list_t temp; + temp.add_items(p_dead); + temp.sort_t(metadb::path_compare); + return g_filter_dead_files_sorted(p_data,temp); +} + + +void file_move_callback_manager::on_library_add_items(const pfc::list_base_const_t & p_data) +{ + m_added.add_items(p_data); +} + +void file_move_callback_manager::on_library_remove_items(const pfc::list_base_const_t & p_data) +{ + m_removed.add_items(p_data); +} + +void file_move_callback_manager::on_moved(const pfc::string_list_const & p_from,const pfc::string_list_const & p_to) +{ + assert(p_from.get_count() == p_to.get_count()); + m_move_from += p_from; + m_move_to += p_to; +} + +void file_move_callback_manager::on_copied(const pfc::string_list_const & p_from,const pfc::string_list_const & p_to) +{ + assert(p_from.get_count() == p_to.get_count()); + m_copy_from += p_from; + m_copy_to += p_to; +} + +void file_move_callback_manager::on_hint(const pfc::list_base_const_t & p_list,const pfc::list_base_const_t & p_infos,const pfc::list_base_const_t & p_stats) +{ + m_hint_handles.add_items(p_list); + m_hint_stats.add_items(p_stats); + + { + t_size old_count = m_hint_infos.get_count(), delta = p_infos.get_count(); + m_hint_infos.set_count(old_count + delta); + for(t_size n=0;n m_hint_infos; + list_t m_hint_stats;*/ + +} + + +void file_move_callback_manager::run_callback() +{ + if (m_hint_handles.get_count() > 0) + { + static_api_ptr_t()->hint_multi( + m_hint_handles, + pfc::ptr_list_const_array_t &>(m_hint_infos,m_hint_infos.get_count()), + m_hint_stats, + bit_array_false()); + + m_hint_infos.remove_all(); + m_hint_stats.remove_all(); + + //trick to make sure values don't get wiped + //m_hint_handles.remove_all(); + + } + + assert(m_copy_from.get_count() == m_copy_to.get_count()); + assert(m_move_from.get_count() == m_move_to.get_count()); + + static_api_ptr_t api_library_manager; + + if (m_added.get_count() > 0) + { + api_library_manager->add_items(m_added); + m_added.remove_all(); + } + + if (m_removed.get_count()) + { + api_library_manager->remove_items(m_removed); + m_removed.remove_all(); + } + + if (m_copy_from.get_count() > 0) + { + file_operation_callback::g_on_files_copied(m_copy_from,m_copy_to); + m_copy_from.remove_all(); + m_copy_to.remove_all(); + } + + if (m_move_from.get_count() > 0) + { + file_operation_callback::g_on_files_moved(m_move_from,m_move_to); + m_move_from.remove_all(); + m_move_to.remove_all(); + } + + //trick to make sure values don't get wiped + m_hint_handles.remove_all(); +} diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/file_move_helper.h b/tools/vio2sf/src/foobar/foobar2000/helpers/file_move_helper.h new file mode 100644 index 000000000..d2e9622e7 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/file_move_helper.h @@ -0,0 +1,60 @@ +class file_move_callback_manager +{ +public: + void on_library_add_items(const pfc::list_base_const_t & p_data); + void on_library_remove_items(const pfc::list_base_const_t & p_data); + + void on_moved(const pfc::string_list_const & p_from,const pfc::string_list_const & p_to); + void on_copied(const pfc::string_list_const & p_from,const pfc::string_list_const & p_to); + + void on_hint(const pfc::list_base_const_t & p_list,const pfc::list_base_const_t & p_infos,const pfc::list_base_const_t & p_stats); + + void run_callback(); +private: + metadb_handle_list m_removed; + metadb_handle_list m_added; + + pfc::string_list_impl m_copy_from,m_copy_to; + pfc::string_list_impl m_move_from,m_move_to; + + metadb_handle_list m_hint_handles; + pfc::list_t m_hint_infos; + pfc::list_t m_hint_stats; +}; + +class file_move_helper +{ +public: + file_move_helper(); + ~file_move_helper(); + file_move_helper(const file_move_helper & p_src); + bool take_snapshot(const char * p_path,abort_callback & p_abort); + bool on_moved(const char * p_path,abort_callback & p_abort); + bool on_copied(const char * p_path,abort_callback & p_abort); + bool on_moved(const char * p_path,abort_callback & p_abort,file_move_callback_manager & p_cb); + bool on_copied(const char * p_path,abort_callback & p_abort,file_move_callback_manager & p_cb); + + static bool g_on_deleted(const pfc::list_base_const_t & p_files); + + static t_size g_filter_dead_files_sorted_make_mask(pfc::list_base_t & p_data,const pfc::list_base_const_t & p_dead,bit_array_var & p_mask); + static t_size g_filter_dead_files_sorted(pfc::list_base_t & p_data,const pfc::list_base_const_t & p_dead); + static t_size g_filter_dead_files(pfc::list_base_t & p_data,const pfc::list_base_const_t & p_dead); + +private: + + struct t_entry + { + playable_location_impl m_location; + file_info_impl m_info; + t_filestats m_stats; + bool m_have_info; + }; + + metadb_handle_list m_source_handles; + + pfc::array_t m_data; + + const char * get_source_path() const; + + void make_new_item_list(pfc::list_base_t & p_out,const char * p_path,file_move_callback_manager & p_cb); +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/file_win32_wrapper.h b/tools/vio2sf/src/foobar/foobar2000/helpers/file_win32_wrapper.h new file mode 100644 index 000000000..5d111889c --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/file_win32_wrapper.h @@ -0,0 +1,183 @@ +namespace file_win32_helpers { + static t_filesize get_size(HANDLE p_handle) { + union { + t_uint64 val64; + t_uint32 val32[2]; + } u; + + u.val64 = 0; + SetLastError(NO_ERROR); + u.val32[0] = GetFileSize(p_handle,reinterpret_cast(&u.val32[1])); + if (GetLastError()!=NO_ERROR) exception_io_from_win32(GetLastError()); + return u.val64; + } + static void seek(HANDLE p_handle,t_sfilesize p_position,file::t_seek_mode p_mode) { + union { + t_int64 temp64; + struct { + DWORD temp_lo; + LONG temp_hi; + }; + }; + + temp64 = p_position; + SetLastError(ERROR_SUCCESS); + temp_lo = SetFilePointer(p_handle,temp_lo,&temp_hi,(DWORD)p_mode); + if (GetLastError() != ERROR_SUCCESS) exception_io_from_win32(GetLastError()); + } +} + +template +class file_win32_wrapper_t : public file { +public: + file_win32_wrapper_t(HANDLE p_handle) : m_handle(p_handle), m_position(0) + { + } + + static service_ptr_t g_CreateFile(const char * p_path,DWORD p_access,DWORD p_sharemode,LPSECURITY_ATTRIBUTES p_security_attributes,DWORD p_createmode,DWORD p_flags,HANDLE p_template) { + SetLastError(NO_ERROR); + HANDLE handle = uCreateFile(p_path,p_access,p_sharemode,p_security_attributes,p_createmode,p_flags,p_template); + if (handle == INVALID_HANDLE_VALUE) exception_io_from_win32(GetLastError()); + try { + return g_create_from_handle(handle); + } catch(...) {CloseHandle(handle); throw;} + } + + static service_ptr_t g_create_from_handle(HANDLE p_handle) { + return new service_impl_t >(p_handle); + } + + + void reopen(abort_callback & p_abort) {seek(0,p_abort);} + + void write(const void * p_buffer,t_size p_bytes,abort_callback & p_abort) { + if (!p_writeable) throw exception_io_denied(); + + pfc::static_assert_t< (sizeof(t_size) >= sizeof(DWORD)) >(); + + t_size bytes_written_total = 0; + + if (sizeof(t_size) == sizeof(DWORD)) { + p_abort.check_e(); + DWORD bytes_written = 0; + SetLastError(ERROR_SUCCESS); + if (!WriteFile(m_handle,p_buffer,(DWORD)p_bytes,&bytes_written,0)) exception_io_from_win32(GetLastError()); + if (bytes_written != p_bytes) throw exception_io("Write failure"); + bytes_written_total = bytes_written; + m_position += bytes_written; + } else { + while(bytes_written_total < p_bytes) { + p_abort.check_e(); + DWORD bytes_written = 0; + DWORD delta = (DWORD) pfc::min_t(p_bytes - bytes_written_total, 0x80000000); + SetLastError(ERROR_SUCCESS); + if (!WriteFile(m_handle,(const t_uint8*)p_buffer + bytes_written_total,delta,&bytes_written,0)) exception_io_from_win32(GetLastError()); + if (bytes_written != delta) throw exception_io("Write failure"); + bytes_written_total += bytes_written; + m_position += bytes_written; + } + } + } + + t_size read(void * p_buffer,t_size p_bytes,abort_callback & p_abort) { + pfc::static_assert_t< (sizeof(t_size) >= sizeof(DWORD)) >(); + + t_size bytes_read_total = 0; + if (sizeof(t_size) == sizeof(DWORD)) { + p_abort.check_e(); + DWORD bytes_read = 0; + SetLastError(ERROR_SUCCESS); + if (!ReadFile(m_handle,p_buffer,pfc::downcast_guarded(p_bytes),&bytes_read,0)) exception_io_from_win32(GetLastError()); + bytes_read_total = bytes_read; + m_position += bytes_read; + } else { + while(bytes_read_total < p_bytes) { + p_abort.check_e(); + DWORD bytes_read = 0; + DWORD delta = (DWORD) pfc::min_t(p_bytes - bytes_read_total, 0x80000000); + SetLastError(ERROR_SUCCESS); + if (!ReadFile(m_handle,(t_uint8*)p_buffer + bytes_read_total,delta,&bytes_read,0)) exception_io_from_win32(GetLastError()); + bytes_read_total += bytes_read; + m_position += bytes_read; + if (bytes_read != delta) break; + } + } + return bytes_read_total; + } + + + t_filesize get_size(abort_callback & p_abort) { + p_abort.check_e(); + return file_win32_helpers::get_size(m_handle); + } + + t_filesize get_position(abort_callback & p_abort) { + p_abort.check_e(); + return m_position; + } + + void resize(t_filesize p_size,abort_callback & p_abort) { + if (!p_writeable) throw exception_io_denied(); + p_abort.check_e(); + if (m_position != p_size) { + file_win32_helpers::seek(m_handle,p_size,file::seek_from_beginning); + } + SetLastError(ERROR_SUCCESS); + if (!SetEndOfFile(m_handle)) { + DWORD code = GetLastError(); + if (m_position != p_size) try {file_win32_helpers::seek(m_handle,m_position,file::seek_from_beginning);} catch(...) {} + exception_io_from_win32(code); + } + if (m_position > p_size) m_position = p_size; + if (m_position != p_size) file_win32_helpers::seek(m_handle,m_position,file::seek_from_beginning); + } + +#if 0 + void set_eof(abort_callback & p_abort) { + if (!p_writeable) throw exception_io_denied(); + p_abort.check_e(); + + SetLastError(ERROR_SUCCESS); + if (!SetEndOfFile(m_handle)) exception_io_from_win32(GetLastError()); + } +#endif + + void seek(t_filesize p_position,abort_callback & p_abort) { + if (!p_seekable) throw exception_io_object_not_seekable(); + p_abort.check_e(); + if (p_position > file_win32_helpers::get_size(m_handle)) throw exception_io_seek_out_of_range(); + file_win32_helpers::seek(m_handle,p_position,file::seek_from_beginning); + m_position = p_position; + //return seek_ex((t_sfilesize)p_position,file::seek_from_beginning,p_abort); + } +#if 0 + void seek_ex(t_sfilesize p_position,file::t_seek_mode p_mode,abort_callback & p_abort) { + if (!p_seekable) throw exception_io_object_not_seekable(); + p_abort.check_e(); + + file_win32_helpers::seek(m_handle,p_position,p_mode); + + m_position = (t_filesize) temp64; + } +#endif + + bool can_seek() {return p_seekable;} + bool get_content_type(pfc::string_base & out) {return false;} + bool is_in_memory() {return false;} + void on_idle(abort_callback & p_abort) {p_abort.check_e();} + + t_filetimestamp get_timestamp(abort_callback & p_abort) { + p_abort.check_e(); + FlushFileBuffers(m_handle); + SetLastError(ERROR_SUCCESS); + t_filetimestamp temp; + if (!GetFileTime(m_handle,0,0,(FILETIME*)&temp)) exception_io_from_win32(GetLastError()); + return temp; + } + + bool is_remote() {return false;} + ~file_win32_wrapper_t() {CloseHandle(m_handle);} +private: + HANDLE m_handle; + t_filesize m_position; +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/file_wrapper_simple.cpp b/tools/vio2sf/src/foobar/foobar2000/helpers/file_wrapper_simple.cpp new file mode 100644 index 000000000..79b61b197 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/file_wrapper_simple.cpp @@ -0,0 +1,75 @@ +#include "stdafx.h" + +t_size file_wrapper_simple::read(void * p_buffer,t_size p_bytes) { + if (m_has_failed) return 0; + try { + return m_file->read(p_buffer,p_bytes,m_abort); + } catch(std::exception const &) { + m_has_failed = true; + return 0; + } +} + +t_size file_wrapper_simple::write(const void * p_buffer,t_size p_bytes) { + if (m_has_failed) return 0; + try { + m_file->write(p_buffer,p_bytes,m_abort); + return p_bytes; + } catch(std::exception const &) { + m_has_failed = true; + return 0; + } +} + +bool file_wrapper_simple::seek(t_filesize p_offset) { + if (m_has_failed) return false; + try { + m_file->seek(p_offset,m_abort); + return true; + } catch(std::exception const &) { + m_has_failed = true; + return false; + } +} + +t_filesize file_wrapper_simple::get_position() { + if (m_has_failed) return filesize_invalid; + try { + return m_file->get_position(m_abort); + } catch(std::exception const &) { + m_has_failed = true; + return filesize_invalid; + } +} + +bool file_wrapper_simple::truncate() { + if (m_has_failed) return false; + try { + m_file->set_eof(m_abort); + return true; + } catch(std::exception) { + m_has_failed = true; + return true; + } +} + + +t_filesize file_wrapper_simple::get_size() { + if (m_has_failed) return filesize_invalid; + try { + return m_file->get_size(m_abort); + } catch(std::exception const &) { + m_has_failed = true; + return filesize_invalid; + } +} + +bool file_wrapper_simple::can_seek() { + if (m_has_failed) return false; + try { + return m_file->can_seek(); + } catch(std::exception const &) { + m_has_failed = true; + return false; + } +} diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/file_wrapper_simple.h b/tools/vio2sf/src/foobar/foobar2000/helpers/file_wrapper_simple.h new file mode 100644 index 000000000..6819d0ddf --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/file_wrapper_simple.h @@ -0,0 +1,21 @@ +class file_wrapper_simple +{ +public: + explicit file_wrapper_simple(const service_ptr_t & p_file,abort_callback & p_abort) : m_file(p_file), m_abort(p_abort), m_has_failed(false) {} + + inline bool has_failed() const {return m_has_failed;} + inline void reset_status() {m_has_failed = false;} + + + t_size read(void * p_buffer,t_size p_bytes); + t_size write(const void * p_buffer,t_size p_bytes); + bool seek(t_filesize p_offset); + t_filesize get_position(); + t_filesize get_size(); + bool can_seek(); + bool truncate(); +private: + service_ptr_t m_file; + abort_callback & m_abort; + bool m_has_failed; +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/filetimetools.cpp b/tools/vio2sf/src/foobar/foobar2000/helpers/filetimetools.cpp new file mode 100644 index 000000000..a52da25c7 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/filetimetools.cpp @@ -0,0 +1,84 @@ +#include "stdafx.h" + + +#ifndef _WIN32 +#error PORTME +#endif + +static bool is_spacing(char c) {return c == ' ' || c==10 || c==13 || c == '\t';} + +static bool is_spacing(const char * str, t_size len) { + for(t_size walk = 0; walk < len; ++walk) if (!is_spacing(str[walk])) return false; + return true; +} + +typedef exception_io_data exception_time_error; + +static unsigned ParseDateElem(const char * ptr, t_size len) { + unsigned ret = 0; + for(t_size walk = 0; walk < len; ++walk) { + const char c = ptr[walk]; + if (c < '0' || c > '9') throw exception_time_error(); + ret = ret * 10 + (unsigned)(c - '0'); + } + return ret; +} + +t_filetimestamp foobar2000_io::filetimestamp_from_string(const char * date) { + // Accepted format + // YYYY-MM-DD HH:MM:SS + try { + t_size remaining = strlen(date); + SYSTEMTIME st = {}; + st.wDay = 1; st.wMonth = 1; + for(;;) { +#define ADVANCE(n) { PFC_ASSERT( remaining >= n); date += n; remaining -= n; } +#define ADVANCE_TEST(n) { if (remaining < n) throw exception_time_error(); } +#define PARSE(var, digits) { ADVANCE_TEST(digits); var = (WORD) ParseDateElem(date, digits); ADVANCE(digits) ; } +#define TEST_END( durationIncrement ) +#define SKIP(c) { ADVANCE_TEST(1); if (date[0] != c) throw exception_time_error(); ADVANCE(1); } +#define SKIP_SPACING() {while(remaining > 0 && is_spacing(*date)) ADVANCE(1);} + SKIP_SPACING(); + PARSE( st.wYear, 4 ); if (st.wYear < 1601) throw exception_time_error(); + TEST_END(wYear); SKIP('-'); + PARSE( st.wMonth, 2 ); if (st.wMonth < 1 || st.wMonth > 12) throw exception_time_error(); + TEST_END(wMonth); SKIP('-'); + PARSE( st.wDay, 2); if (st.wDay < 1 || st.wDay > 31) throw exception_time_error(); + TEST_END(wDay); SKIP(' '); + PARSE( st.wHour, 2); if (st.wHour >= 24) throw exception_time_error(); + TEST_END(wHour); SKIP(':'); + PARSE( st.wMinute, 2); if (st.wMinute >= 60) throw exception_time_error(); + TEST_END(wMinute); SKIP(':'); + PARSE( st.wSecond, 2); if (st.wSecond >= 60) throw exception_time_error(); + SKIP_SPACING(); + TEST_END( wSecond ); +#undef ADVANCE +#undef ADVANCE_TEST +#undef PARSE +#undef TEST_END +#undef SKIP +#undef SKIP_SPACING + if (remaining > 0) throw exception_time_error(); + break; + } + t_filetimestamp base, out; + if (!SystemTimeToFileTime(&st, (FILETIME*) &base)) throw exception_time_error(); + if (!LocalFileTimeToFileTime((const FILETIME*)&base, (FILETIME*)&out)) throw exception_time_error(); + return out; + } catch(exception_time_error) { + return filetimestamp_invalid; + } +} + + + +format_filetimestamp::format_filetimestamp(t_filetimestamp p_timestamp) { + SYSTEMTIME st; FILETIME ft; + if (FileTimeToLocalFileTime((FILETIME*)&p_timestamp,&ft)) { + if (FileTimeToSystemTime(&ft,&st)) { + m_buffer + << pfc::format_uint(st.wYear,4) << "-" << pfc::format_uint(st.wMonth,2) << "-" << pfc::format_uint(st.wDay,2) << " " + << pfc::format_uint(st.wHour,2) << ":" << pfc::format_uint(st.wMinute,2) << ":" << pfc::format_uint(st.wSecond,2); + } else m_buffer << ""; + } else m_buffer << ""; +} diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/filetimetools.h b/tools/vio2sf/src/foobar/foobar2000/helpers/filetimetools.h new file mode 100644 index 000000000..b376be137 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/filetimetools.h @@ -0,0 +1,14 @@ +namespace foobar2000_io { + t_filetimestamp filetimestamp_from_string(const char * date); + + //! Warning: this formats according to system timezone settings, created strings should be used for display only, never for storage. + class format_filetimestamp { + public: + format_filetimestamp(t_filetimestamp p_timestamp); + operator const char*() const {return m_buffer;} + const char * get_ptr() const {return m_buffer;} + private: + pfc::string_fixed_t<32> m_buffer; + }; + +} diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/foobar2000_sdk_helpers.vcproj b/tools/vio2sf/src/foobar/foobar2000/helpers/foobar2000_sdk_helpers.vcproj new file mode 100644 index 000000000..b68498d52 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/foobar2000_sdk_helpers.vcproj @@ -0,0 +1,909 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/helpers.h b/tools/vio2sf/src/foobar/foobar2000/helpers/helpers.h new file mode 100644 index 000000000..f1232b9cf --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/helpers.h @@ -0,0 +1,45 @@ +#ifndef _FOOBAR2000_SDK_HELPERS_H_ +#define _FOOBAR2000_SDK_HELPERS_H_ + +#include "file_info_update_helper.h" +#include "input_helpers.h" +#include "create_directory_helper.h" +#include "dialog_resize_helper.h" +#include "dropdown_helper.h" +#include "window_placement_helper.h" +#include "win32_dialog.h" +#include "wildcard.h" +#include "cuesheet_index_list.h" +#include "cue_creator.h" +#include "cue_parser.h" +#include "text_file_loader.h" +#include "file_list_helper.h" +#include "preload_info_helper.h" +#include "listview_helper.h" +#include "stream_buffer_helper.h" +#include "file_info_const_impl.h" +#include "file_wrapper_simple.h" +#include "dynamic_bitrate_helper.h" +#include "cfg_guidlist.h" +#include "file_win32_wrapper.h" +#include "file_move_helper.h" +#include "file_cached.h" +#include "seekabilizer.h" +#include "string_filter.h" +#include "bitreader_helper.h" +#include "mp3_utils.h" +#include "win32_misc.h" +#include "COM_utils.h" +#include "metadb_io_hintlist.h" +#include "meta_table_builder.h" +#include "icon_remapping_wildcard.h" +#include "album_art_helpers.h" +#include "clipboard.h" +#include "IDataObjectUtils.h" +#include "CallForwarder.h" +#include "playlist_position_reference_tracker.h" +#include "ThreadUtils.h" +#include "VisUtils.h" +#include "filetimetools.h" + +#endif //_FOOBAR2000_SDK_HELPERS_H_ diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/icon_remapping_wildcard.h b/tools/vio2sf/src/foobar/foobar2000/helpers/icon_remapping_wildcard.h new file mode 100644 index 000000000..c6bb98129 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/icon_remapping_wildcard.h @@ -0,0 +1,13 @@ +class icon_remapping_wildcard_impl : public icon_remapping { +public: + icon_remapping_wildcard_impl(const char * p_pattern,const char * p_iconname) : m_pattern(p_pattern), m_iconname(p_iconname) {} + bool query(const char * p_extension,pfc::string_base & p_iconname) { + if (wildcard_helper::test(p_extension,m_pattern,true)) { + p_iconname = m_iconname; return true; + } else { + return false; + } + } +private: + pfc::string8 m_pattern,m_iconname; +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/input_helpers.cpp b/tools/vio2sf/src/foobar/foobar2000/helpers/input_helpers.cpp new file mode 100644 index 000000000..f36873054 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/input_helpers.cpp @@ -0,0 +1,405 @@ +#include "stdafx.h" + +void input_helper::open(service_ptr_t p_filehint,metadb_handle_ptr p_location,unsigned p_flags,abort_callback & p_abort,bool p_from_redirect,bool p_skip_hints) +{ + open(p_filehint,p_location->get_location(),p_flags,p_abort,p_from_redirect,p_skip_hints); +} + +static void process_fullbuffer(service_ptr_t & p_file,const char * p_path,t_filesize p_fullbuffer,abort_callback & p_abort) { + if (p_fullbuffer > 0) { + if (p_file.is_empty()) { + service_ptr_t fs; + if (filesystem::g_get_interface(fs,p_path)) { + fs->open(p_file,p_path,filesystem::open_mode_read,p_abort); + } + } + + if (p_file.is_valid()) { + t_filesize size = p_file->get_size(p_abort); + if (size != filesize_invalid && size <= p_fullbuffer) { + service_ptr_t l_file_buffered; + if (reader_membuffer_mirror::g_create(l_file_buffered,p_file,p_abort)) { + p_file = l_file_buffered; + } + } + } + } +} + +bool input_helper::need_file_reopen(const char * newPath) const { + return m_input.is_empty() || metadb::path_compare(m_path, newPath) != 0; +} + +bool input_helper::open_path(file::ptr p_filehint,const char * path,abort_callback & p_abort,bool p_from_redirect,bool p_skip_hints) { + p_abort.check(); + + if (!need_file_reopen(path)) return false; + m_input.release(); + + service_ptr_t l_file = p_filehint; + process_fullbuffer(l_file,path,m_fullbuffer,p_abort); + + TRACK_CODE("input_entry::g_open_for_decoding", + input_entry::g_open_for_decoding(m_input,l_file,path,p_abort,p_from_redirect) + ); + + + if (!p_skip_hints) { + try { + static_api_ptr_t()->hint_reader(m_input.get_ptr(),path,p_abort); + } catch(exception_io_data) { + //Don't fail to decode when this barfs, might be barfing when reading info from another subsong than the one we're trying to decode etc. + m_input.release(); + if (l_file.is_valid()) l_file->reopen(p_abort); + TRACK_CODE("input_entry::g_open_for_decoding", + input_entry::g_open_for_decoding(m_input,l_file,path,p_abort,p_from_redirect) + ); + } + } + + m_path = path; + return true; +} + +void input_helper::open_decoding(t_uint32 subsong, t_uint32 flags, abort_callback & p_abort) { + TRACK_CODE("input_decoder::initialize",m_input->initialize(subsong,flags,p_abort)); +} + +void input_helper::open(service_ptr_t p_filehint,const playable_location & p_location,unsigned p_flags,abort_callback & p_abort,bool p_from_redirect,bool p_skip_hints) { + open_path(p_filehint, p_location.get_path(), p_abort, p_from_redirect, p_skip_hints); + + open_decoding(p_location.get_subsong(), p_flags, p_abort); +} + + +void input_helper::close() { + m_input.release(); +} + +bool input_helper::is_open() { + return m_input.is_valid(); +} + +void input_helper::set_logger(event_logger::ptr ptr) { + if (m_input.is_empty()) throw pfc::exception_bug_check_v2(); + input_decoder_v2::ptr v2; + if (m_input->service_query_t(v2)) v2->set_logger(ptr); +} + +bool input_helper::run_raw(audio_chunk & p_chunk, mem_block_container & p_raw, abort_callback & p_abort) { + if (m_input.is_empty()) throw pfc::exception_bug_check_v2(); + input_decoder_v2::ptr v2; + if (!m_input->service_query_t(v2)) throw pfc::exception_not_implemented(); + return v2->run_raw(p_chunk, p_raw, p_abort); +} + +bool input_helper::run(audio_chunk & p_chunk,abort_callback & p_abort) +{ + if (m_input.is_valid()) { + TRACK_CODE("input_decoder::run",return m_input->run(p_chunk,p_abort)); + } else { + throw pfc::exception_bug_check_v2(); + } +} + +void input_helper::seek(double seconds,abort_callback & p_abort) +{ + if (m_input.is_valid()) { + TRACK_CODE("input_decoder::seek",m_input->seek(seconds,p_abort)); + } else { + throw pfc::exception_bug_check_v2(); + } +} + +bool input_helper::can_seek() { + if (m_input.is_valid()) { + return m_input->can_seek(); + } else { + throw pfc::exception_bug_check_v2(); + } +} + +void input_helper::set_full_buffer(t_filesize val) { + m_fullbuffer = val; +} +void input_helper::on_idle(abort_callback & p_abort) { + if (m_input.is_valid()) { + TRACK_CODE("input_decoder::on_idle",m_input->on_idle(p_abort)); + } +} + +bool input_helper::get_dynamic_info(file_info & p_out,double & p_timestamp_delta) { + if (m_input.is_valid()) { + TRACK_CODE("input_decoder::get_dynamic_info",return m_input->get_dynamic_info(p_out,p_timestamp_delta)); + } else { + throw pfc::exception_bug_check_v2(); + } +} + +bool input_helper::get_dynamic_info_track(file_info & p_out,double & p_timestamp_delta) { + if (m_input.is_valid()) { + TRACK_CODE("input_decoder::get_dynamic_info_track",return m_input->get_dynamic_info_track(p_out,p_timestamp_delta)); + } else { + throw pfc::exception_bug_check_v2(); + } +} + +void input_helper::get_info(t_uint32 p_subsong,file_info & p_info,abort_callback & p_abort) { + if (m_input.is_valid()) { + TRACK_CODE("input_decoder::get_info",m_input->get_info(p_subsong,p_info,p_abort)); + } else { + throw pfc::exception_bug_check_v2(); + } +} + +const char * input_helper::get_path() const { + return m_path; +} + + +input_helper::input_helper() : m_fullbuffer(0) +{ +} + + +void input_helper::g_get_info(const playable_location & p_location,file_info & p_info,abort_callback & p_abort,bool p_from_redirect) { + service_ptr_t instance; + input_entry::g_open_for_info_read(instance,0,p_location.get_path(),p_abort,p_from_redirect); + instance->get_info(p_location.get_subsong_index(),p_info,p_abort); +} + +void input_helper::g_set_info(const playable_location & p_location,file_info & p_info,abort_callback & p_abort,bool p_from_redirect) { + service_ptr_t instance; + input_entry::g_open_for_info_write(instance,0,p_location.get_path(),p_abort,p_from_redirect); + instance->set_info(p_location.get_subsong_index(),p_info,p_abort); + instance->commit(p_abort); +} + + +bool dead_item_filter::run(const pfc::list_base_const_t & p_list,bit_array_var & p_mask) { + file_list_helper::file_list_from_metadb_handle_list path_list; + path_list.init_from_list(p_list); + metadb_handle_list valid_handles; + static_api_ptr_t l_metadb; + for(t_size pathidx=0;pathidxhandle_create(temp,make_playable_location(path,0)); + valid_handles.add_item(temp); + } else { + try { + service_ptr_t reader; + + input_entry::g_open_for_info_read(reader,0,path,*this); + t_uint32 count = reader->get_subsong_count(); + for(t_uint32 n=0;nget_subsong(n); + l_metadb->handle_create(ptr,make_playable_location(path,index)); + valid_handles.add_item(ptr); + } + } catch(...) {} + } + } + + if (is_aborting()) return false; + + valid_handles.sort_by_pointer(); + for(t_size listidx=0;listidx & p_list,bit_array_var & p_mask,abort_callback & p_abort) +{ + dead_item_filter_impl_simple filter(p_abort); + return filter.run(p_list,p_mask); +} + +void input_info_read_helper::open(const char * p_path,abort_callback & p_abort) { + if (m_input.is_empty() || metadb::path_compare(m_path,p_path) != 0) + { + TRACK_CODE("input_entry::g_open_for_info_read",input_entry::g_open_for_info_read(m_input,0,p_path,p_abort)); + + m_path = p_path; + } +} + +void input_info_read_helper::get_info(const playable_location & p_location,file_info & p_info,t_filestats & p_stats,abort_callback & p_abort) { + open(p_location.get_path(),p_abort); + + TRACK_CODE("input_info_reader::get_file_stats",p_stats = m_input->get_file_stats(p_abort)); + + TRACK_CODE("input_info_reader::get_info",m_input->get_info(p_location.get_subsong_index(),p_info,p_abort)); +} + +void input_info_read_helper::get_info_check(const playable_location & p_location,file_info & p_info,t_filestats & p_stats,bool & p_reloaded,abort_callback & p_abort) { + open(p_location.get_path(),p_abort); + t_filestats newstats; + TRACK_CODE("input_info_reader::get_file_stats",newstats = m_input->get_file_stats(p_abort)); + if (metadb_handle::g_should_reload(p_stats,newstats,true)) { + p_stats = newstats; + TRACK_CODE("input_info_reader::get_info",m_input->get_info(p_location.get_subsong_index(),p_info,p_abort)); + p_reloaded = true; + } else { + p_reloaded = false; + } +} + + + + + + +void input_helper_cue::open(service_ptr_t p_filehint,const playable_location & p_location,unsigned p_flags,abort_callback & p_abort,double p_start,double p_length) { + p_abort.check(); + + m_start = p_start; + m_position = 0; + m_dynamic_info_trigger = false; + m_dynamic_info_track_trigger = false; + + m_input.open(p_filehint,p_location,p_flags,p_abort,true,true); + + if (!m_input.can_seek()) throw exception_io_object_not_seekable(); + + if (m_start > 0) { + m_input.seek(m_start,p_abort); + } + + if (p_length > 0) { + m_length = p_length; + } else { + file_info_impl temp; + m_input.get_info(0,temp,p_abort); + double ref_length = temp.get_length(); + if (ref_length <= 0) throw exception_io_data(); + m_length = ref_length - m_start + p_length /* negative or zero */; + if (m_length <= 0) throw exception_io_data(); + } +} + +void input_helper_cue::close() {m_input.close();} +bool input_helper_cue::is_open() {return m_input.is_open();} + +bool input_helper_cue::_m_input_run(audio_chunk & p_chunk, mem_block_container * p_raw, abort_callback & p_abort) { + if (p_raw == NULL) { + return m_input.run(p_chunk, p_abort); + } else { + return m_input.run_raw(p_chunk, *p_raw, p_abort); + } +} +bool input_helper_cue::_run(audio_chunk & p_chunk, mem_block_container * p_raw, abort_callback & p_abort) { + p_abort.check(); + + if (m_length > 0) { + if (m_position >= m_length) return false; + + if (!_m_input_run(p_chunk, p_raw, p_abort)) return false; + + m_dynamic_info_trigger = true; + m_dynamic_info_track_trigger = true; + + t_uint64 max = (t_uint64) audio_math::time_to_samples(m_length - m_position, p_chunk.get_sample_rate()); + if (max == 0) + {//handle rounding accidents, this normally shouldn't trigger + m_position = m_length; + return false; + } + + t_size samples = p_chunk.get_sample_count(); + if ((t_uint64)samples > max) + { + p_chunk.set_sample_count((unsigned)max); + if (p_raw != NULL) { + const t_size rawSize = p_raw->get_size(); + PFC_ASSERT( rawSize % samples == 0 ); + p_raw->set_size( (t_size) ( (t_uint64) rawSize * max / samples ) ); + } + m_position = m_length; + } + else + { + m_position += p_chunk.get_duration(); + } + return true; + } + else + { + if (!_m_input_run(p_chunk, p_raw, p_abort)) return false; + m_position += p_chunk.get_duration(); + return true; + } +} +bool input_helper_cue::run_raw(audio_chunk & p_chunk, mem_block_container & p_raw, abort_callback & p_abort) { + return _run(p_chunk, &p_raw, p_abort); +} + +bool input_helper_cue::run(audio_chunk & p_chunk,abort_callback & p_abort) { + return _run(p_chunk, NULL, p_abort); +} + +void input_helper_cue::seek(double p_seconds,abort_callback & p_abort) +{ + m_dynamic_info_trigger = false; + m_dynamic_info_track_trigger = false; + if (m_length <= 0 || p_seconds < m_length) { + m_input.seek(p_seconds + m_start,p_abort); + m_position = p_seconds; + } else { + m_position = m_length; + } +} + +bool input_helper_cue::can_seek() {return true;} +void input_helper_cue::set_full_buffer(t_filesize val) {m_input.set_full_buffer(val);} + +void input_helper_cue::on_idle(abort_callback & p_abort) {m_input.on_idle(p_abort);} + +bool input_helper_cue::get_dynamic_info(file_info & p_out,double & p_timestamp_delta) { + if (m_dynamic_info_trigger) { + m_dynamic_info_trigger = false; + return m_input.get_dynamic_info(p_out,p_timestamp_delta); + } else { + return false; + } +} + +bool input_helper_cue::get_dynamic_info_track(file_info & p_out,double & p_timestamp_delta) { + if (m_dynamic_info_track_trigger) { + m_dynamic_info_track_trigger = false; + return m_input.get_dynamic_info_track(p_out,p_timestamp_delta); + } else { + return false; + } +} + +const char * input_helper_cue::get_path() const {return m_input.get_path();} + +void input_helper_cue::get_info(t_uint32 p_subsong,file_info & p_info,abort_callback & p_abort) {m_input.get_info(p_subsong,p_info,p_abort);} + + diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/input_helpers.h b/tools/vio2sf/src/foobar/foobar2000/helpers/input_helpers.h new file mode 100644 index 000000000..5c2486c0b --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/input_helpers.h @@ -0,0 +1,97 @@ +#ifndef _INPUT_HELPERS_H_ +#define _INPUT_HELPERS_H_ + +class input_helper { +public: + input_helper(); + void open(service_ptr_t p_filehint,metadb_handle_ptr p_location,unsigned p_flags,abort_callback & p_abort,bool p_from_redirect = false,bool p_skip_hints = false); + void open(service_ptr_t p_filehint,const playable_location & p_location,unsigned p_flags,abort_callback & p_abort,bool p_from_redirect = false,bool p_skip_hints = false); + + //! Multilevel open helpers. + //! @returns Diagnostic/helper value: true if the decoder had to be re-opened entirely, false if the instance was reused. + bool open_path(file::ptr p_filehint,const char * path,abort_callback & p_abort,bool p_from_redirect,bool p_skip_hints); + //! Multilevel open helpers. + void open_decoding(t_uint32 subsong, t_uint32 flags, abort_callback & p_abort); + + bool need_file_reopen(const char * newPath) const; + + void close(); + bool is_open(); + bool run(audio_chunk & p_chunk,abort_callback & p_abort); + bool run_raw(audio_chunk & p_chunk, mem_block_container & p_raw, abort_callback & p_abort); + void seek(double seconds,abort_callback & p_abort); + bool can_seek(); + void set_full_buffer(t_filesize val); + void on_idle(abort_callback & p_abort); + bool get_dynamic_info(file_info & p_out,double & p_timestamp_delta); + bool get_dynamic_info_track(file_info & p_out,double & p_timestamp_delta); + void set_logger(event_logger::ptr ptr); + + //! Retrieves path of currently open file. + const char * get_path() const; + + //! Retrieves info about specific subsong of currently open file. + void get_info(t_uint32 p_subsong,file_info & p_info,abort_callback & p_abort); + + static void g_get_info(const playable_location & p_location,file_info & p_info,abort_callback & p_abort,bool p_from_redirect = false); + static void g_set_info(const playable_location & p_location,file_info & p_info,abort_callback & p_abort,bool p_from_redirect = false); + + + static bool g_mark_dead(const pfc::list_base_const_t & p_list,bit_array_var & p_mask,abort_callback & p_abort); + +private: + service_ptr_t m_input; + pfc::string8 m_path; + t_filesize m_fullbuffer; +}; + +class NOVTABLE dead_item_filter : public abort_callback { +public: + virtual void on_progress(t_size p_position,t_size p_total) = 0; + + bool run(const pfc::list_base_const_t & p_list,bit_array_var & p_mask); +}; + +class input_info_read_helper { +public: + input_info_read_helper() {} + void get_info(const playable_location & p_location,file_info & p_info,t_filestats & p_stats,abort_callback & p_abort); + void get_info_check(const playable_location & p_location,file_info & p_info,t_filestats & p_stats,bool & p_reloaded,abort_callback & p_abort); +private: + void open(const char * p_path,abort_callback & p_abort); + + pfc::string8 m_path; + service_ptr_t m_input; +}; + + + +class input_helper_cue { +public: + void open(service_ptr_t p_filehint,const playable_location & p_location,unsigned p_flags,abort_callback & p_abort,double p_start,double p_length); + + void close(); + bool is_open(); + bool run(audio_chunk & p_chunk,abort_callback & p_abort); + bool run_raw(audio_chunk & p_chunk, mem_block_container & p_raw, abort_callback & p_abort); + void seek(double seconds,abort_callback & p_abort); + bool can_seek(); + void set_full_buffer(t_filesize val); + void on_idle(abort_callback & p_abort); + bool get_dynamic_info(file_info & p_out,double & p_timestamp_delta); + bool get_dynamic_info_track(file_info & p_out,double & p_timestamp_delta); + void set_logger(event_logger::ptr ptr) {m_input.set_logger(ptr);} + + const char * get_path() const; + + void get_info(t_uint32 p_subsong,file_info & p_info,abort_callback & p_abort); + +private: + bool _run(audio_chunk & p_chunk, mem_block_container * p_raw, abort_callback & p_abort); + bool _m_input_run(audio_chunk & p_chunk, mem_block_container * p_raw, abort_callback & p_abort); + input_helper m_input; + double m_start,m_length,m_position; + bool m_dynamic_info_trigger,m_dynamic_info_track_trigger; +}; + +#endif \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/listview_helper.cpp b/tools/vio2sf/src/foobar/foobar2000/helpers/listview_helper.cpp new file mode 100644 index 000000000..c18e51ac7 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/listview_helper.cpp @@ -0,0 +1,168 @@ +#include "stdafx.h" + + + +namespace listview_helper { + + unsigned insert_item(HWND p_listview,unsigned p_index,const char * p_name,LPARAM p_param) + { + if (p_index == infinite) p_index = ListView_GetItemCount(p_listview); + LVITEM item = {}; + + pfc::stringcvt::string_os_from_utf8 os_string_temp(p_name); + + item.mask = LVIF_TEXT | LVIF_PARAM; + item.iItem = p_index; + item.lParam = p_param; + item.pszText = const_cast(os_string_temp.get_ptr()); + + LRESULT ret = uSendMessage(p_listview,LVM_INSERTITEM,0,(LPARAM)&item); + if (ret < 0) return infinite; + else return (unsigned) ret; + } + + + + unsigned insert_column(HWND p_listview,unsigned p_index,const char * p_name,unsigned p_width_dlu) + { + pfc::stringcvt::string_os_from_utf8 os_string_temp(p_name); + + RECT rect = {0,0,p_width_dlu,0}; + MapDialogRect(GetParent(p_listview),&rect); + + LVCOLUMN data = {}; + data.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_FMT; + data.fmt = LVCFMT_LEFT; + data.cx = rect.right; + data.pszText = const_cast(os_string_temp.get_ptr()); + + LRESULT ret = uSendMessage(p_listview,LVM_INSERTCOLUMN,p_index,(LPARAM)&data); + if (ret < 0) return infinite; + else return (unsigned) ret; + } + + void get_item_text(HWND p_listview,unsigned p_index,unsigned p_column,pfc::string_base & p_out) { + enum {buffer_length = 4096}; + TCHAR buffer[buffer_length]; + ListView_GetItemText(p_listview,p_index,p_column,buffer,buffer_length); + p_out = pfc::stringcvt::string_utf8_from_os(buffer,buffer_length); + } + + bool set_item_text(HWND p_listview,unsigned p_index,unsigned p_column,const char * p_name) + { + LVITEM item = {}; + + pfc::stringcvt::string_os_from_utf8 os_string_temp(p_name); + + item.mask = LVIF_TEXT; + item.iItem = p_index; + item.iSubItem = p_column; + item.pszText = const_cast(os_string_temp.get_ptr()); + return uSendMessage(p_listview,LVM_SETITEM,0,(LPARAM)&item) ? true : false; + } + + bool is_item_selected(HWND p_listview,unsigned p_index) + { + LVITEM item = {}; + item.mask = LVIF_STATE; + item.iItem = p_index; + item.stateMask = LVIS_SELECTED; + if (!uSendMessage(p_listview,LVM_GETITEM,0,(LPARAM)&item)) return false; + return (item.state & LVIS_SELECTED) ? true : false; + } + + void set_item_selection(HWND p_listview,unsigned p_index,bool p_state) + { + PFC_ASSERT( ::IsWindow(p_listview) ); + LVITEM item = {}; + item.stateMask = LVIS_SELECTED; + item.state = p_state ? LVIS_SELECTED : 0; + WIN32_OP_D( SendMessage(p_listview,LVM_SETITEMSTATE,(WPARAM)p_index,(LPARAM)&item) ); + } + + bool select_single_item(HWND p_listview,unsigned p_index) + { + LRESULT temp = SendMessage(p_listview,LVM_GETITEMCOUNT,0,0); + if (temp < 0) return false; + ListView_SetSelectionMark(p_listview,p_index); + unsigned n; const unsigned m = pfc::downcast_guarded(temp); + for(n=0;n= 0) { + RECT rect; + WIN32_OP_D( ListView_GetItemRect(p_list,firstsel,&rect,LVIR_BOUNDS) ); + p_point.x = (rect.left + rect.right) / 2; + p_point.y = (rect.top + rect.bottom) / 2; + WIN32_OP_D( ClientToScreen(p_list,&p_point) ); + } else { + RECT rect; + WIN32_OP_D(GetClientRect(p_list,&rect)); + p_point.x = (rect.left + rect.right) / 2; + p_point.y = (rect.top + rect.bottom) / 2; + WIN32_OP_D(ClientToScreen(p_list,&p_point)); + } + p_selection = firstsel; + } else { + POINT pt = {(short)LOWORD(p_coords),(short)HIWORD(p_coords)}; + p_point = pt; + POINT client = pt; + WIN32_OP_D( ScreenToClient(p_list,&client) ); + LVHITTESTINFO info = {}; + info.pt = client; + p_selection = ListView_HitTest(p_list,&info); + } +} + +#if 0 +static bool ProbeColumn(HWND view, int index) { + LVCOLUMN col = {LVCF_ORDER}; + return !! ListView_GetColumn(view, index, &col); +} +int ListView_GetColumnCount(HWND listView) { + if (!ProbeColumn(listView, 0)) return 0; + int hi = 1; + for(;;) { + if (!ProbeColumn(listView, hi)) break; + hi <<= 1; + if (hi <= 0) { + PFC_ASSERT(!"Shouldn't get here!"); + return -1; + } + } + int lo = hi >> 1; + //lo is the highest known valid column, hi is the lowest known invalid, let's bsearch thru + while(lo + 1 < hi) { + PFC_ASSERT( lo < hi ); + const int mid = lo + (hi - lo) / 2; + PFC_ASSERT( lo < mid && mid < hi ); + if (ProbeColumn(listView, mid)) { + lo = mid; + } else { + hi = mid; + } + } + return hi; +} +#else +int ListView_GetColumnCount(HWND listView) { + HWND header = ListView_GetHeader(listView); + PFC_ASSERT(header != NULL); + return Header_GetItemCount(header); +} +#endif diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/listview_helper.h b/tools/vio2sf/src/foobar/foobar2000/helpers/listview_helper.h new file mode 100644 index 000000000..9f5831afd --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/listview_helper.h @@ -0,0 +1,40 @@ +namespace listview_helper +{ + unsigned insert_item(HWND p_listview,unsigned p_index,const char * p_name,LPARAM p_param);//returns index of new item on success, infinite on failure + + unsigned insert_column(HWND p_listview,unsigned p_index,const char * p_name,unsigned p_width_dlu);//returns index of new item on success, infinite on failure + + bool set_item_text(HWND p_listview,unsigned p_index,unsigned p_column,const char * p_name); + + bool is_item_selected(HWND p_listview,unsigned p_index); + + void set_item_selection(HWND p_listview,unsigned p_index,bool p_state); + + bool select_single_item(HWND p_listview,unsigned p_index); + + bool ensure_visible(HWND p_listview,unsigned p_index); + + void get_item_text(HWND p_listview,unsigned p_index,unsigned p_column,pfc::string_base & p_out); + +}; + +static int ListView_GetFirstSelection(HWND p_listview) { + return ListView_GetNextItem(p_listview,-1,LVNI_SELECTED); +} + +static int ListView_GetSingleSelection(HWND p_listview) { + if (ListView_GetSelectedCount(p_listview) != 1) return -1; + return ListView_GetFirstSelection(p_listview); +} + +static int ListView_GetFocusItem(HWND p_listview) { + return ListView_GetNextItem(p_listview,-1,LVNI_FOCUSED); +} + +static bool ListView_IsItemSelected(HWND p_listview,int p_index) { + return ListView_GetItemState(p_listview,p_index,LVIS_SELECTED) != 0; +} + +void ListView_GetContextMenuPoint(HWND p_list,LPARAM p_coords,POINT & p_point,int & p_selection); + +int ListView_GetColumnCount(HWND listView); diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/meta_table_builder.h b/tools/vio2sf/src/foobar/foobar2000/helpers/meta_table_builder.h new file mode 100644 index 000000000..45f4594cb --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/meta_table_builder.h @@ -0,0 +1,74 @@ +class __meta_table_enum_wrapper { +public: + __meta_table_enum_wrapper(file_info & p_info) : m_info(p_info) {} + template + void operator() (const char * p_name,const t_values & p_values) { + t_size index = infinite; + for(t_values::const_iterator iter = p_values.first(); iter.is_valid(); ++iter) { + if (index == infinite) index = m_info.__meta_add_unsafe(p_name,*iter); + else m_info.meta_add_value(index,*iter); + } + } +private: + file_info & m_info; +}; + +//! Purpose: building a file_info metadata table from loose input without search-for-existing-entry bottleneck +class meta_table_builder { +public: + typedef pfc::chain_list_v2_t t_entry; + typedef pfc::map_t t_content; + + t_content & content() {return m_data;} + t_content const & content() const {return m_data;} + + void add(const char * p_name,const char * p_value,t_size p_value_len = infinite) { + if (file_info::g_is_valid_field_name(p_name)) { + __add(p_name).insert_last()->set_string(p_value,p_value_len); + } + } + + void remove(const char * p_name) { + m_data.remove(p_name); + } + void set(const char * p_name,const char * p_value,t_size p_value_len = infinite) { + if (file_info::g_is_valid_field_name(p_name)) { + t_entry & entry = __add(p_name); + entry.remove_all(); + entry.insert_last()->set_string(p_value,p_value_len); + } + } + t_entry & add(const char * p_name) { + if (!file_info::g_is_valid_field_name(p_name)) throw pfc::exception_bug_check_v2();//we return a reference, nothing smarter to do + return __add(p_name); + } + void finalize(file_info & p_info) const { + p_info.meta_remove_all(); + m_data.enumerate(__meta_table_enum_wrapper(p_info)); + } + + void from_info(const file_info & p_info) { + m_data.remove_all(); + from_info_overwrite(p_info); + } + void from_info_overwrite(const file_info & p_info) { + for(t_size metawalk = 0, metacount = p_info.meta_get_count(); metawalk < metacount; ++metawalk ) { + const t_size valuecount = p_info.meta_enum_value_count(metawalk); + if (valuecount > 0) { + t_entry & entry = add(p_info.meta_enum_name(metawalk)); + entry.remove_all(); + for(t_size valuewalk = 0; valuewalk < valuecount; ++valuewalk) { + entry.insert_last(p_info.meta_enum_value(metawalk,valuewalk)); + } + } + } + } + void reset() {m_data.remove_all();} +private: + + t_entry & __add(const char * p_name) { + return m_data.find_or_add(p_name); + } + + t_content m_data; +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/metadb_io_hintlist.cpp b/tools/vio2sf/src/foobar/foobar2000/helpers/metadb_io_hintlist.cpp new file mode 100644 index 000000000..4849f1134 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/metadb_io_hintlist.cpp @@ -0,0 +1,39 @@ +#include "stdafx.h" + +void metadb_io_hintlist::run() { + if (m_entries.get_count() > 0) { + static_api_ptr_t()->hint_multi_async( + metadb_io_hintlist_wrapper_part1(m_entries), + metadb_io_hintlist_wrapper_part2(m_entries), + metadb_io_hintlist_wrapper_part3(m_entries), + metadb_io_hintlist_wrapper_part4(m_entries) + ); + } + m_entries.remove_all(); +} + +void metadb_io_hintlist::add(metadb_handle_ptr const & p_handle,const file_info & p_info,t_filestats const & p_stats,bool p_fresh) { + t_entry entry; + entry.m_handle = p_handle; + entry.m_info.new_t(p_info); + entry.m_stats = p_stats; + entry.m_fresh = p_fresh; + m_entries.add_item(entry); +} + +void metadb_io_hintlist::hint_reader(service_ptr_t p_reader, const char * p_path,abort_callback & p_abort) { + static_api_ptr_t api; + const t_uint32 subsongcount = p_reader->get_subsong_count(); + t_filestats stats = p_reader->get_file_stats(p_abort); + for(t_uint32 subsong = 0; subsong < subsongcount; subsong++) { + t_uint32 subsong_id = p_reader->get_subsong(subsong); + metadb_handle_ptr handle; + api->handle_create(handle,make_playable_location(p_path,subsong_id)); + if (handle->should_reload(stats,true)) { + file_info_impl temp; + p_reader->get_info(subsong_id,temp,p_abort); + + add(handle,temp,stats,true); + } + } +} diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/metadb_io_hintlist.h b/tools/vio2sf/src/foobar/foobar2000/helpers/metadb_io_hintlist.h new file mode 100644 index 000000000..054964955 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/metadb_io_hintlist.h @@ -0,0 +1,50 @@ + +class metadb_io_hintlist { +public: + void hint_reader(service_ptr_t p_reader, const char * p_path,abort_callback & p_abort); + void add(metadb_handle_ptr const & p_handle,const file_info & p_info,t_filestats const & p_stats,bool p_fresh); + void run(); + t_size get_pending_count() const {return m_entries.get_count();} +private: + struct t_entry { + metadb_handle_ptr m_handle; + pfc::rcptr_t m_info; + t_filestats m_stats; + bool m_fresh; + }; + class metadb_io_hintlist_wrapper_part1 : public pfc::list_base_const_t { + public: + metadb_io_hintlist_wrapper_part1(const pfc::list_base_const_t & p_list) : m_list(p_list) {} + t_size get_count() const {return m_list.get_count();} + void get_item_ex(metadb_handle_ptr & p_out, t_size n) const {p_out = m_list[n].m_handle;} + + private: + const pfc::list_base_const_t & m_list; + }; + class metadb_io_hintlist_wrapper_part2 : public pfc::list_base_const_t { + public: + metadb_io_hintlist_wrapper_part2(const pfc::list_base_const_t & p_list) : m_list(p_list) {} + t_size get_count() const {return m_list.get_count();} + void get_item_ex(const file_info* & p_out, t_size n) const {p_out = &*m_list[n].m_info;} + private: + const pfc::list_base_const_t & m_list; + }; + class metadb_io_hintlist_wrapper_part3 : public pfc::list_base_const_t { + public: + metadb_io_hintlist_wrapper_part3(const pfc::list_base_const_t & p_list) : m_list(p_list) {} + t_size get_count() const {return m_list.get_count();} + void get_item_ex(t_filestats & p_out, t_size n) const {p_out = m_list[n].m_stats;} + private: + const pfc::list_base_const_t & m_list; + }; + class metadb_io_hintlist_wrapper_part4 : public bit_array { + public: + metadb_io_hintlist_wrapper_part4(const pfc::list_base_const_t & p_list) : m_list(p_list) {} + bool get(t_size n) const {return m_list[n].m_fresh;} + private: + const pfc::list_base_const_t & m_list; + }; + + pfc::list_t m_entries; +}; + diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/mp3_utils.cpp b/tools/vio2sf/src/foobar/foobar2000/helpers/mp3_utils.cpp new file mode 100644 index 000000000..a3ace28e3 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/mp3_utils.cpp @@ -0,0 +1,261 @@ +#include "stdafx.h" + +using namespace bitreader_helper; + +static unsigned extract_header_bits(const t_uint8 p_header[4],unsigned p_base,unsigned p_bits) +{ + assert(p_base+p_bits<=32); + return extract_bits(p_header,p_base,p_bits); +} + +namespace { + + class header_parser + { + public: + header_parser(const t_uint8 p_header[4]) : m_bitptr(0) + { + memcpy(m_header,p_header,4); + } + unsigned read(unsigned p_bits) + { + unsigned ret = extract_header_bits(m_header,m_bitptr,p_bits); + m_bitptr += p_bits; + return ret; + } + private: + t_uint8 m_header[4]; + unsigned m_bitptr; + }; +} + +typedef t_uint16 uint16; + +static const uint16 bitrate_table_l1v1[16] = { 0, 32, 64, 96,128,160,192,224,256,288,320,352,384,416,448, 0}; +static const uint16 bitrate_table_l2v1[16] = { 0, 32, 48, 56, 64, 80, 96,112,128,160,192,224,256,320,384, 0}; +static const uint16 bitrate_table_l3v1[16] = { 0, 32, 40, 48, 56, 64, 80, 96,112,128,160,192,224,256,320, 0}; +static const uint16 bitrate_table_l1v2[16] = { 0, 32, 48, 56, 64, 80, 96,112,128,144,160,176,192,224,256, 0}; +static const uint16 bitrate_table_l23v2[16] = { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96,112,128,144,160, 0}; +static const uint16 sample_rate_table[] = {11025,12000,8000}; + +unsigned mp3_utils::QueryMPEGFrameSize(const t_uint8 p_header[4]) +{ + TMPEGFrameInfo info; + if (!ParseMPEGFrameHeader(info,p_header)) return 0; + return info.m_bytes; +} + +bool mp3_utils::ParseMPEGFrameHeader(TMPEGFrameInfo & p_info,const t_uint8 p_header[4]) +{ + enum {MPEG_LAYER_1 = 3, MPEG_LAYER_2 = 2, MPEG_LAYER_3 = 1}; + enum {_MPEG_1 = 3, _MPEG_2 = 2, _MPEG_25 = 0}; + + header_parser parser(p_header); + if (parser.read(11) != 0x7FF) return false; + unsigned mpeg_version = parser.read(2); + unsigned layer = parser.read(2); + unsigned protection = parser.read(1); + unsigned bitrate_index = parser.read(4); + unsigned sample_rate_index = parser.read(2); + if (sample_rate_index == 11) return false;//reserved + unsigned paddingbit = parser.read(1); + int paddingdelta = 0; + parser.read(1);//private + unsigned channel_mode = parser.read(2); + parser.read(2);//channel_mode_extension + parser.read(1);//copyright + parser.read(1);//original + parser.read(2);//emphasis + + unsigned bitrate = 0,sample_rate = 0; + + switch(layer) + { + default: + return false; + case MPEG_LAYER_3: + paddingdelta = paddingbit ? 1 : 0; + + p_info.m_layer = 3; + switch(mpeg_version) + { + case _MPEG_1: + p_info.m_duration = 1152; + bitrate = bitrate_table_l3v1[bitrate_index]; + break; + case _MPEG_2: + case _MPEG_25: + p_info.m_duration = 576; + bitrate = bitrate_table_l23v2[bitrate_index]; + break; + default: + return false; + } + + break; + case MPEG_LAYER_2: + paddingdelta = paddingbit ? 1 : 0; + p_info.m_duration = 1152; + p_info.m_layer = 2; + switch(mpeg_version) + { + case _MPEG_1: + bitrate = bitrate_table_l2v1[bitrate_index]; + break; + case _MPEG_2: + case _MPEG_25: + bitrate = bitrate_table_l23v2[bitrate_index]; + break; + default: + return false; + } + break; + case MPEG_LAYER_1: + paddingdelta = paddingbit ? 4 : 0; + p_info.m_duration = 384; + p_info.m_layer = 1; + switch(mpeg_version) + { + case _MPEG_1: + bitrate = bitrate_table_l1v1[bitrate_index]; + break; + case _MPEG_2: + case _MPEG_25: + bitrate = bitrate_table_l1v2[bitrate_index]; + break; + default: + return false; + } + break; + } + if (bitrate == 0) return false; + + sample_rate = sample_rate_table[sample_rate_index]; + if (sample_rate == 0) return false; + switch(mpeg_version) + { + case _MPEG_1: + sample_rate *= 4; + p_info.m_mpegversion = MPEG_1; + break; + case _MPEG_2: + sample_rate *= 2; + p_info.m_mpegversion = MPEG_2; + break; + case _MPEG_25: + p_info.m_mpegversion = MPEG_25; + break; + } + + switch(channel_mode) + { + case 0: + case 1: + case 2: + p_info.m_channels = 2; + break; + case 3: + p_info.m_channels = 1; + break; + } + + p_info.m_channel_mode = channel_mode; + + p_info.m_sample_rate = sample_rate; + + + p_info.m_bytes = ( bitrate /*kbps*/ * (1000/8) /* kbps-to-bytes*/ * p_info.m_duration /*samples-per-frame*/ ) / sample_rate + paddingdelta; + + if (p_info.m_layer == 1) p_info.m_bytes &= ~3; + + p_info.m_crc = protection == 0; + + return true; +} + +unsigned mp3header::get_samples_per_frame() +{ + mp3_utils::TMPEGFrameInfo fr; + if (!decode(fr)) return 0; + return fr.m_duration; +} + +bool mp3_utils::IsSameStream(TMPEGFrameInfo const & p_frame1,TMPEGFrameInfo const & p_frame2) { + return + p_frame1.m_channel_mode == p_frame2.m_channel_mode && + p_frame1.m_sample_rate == p_frame2.m_sample_rate && + p_frame1.m_layer == p_frame2.m_layer && + p_frame1.m_mpegversion == p_frame2.m_mpegversion; +} + + + +bool mp3_utils::ValidateFrameCRC(const t_uint8 * frameData, t_size frameSize, TMPEGFrameInfo const & info) { + if (frameSize < info.m_bytes) return false; //FAIL, incomplete data + if (!info.m_crc) return true; //nothing to check, frame appears valid + return ExtractFrameCRC(frameData, frameSize, info) == CalculateFrameCRC(frameData, frameSize, info); +} + +static t_uint32 CRC_update(unsigned value, t_uint32 crc) +{ + enum { CRC16_POLYNOMIAL = 0x8005 }; + unsigned i; + value <<= 8; + for (i = 0; i < 8; i++) { + value <<= 1; + crc <<= 1; + if (((crc ^ value) & 0x10000)) crc ^= CRC16_POLYNOMIAL; + } + return crc; +} + + +void mp3_utils::RecalculateFrameCRC(t_uint8 * frameData, t_size frameSize, TMPEGFrameInfo const & info) { + PFC_ASSERT( frameSize >= info.m_bytes && info.m_crc ); + + const t_uint16 crc = ExtractFrameCRC(frameData, frameSize, info); + frameData[4] = (t_uint8)(crc >> 8); + frameData[5] = (t_uint8)(crc & 0xFF); +} + +static t_uint16 grabFrameCRC(const t_uint8 * frameData, t_size sideInfoLen) { + t_uint32 crc = 0xffff; + crc = CRC_update(frameData[2], crc); + crc = CRC_update(frameData[3], crc); + for (t_size i = 6; i < sideInfoLen; i++) { + crc = CRC_update(frameData[i], crc); + } + + return (t_uint32) (crc & 0xFFFF); +} + +t_uint16 mp3_utils::ExtractFrameCRC(const t_uint8 * frameData, t_size frameSize, TMPEGFrameInfo const & info) { + PFC_ASSERT( frameSize >= info.m_bytes && info.m_crc ); + + return ((t_uint16)frameData[4] << 8) | (t_uint16)frameData[5]; + +} +t_uint16 mp3_utils::CalculateFrameCRC(const t_uint8 * frameData, t_size frameSize, TMPEGFrameInfo const & info) { + PFC_ASSERT( frameSize >= info.m_bytes && info.m_crc ); + + t_size sideInfoLen = 0; + if (info.m_mpegversion == MPEG_1) + sideInfoLen = (info.m_channels == 1) ? 4 + 17 : 4 + 32; + else + sideInfoLen = (info.m_channels == 1) ? 4 + 9 : 4 + 17; + + //CRC + sideInfoLen += 2; + + PFC_ASSERT( sideInfoLen <= frameSize ); + + return grabFrameCRC(frameData, sideInfoLen); +} + + +bool mp3_utils::ValidateFrameCRC(const t_uint8 * frameData, t_size frameSize) { + if (frameSize < 4) return false; //FAIL, not a valid frame + TMPEGFrameInfo info; + if (!ParseMPEGFrameHeader(info, frameData)) return false; //FAIL, not a valid frame + return ValidateFrameCRC(frameData, frameSize, info); +} diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/mp3_utils.h b/tools/vio2sf/src/foobar/foobar2000/helpers/mp3_utils.h new file mode 100644 index 000000000..0d058f29d --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/mp3_utils.h @@ -0,0 +1,68 @@ +namespace mp3_utils +{ + + enum { + MPG_MD_STEREO=0, + MPG_MD_JOINT_STEREO=1, + MPG_MD_DUAL_CHANNEL=2, + MPG_MD_MONO=3, + }; + + typedef t_uint8 byte; + + enum {MPEG_1, MPEG_2, MPEG_25}; + + struct TMPEGFrameInfo + { + unsigned m_bytes; + unsigned m_sample_rate; + unsigned m_layer; + unsigned m_mpegversion; + unsigned m_channels; + unsigned m_duration; + unsigned m_channel_mode; + bool m_crc; + }; + + + bool ParseMPEGFrameHeader(TMPEGFrameInfo & p_info,const t_uint8 p_header[4]); + bool ValidateFrameCRC(const t_uint8 * frameData, t_size frameSize); + bool ValidateFrameCRC(const t_uint8 * frameData, t_size frameSize, TMPEGFrameInfo const & frameInfo); + + //! Assumes valid frame with CRC (frameInfo.m_crc set, frameInfo.m_bytes <= frameSize). + t_uint16 ExtractFrameCRC(const t_uint8 * frameData, t_size frameSize, TMPEGFrameInfo const & frameInfo); + //! Assumes valid frame with CRC (frameInfo.m_crc set, frameInfo.m_bytes <= frameSize). + t_uint16 CalculateFrameCRC(const t_uint8 * frameData, t_size frameSize, TMPEGFrameInfo const & frameInfo); + //! Assumes valid frame with CRC (frameInfo.m_crc set, frameInfo.m_bytes <= frameSize). + void RecalculateFrameCRC(t_uint8 * frameData, t_size frameSize, TMPEGFrameInfo const & frameInfo); + + unsigned QueryMPEGFrameSize(const t_uint8 p_header[4]); + bool IsSameStream(TMPEGFrameInfo const & p_frame1,TMPEGFrameInfo const & p_frame2); +}; + +class mp3header +{ + t_uint8 bytes[4]; +public: + + inline void copy(const mp3header & src) {memcpy(bytes,src.bytes,4);} + inline void copy_raw(const void * src) {memcpy(bytes,src,4);} + + inline mp3header(const mp3header & src) {copy(src);} + inline mp3header() {} + + inline const mp3header & operator=(const mp3header & src) {copy(src); return *this;} + + inline void get_bytes(void * out) {memcpy(out,bytes,4);} + inline unsigned get_frame_size() const {return mp3_utils::QueryMPEGFrameSize(bytes);} + inline bool decode(mp3_utils::TMPEGFrameInfo & p_out) {return mp3_utils::ParseMPEGFrameHeader(p_out,bytes);} + + unsigned get_samples_per_frame(); +}; + +static inline mp3header mp3header_from_buffer(const void * p_buffer) +{ + mp3header temp; + temp.copy_raw(p_buffer); + return temp; +} \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/playlist_position_reference_tracker.h b/tools/vio2sf/src/foobar/foobar2000/helpers/playlist_position_reference_tracker.h new file mode 100644 index 000000000..4108b071a --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/playlist_position_reference_tracker.h @@ -0,0 +1,73 @@ +class playlist_position_reference_tracker : public playlist_callback_impl_base { +public: + //! @param p_trackitem Specifies whether we want to track some specific item rather than just an offset in a playlist. When set to true, item index becomes invalidated when the item we're tracking is removed. + playlist_position_reference_tracker(bool p_trackitem = true) : playlist_callback_impl_base(~0), m_trackitem(p_trackitem), m_playlist(infinite), m_item(infinite) {} + + void on_items_added(t_size p_playlist,t_size p_start, const pfc::list_base_const_t & p_data,const bit_array & p_selection) { + if (p_playlist == m_playlist && m_item != infinite && p_start <= m_item) { + m_item += p_data.get_count(); + } + } + void on_items_reordered(t_size p_playlist,const t_size * p_order,t_size p_count) { + if (p_playlist == m_playlist) { + if (m_item < p_count) { + m_item = order_helper::g_find_reverse(p_order,m_item); + } else { + m_item = infinite; + } + } + } + + void on_items_removed(t_size p_playlist,const bit_array & p_mask,t_size p_old_count,t_size p_new_count) { + if (p_playlist == m_playlist) { + if (m_item < p_old_count) { + const t_size item_before = m_item; + for(t_size walk = p_mask.find_first(true,0,p_old_count); walk < p_old_count; walk = p_mask.find_next(true,walk,p_old_count)) { + if (walk < item_before) { + m_item--; + } else if (walk == item_before) { + if (m_trackitem) m_item = infinite; + break; + } else { + break; + } + } + if (m_item >= p_new_count) m_item = infinite; + } else { + m_item = infinite; + } + } + } + + //todo? could be useful in some cases + void on_items_replaced(t_size p_playlist,const bit_array & p_mask,const pfc::list_base_const_t & p_data) {} + + void on_playlist_created(t_size p_index,const char * p_name,t_size p_name_len) { + if (m_playlist != infinite && p_index <= m_playlist) m_playlist++; + } + void on_playlists_reorder(const t_size * p_order,t_size p_count) { + if (m_playlist < p_count) m_playlist = order_helper::g_find_reverse(p_order,m_playlist); + else m_playlist = infinite; + } + void on_playlists_removed(const bit_array & p_mask,t_size p_old_count,t_size p_new_count) { + if (m_playlist < p_old_count) { + const t_size playlist_before = m_playlist; + for(t_size walk = p_mask.find_first(true,0,p_old_count); walk < p_old_count; walk = p_mask.find_next(true,walk,p_old_count)) { + if (walk < playlist_before) { + m_playlist--; + } else if (walk == playlist_before) { + m_playlist = infinite; + break; + } else { + break; + } + } + } else { + m_playlist = infinite; + } + } + + t_size m_playlist, m_item; +private: + const bool m_trackitem; +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/preload_info_helper.cpp b/tools/vio2sf/src/foobar/foobar2000/helpers/preload_info_helper.cpp new file mode 100644 index 000000000..1d352605a --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/preload_info_helper.cpp @@ -0,0 +1,29 @@ +#include "stdafx.h" + +bool preload_info_helper::preload_info(metadb_handle_ptr p_item,HWND p_parent_window,bool p_showerror) { + if (p_item->is_info_loaded()) return true; + return static_api_ptr_t()->load_info(p_item,metadb_io::load_info_default,p_parent_window,p_showerror) == metadb_io::load_info_success; +} + +bool preload_info_helper::are_all_loaded(const pfc::list_base_const_t & p_items) +{ + t_size n, m = p_items.get_count(); + for(n=0;nis_info_loaded()) return false; + } + return true; +} + +bool preload_info_helper::preload_info_multi(const pfc::list_base_const_t & p_items,HWND p_parent_window,bool p_showerror) +{ + if (are_all_loaded(p_items)) return true; + return static_api_ptr_t()->load_info_multi(p_items,metadb_io::load_info_default,p_parent_window,p_showerror) == metadb_io::load_info_success; +} + +bool preload_info_helper::preload_info_multi_modalcheck(const pfc::list_base_const_t & p_items,HWND p_parent_window,bool p_showerror) +{ + if (are_all_loaded(p_items)) return true; + if (!modal_dialog_scope::can_create()) return false; + return static_api_ptr_t()->load_info_multi(p_items,metadb_io::load_info_default,p_parent_window,p_showerror) == metadb_io::load_info_success; +} diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/preload_info_helper.h b/tools/vio2sf/src/foobar/foobar2000/helpers/preload_info_helper.h new file mode 100644 index 000000000..5f3451f36 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/preload_info_helper.h @@ -0,0 +1,6 @@ +namespace preload_info_helper { + bool __declspec(deprecated("Use metadb_io_v2 methods instead.")) preload_info(metadb_handle_ptr p_item,HWND p_parent_window,bool p_showerror); + bool __declspec(deprecated("Use metadb_io_v2 methods instead.")) preload_info_multi(const pfc::list_base_const_t & p_items,HWND p_parent_window,bool p_showerror); + bool __declspec(deprecated("Use metadb_io_v2 methods instead.")) preload_info_multi_modalcheck(const pfc::list_base_const_t & p_items,HWND p_parent_window,bool p_showerror); + bool are_all_loaded(const pfc::list_base_const_t & p_items); +}; \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/seekabilizer.cpp b/tools/vio2sf/src/foobar/foobar2000/helpers/seekabilizer.cpp new file mode 100644 index 000000000..5173d39ec --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/seekabilizer.cpp @@ -0,0 +1,218 @@ +#include "stdafx.h" + +enum {backread_on_seek = 1024}; + +void seekabilizer_backbuffer::initialize(t_size p_size) +{ + m_depth = m_cursor = 0; + + m_buffer.set_size(p_size); +} + +void seekabilizer_backbuffer::write(const void * p_buffer,t_size p_bytes) +{ + if (p_bytes >= m_buffer.get_size()) + { + memcpy(m_buffer.get_ptr(),(const t_uint8*)p_buffer + p_bytes - m_buffer.get_size(),m_buffer.get_size()); + m_cursor = 0; + m_depth = m_buffer.get_size(); + } + else + { + const t_uint8* sourceptr = (const t_uint8*) p_buffer; + t_size remaining = p_bytes; + while(remaining > 0) + { + t_size delta = m_buffer.get_size() - m_cursor; + if (delta > remaining) delta = remaining; + + memcpy(m_buffer.get_ptr() + m_cursor,sourceptr,delta); + + sourceptr += delta; + remaining -= delta; + m_cursor = (m_cursor + delta) % m_buffer.get_size(); + + m_depth = pfc::min_t(m_buffer.get_size(),m_depth + delta); + + } + } +} + +void seekabilizer_backbuffer::read(t_size p_backlogdepth,void * p_buffer,t_size p_bytes) const +{ + assert(p_backlogdepth <= m_depth); + assert(p_backlogdepth >= p_bytes); + + + t_uint8* targetptr = (t_uint8*) p_buffer; + t_size remaining = p_bytes; + t_size cursor = (m_cursor + m_buffer.get_size() - p_backlogdepth) % m_buffer.get_size(); + + while(remaining > 0) + { + t_size delta = m_buffer.get_size() - cursor; + if (delta > remaining) delta = remaining; + + memcpy(targetptr,m_buffer.get_ptr() + cursor,delta); + + targetptr += delta; + remaining -= delta; + cursor = (cursor + delta) % m_buffer.get_size(); + } +} + +t_size seekabilizer_backbuffer::get_depth() const +{ + return m_depth; +} + +t_size seekabilizer_backbuffer::get_max_depth() const +{ + return m_buffer.get_size(); +} + +void seekabilizer_backbuffer::reset() +{ + m_depth = m_cursor = 0; +} + + +void seekabilizer::initialize(service_ptr_t p_base,t_size p_buffer_size,abort_callback & p_abort) { + m_buffer.initialize(p_buffer_size); + m_file = p_base; + m_position = m_position_base = 0; + m_size = m_file->get_size(p_abort); +} + +void seekabilizer::g_seekabilize(service_ptr_t & p_reader,t_size p_buffer_size,abort_callback & p_abort) { + if (p_reader.is_valid() && p_reader->is_remote() && p_buffer_size > 0) { + service_ptr_t instance = new service_impl_t(); + instance->initialize(p_reader,p_buffer_size,p_abort); + p_reader = instance.get_ptr(); + } +} + +t_size seekabilizer::read(void * p_buffer,t_size p_bytes,abort_callback & p_abort) { + p_abort.check_e(); + + if (m_position > m_position_base + pfc::max_t(m_buffer.get_max_depth(),backread_on_seek) && m_file->can_seek()) { + t_filesize target = m_position; + if (target < backread_on_seek) target = 0; + else target -= backread_on_seek; + m_file->seek(target,p_abort); + m_position_base = target; + } + + //seek ahead + while(m_position > m_position_base) { + enum {tempsize = 1024}; + t_uint8 temp[tempsize]; + t_size delta = (t_size) pfc::min_t(tempsize,m_position - m_position_base); + t_size bytes_read = 0; + bytes_read = m_file->read(temp,delta,p_abort); + m_buffer.write(temp,bytes_read); + m_position_base += bytes_read; + + if (bytes_read < delta) { + return 0; + } + } + + t_size done = 0; + t_uint8 * targetptr = (t_uint8*) p_buffer; + + //try to read backbuffer + if (m_position < m_position_base) { + if (m_position_base - m_position > (t_filesize)m_buffer.get_depth()) throw exception_io_seek_out_of_range(); + t_size backread_depth = (t_size) (m_position_base - m_position); + t_size delta = pfc::min_t(backread_depth,p_bytes-done); + m_buffer.read(backread_depth,targetptr,delta); + done += delta; + m_position += delta; + } + + //regular read + if (done < p_bytes) + { + t_size bytes_read; + bytes_read = m_file->read(targetptr+done,p_bytes-done,p_abort); + + m_buffer.write(targetptr+done,bytes_read); + + done += bytes_read; + m_position += bytes_read; + m_position_base += bytes_read; + } + + return done; +} + +t_filesize seekabilizer::get_size(abort_callback & p_abort) { + p_abort.check_e(); + return m_size; +} + +t_filesize seekabilizer::get_position(abort_callback & p_abort) { + p_abort.check_e(); + return m_position; +} + +void seekabilizer::seek(t_filesize p_position,abort_callback & p_abort) { + assert(m_position_base >= m_buffer.get_depth()); + p_abort.check_e(); + + if (m_size != filesize_invalid && p_position > m_size) throw exception_io_seek_out_of_range(); + + t_filesize lowest = m_position_base - m_buffer.get_depth(); + + if (p_position < lowest) { + if (m_file->can_seek()) { + m_buffer.reset(); + t_filesize target = p_position; + t_size delta = m_buffer.get_max_depth(); + if (delta > backread_on_seek) delta = backread_on_seek; + if (target > delta) target -= delta; + else target = 0; + m_file->seek(target,p_abort); + m_position_base = target; + } + else { + m_buffer.reset(); + m_file->reopen(p_abort); + m_position_base = 0; + } + } + + m_position = p_position; +} + +bool seekabilizer::can_seek() +{ + return true; +} + +bool seekabilizer::get_content_type(pfc::string_base & p_out) {return m_file->get_content_type(p_out);} + +bool seekabilizer::is_in_memory() {return false;} + +void seekabilizer::on_idle(abort_callback & p_abort) {return m_file->on_idle(p_abort);} + +t_filetimestamp seekabilizer::get_timestamp(abort_callback & p_abort) { + p_abort.check_e(); + return m_file->get_timestamp(p_abort); +} + +void seekabilizer::reopen(abort_callback & p_abort) { + if (m_position_base - m_buffer.get_depth() == 0) { + seek(0,p_abort); + } else { + m_position = m_position_base = 0; + m_buffer.reset(); + m_file->reopen(p_abort); + } +} + +bool seekabilizer::is_remote() +{ + return m_file->is_remote(); +} diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/seekabilizer.h b/tools/vio2sf/src/foobar/foobar2000/helpers/seekabilizer.h new file mode 100644 index 000000000..454546b14 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/seekabilizer.h @@ -0,0 +1,36 @@ +class seekabilizer_backbuffer +{ +public: + void initialize(t_size p_size); + void write(const void * p_buffer,t_size p_bytes); + void read(t_size p_backlogdepth,void * p_buffer,t_size p_bytes) const; + t_size get_depth() const; + void reset(); + t_size get_max_depth() const; +private: + pfc::array_t m_buffer; + t_size m_depth,m_cursor; +}; + +class seekabilizer : public file_readonly { +public: + void initialize(service_ptr_t p_base,t_size p_buffer_size,abort_callback & p_abort); + + static void g_seekabilize(service_ptr_t & p_reader,t_size p_buffer_size,abort_callback & p_abort); + + t_size read(void * p_buffer,t_size p_bytes,abort_callback & p_abort); + t_filesize get_size(abort_callback & p_abort); + t_filesize get_position(abort_callback & p_abort); + void seek(t_filesize p_position,abort_callback & p_abort); + bool can_seek(); + bool get_content_type(pfc::string_base & p_out); + bool is_in_memory(); + void on_idle(abort_callback & p_abort); + t_filetimestamp get_timestamp(abort_callback & p_abort); + void reopen(abort_callback & p_abort); + bool is_remote(); +private: + service_ptr_t m_file; + seekabilizer_backbuffer m_buffer; + t_filesize m_size,m_position,m_position_base; +}; \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/stream_buffer_helper.cpp b/tools/vio2sf/src/foobar/foobar2000/helpers/stream_buffer_helper.cpp new file mode 100644 index 000000000..6e6c099a2 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/stream_buffer_helper.cpp @@ -0,0 +1,79 @@ +#include "stdafx.h" + +stream_reader_buffered::stream_reader_buffered(stream_reader * p_base,t_size p_buffer) : m_base(p_base) +{ + m_buffer.set_size(p_buffer); + m_buffer_ptr = 0; + m_buffer_max = 0; +} + +t_size stream_reader_buffered::read(void * p_buffer,t_size p_bytes,abort_callback & p_abort) { + p_abort.check_e(); + char * output = (char*) p_buffer; + t_size output_ptr = 0; + + while(output_ptr < p_bytes) { + { + t_size delta = pfc::min_t(p_bytes - output_ptr, m_buffer_max - m_buffer_ptr); + if (delta > 0) + { + memcpy(output + output_ptr, m_buffer.get_ptr() + m_buffer_ptr, delta); + output_ptr += delta; + m_buffer_ptr += delta; + } + } + + if (m_buffer_ptr == m_buffer_max) + { + t_size bytes_read; + bytes_read = m_base->read(m_buffer.get_ptr(), m_buffer.get_size(), p_abort); + m_buffer_ptr = 0; + m_buffer_max = bytes_read; + + if (m_buffer_max == 0) break; + } + } + + return output_ptr; +} + +stream_writer_buffered::stream_writer_buffered(stream_writer * p_base,t_size p_buffer) + : m_base(p_base) +{ + m_buffer.set_size(p_buffer); + m_buffer_ptr = 0; +} + +void stream_writer_buffered::write(const void * p_buffer,t_size p_bytes,abort_callback & p_abort) { + p_abort.check_e(); + const char * source = (const char*)p_buffer; + t_size source_remaining = p_bytes; + const t_size buffer_size = m_buffer.get_size(); + if (source_remaining >= buffer_size) + { + flush(p_abort); + m_base->write_object(source,source_remaining,p_abort); + return; + } + + if (m_buffer_ptr + source_remaining >= buffer_size) + { + t_size delta = buffer_size - m_buffer_ptr; + memcpy(m_buffer.get_ptr() + m_buffer_ptr, source,delta); + source += delta; + source_remaining -= delta; + m_buffer_ptr += delta; + flush(p_abort); + } + + memcpy(m_buffer.get_ptr() + m_buffer_ptr, source,source_remaining); + m_buffer_ptr += source_remaining; +} + + +void stream_writer_buffered::flush(abort_callback & p_abort) { + if (m_buffer_ptr > 0) { + m_base->write_object(m_buffer.get_ptr(),m_buffer_ptr,p_abort); + m_buffer_ptr = 0; + } +} \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/stream_buffer_helper.h b/tools/vio2sf/src/foobar/foobar2000/helpers/stream_buffer_helper.h new file mode 100644 index 000000000..b58c382c4 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/stream_buffer_helper.h @@ -0,0 +1,26 @@ +class stream_reader_buffered : public stream_reader +{ +public: + stream_reader_buffered(stream_reader * p_base,t_size p_buffer); + t_size read(void * p_buffer,t_size p_bytes,abort_callback & p_abort); +private: + stream_reader * m_base; + pfc::array_t m_buffer; + t_size m_buffer_ptr, m_buffer_max; +}; + +class stream_writer_buffered : public stream_writer +{ +public: + stream_writer_buffered(stream_writer * p_base,t_size p_buffer); + + void write(const void * p_buffer,t_size p_bytes,abort_callback & p_abort); + + void flush(abort_callback & p_abort); + +private: + stream_writer * m_base; + pfc::array_t m_buffer; + t_size m_buffer_ptr; +}; + diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/string_filter.h b/tools/vio2sf/src/foobar/foobar2000/helpers/string_filter.h new file mode 100644 index 000000000..6507407de --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/string_filter.h @@ -0,0 +1,24 @@ +class string_filter_noncasesensitive { +public: + string_filter_noncasesensitive(const char * p_string,t_size p_string_len = infinite) { + uStringLower(m_pattern,p_string,p_string_len); + } + + bool test(const char * p_string,t_size p_string_len = infinite) const { + ::uStringLower(m_lowercasebuffer,p_string,p_string_len); + t_size walk = 0; + while(m_pattern[walk] != 0) { + while(m_pattern[walk] == ' ') walk++; + t_size delta = 0; + while(m_pattern[walk+delta] != 0 && m_pattern[walk+delta] != ' ') delta++; + if (delta > 0) { + if (pfc::string_find_first_ex(m_lowercasebuffer,infinite,m_pattern+walk,delta) == infinite) return false; + } + walk += delta; + } + return true; + } +private: + mutable pfc::string8_fastalloc m_lowercasebuffer; + pfc::string8 m_pattern; +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/text_file_loader.cpp b/tools/vio2sf/src/foobar/foobar2000/helpers/text_file_loader.cpp new file mode 100644 index 000000000..ec63ff403 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/text_file_loader.cpp @@ -0,0 +1,100 @@ +#include "StdAfx.h" + +static const unsigned char utf8_header[3] = {0xEF,0xBB,0xBF}; + +namespace text_file_loader +{ + void write(const service_ptr_t & p_file,abort_callback & p_abort,const char * p_string,bool is_utf8) + { + p_file->seek(0,p_abort); + p_file->set_eof(p_abort); + if (is_utf8) + { + p_file->write_object(utf8_header,sizeof(utf8_header),p_abort); + p_file->write_object(p_string,strlen(p_string),p_abort); + } + else + { + pfc::stringcvt::string_ansi_from_utf8 bah(p_string); + p_file->write_object(bah,bah.length(),p_abort); + } + } + + void read(const service_ptr_t & p_file,abort_callback & p_abort,pfc::string_base & p_out,bool & is_utf8) { + p_out.reset(); + if (p_file->can_seek()) + { + p_file->seek(0,p_abort); + } + + pfc::array_t mem; + t_filesize size64; + size64 = p_file->get_size(p_abort); + if (size64 == filesize_invalid)//typically HTTP + { + pfc::string8 ansitemp; + is_utf8 = false; + enum {delta = 1024*64, max = 1024*512}; + char temp[3]; + t_size done; + done = p_file->read(temp,3,p_abort); + if (done != 3) + { + if (done > 0) p_out = pfc::stringcvt::string_utf8_from_ansi(temp,done); + return; + } + if (!memcmp(utf8_header,temp,3)) is_utf8 = true; + else ansitemp.add_string(temp,3); + + mem.set_size(delta); + + for(;;) + { + done = p_file->read(mem.get_ptr(),delta,p_abort); + if (done > 0) + { + if (is_utf8) p_out.add_string(mem.get_ptr(),done); + else ansitemp.add_string(mem.get_ptr(),done); + } + if (done < delta) break; + } + + if (!is_utf8) + { + p_out = pfc::stringcvt::string_utf8_from_ansi(ansitemp); + } + + return; + } + else + { + if (size64>1024*1024*128) throw exception_io_data();//hard limit + t_size size = pfc::downcast_guarded(size64); + mem.set_size(size+1); + char * asdf = mem.get_ptr(); + p_file->read_object(asdf,size,p_abort); + asdf[size]=0; + if (size>3 && !memcmp(utf8_header,asdf,3)) {is_utf8 = true; p_out.add_string(asdf+3); } + else { + is_utf8 = false; + p_out = pfc::stringcvt::string_utf8_from_ansi(asdf); + } + return; + } + } + + void write(const char * p_path,abort_callback & p_abort,const char * p_string,bool is_utf8) + { + service_ptr_t f; + filesystem::g_open_write_new(f,p_path,p_abort); + write(f,p_abort,p_string,is_utf8); + } + + void read(const char * p_path,abort_callback & p_abort,pfc::string_base & p_out,bool & is_utf8) + { + service_ptr_t f; + filesystem::g_open_read(f,p_path,p_abort); + read(f,p_abort,p_out,is_utf8); + } + +} \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/text_file_loader.h b/tools/vio2sf/src/foobar/foobar2000/helpers/text_file_loader.h new file mode 100644 index 000000000..fd4b83622 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/text_file_loader.h @@ -0,0 +1,9 @@ +namespace text_file_loader +{ + void write(const service_ptr_t & p_file,abort_callback & p_abort,const char * p_string,bool is_utf8); + void read(const service_ptr_t & p_file,abort_callback & p_abort,pfc::string_base & p_out,bool & is_utf8); + + void write(const char * p_path,abort_callback & p_abort,const char * p_string,bool is_utf8); + void read(const char * p_path,abort_callback & p_abort,pfc::string_base & p_out,bool & is_utf8); + +}; \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/wildcard.cpp b/tools/vio2sf/src/foobar/foobar2000/helpers/wildcard.cpp new file mode 100644 index 000000000..de15870eb --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/wildcard.cpp @@ -0,0 +1,44 @@ +#include "stdafx.h" + +static bool test_recur(const char * fn,const char * rm,bool b_sep) +{ + for(;;) + { + if ((b_sep && *rm==';') || *rm==0) return *fn==0; + else if (*rm=='*') + { + rm++; + do + { + if (test_recur(fn,rm,b_sep)) return true; + } while(pfc::utf8_advance(fn)); + return false; + } + else if (*fn==0) return false; + else if (*rm!='?' && uCharLower(pfc::utf8_get_char(fn))!=uCharLower(pfc::utf8_get_char(rm))) return false; + + fn = pfc::utf8_char_next(fn); rm = pfc::utf8_char_next(rm); + } +} + +bool wildcard_helper::test_path(const char * path,const char * pattern,bool b_sep) {return test(path + pfc::scan_filename(path),pattern,b_sep);} + +bool wildcard_helper::test(const char * fn,const char * pattern,bool b_sep) +{ + if (!b_sep) return test_recur(fn,pattern,false); + const char * rm=pattern; + while(*rm) + { + if (test_recur(fn,rm,true)) return true; + while(*rm && *rm!=';') rm++; + if (*rm==';') + { + while(*rm==';') rm++; + while(*rm==' ') rm++; + } + }; + + return false; +} + +bool wildcard_helper::has_wildcards(const char * str) {return strchr(str,'*') || strchr(str,'?');} \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/wildcard.h b/tools/vio2sf/src/foobar/foobar2000/helpers/wildcard.h new file mode 100644 index 000000000..c38aed9f7 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/wildcard.h @@ -0,0 +1,13 @@ +#ifndef __FOOBAR2000_HELPER_WILDCARD_H__ +#define __FOOBAR2000_HELPER_WILDCARD_H__ + +namespace wildcard_helper +{ + bool test_path(const char * path,const char * pattern,bool b_separate_by_semicolon = false);//will extract filename from path first + bool test(const char * str,const char * pattern,bool b_separate_by_semicolon = false);//tests if str matches pattern + bool has_wildcards(const char * str); +}; + + + +#endif //__FOOBAR2000_HELPER_WILDCARD_H__ \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/win32_dialog.cpp b/tools/vio2sf/src/foobar/foobar2000/helpers/win32_dialog.cpp new file mode 100644 index 000000000..1c38be59a --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/win32_dialog.cpp @@ -0,0 +1,288 @@ +#include "stdafx.h" + + +namespace dialog_helper { + + + INT_PTR CALLBACK dialog::DlgProc(HWND wnd,UINT msg,WPARAM wp,LPARAM lp) + { + dialog * p_this; + BOOL rv; + if (msg==WM_INITDIALOG) + { + p_this = reinterpret_cast(lp); + p_this->wnd = wnd; + SetWindowLongPtr(wnd,DWLP_USER,lp); + + if (p_this->m_is_modal) p_this->m_modal_scope.initialize(wnd); + } + else p_this = reinterpret_cast(GetWindowLongPtr(wnd,DWLP_USER)); + + rv = p_this ? p_this->on_message(msg,wp,lp) : FALSE; + + if (msg==WM_DESTROY && p_this) + { + SetWindowLongPtr(wnd,DWLP_USER,0); +// p_this->wnd = 0; + } + + return rv; + } + + + int dialog::run_modal(unsigned id,HWND parent) + { + assert(wnd == 0); + if (wnd != 0) return -1; + m_is_modal = true; + return uDialogBox(id,parent,DlgProc,reinterpret_cast(this)); + } + HWND dialog::run_modeless(unsigned id,HWND parent) + { + assert(wnd == 0); + if (wnd != 0) return 0; + m_is_modal = false; + return uCreateDialog(id,parent,DlgProc,reinterpret_cast(this)); + } + + void dialog::end_dialog(int code) + { + assert(m_is_modal); + if (m_is_modal) uEndDialog(wnd,code); + } + + + + + + + + + + + int dialog_modal::run(unsigned p_id,HWND p_parent,HINSTANCE p_instance) + { + int status; + + // note: uDialogBox() has its own modal scope, we don't want that to trigger + // if this is ever changed, move deinit to WM_DESTROY handler in DlgProc + + status = (int)DialogBoxParam(p_instance,MAKEINTRESOURCE(p_id),p_parent,DlgProc,reinterpret_cast(this)); + + m_modal_scope.deinitialize(); + + return status; + } + + void dialog_modal::end_dialog(int p_code) + { + EndDialog(m_wnd,p_code); + } + + + INT_PTR CALLBACK dialog_modal::DlgProc(HWND wnd,UINT msg,WPARAM wp,LPARAM lp) + { + dialog_modal * _this; + if (msg==WM_INITDIALOG) + { + _this = reinterpret_cast(lp); + _this->m_wnd = wnd; + SetWindowLongPtr(wnd,DWLP_USER,lp); + + _this->m_modal_scope.initialize(wnd); + } + else _this = reinterpret_cast(GetWindowLongPtr(wnd,DWLP_USER)); + + assert(_this == 0 || _this->m_wnd == wnd); + + return _this ? _this->on_message(msg,wp,lp) : FALSE; + } + + + bool dialog_modeless::create(unsigned p_id,HWND p_parent,HINSTANCE p_instance) { + assert(!m_is_in_create); + if (m_is_in_create) return false; + pfc::vartoggle_t scope(m_is_in_create,true); + if (CreateDialogParam(p_instance,MAKEINTRESOURCE(p_id),p_parent,DlgProc,reinterpret_cast(this)) == 0) return false; + return m_wnd != 0; + } + + dialog_modeless::~dialog_modeless() { + assert(!m_is_in_create); + switch(m_destructor_status) + { + case destructor_none: + m_destructor_status = destructor_normal; + if (m_wnd != 0) + { + DestroyWindow(m_wnd); + m_wnd = 0; + } + break; + case destructor_fromwindow: + if (m_wnd != 0) SetWindowLongPtr(m_wnd,DWLP_USER,0); + break; + default: + //should never trigger + pfc::crash(); + break; + } + } + + void dialog_modeless::on_window_destruction() + { + if (m_is_in_create) + { + m_wnd = 0; + } + else + switch(m_destructor_status) + { + case destructor_none: + m_destructor_status = destructor_fromwindow; + delete this; + break; + case destructor_fromwindow: + pfc::crash(); + break; + default: + break; + } + } + + BOOL dialog_modeless::on_message_wrap(UINT msg,WPARAM wp,LPARAM lp) + { + if (m_destructor_status == destructor_none) + return on_message(msg,wp,lp); + else + return FALSE; + } + + INT_PTR CALLBACK dialog_modeless::DlgProc(HWND wnd,UINT msg,WPARAM wp,LPARAM lp) + { + dialog_modeless * thisptr; + BOOL rv; + if (msg == WM_INITDIALOG) + { + thisptr = reinterpret_cast(lp); + thisptr->m_wnd = wnd; + SetWindowLongPtr(wnd,DWLP_USER,lp); + modeless_dialog_manager::g_add(wnd); + } + else thisptr = reinterpret_cast(GetWindowLongPtr(wnd,DWLP_USER)); + + rv = thisptr ? thisptr->on_message_wrap(msg,wp,lp) : FALSE; + + if (msg == WM_DESTROY) + modeless_dialog_manager::g_remove(wnd); + + if (msg == WM_DESTROY && thisptr != 0) + thisptr->on_window_destruction(); + + return rv; + } + + + + + + + + + + + + + + + + + dialog_modeless_v2::dialog_modeless_v2(unsigned p_id,HWND p_parent,HINSTANCE p_instance,bool p_stealfocus) : m_wnd(0), m_status(status_construction), m_stealfocus(p_stealfocus) + { + WIN32_OP( CreateDialogParam(p_instance,MAKEINTRESOURCE(p_id),p_parent,DlgProc,reinterpret_cast(this)) != NULL ); + m_status = status_lifetime; + } + + dialog_modeless_v2::~dialog_modeless_v2() + { + bool is_window_being_destroyed = (m_status == status_destruction_requested); + m_status = status_destruction; + + if (m_wnd != 0) + { + if (is_window_being_destroyed) + detach_window(); + else + DestroyWindow(m_wnd); + } + } + + INT_PTR CALLBACK dialog_modeless_v2::DlgProc(HWND wnd,UINT msg,WPARAM wp,LPARAM lp) + { + dialog_modeless_v2 * thisptr; + BOOL rv = FALSE; + if (msg == WM_INITDIALOG) + { + thisptr = reinterpret_cast(lp); + assert(thisptr->m_status == status_construction); + thisptr->m_wnd = wnd; + SetWindowLongPtr(wnd,DWLP_USER,lp); + if (GetWindowLong(wnd,GWL_STYLE) & WS_POPUP) { + modeless_dialog_manager::g_add(wnd); + } + } + else thisptr = reinterpret_cast(GetWindowLongPtr(wnd,DWLP_USER)); + + if (thisptr != NULL) rv = thisptr->on_message_internal(msg,wp,lp); + + if (msg == WM_DESTROY) + { + modeless_dialog_manager::g_remove(wnd); + } + + return rv; + } + + + void dialog_modeless_v2::detach_window() + { + if (m_wnd != 0) + { + SetWindowLongPtr(m_wnd,DWLP_USER,0); + m_wnd = 0; + } + } + + + BOOL dialog_modeless_v2::on_message_internal(UINT msg,WPARAM wp,LPARAM lp) + { + if (m_status == status_lifetime || m_status == status_destruction_requested) + { + if (msg == WM_DESTROY) + { + assert(m_status == status_lifetime); + m_status = status_destruction_requested; + delete this; + return TRUE; + } + else + return on_message(msg,wp,lp); + } + else if (m_status == status_construction) + { + if (msg == WM_INITDIALOG) return m_stealfocus ? TRUE : FALSE; + else return FALSE; + } + else return FALSE; + } +} + +HWND uCreateDialog(UINT id,HWND parent,DLGPROC proc,LPARAM param) +{ + return CreateDialogParam(core_api::get_my_instance(),MAKEINTRESOURCE(id),parent,proc,param); +} + +int uDialogBox(UINT id,HWND parent,DLGPROC proc,LPARAM param) +{ + return (int)DialogBoxParam(core_api::get_my_instance(),MAKEINTRESOURCE(id),parent,proc,param); +} diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/win32_dialog.h b/tools/vio2sf/src/foobar/foobar2000/helpers/win32_dialog.h new file mode 100644 index 000000000..6c409c1e5 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/win32_dialog.h @@ -0,0 +1,121 @@ +#ifndef _FOOBAR2000_HELPERS_WIN32_DIALOG_H_ +#define _FOOBAR2000_HELPERS_WIN32_DIALOG_H_ + +//DEPRECATED dialog helpers - kept only for compatibility with old code - do not use in new code, use WTL instead. + +namespace dialog_helper +{ + + class dialog + { + protected: + + dialog() : wnd(0), m_is_modal(false) {} + ~dialog() { } + + virtual BOOL on_message(UINT msg,WPARAM wp,LPARAM lp)=0; + + void end_dialog(int code); + + public: + inline HWND get_wnd() {return wnd;} + + __declspec(deprecated) int run_modal(unsigned id,HWND parent); + + __declspec(deprecated) HWND run_modeless(unsigned id,HWND parent); + private: + HWND wnd; + static INT_PTR CALLBACK DlgProc(HWND wnd,UINT msg,WPARAM wp,LPARAM lp); + + bool m_is_modal; + + modal_dialog_scope m_modal_scope; + }; + + //! This class is meant to be instantiated on-stack, as a local variable. Using new/delete operators instead or even making this a member of another object works, but does not make much sense because of the way this works (single run() call). + class dialog_modal + { + public: + __declspec(deprecated) int run(unsigned p_id,HWND p_parent,HINSTANCE p_instance = core_api::get_my_instance()); + protected: + virtual BOOL on_message(UINT msg,WPARAM wp,LPARAM lp)=0; + + inline dialog_modal() : m_wnd(0) {} + void end_dialog(int p_code); + inline HWND get_wnd() const {return m_wnd;} + private: + static INT_PTR CALLBACK DlgProc(HWND wnd,UINT msg,WPARAM wp,LPARAM lp); + + HWND m_wnd; + modal_dialog_scope m_modal_scope; + }; + + //! This class is meant to be used with new/delete operators only. Destroying the window - outside create() / WM_INITDIALOG - will result in object calling delete this. If object is deleted directly using delete operator, WM_DESTROY handler may not be called so it should not be used (use destructor of derived class instead). + //! Classes derived from dialog_modeless must not be instantiated in any other way than operator new(). + /*! Typical usage : \n + class mydialog : public dialog_helper::dialog_modeless {...}; + (...) + bool createmydialog() + { + mydialog * instance = new mydialog; + if (instance == 0) return flase; + if (!instance->create(...)) {delete instance; return false;} + return true; + } + + */ + class dialog_modeless + { + public: + //! Creates the dialog window. This will call on_message with WM_INITDIALOG. To abort creation, you can call DestroyWindow() on our window; it will not delete the object but make create() return false instead. You should not delete the object from inside WM_INITDIALOG handler or anything else possibly called from create(). + //! @returns true on success, false on failure. + __declspec(deprecated) bool create(unsigned p_id,HWND p_parent,HINSTANCE p_instance = core_api::get_my_instance()); + protected: + //! Standard windows message handler (DialogProc-style). Use get_wnd() to retrieve our dialog window handle. + virtual BOOL on_message(UINT msg,WPARAM wp,LPARAM lp)=0; + + inline dialog_modeless() : m_wnd(0), m_destructor_status(destructor_none), m_is_in_create(false) {} + inline HWND get_wnd() const {return m_wnd;} + virtual ~dialog_modeless(); + private: + static INT_PTR CALLBACK DlgProc(HWND wnd,UINT msg,WPARAM wp,LPARAM lp); + void on_window_destruction(); + + BOOL on_message_wrap(UINT msg,WPARAM wp,LPARAM lp); + + HWND m_wnd; + enum {destructor_none,destructor_normal,destructor_fromwindow} m_destructor_status; + bool m_is_in_create; + }; + + + class dialog_modeless_v2 + { + protected: + __declspec(deprecated) explicit dialog_modeless_v2(unsigned p_id,HWND p_parent,HINSTANCE p_instance = core_api::get_my_instance(),bool p_stealfocus = true); + virtual ~dialog_modeless_v2(); + HWND get_wnd() const {return m_wnd;} + virtual BOOL on_message(UINT msg,WPARAM wp,LPARAM lp) {return FALSE;} + + static dialog_modeless_v2 * __unsafe__instance_from_window(HWND p_wnd) {return reinterpret_cast(GetWindowLongPtr(p_wnd,DWLP_USER));} + private: + static INT_PTR CALLBACK DlgProc(HWND wnd,UINT msg,WPARAM wp,LPARAM lp); + void detach_window(); + BOOL on_message_internal(UINT msg,WPARAM wp,LPARAM lp); + enum {status_construction, status_lifetime, status_destruction_requested, status_destruction} m_status; + HWND m_wnd; + const bool m_stealfocus; + + const dialog_modeless_v2 & operator=(const dialog_modeless_v2 &); + dialog_modeless_v2(const dialog_modeless_v2 &); + }; + +}; + +//! Wrapper (provided mainly for old code), simplifies parameters compared to standard CreateDialog() by using core_api::get_my_instance(). +HWND uCreateDialog(UINT id,HWND parent,DLGPROC proc,LPARAM param = 0); +//! Wrapper (provided mainly for old code), simplifies parameters compared to standard DialogBox() by using core_api::get_my_instance(). +int uDialogBox(UINT id,HWND parent,DLGPROC proc,LPARAM param = 0); + + +#endif diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/win32_misc.cpp b/tools/vio2sf/src/foobar/foobar2000/helpers/win32_misc.cpp new file mode 100644 index 000000000..76d71b53d --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/win32_misc.cpp @@ -0,0 +1,70 @@ +#include "stdafx.h" + +void registerclass_scope_delayed::toggle_on(UINT p_style,WNDPROC p_wndproc,int p_clsextra,int p_wndextra,HICON p_icon,HCURSOR p_cursor,HBRUSH p_background,const TCHAR * p_class_name,const TCHAR * p_menu_name) { + toggle_off(); + WNDCLASS wc = {}; + wc.style = p_style; + wc.lpfnWndProc = p_wndproc; + wc.cbClsExtra = p_clsextra; + wc.cbWndExtra = p_wndextra; + wc.hInstance = core_api::get_my_instance(); + wc.hIcon = p_icon; + wc.hCursor = p_cursor; + wc.hbrBackground = p_background; + wc.lpszMenuName = p_menu_name; + wc.lpszClassName = p_class_name; + WIN32_OP( (m_class = RegisterClass(&wc)) != 0); +} + +void registerclass_scope_delayed::toggle_off() { + if (m_class != 0) { + UnregisterClass((LPCTSTR)m_class,core_api::get_my_instance()); + m_class = 0; + } +} + + +unsigned QueryScreenDPI() { + HDC dc = GetDC(0); + unsigned ret = GetDeviceCaps(dc,LOGPIXELSY); + ReleaseDC(0,dc); + return ret; +} + + +SIZE QueryScreenDPIEx() { + HDC dc = GetDC(0); + SIZE ret = { GetDeviceCaps(dc,LOGPIXELSY), GetDeviceCaps(dc,LOGPIXELSY) }; + ReleaseDC(0,dc); + return ret; +} + + +bool IsMenuNonEmpty(HMENU menu) { + unsigned n,m=GetMenuItemCount(menu); + for(n=0;n msgFormatted; msgFormatted.set_size(pfc::strlen_t(_Message) + 64); + wsprintfW(msgFormatted.get_ptr(), L"%s (code: %u)", _Message, code); + if (IsDebuggerPresent()) { + OutputDebugString(TEXT("WIN32_OP_D() failure:\n")); + OutputDebugString(msgFormatted.get_ptr()); + OutputDebugString(TEXT("\n")); + pfc::crash(); + } + _wassert(msgFormatted.get_ptr(),_File,_Line); +} +#endif \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/win32_misc.h b/tools/vio2sf/src/foobar/foobar2000/helpers/win32_misc.h new file mode 100644 index 000000000..3862ed637 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/win32_misc.h @@ -0,0 +1,399 @@ +void WIN32_OP_FAIL(); +#ifdef _DEBUG +void WIN32_OP_D_FAIL(const wchar_t * _Message, const wchar_t *_File, unsigned _Line); +#endif + +//Throws an exception when (OP) evaluates to false/zero. +#define WIN32_OP(OP) \ + { \ + SetLastError(NO_ERROR); \ + if (!(OP)) WIN32_OP_FAIL(); \ + } + +//WIN32_OP_D() acts like an assert specialized for win32 operations in debug build, ignores the return value / error codes in release build. +//Use WIN32_OP_D() instead of WIN32_OP() on operations that are extremely unlikely to fail, so failure condition checks are performed in the debug build only, to avoid bloating release code with pointless error checks. +#ifdef _DEBUG +#define WIN32_OP_D(OP) \ + { \ + SetLastError(NO_ERROR); \ + if (!(OP)) WIN32_OP_D_FAIL(PFC_WIDESTRING(#OP), PFC_WIDESTRING(__FILE__), __LINE__); \ + } + +#else +#define WIN32_OP_D(OP) (void)( (OP), 0); +#endif + + +class registerclass_scope_delayed { +public: + registerclass_scope_delayed() : m_class(0) {} + + bool is_registered() const {return m_class != 0;} + void toggle_on(UINT p_style,WNDPROC p_wndproc,int p_clsextra,int p_wndextra,HICON p_icon,HCURSOR p_cursor,HBRUSH p_background,const TCHAR * p_classname,const TCHAR * p_menuname); + void toggle_off(); + ATOM get_class() const {return m_class;} + + ~registerclass_scope_delayed() {toggle_off();} +private: + registerclass_scope_delayed(const registerclass_scope_delayed &) {throw pfc::exception_not_implemented();} + const registerclass_scope_delayed & operator=(const registerclass_scope_delayed &) {throw pfc::exception_not_implemented();} + + ATOM m_class; +}; + + + +template +class syncd_storage { +private: + typedef syncd_storage t_self; +public: + syncd_storage() {} + template + syncd_storage(const t_source & p_source) : m_object(p_source) {} + template + void set(t_source const & p_in) { + insync(m_sync); + m_object = p_in; + } + template + void get(t_destination & p_out) const { + insync(m_sync); + p_out = m_object; + } + t_object get() const { + insync(m_sync); + return m_object; + } + template + const t_self & operator=(t_source const & p_source) {set(p_source); return *this;} +private: + mutable critical_section m_sync; + t_object m_object; +}; + +template +class syncd_storage_flagged { +private: + typedef syncd_storage_flagged t_self; +public: + syncd_storage_flagged() : m_changed_flag(false) {} + template + syncd_storage_flagged(const t_source & p_source) : m_changed_flag(false), m_object(p_source) {} + void set_changed(bool p_flag = true) { + insync(m_sync); + m_changed_flag = p_flag; + } + template + void set(t_source const & p_in) { + insync(m_sync); + m_object = p_in; + m_changed_flag = true; + } + bool has_changed() const { + insync(m_sync); + return m_changed_flag; + } + t_object peek() const {insync(m_sync); return m_object;} + template + bool get_if_changed(t_destination & p_out) { + insync(m_sync); + if (m_changed_flag) { + p_out = m_object; + m_changed_flag = false; + return true; + } else { + return false; + } + } + t_object get() { + insync(m_sync); + m_changed_flag = false; + return m_object; + } + template + void get(t_destination & p_out) { + insync(m_sync); + p_out = m_object; + m_changed_flag = false; + } + template + const t_self & operator=(t_source const & p_source) {set(p_source); return *this;} +private: + bool m_changed_flag; + mutable critical_section m_sync; + t_object m_object; +}; + +typedef CGlobalLockScope CGlobalLock;//for compatibility, implementation moved elsewhere + +static bool SetClipboardDataBlock(UINT p_format,const void * p_block,t_size p_block_size) { + bool success = false; + if (OpenClipboard(NULL)) { + EmptyClipboard(); + HANDLE handle = GlobalAlloc(GMEM_MOVEABLE,p_block_size); + if (handle == NULL) { + CloseClipboard(); + throw std::bad_alloc(); + } + {CGlobalLock lock(handle);memcpy(lock.GetPtr(),p_block,p_block_size);} + if (SetClipboardData(p_format,handle) == NULL) { + GlobalFree(handle);//todo? + } else { + success = true; + } + CloseClipboard(); + } + return success; +} + +template +static bool SetClipboardDataBlock(UINT p_format,const t_array & p_array) { + pfc::static_assert(); + return SetClipboardDataBlock(p_format,p_array.get_ptr(),p_array.get_size()); +} + +template +static bool GetClipboardDataBlock(UINT p_format,t_array & p_array) { + pfc::static_assert(); + if (OpenClipboard(NULL)) { + HANDLE handle = GetClipboardData(p_format); + if (handle == NULL) { + CloseClipboard(); + return false; + } + { + CGlobalLock lock(handle); + const t_size size = lock.GetSize(); + try { + p_array.set_size(size); + } catch(...) { + CloseClipboard(); + throw; + } + memcpy(p_array.get_ptr(),lock.GetPtr(),size); + } + CloseClipboard(); + return true; + } else { + return false; + } +} + + +class OleInitializeScope { +public: + OleInitializeScope() { + if (FAILED(OleInitialize(NULL))) throw pfc::exception("OleInitialize() failure"); + } + ~OleInitializeScope() { + OleUninitialize(); + } + +private: + PFC_CLASS_NOT_COPYABLE(OleInitializeScope,OleInitializeScope); +}; + +class CoInitializeScope { +public: + CoInitializeScope() { + if (FAILED(CoInitialize(NULL))) throw pfc::exception("CoInitialize() failed"); + } + ~CoInitializeScope() { + CoUninitialize(); + } + PFC_CLASS_NOT_COPYABLE_EX(CoInitializeScope) +}; + + +unsigned QueryScreenDPI(); + +SIZE QueryScreenDPIEx(); + +static WORD GetOSVersion() { + const DWORD ver = GetVersion(); + return (WORD)HIBYTE(LOWORD(ver)) | ((WORD)LOBYTE(LOWORD(ver)) << 8); +} + +#if _WIN32_WINNT >= 0x501 +#define WS_EX_COMPOSITED_Safe() WS_EX_COMPOSITED +#else +static DWORD WS_EX_COMPOSITED_Safe() { + return (GetOSVersion() < 0x501) ? 0 : 0x02000000L; +} +#endif + + +static t_size GetOptimalWorkerThreadCount() throw() { + DWORD_PTR mask,system; + t_size ret = 0; + GetProcessAffinityMask(GetCurrentProcess(),&mask,&system); + for(t_size n=0;n(this),0,NULL) ) != NULL); + m_thread = thread; + } + bool IsThreadActive() const { + return m_thread != INVALID_HANDLE_VALUE; + } + void WaitTillThreadDone() { + CloseThread(); + } +protected: + virtual void ThreadProc() {} +private: + void CloseThread() { + if (IsThreadActive()) { + WaitForSingleObject(m_thread,INFINITE); + CloseHandle(m_thread); m_thread = INVALID_HANDLE_VALUE; + } + } + + static DWORD CALLBACK g_entry(void* p_instance) { + return reinterpret_cast(p_instance)->entry(); + } + unsigned entry() { + try { + ThreadProc(); + } catch(...) {} + return 0; + } + HANDLE m_thread; + + PFC_CLASS_NOT_COPYABLE_EX(CVerySimpleThread) +}; + +//! IMPORTANT: all classes derived from CSimpleThread must call AbortThread()/WaitTillThreadDone() in their destructors, to avoid object destruction during a virtual function call! +class CSimpleThread : private completion_notify_receiver { +public: + CSimpleThread() : m_thread(INVALID_HANDLE_VALUE) {} + ~CSimpleThread() {AbortThread();} + void StartThread() { + AbortThread(); + m_abort.reset(); + m_ownNotify = create_task(0); + HANDLE thread; + WIN32_OP( (thread = CreateThread(NULL,0,g_entry,reinterpret_cast(this),0,NULL) ) != NULL); + m_thread = thread; + } + void AbortThread() { + m_abort.abort(); + CloseThread(); + } + bool IsThreadActive() const { + return m_thread != INVALID_HANDLE_VALUE; + } + void WaitTillThreadDone() { + CloseThread(); + } +protected: + virtual unsigned ThreadProc(abort_callback & p_abort) {return 0;} + //! Called when the thread has completed normally, with p_code equal to ThreadProc retval. Not called when AbortThread() or WaitTillThreadDone() was used to abort the thread / wait for the thread to finish. + virtual void ThreadDone(unsigned p_code) {}; +private: + void CloseThread() { + if (IsThreadActive()) { + WaitForSingleObject(m_thread,INFINITE); + CloseHandle(m_thread); m_thread = INVALID_HANDLE_VALUE; + } + orphan_all_tasks(); + } + + void on_task_completion(unsigned p_id,unsigned p_status) { + if (IsThreadActive()) { + CloseThread(); + ThreadDone(p_status); + } + } + static DWORD CALLBACK g_entry(void* p_instance) { + return reinterpret_cast(p_instance)->entry(); + } + unsigned entry() { + unsigned code = ~0; + try { + code = ThreadProc(m_abort); + } catch(...) {} + if (!m_abort.is_aborting()) m_ownNotify->on_completion_async(code); + return code; + } + abort_callback_impl m_abort; + HANDLE m_thread; + completion_notify_ptr m_ownNotify; + + PFC_CLASS_NOT_COPYABLE_EX(CSimpleThread); +}; + + + +class EnableWindowScope { +public: + EnableWindowScope(HWND p_window,BOOL p_state) throw() : m_window(p_window) { + m_oldState = IsWindowEnabled(m_window); + EnableWindow(m_window,p_state); + } + ~EnableWindowScope() throw() { + EnableWindow(m_window,m_oldState); + } + +private: + BOOL m_oldState; + HWND m_window; +}; + +bool IsMenuNonEmpty(HMENU menu); + +class SetTextColorScope { +public: + SetTextColorScope(HDC dc, COLORREF col) throw() : m_dc(dc) { + m_oldCol = SetTextColor(dc,col); + } + ~SetTextColorScope() throw() { + SetTextColor(m_dc,m_oldCol); + } + PFC_CLASS_NOT_COPYABLE_EX(SetTextColorScope) +private: + HDC m_dc; + COLORREF m_oldCol; +}; + +class CloseHandleScope { +public: + CloseHandleScope(HANDLE handle) throw() : m_handle(handle) {} + ~CloseHandleScope() throw() {CloseHandle(m_handle);} + HANDLE Detach() throw() {return pfc::replace_t(m_handle,INVALID_HANDLE_VALUE);} + HANDLE Get() const throw() {return m_handle;} + void Close() throw() {CloseHandle(Detach());} + PFC_CLASS_NOT_COPYABLE_EX(CloseHandleScope) +private: + HANDLE m_handle; +}; + +class CModelessDialogEntry { +public: + inline CModelessDialogEntry() : m_wnd() {} + inline CModelessDialogEntry(HWND p_wnd) : m_wnd() {Set(p_wnd);} + inline ~CModelessDialogEntry() {Set(NULL);} + + void Set(HWND p_new) { + static_api_ptr_t api; + if (m_wnd) api->remove(m_wnd); + m_wnd = p_new; + if (m_wnd) api->add(m_wnd); + } +private: + PFC_CLASS_NOT_COPYABLE_EX(CModelessDialogEntry); + HWND m_wnd; +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/window_placement_helper.cpp b/tools/vio2sf/src/foobar/foobar2000/helpers/window_placement_helper.cpp new file mode 100644 index 000000000..93856a576 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/window_placement_helper.cpp @@ -0,0 +1,206 @@ +#include "stdafx.h" + +static bool g_is_enabled() +{ + return standard_config_objects::query_remember_window_positions(); +} + +static BOOL CALLBACK __MonitorEnumProc( + HMONITOR hMonitor, // handle to display monitor + HDC hdcMonitor, // handle to monitor DC + LPRECT lprcMonitor, // monitor intersection rectangle + LPARAM dwData // data + ) { + RECT * clip = (RECT*)dwData; + RECT newclip; + if (UnionRect(&newclip,clip,lprcMonitor)) { + *clip = newclip; + } + return TRUE; +} + +static bool test_rect(const RECT * rc) { + RECT clip = {}; + if (EnumDisplayMonitors(NULL,NULL,__MonitorEnumProc,(LPARAM)&clip)) { + const LONG sanitycheck = 4; + const LONG cwidth = clip.right - clip.left; + const LONG cheight = clip.bottom - clip.top; + + const LONG width = rc->right - rc->left; + const LONG height = rc->bottom - rc->top; + + if (width > cwidth * sanitycheck || height > cheight * sanitycheck) return false; + } + + return MonitorFromRect(rc,MONITOR_DEFAULTTONULL) != NULL; +} + + +bool cfg_window_placement::read_from_window(HWND window) +{ + WINDOWPLACEMENT wp = {}; + if (g_is_enabled()) { + wp.length = sizeof(wp); + if (!GetWindowPlacement(window,&wp)) + memset(&wp,0,sizeof(wp)); + /*else + { + if (!IsWindowVisible(window)) wp.showCmd = SW_HIDE; + }*/ + } + m_data = wp; + return m_data.length == sizeof(m_data); +} + +void cfg_window_placement::on_window_creation_silent(HWND window) { + PFC_ASSERT(!m_windows.have_item(window)); + m_windows.add_item(window); +} +bool cfg_window_placement::on_window_creation(HWND window) +{ + bool ret = false; + PFC_ASSERT(!m_windows.have_item(window)); + m_windows.add_item(window); + + if (g_is_enabled()) + { + if (m_data.length==sizeof(m_data) && test_rect(&m_data.rcNormalPosition)) + { + if (SetWindowPlacement(window,&m_data)) + { + ret = true; + } + } + } + + return ret; +} + + +void cfg_window_placement::on_window_destruction(HWND window) +{ + if (m_windows.have_item(window)) + { + read_from_window(window); + m_windows.remove_item(window); + } +} + +void cfg_window_placement::get_data_raw(stream_writer * p_stream,abort_callback & p_abort) { + if (g_is_enabled()) { + { + t_size n, m = m_windows.get_count(); + for(n=0;nwrite_object(&m_data,sizeof(m_data),p_abort); + } + } +} + +void cfg_window_placement::set_data_raw(stream_reader * p_stream,t_size p_sizehint,abort_callback & p_abort) { + if (p_sizehint == 0) return; + WINDOWPLACEMENT temp; + try { + p_stream->read_object(&temp,sizeof(temp),p_abort); + } catch(exception_io_data) {return;} + if (temp.length == sizeof(temp)) m_data = temp; +} + + +cfg_window_placement::cfg_window_placement(const GUID & p_guid) : cfg_var(p_guid) +{ + memset(&m_data,0,sizeof(m_data)); +} + + +cfg_window_size::cfg_window_size(const GUID & p_guid) : cfg_var(p_guid), m_width(infinite32), m_height(infinite32) {} + +static BOOL SetWindowSize(HWND p_wnd,unsigned p_x,unsigned p_y) +{ + if (p_x != infinite32 && p_y != infinite32) + return SetWindowPos(p_wnd,0,0,0,p_x,p_y,SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER); + else + return FALSE; +} + +bool cfg_window_size::on_window_creation(HWND p_wnd) +{ + bool ret = false; + PFC_ASSERT(!m_windows.have_item(p_wnd)); + m_windows.add_item(p_wnd); + + if (g_is_enabled()) + { + if (SetWindowSize(p_wnd,m_width,m_height)) ret = true; + } + + return ret; +} + +void cfg_window_size::on_window_destruction(HWND p_wnd) +{ + if (m_windows.have_item(p_wnd)) + { + read_from_window(p_wnd); + m_windows.remove_item(p_wnd); + } +} + +bool cfg_window_size::read_from_window(HWND p_wnd) +{ + if (g_is_enabled()) + { + RECT r; + if (GetWindowRect(p_wnd,&r)) + { + m_width = r.right - r.left; + m_height = r.bottom - r.top; + return true; + } + else + { + m_width = m_height = infinite32; + return false; + } + } + else + { + m_width = m_height = infinite32; + return false; + } +} + +void cfg_window_size::get_data_raw(stream_writer * p_stream,abort_callback & p_abort) { + if (g_is_enabled()) { + { + t_size n, m = m_windows.get_count(); + for(n=0;nwrite_lendian_t(m_width,p_abort); + p_stream->write_lendian_t(m_height,p_abort); + } + } +} + +void cfg_window_size::set_data_raw(stream_reader * p_stream,t_size p_sizehint,abort_callback & p_abort) { + if (p_sizehint == 0) return; + t_uint32 width,height; + try { + p_stream->read_lendian_t(width,p_abort); + p_stream->read_lendian_t(height,p_abort); + } catch(exception_io_data) {return;} + + m_width = width; m_height = height; +} \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/helpers/window_placement_helper.h b/tools/vio2sf/src/foobar/foobar2000/helpers/window_placement_helper.h new file mode 100644 index 000000000..24cfe20dd --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/helpers/window_placement_helper.h @@ -0,0 +1,34 @@ +#ifndef _WINDOW_PLACEMENT_HELPER_H_ +#define _WINDOW_PLACEMENT_HELPER_H_ + +class cfg_window_placement : public cfg_var +{ +public: + bool on_window_creation(HWND window);//returns true if window position has been changed, false if not + void on_window_creation_silent(HWND window); + void on_window_destruction(HWND window); + bool read_from_window(HWND window); + void get_data_raw(stream_writer * p_stream,abort_callback & p_abort); + void set_data_raw(stream_reader * p_stream,t_size p_sizehint,abort_callback & p_abort); + cfg_window_placement(const GUID & p_guid); +private: + pfc::list_hybrid_t m_windows; + WINDOWPLACEMENT m_data; +}; + +class cfg_window_size : public cfg_var +{ +public: + bool on_window_creation(HWND window);//returns true if window position has been changed, false if not + void on_window_destruction(HWND window); + bool read_from_window(HWND window); + void get_data_raw(stream_writer * p_stream,abort_callback & p_abort); + void set_data_raw(stream_reader * p_stream,t_size p_sizehint,abort_callback & p_abort); + cfg_window_size(const GUID & p_guid); +private: + pfc::list_hybrid_t m_windows; + t_uint32 m_width,m_height; +}; + + +#endif //_WINDOW_PLACEMENT_HELPER_H_ \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/shared/audio_math.h b/tools/vio2sf/src/foobar/foobar2000/shared/audio_math.h new file mode 100644 index 000000000..f58c171de --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/shared/audio_math.h @@ -0,0 +1,78 @@ +#include + +#ifdef _M_X64 +#include +#include +#endif + + +#define audio_sample_size 32 + +#if audio_sample_size == 32 +typedef float audio_sample; +#define audio_sample_asm dword +#elif audio_sample_size == 64 +typedef double audio_sample; +#define audio_sample_asm qword +#else +#error wrong audio_sample_size +#endif + +#define audio_sample_bytes (audio_sample_size/8) + +namespace audio_math +{ + //! p_source/p_output can point to same buffer + void SHARED_EXPORT scale(const audio_sample * p_source,t_size p_count,audio_sample * p_output,audio_sample p_scale); + void SHARED_EXPORT convert_to_int16(const audio_sample * p_source,t_size p_count,t_int16 * p_output,audio_sample p_scale); + void SHARED_EXPORT convert_to_int32(const audio_sample * p_source,t_size p_count,t_int32 * p_output,audio_sample p_scale); + audio_sample SHARED_EXPORT convert_to_int16_calculate_peak(const audio_sample * p_source,t_size p_count,t_int16 * p_output,audio_sample p_scale); + void SHARED_EXPORT convert_from_int16(const t_int16 * p_source,t_size p_count,audio_sample * p_output,audio_sample p_scale); + void SHARED_EXPORT convert_from_int32(const t_int32 * p_source,t_size p_count,audio_sample * p_output,audio_sample p_scale); + audio_sample SHARED_EXPORT convert_to_int32_calculate_peak(const audio_sample * p_source,t_size p_count,t_int32 * p_output,audio_sample p_scale); + audio_sample SHARED_EXPORT calculate_peak(const audio_sample * p_source,t_size p_count); + void SHARED_EXPORT remove_denormals(audio_sample * p_buffer,t_size p_count); + void SHARED_EXPORT add_offset(audio_sample * p_buffer,audio_sample p_delta,t_size p_count); + + + inline t_uint64 time_to_samples(double p_time,t_uint32 p_sample_rate) { + return (t_uint64)floor((double)p_sample_rate * p_time + 0.5); + } + + inline double samples_to_time(t_uint64 p_samples,t_uint32 p_sample_rate) { + PFC_ASSERT(p_sample_rate > 0); + return (double) p_samples / (double) p_sample_rate; + } + + +#ifdef _M_IX86 + inline static t_int64 rint64(audio_sample val) { + t_int64 rv; + _asm { + fld val; + fistp rv; + } + return rv; + } + inline static t_int32 rint32(audio_sample val) { + t_int32 rv; + _asm { + fld val; + fistp rv; + } + return rv; + } +#elif defined(_M_X64) + inline static t_int64 rint64(audio_sample val) {return (t_int64)floor(val+0.5);} + static inline t_int32 rint32(float p_val) { + return (t_int32)_mm_cvtss_si32(_mm_load_ss(&p_val)); + } +#else + inline static t_int64 rint64(audio_sample val) {return (t_int64)floor(val+0.5);} + inline static t_int32 rint32(audio_sample val) {return (t_int32)floor(val+0.5);} +#endif + + + inline audio_sample gain_to_scale(double p_gain) {return (audio_sample) pow(10.0,p_gain / 20.0);} + +} \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/foobar2000/shared/filedialogs.h b/tools/vio2sf/src/foobar/foobar2000/shared/filedialogs.h new file mode 100644 index 000000000..8d2169a17 --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/shared/filedialogs.h @@ -0,0 +1,7 @@ +class uGetOpenFileNameMultiResult_impl : public uGetOpenFileNameMultiResult { + pfc::list_t m_data; +public: + void AddItem(pfc::stringp param) {m_data.add_item(param);} + t_size get_count() const {return m_data.get_count();} + void get_item_ex(const char * & out,t_size n) const {out = m_data[n].ptr();} +}; diff --git a/tools/vio2sf/src/foobar/foobar2000/shared/shared.h b/tools/vio2sf/src/foobar/foobar2000/shared/shared.h new file mode 100644 index 000000000..b32ca1ffe --- /dev/null +++ b/tools/vio2sf/src/foobar/foobar2000/shared/shared.h @@ -0,0 +1,788 @@ +#ifndef _SHARED_DLL__SHARED_H_ +#define _SHARED_DLL__SHARED_H_ + +#include "../../pfc/pfc.h" + +#ifndef WIN32 +#error N/A +#endif + +#ifndef STRICT +#define STRICT +#endif + +#include +#include +#include + +#ifndef NOTHROW +#ifdef _MSC_VER +#define NOTHROW __declspec(nothrow) +#else +#define NOTHROW +#endif +#endif + +#define SHARED_API /*NOTHROW*/ __stdcall + +#ifndef SHARED_EXPORTS +#define SHARED_EXPORT __declspec(dllimport) SHARED_API +#else +#define SHARED_EXPORT __declspec(dllexport) SHARED_API +#endif + +extern "C" { + +//SHARED_EXPORT BOOL IsUnicode(); +#ifdef UNICODE +#define IsUnicode() 1 +#else +#define IsUnicode() 0 +#endif + +LRESULT SHARED_EXPORT uSendMessageText(HWND wnd,UINT msg,WPARAM wp,const char * text); +LRESULT SHARED_EXPORT uSendDlgItemMessageText(HWND wnd,UINT id,UINT msg,WPARAM wp,const char * text); +BOOL SHARED_EXPORT uGetWindowText(HWND wnd,pfc::string_base & out); +BOOL SHARED_EXPORT uSetWindowText(HWND wnd,const char * p_text); +BOOL SHARED_EXPORT uSetWindowTextEx(HWND wnd,const char * p_text,unsigned p_text_length); +BOOL SHARED_EXPORT uGetDlgItemText(HWND wnd,UINT id,pfc::string_base & out); +BOOL SHARED_EXPORT uSetDlgItemText(HWND wnd,UINT id,const char * p_text); +BOOL SHARED_EXPORT uSetDlgItemTextEx(HWND wnd,UINT id,const char * p_text,unsigned p_text_length); +BOOL SHARED_EXPORT uBrowseForFolder(HWND parent,const char * title,pfc::string_base & out); +BOOL SHARED_EXPORT uBrowseForFolderWithFile(HWND parent,const char * title,pfc::string_base & out,const char * p_file_to_find); +int SHARED_EXPORT uMessageBox(HWND wnd,const char * text,const char * caption,UINT type); +void SHARED_EXPORT uOutputDebugString(const char * msg); +BOOL SHARED_EXPORT uAppendMenu(HMENU menu,UINT flags,UINT_PTR id,const char * content); +BOOL SHARED_EXPORT uInsertMenu(HMENU menu,UINT position,UINT flags,UINT_PTR id,const char * content); +int SHARED_EXPORT uStringCompare(const char * elem1, const char * elem2); +int SHARED_EXPORT uCharCompare(t_uint32 p_char1,t_uint32 p_char2); +int SHARED_EXPORT uStringCompare_ConvertNumbers(const char * elem1,const char * elem2); +HINSTANCE SHARED_EXPORT uLoadLibrary(const char * name); +HANDLE SHARED_EXPORT uCreateEvent(LPSECURITY_ATTRIBUTES lpEventAttributes,BOOL bManualReset,BOOL bInitialState, const char * lpName); +DWORD SHARED_EXPORT uGetModuleFileName(HMODULE hMod,pfc::string_base & out); +BOOL SHARED_EXPORT uSetClipboardString(const char * ptr); +BOOL SHARED_EXPORT uGetClipboardString(pfc::string_base & out); +BOOL SHARED_EXPORT uSetClipboardRawData(UINT format,const void * ptr,t_size size);//does not empty the clipboard +BOOL SHARED_EXPORT uGetClassName(HWND wnd,pfc::string_base & out); +t_size SHARED_EXPORT uCharLength(const char * src); +BOOL SHARED_EXPORT uDragQueryFile(HDROP hDrop,UINT idx,pfc::string_base & out); +UINT SHARED_EXPORT uDragQueryFileCount(HDROP hDrop); +BOOL SHARED_EXPORT uGetTextExtentPoint32(HDC dc,const char * text,UINT cb,LPSIZE size);//note, cb is number of bytes, not actual unicode characters in the string (read: plain strlen() will do) +BOOL SHARED_EXPORT uExtTextOut(HDC dc,int x,int y,UINT flags,const RECT * rect,const char * text,UINT cb,const int * lpdx); +BOOL SHARED_EXPORT uTextOutColors(HDC dc,const char * src,UINT len,int x,int y,const RECT * clip,BOOL is_selected,DWORD default_color); +BOOL SHARED_EXPORT uTextOutColorsTabbed(HDC dc,const char * src,UINT src_len,const RECT * item,int border,const RECT * clip,BOOL selected,DWORD default_color,BOOL use_columns); +UINT SHARED_EXPORT uGetTextHeight(HDC dc); +UINT SHARED_EXPORT uGetFontHeight(HFONT font); +BOOL SHARED_EXPORT uChooseColor(DWORD * p_color,HWND parent,DWORD * p_custom_colors); +HCURSOR SHARED_EXPORT uLoadCursor(HINSTANCE hIns,const char * name); +HICON SHARED_EXPORT uLoadIcon(HINSTANCE hIns,const char * name); +HMENU SHARED_EXPORT uLoadMenu(HINSTANCE hIns,const char * name); +BOOL SHARED_EXPORT uGetEnvironmentVariable(const char * name,pfc::string_base & out); +HMODULE SHARED_EXPORT uGetModuleHandle(const char * name); +UINT SHARED_EXPORT uRegisterWindowMessage(const char * name); +BOOL SHARED_EXPORT uMoveFile(const char * src,const char * dst); +BOOL SHARED_EXPORT uDeleteFile(const char * fn); +DWORD SHARED_EXPORT uGetFileAttributes(const char * fn); +BOOL SHARED_EXPORT uFileExists(const char * fn); +BOOL SHARED_EXPORT uRemoveDirectory(const char * fn); +HANDLE SHARED_EXPORT uCreateFile(const char * p_path,DWORD p_access,DWORD p_sharemode,LPSECURITY_ATTRIBUTES p_security_attributes,DWORD p_createmode,DWORD p_flags,HANDLE p_template); +HANDLE SHARED_EXPORT uCreateFileMapping(HANDLE hFile,LPSECURITY_ATTRIBUTES lpFileMappingAttributes,DWORD flProtect,DWORD dwMaximumSizeHigh,DWORD dwMaximumSizeLow,const char * lpName); +BOOL SHARED_EXPORT uCreateDirectory(const char * fn,LPSECURITY_ATTRIBUTES blah); +HANDLE SHARED_EXPORT uCreateMutex(LPSECURITY_ATTRIBUTES blah,BOOL bInitialOwner,const char * name); +BOOL SHARED_EXPORT uGetLongPathName(const char * name,pfc::string_base & out);//may just fail to work on old windows versions, present on win98/win2k+ +BOOL SHARED_EXPORT uGetFullPathName(const char * name,pfc::string_base & out); +BOOL SHARED_EXPORT uSearchPath(const char * path, const char * filename, const char * extension, pfc::string_base & p_out); +BOOL SHARED_EXPORT uFixPathCaps(const char * path,pfc::string_base & p_out); +void SHARED_EXPORT uGetCommandLine(pfc::string_base & out); +BOOL SHARED_EXPORT uGetTempPath(pfc::string_base & out); +BOOL SHARED_EXPORT uGetTempFileName(const char * path_name,const char * prefix,UINT unique,pfc::string_base & out); +BOOL SHARED_EXPORT uGetOpenFileName(HWND parent,const char * p_ext_mask,unsigned def_ext_mask,const char * p_def_ext,const char * p_title,const char * p_directory,pfc::string_base & p_filename,BOOL b_save); +//note: uGetOpenFileName extension mask uses | as separator, not null +HANDLE SHARED_EXPORT uLoadImage(HINSTANCE hIns,const char * name,UINT type,int x,int y,UINT flags); +UINT SHARED_EXPORT uRegisterClipboardFormat(const char * name); +BOOL SHARED_EXPORT uGetClipboardFormatName(UINT format,pfc::string_base & out); +BOOL SHARED_EXPORT uFormatSystemErrorMessage(pfc::string_base & p_out,DWORD p_code); + +HANDLE SHARED_EXPORT uSortStringCreate(const char * src); +int SHARED_EXPORT uSortStringCompare(HANDLE string1,HANDLE string2); +int SHARED_EXPORT uSortStringCompareEx(HANDLE string1,HANDLE string2,DWORD flags);//flags - see win32 CompareString +int SHARED_EXPORT uSortPathCompare(HANDLE string1,HANDLE string2); +void SHARED_EXPORT uSortStringFree(HANDLE string); + + +int SHARED_EXPORT uCompareString(DWORD flags,const char * str1,unsigned len1,const char * str2,unsigned len2); + +class NOVTABLE uGetOpenFileNameMultiResult : public pfc::list_base_const_t +{ +public: + inline t_size GetCount() {return get_count();} + inline const char * GetFileName(t_size index) {return get_item(index);} + virtual ~uGetOpenFileNameMultiResult() {} +}; + +typedef uGetOpenFileNameMultiResult * puGetOpenFileNameMultiResult; + +puGetOpenFileNameMultiResult SHARED_EXPORT uGetOpenFileNameMulti(HWND parent,const char * p_ext_mask,unsigned def_ext_mask,const char * p_def_ext,const char * p_title,const char * p_directory); + +class NOVTABLE uFindFile +{ +protected: + uFindFile() {} +public: + virtual BOOL FindNext()=0; + virtual const char * GetFileName()=0; + virtual t_uint64 GetFileSize()=0; + virtual DWORD GetAttributes()=0; + virtual FILETIME GetCreationTime()=0; + virtual FILETIME GetLastAccessTime()=0; + virtual FILETIME GetLastWriteTime()=0; + virtual ~uFindFile() {}; + inline bool IsDirectory() {return (GetAttributes() & FILE_ATTRIBUTE_DIRECTORY) ? true : false;} +}; + +typedef uFindFile * puFindFile; + +puFindFile SHARED_EXPORT uFindFirstFile(const char * path); + +HINSTANCE SHARED_EXPORT uShellExecute(HWND wnd,const char * oper,const char * file,const char * params,const char * dir,int cmd); +HWND SHARED_EXPORT uCreateStatusWindow(LONG style,const char * text,HWND parent,UINT id); + +BOOL SHARED_EXPORT uShellNotifyIcon(DWORD dwMessage,HWND wnd,UINT id,UINT callbackmsg,HICON icon,const char * tip); +BOOL SHARED_EXPORT uShellNotifyIconEx(DWORD dwMessage,HWND wnd,UINT id,UINT callbackmsg,HICON icon,const char * tip,const char * balloon_title,const char * balloon_msg); + +HWND SHARED_EXPORT uCreateWindowEx(DWORD dwExStyle,const char * lpClassName,const char * lpWindowName,DWORD dwStyle,int x,int y,int nWidth,int nHeight,HWND hWndParent,HMENU hMenu,HINSTANCE hInstance,LPVOID lpParam); + +BOOL SHARED_EXPORT uGetSystemDirectory(pfc::string_base & out); +BOOL SHARED_EXPORT uGetWindowsDirectory(pfc::string_base & out); +BOOL SHARED_EXPORT uSetCurrentDirectory(const char * path); +BOOL SHARED_EXPORT uGetCurrentDirectory(pfc::string_base & out); +BOOL SHARED_EXPORT uExpandEnvironmentStrings(const char * src,pfc::string_base & out); +BOOL SHARED_EXPORT uGetUserName(pfc::string_base & out); +BOOL SHARED_EXPORT uGetShortPathName(const char * src,pfc::string_base & out); + +HSZ SHARED_EXPORT uDdeCreateStringHandle(DWORD ins,const char * src); +BOOL SHARED_EXPORT uDdeQueryString(DWORD ins,HSZ hsz,pfc::string_base & out); +UINT SHARED_EXPORT uDdeInitialize(LPDWORD pidInst,PFNCALLBACK pfnCallback,DWORD afCmd,DWORD ulRes); +BOOL SHARED_EXPORT uDdeAccessData_Text(HDDEDATA data,pfc::string_base & out); + +HIMAGELIST SHARED_EXPORT uImageList_LoadImage(HINSTANCE hi, const char * lpbmp, int cx, int cGrow, COLORREF crMask, UINT uType, UINT uFlags); + +#define uDdeFreeStringHandle DdeFreeStringHandle +#define uDdeCmpStringHandles DdeCmpStringHandles +#define uDdeKeepStringHandle DdeKeepStringHandle +#define uDdeUninitialize DdeUninitialize +#define uDdeNameService DdeNameService +#define uDdeFreeDataHandle DdeFreeDataHandle + + +typedef TVINSERTSTRUCTA uTVINSERTSTRUCT; + +HTREEITEM SHARED_EXPORT uTreeView_InsertItem(HWND wnd,const uTVINSERTSTRUCT * param); +LPARAM SHARED_EXPORT uTreeView_GetUserData(HWND wnd,HTREEITEM item); +bool SHARED_EXPORT uTreeView_GetText(HWND wnd,HTREEITEM item,pfc::string_base & out); + +#define uSetWindowsHookEx SetWindowsHookEx +#define uUnhookWindowsHookEx UnhookWindowsHookEx +#define uCallNextHookEx CallNextHookEx + + +/* usage: + + const char * src = "something"; + + void * temp = malloc(uOSStringEstimateSize(src)); + uOSStringConvert(src,temp); + //now temp contains OS-friendly (TCHAR) version of src +*/ + +typedef TCITEMA uTCITEM; +int SHARED_EXPORT uTabCtrl_InsertItem(HWND wnd,t_size idx,const uTCITEM * item); +int SHARED_EXPORT uTabCtrl_SetItem(HWND wnd,t_size idx,const uTCITEM * item); + +int SHARED_EXPORT uGetKeyNameText(LONG lparam,pfc::string_base & out); + +void SHARED_EXPORT uFixAmpersandChars(const char * src,pfc::string_base & out);//for systray +void SHARED_EXPORT uFixAmpersandChars_v2(const char * src,pfc::string_base & out);//for other controls + +//deprecated +t_size SHARED_EXPORT uPrintCrashInfo(LPEXCEPTION_POINTERS param,const char * extrainfo,char * out); +enum {uPrintCrashInfo_max_length = 1024}; + +void SHARED_EXPORT uPrintCrashInfo_Init(const char * name);//called only by exe on startup +void SHARED_EXPORT uPrintCrashInfo_AddInfo(const char * p_info);//called only by exe on startup +void SHARED_EXPORT uPrintCrashInfo_SetDumpPath(const char * name);//called only by exe on startup + + +void SHARED_EXPORT uDumpCrashInfo(LPEXCEPTION_POINTERS param); + +BOOL SHARED_EXPORT uListBox_GetText(HWND listbox,UINT index,pfc::string_base & out); + +void SHARED_EXPORT uPrintfV(pfc::string_base & out,const char * fmt,va_list arglist); +static inline void uPrintf(pfc::string_base & out,const char * fmt,...) {va_list list;va_start(list,fmt);uPrintfV(out,fmt,list);va_end(list);} + + +class NOVTABLE uResource +{ +public: + virtual const void * GetPointer() = 0; + virtual unsigned GetSize() = 0; + virtual ~uResource() {} +}; + +typedef uResource* puResource; + +puResource SHARED_EXPORT uLoadResource(HMODULE hMod,const char * name,const char * type,WORD wLang = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL) ); +puResource SHARED_EXPORT LoadResourceEx(HMODULE hMod,const TCHAR * name,const TCHAR * type,WORD wLang = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL) ); +HRSRC SHARED_EXPORT uFindResource(HMODULE hMod,const char * name,const char * type,WORD wLang = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL) ); + +BOOL SHARED_EXPORT uLoadString(HINSTANCE ins,UINT id,pfc::string_base & out); + +UINT SHARED_EXPORT uCharLower(UINT c); +UINT SHARED_EXPORT uCharUpper(UINT c); + +BOOL SHARED_EXPORT uGetMenuString(HMENU menu,UINT id,pfc::string_base & out,UINT flag); +BOOL SHARED_EXPORT uModifyMenu(HMENU menu,UINT id,UINT flags,UINT newitem,const char * data); +UINT SHARED_EXPORT uGetMenuItemType(HMENU menu,UINT position); + + +}//extern "C" + +inline char * uCharNext(char * src) {return src+uCharLength(src);} +inline const char * uCharNext(const char * src) {return src+uCharLength(src);} + + +class string_utf8_from_window +{ +public: + string_utf8_from_window(HWND wnd) + { + uGetWindowText(wnd,m_data); + } + string_utf8_from_window(HWND wnd,UINT id) + { + uGetDlgItemText(wnd,id,m_data); + } + inline operator const char * () const {return m_data.get_ptr();} + inline t_size length() const {return m_data.length();} + inline bool is_empty() const {return length() == 0;} + inline const char * get_ptr() const {return m_data.get_ptr();} +private: + pfc::string8 m_data; +}; + +static pfc::string uGetWindowText(HWND wnd) { + pfc::string8 temp; + if (!uGetWindowText(wnd,temp)) return ""; + return temp.toString(); +} +static pfc::string uGetDlgItemText(HWND wnd,UINT id) { + pfc::string8 temp; + if (!uGetDlgItemText(wnd,id,temp)) return ""; + return temp.toString(); +} + +#define uMAKEINTRESOURCE(x) ((const char*)LOWORD(x)) + +#ifdef _DEBUG +class critical_section { +private: + CRITICAL_SECTION sec; + int count; +public: + int enter() {EnterCriticalSection(&sec);return ++count;} + int leave() {int rv = --count;LeaveCriticalSection(&sec);return rv;} + int get_lock_count() {return count;} + int get_lock_count_check() {enter();return leave();} + inline void assert_locked() {assert(get_lock_count_check()>0);} + inline void assert_not_locked() {assert(get_lock_count_check()==0);} + critical_section() {InitializeCriticalSection(&sec);count=0;} + ~critical_section() {DeleteCriticalSection(&sec);} +private: + critical_section(const critical_section&) {throw pfc::exception_not_implemented();} + const critical_section & operator=(const critical_section &) {throw pfc::exception_not_implemented();} +}; +#else +class critical_section { +private: + CRITICAL_SECTION sec; +public: + void enter() throw() {EnterCriticalSection(&sec);} + void leave() throw() {LeaveCriticalSection(&sec);} + critical_section() {InitializeCriticalSection(&sec);} + ~critical_section() {DeleteCriticalSection(&sec);} +private: + critical_section(const critical_section&) {throw pfc::exception_not_implemented();} + const critical_section & operator=(const critical_section &) {throw pfc::exception_not_implemented();} +}; +#endif +class c_insync +{ +private: + critical_section & m_section; +public: + c_insync(critical_section * p_section) throw() : m_section(*p_section) {m_section.enter();} + c_insync(critical_section & p_section) throw() : m_section(p_section) {m_section.enter();} + ~c_insync() throw() {m_section.leave();} +}; + +#define insync(X) c_insync blah____sync(X) + + +class critical_section2 //smarter version, has try_enter() +{ +private: + HANDLE hMutex; + int count; +public: + int enter() {return enter_timeout(INFINITE);} + int leave() {int rv = --count;ReleaseMutex(hMutex);return rv;} + int get_lock_count() {return count;} + int get_lock_count_check() + { + int val = try_enter(); + if (val>0) val = leave(); + return val; + } + int enter_timeout(DWORD t) {return WaitForSingleObject(hMutex,t)==WAIT_OBJECT_0 ? ++count : 0;} + int try_enter() {return enter_timeout(0);} + int check_count() {enter();return leave();} + critical_section2() + { + hMutex = uCreateMutex(0,0,0); + count=0; + } + ~critical_section2() {CloseHandle(hMutex);} + + inline void assert_locked() {assert(get_lock_count_check()>0);} + inline void assert_not_locked() {assert(get_lock_count_check()==0);} + +}; + +class c_insync2 +{ +private: + critical_section2 * ptr; +public: + c_insync2(critical_section2 * p) {ptr=p;ptr->enter();} + c_insync2(critical_section2 & p) {ptr=&p;ptr->enter();} + ~c_insync2() {ptr->leave();} +}; + +#define insync2(X) c_insync2 blah____sync2(X) + + +//other + +#define uIsDialogMessage IsDialogMessage +#define uGetMessage GetMessage +#define uPeekMessage PeekMessage +#define uDispatchMessage DispatchMessage + +#define uCallWindowProc CallWindowProc +#define uDefWindowProc DefWindowProc +#define uGetWindowLong GetWindowLong +#define uSetWindowLong SetWindowLong + +#define uEndDialog EndDialog +#define uDestroyWindow DestroyWindow +#define uGetDlgItem GetDlgItem +#define uEnableWindow EnableWindow +#define uGetDlgItemInt GetDlgItemInt +#define uSetDlgItemInt SetDlgItemInt + +#define _uHookWindowProc(WND,PROC) ((WNDPROC)SetWindowLongPtr(WND,GWLP_WNDPROC,(LONG_PTR)(PROC))) +static WNDPROC uHookWindowProc(HWND p_wnd,WNDPROC p_proc) {return _uHookWindowProc(p_wnd,p_proc);} + +#define uSendMessage SendMessage +#define uSendDlgItemMessage SendDlgItemMessage +#define uSendMessageTimeout SendMessageTimeout +#define uSendNotifyMessage SendNotifyMessage +#define uSendMessageCallback SendMessageCallback +#define uPostMessage PostMessage +#define uPostThreadMessage PostThreadMessage + + +class uStringPrintf +{ +public: + inline explicit uStringPrintf(const char * fmt,...) + { + va_list list; + va_start(list,fmt); + uPrintfV(m_data,fmt,list); + va_end(list); + } + inline operator const char * () const {return m_data.get_ptr();} + inline t_size length() const {return m_data.length();} + inline bool is_empty() const {return length() == 0;} + inline const char * get_ptr() const {return m_data.get_ptr();} + const char * toString() const {return get_ptr();} +private: + pfc::string8_fastalloc m_data; +}; +#pragma deprecated(uStringPrintf, uPrintf, uPrintfV) + +inline LRESULT uButton_SetCheck(HWND wnd,UINT id,bool state) {return uSendDlgItemMessage(wnd,id,BM_SETCHECK,state ? BST_CHECKED : BST_UNCHECKED,0); } +inline bool uButton_GetCheck(HWND wnd,UINT id) {return uSendDlgItemMessage(wnd,id,BM_GETCHECK,0,0) == BST_CHECKED;} + +class uCallStackTracker +{ + t_size param; +public: + explicit SHARED_EXPORT uCallStackTracker(const char * name); + SHARED_EXPORT ~uCallStackTracker(); +}; + +extern "C" +{ + LPCSTR SHARED_EXPORT uGetCallStackPath(); +} + +namespace pfc { + class formatBugCheck : public string_formatter { + public: + formatBugCheck(const char * msg) { + *this << msg; + const char * path = uGetCallStackPath(); + if (*path) { + *this << " (at: " << path << ")"; + } + } + }; + class exception_bug_check_v2 : public exception_bug_check { + public: + exception_bug_check_v2(const char * msg = exception_bug_check::g_what()) : exception_bug_check(formatBugCheck(msg)) { + PFC_ASSERT(!"exception_bug_check_v2 triggered"); + } + }; +} + +#if 1 +#define TRACK_CALL(X) uCallStackTracker TRACKER__##X(#X) +#define TRACK_CALL_TEXT(X) uCallStackTracker TRACKER__BLAH(X) +#define TRACK_CODE(description,code) {uCallStackTracker __call_tracker(description); code;} +#else +#define TRACK_CALL(X) +#define TRACK_CALL_TEXT(X) +#define TRACK_CODE(description,code) {code;} +#endif + +extern "C" { +int SHARED_EXPORT stricmp_utf8(const char * p1,const char * p2) throw(); +int SHARED_EXPORT stricmp_utf8_ex(const char * p1,t_size len1,const char * p2,t_size len2) throw(); +int SHARED_EXPORT stricmp_utf8_stringtoblock(const char * p1,const char * p2,t_size p2_bytes) throw(); +int SHARED_EXPORT stricmp_utf8_partial(const char * p1,const char * p2,t_size num = ~0) throw(); +int SHARED_EXPORT stricmp_utf8_max(const char * p1,const char * p2,t_size p1_bytes) throw(); +t_size SHARED_EXPORT uReplaceStringAdd(pfc::string_base & out,const char * src,t_size src_len,const char * s1,t_size len1,const char * s2,t_size len2,bool casesens); +t_size SHARED_EXPORT uReplaceCharAdd(pfc::string_base & out,const char * src,t_size src_len,unsigned c1,unsigned c2,bool casesens); +//all lengths in uReplaceString functions are optional, set to -1 if parameters is a simple null-terminated string +void SHARED_EXPORT uAddStringLower(pfc::string_base & out,const char * src,t_size len = ~0); +void SHARED_EXPORT uAddStringUpper(pfc::string_base & out,const char * src,t_size len = ~0); +} + +class comparator_stricmp_utf8 { +public: + static int compare(const char * p_string1,const char * p_string2) throw() {return stricmp_utf8(p_string1,p_string2);} +}; + +inline void uStringLower(pfc::string_base & out,const char * src,t_size len = ~0) {out.reset();uAddStringLower(out,src,len);} +inline void uStringUpper(pfc::string_base & out,const char * src,t_size len = ~0) {out.reset();uAddStringUpper(out,src,len);} + +inline t_size uReplaceString(pfc::string_base & out,const char * src,t_size src_len,const char * s1,t_size len1,const char * s2,t_size len2,bool casesens) +{ + out.reset(); + return uReplaceStringAdd(out,src,src_len,s1,len1,s2,len2,casesens); +} + +inline t_size uReplaceChar(pfc::string_base & out,const char * src,t_size src_len,unsigned c1,unsigned c2,bool casesens) +{ + out.reset(); + return uReplaceCharAdd(out,src,src_len,c1,c2,casesens); +} + +class string_lower +{ +public: + explicit string_lower(const char * ptr,t_size p_count = ~0) {uAddStringLower(m_data,ptr,p_count);} + inline operator const char * () const {return m_data.get_ptr();} + inline t_size length() const {return m_data.length();} + inline bool is_empty() const {return length() == 0;} + inline const char * get_ptr() const {return m_data.get_ptr();} +private: + pfc::string8 m_data; +}; + +class string_upper +{ +public: + explicit string_upper(const char * ptr,t_size p_count = ~0) {uAddStringUpper(m_data,ptr,p_count);} + inline operator const char * () const {return m_data.get_ptr();} + inline t_size length() const {return m_data.length();} + inline bool is_empty() const {return length() == 0;} + inline const char * get_ptr() const {return m_data.get_ptr();} +private: + pfc::string8 m_data; +}; + + +inline BOOL uGetLongPathNameEx(const char * name,pfc::string_base & out) +{ + if (uGetLongPathName(name,out)) return TRUE; + return uGetFullPathName(name,out); +} + +struct t_font_description +{ + enum + { + m_facename_length = LF_FACESIZE*2, + m_height_dpi = 480, + }; + + t_uint32 m_height; + t_uint32 m_weight; + t_uint8 m_italic; + t_uint8 m_charset; + char m_facename[m_facename_length]; + + HFONT SHARED_EXPORT create() const; + bool SHARED_EXPORT popup_dialog(HWND p_parent); + void SHARED_EXPORT from_font(HFONT p_font); + static t_font_description SHARED_EXPORT g_from_font(HFONT p_font); + + template void to_stream(t_stream p_stream,t_abort & p_abort) const; + template void from_stream(t_stream p_stream,t_abort & p_abort); +}; + +template void t_font_description::to_stream(t_stream p_stream,t_abort & p_abort) const { + p_stream->write_lendian_t(m_height,p_abort); + p_stream->write_lendian_t(m_weight,p_abort); + p_stream->write_lendian_t(m_italic,p_abort); + p_stream->write_lendian_t(m_charset,p_abort); + p_stream->write_string(m_facename,tabsize(m_facename),p_abort); +} + +template void t_font_description::from_stream(t_stream p_stream,t_abort & p_abort) { + p_stream->read_lendian_t(m_height,p_abort); + p_stream->read_lendian_t(m_weight,p_abort); + p_stream->read_lendian_t(m_italic,p_abort); + p_stream->read_lendian_t(m_charset,p_abort); + pfc::string8 temp; + p_stream->read_string(temp,p_abort); + strncpy_s(m_facename,temp,tabsize(m_facename)); +} + + +struct t_modal_dialog_entry +{ + HWND m_wnd_to_poke; + bool m_in_use; +}; + +extern "C" { + void SHARED_EXPORT ModalDialog_Switch(t_modal_dialog_entry & p_entry); + void SHARED_EXPORT ModalDialog_PokeExisting(); + bool SHARED_EXPORT ModalDialog_CanCreateNew(); + + HWND SHARED_EXPORT FindOwningPopup(HWND p_wnd); + void SHARED_EXPORT PokeWindow(HWND p_wnd); +}; + +//! The purpose of modal_dialog_scope is to help to avoid the modal dialog recursion problem. Current toplevel modal dialog handle is stored globally, so when creation of a new modal dialog is blocked, it can be activated to indicate the reason for the task being blocked. +class modal_dialog_scope { +public: + //! This constructor initializes the modal dialog scope with specified dialog handle. + inline modal_dialog_scope(HWND p_wnd) throw() : m_initialized(false) {initialize(p_wnd);} + //! This constructor leaves the scope uninitialized (you can call initialize() later with your window handle). + inline modal_dialog_scope() throw() : m_initialized(false) {} + inline ~modal_dialog_scope() throw() {deinitialize();} + + //! Returns whether creation of a new modal dialog is allowed (false when there's another one active).\n + //! NOTE: when calling context is already inside a modal dialog that you own, you should not be checking this before creating a new modal dialog. + inline static bool can_create() throw(){return ModalDialog_CanCreateNew();} + //! Activates the top-level modal dialog existing, if one exists. + inline static void poke_existing() throw() {ModalDialog_PokeExisting();} + + //! Initializes the scope with specified window handle. + void initialize(HWND p_wnd) throw() + { + if (!m_initialized) + { + m_initialized = true; + m_entry.m_in_use = true; + m_entry.m_wnd_to_poke = p_wnd; + ModalDialog_Switch(m_entry); + } + } + + void deinitialize() throw() + { + if (m_initialized) + { + ModalDialog_Switch(m_entry); + m_initialized = false; + } + } + + + +private: + modal_dialog_scope(const modal_dialog_scope & p_scope) {assert(0);} + const modal_dialog_scope & operator=(const modal_dialog_scope &) {assert(0); return *this;} + + t_modal_dialog_entry m_entry; + + bool m_initialized; +}; + +class format_win32_error { +public: + format_win32_error(DWORD p_code) { + if (p_code == 0) m_buffer = "Undefined error"; + else if (!uFormatSystemErrorMessage(m_buffer,p_code)) m_buffer << "Unknown error code (" << (unsigned)p_code << ")"; + } + + const char * get_ptr() const {return m_buffer.get_ptr();} + operator const char*() const {return m_buffer.get_ptr();} +private: + pfc::string8 m_buffer; +}; + +struct exception_win32 : public std::exception { + exception_win32(DWORD p_code) : std::exception(format_win32_error(p_code)), m_code(p_code) {} + DWORD get_code() const {return m_code;} +private: + DWORD m_code; +}; + +class uDebugLog : public pfc::string_formatter { +public: + ~uDebugLog() {*this << "\n"; uOutputDebugString(get_ptr());} +}; + +static void uAddWindowStyle(HWND p_wnd,LONG p_style) { + SetWindowLong(p_wnd,GWL_STYLE, GetWindowLong(p_wnd,GWL_STYLE) | p_style); +} + +static void uRemoveWindowStyle(HWND p_wnd,LONG p_style) { + SetWindowLong(p_wnd,GWL_STYLE, GetWindowLong(p_wnd,GWL_STYLE) & ~p_style); +} + +static void uAddWindowExStyle(HWND p_wnd,LONG p_style) { + SetWindowLong(p_wnd,GWL_EXSTYLE, GetWindowLong(p_wnd,GWL_EXSTYLE) | p_style); +} + +static void uRemoveWindowExStyle(HWND p_wnd,LONG p_style) { + SetWindowLong(p_wnd,GWL_EXSTYLE, GetWindowLong(p_wnd,GWL_EXSTYLE) & ~p_style); +} + +static unsigned MapDialogWidth(HWND p_dialog,unsigned p_value) { + RECT temp; + temp.left = 0; temp.right = p_value; temp.top = temp.bottom = 0; + if (!MapDialogRect(p_dialog,&temp)) return 0; + return temp.right; +} + +static bool IsKeyPressed(unsigned vk) { + return (GetKeyState(vk) & 0x8000) ? true : false; +} + +//! Returns current modifier keys pressed, using win32 MOD_* flags. +static unsigned GetHotkeyModifierFlags() { + unsigned ret = 0; + if (IsKeyPressed(VK_CONTROL)) ret |= MOD_CONTROL; + if (IsKeyPressed(VK_SHIFT)) ret |= MOD_SHIFT; + if (IsKeyPressed(VK_MENU)) ret |= MOD_ALT; + if (IsKeyPressed(VK_LWIN) || IsKeyPressed(VK_RWIN)) ret |= MOD_WIN; + return ret; +} + +class CClipboardOpenScope { +public: + CClipboardOpenScope() : m_open(false) {} + ~CClipboardOpenScope() {Close();} + bool Open(HWND p_owner) { + Close(); + if (OpenClipboard(p_owner)) { + m_open = true; + return true; + } else { + return false; + } + } + void Close() { + if (m_open) { + m_open = false; + CloseClipboard(); + } + } +private: + bool m_open; + + PFC_CLASS_NOT_COPYABLE_EX(CClipboardOpenScope) +}; + +class CGlobalLockScope { +public: + CGlobalLockScope(HGLOBAL p_handle) : m_handle(p_handle), m_ptr(GlobalLock(p_handle)) { + if (m_ptr == NULL) throw std::bad_alloc(); + } + ~CGlobalLockScope() { + if (m_ptr != NULL) GlobalUnlock(m_handle); + } + void * GetPtr() const {return m_ptr;} + t_size GetSize() const {return GlobalSize(m_handle);} +private: + void * m_ptr; + HGLOBAL m_handle; + + PFC_CLASS_NOT_COPYABLE_EX(CGlobalLockScope) +}; + +template class CGlobalLockScopeT { +public: + CGlobalLockScopeT(HGLOBAL handle) : m_scope(handle) {} + TItem * GetPtr() const {return reinterpret_cast(m_scope.GetPtr());} + t_size GetSize() const { + const t_size val = m_scope.GetSize(); + PFC_ASSERT( val % sizeof(TItem) == 0 ); + return val / sizeof(TItem); + } +private: + CGlobalLockScope m_scope; +}; + + +static bool IsPointInsideControl(const POINT& pt, HWND wnd) { + HWND walk = WindowFromPoint(pt); + for(;;) { + if (walk == NULL) return false; + if (walk == wnd) return true; + if (GetWindowLong(walk,GWL_STYLE) & WS_POPUP) return false; + walk = GetParent(walk); + } +} + +static bool IsWindowChildOf(HWND child, HWND parent) { + HWND walk = child; + while(walk != parent && walk != NULL && (GetWindowLong(walk,GWL_STYLE) & WS_CHILD) != 0) { + walk = GetParent(walk); + } + return walk == parent; +} + + +#include "audio_math.h" +#include "win32_misc.h" + +template +class CoTaskMemObject { +public: + CoTaskMemObject() : m_ptr() {} + + ~CoTaskMemObject() {CoTaskMemFree(m_ptr);} + + TPtr m_ptr; + PFC_CLASS_NOT_COPYABLE(CoTaskMemObject, CoTaskMemObject ); +}; +#endif //_SHARED_DLL__SHARED_H_ diff --git a/tools/vio2sf/src/foobar/foobar2000/shared/shared.lib b/tools/vio2sf/src/foobar/foobar2000/shared/shared.lib new file mode 100644 index 0000000000000000000000000000000000000000..da00a263850d16945666b88e5408111b15f8d799 GIT binary patch literal 34822 zcmd^IU2Gj!wO&a}DWO22C6xZ8X(=?NB~2XLaUrdbf8xZA?Krmc+q5UgK4beN$LE}$ zpV&#$v`v5cxxEpW2UPKdDjpCIs6vP*R8>46)Q2l{)dz%79}q%3REQ^ps&c=ze`fEQ z*|R;zlirtWY30nUz1IHr|E$?-?a4j+O3j7k$F@AYJ^Hu1XLn!!o;`g7{Zaldbvw}C zt5VKvA=-2o(dbs9v3*1bnndHjlyvy#L`;wON;*^^Vw!A7n)oXb)8mk5nwXJv=y#9< zO}{NE0H106F-ZsCA!1sCF4O8qlGfU|2d%y?>CE4Wn2!HJ(OLY0R!~l+>bsH-Z$mjj zQ&%NT?*cAp>IO+Ow-E_K`V46HMnxC#3p#?lm|i$0>G{79F)jQ{(QEhxy)q!_Wz>zS z4jHDoX-UUWZb2x^G0-zR6#WptpgFV$(@~U7(3|)L&Hh=^$?p>hg5F6`8TDqGAC`3a zS42$Dy&>t9pP@XUSAoS;u1UJIg@|c!r=$xgE7J?Vm2~bVBBt{PC7rv3dr+q#Y2kL% z7j)#Ok~*8g2c24$bYUL(ftpt&od!13S>Q3fd`i+wXd9-de=Mnjc4B%J^<;YSbxBtS zhy(%e3g|`T#q{L+lAc1jnTq|Ao|?fuXyq+QjX5Hw(o>R_ULs<;JSypFl!>W!ucX#* zh?t&4eVI;wDCzk%^gC!CZOT;pfu#EN=x5NL@$Ynahf9 z#xLju%Ec7CBWdwXj04cKzgP4WenIE{Ch3VWlo!-S8!^3fR?>^WVmdJ+sfqeC9s5Yq z>YbRUpw1s9J+}kn614PBNzdPi_5?LB=9w;?SM&jXKPVQ*C#Mh3%oRuX&yLKDPtP5m zDYlkN&7e%h;?&WJiDWuGCk15k+`*$$hl-;^b3-&(Dwm7(#l=?8E|fauO1-#JYA+WG zCl8#M9-5pSFPuW2m6b*@gW%w~O0`-n2eo>0rBrofXXTbfba0_mUFcLx?V#8QO6Ou3 zPEHTo#mgi+xKOX151Q@bVza(dtkl|jdSbbrm>xbj&NVj`?@A{`XxC-_#q|p|J#^3k z*L?;F>}1_0Q8yo$M!=DY0z3|RvPU}y;dm99vB=ty1OtvboAiZ;if^7y-&hUo35V=_ODf1?MiLQtsR%JwP#l=?S*BYElE_9#yK3X)XMc$ zBN^q5A@%TT4P}_-zA|E|37y&Hpjw@(w=0Vm#_^!vza~ewo2}+UEKyD(7gNcPRn~@9 z8bPyFs+C7zr?rabdkO=XLumwWXsCw3S@W z9K5*nM13_OZFow0CTLVk3jsGivXmX>;6{h^ijUj;+Y}4bqxAqiX~YIS=ISsIva6|o2J1dlWq2dl1fPGNz;=T zc1tH@D*4fJFto6MHJz8bV%X%KDko)Ip^XVEcp~{C9qt4qa`2i2_*+x z=~(lSn=X2*WMpSaV2sdS?n4JJB8{z(cBdtEJjPdA!d&0K7A$n|iY1n|1V>5o znm<-)w%WYvDMKX2QIhDHxnQNia$;4I|v&=NSS5h;< zO8tCb^m*twcuE@0!x;>I==>s zWmC*ebz`Mt8EMsD)A#6mb- zms|E`V!2Y3=4i9DBpwyqX(ROx_M}ALI@vBAS^7vef~92nooFJ!8<^O*kgr4GtttIT zwbW|alQF`u<&@p7o_1;wgx0uWD;-|ZwXJUw#X_HCJ9K7BtKt{`2THdpR}?CC7toqB7qssi#})UYA=K^~%yIjz}lYRA*%#n<~;AT1UW@ zPg0RNy8P%}%d!&PYuzg;Y22ANli0nI8p4J~P0l+pa%1;O3i~#VPJ1+%?<`r}>EtR6 zwZ_1#mrWeIS5g=!)*CWge7qs#6yAUETFuRWc=?f!3t`gDKQKEhD0XGj2{c@b> z=ZA@UA15jtg70>c=&uvt<9-IezXR{>XO zt0SfZKK|E_As^6=XNZ0XdK+F-7MxP=mY>r05YLAiE9|K1wW zZ(6{G{D;VY4R!w+%KZcIuScD?LiR_%{55c{BK$CqEG*b_Sk{8{3ptEBg*+U>T~`Q(FdTrHX(2N99>U0&=&e6-9(?J zPtlEZ7u`X((#34<5Z_-=pucQo}e}Ar!tMw*XXPCE$XAs(zEm^U8W^E zP2Zyy)#xx)=nySafrjY?YSNeKHabZ~3TTlo&;xXeUZuRXo2pduh1aP&@9c- z5qgu5a>t=9vbC8lHj@CCT=LhpH|*notzHwq(^)=>d& zH@fi5CuFln5X4knMGAu_60(_KMBGJpUcK(Un;Z1OW(wWekOy@A&~}WH?)$kb8PEK}KSw5Cu;ECWKfdcI16A0K1w$z1EU|S;bR&TY zN;PAwl4EvD1KlylWr97M*N;kw&-Y{=CW1hw#pXT-H>P+&TX?ICd$465kreImbtHA| z!^HeORJ#53t*B9Niz%>Ir9; zP7u@1?EP8q=prStrQqH|G+f)E6~Qojn-O+mYdMlC-(1x;wMtpf10u^J-|~&0!YF5U zhiH|^_N8Xp8(sFsRb)pi+!)hZ@%S~x&)~3dZ{YEcQNnAV*i%<1%-7F-u}=~5V-Ymg zPR;s3G`zvB-RnBT^`j54D-niHat;mI10i*Si5C-*FQ|KB4o9m4(Cy; zt=&msNDtB+aeQI2Ran@nE$bbE8^FGIM#bv4iHM;69uZ04n`jiM>)pZd%v(bz=7x%& zIS^HkGb8T^ai>_!2P$txcrH6LBkuyZi@pVP)R3DM^^ravIm{xKzlsAfHos!9H6SCq z+;+YaGZwyLBy4-dmlGA^Uj(1H?fLY$B2J0f@UFn6Se!v8VwlV3kFY{py^}ao((&2n zNQ}DLqc%Ch&|~o|f)jb7CPUSEEGM~EWV>y3cf6s%m`@2yJ7Hr>#`>|XY5?(w<9wqQ zwO~2cd*)l~xomszQtW3IPg>4`n~WNaS<5UHvy+(>w~(0^w~aMVRZ%!JSu9}>3qeOj ziEZeLMUe$UYlTtNw!q#P3+sc*qF8fxeM58Tjo0cWaqf?B$kQ23I zQv*9YG26A{vRXw*jImc`bXp`FCbUsSnq{3vqG`lUbpFI_(N4??jmI=c0*pFNn=^J^ zPLA1_8EM&>G4Z0dFynl-Y!avPbYQWz7Q?_3Ij==vjZTvtWm%H0NGNBe-S!M-A9sQo$9m;R;>DQD&7q zdz6epG^dfQz(m7@wm6T%HkVjqjU8tP>-xB10UQ>cm4~+F)N8o44;bY*?6;1#%`9U` z1R7~R8YHyYqNkH&?b7Tt6Idm1wye?E@x^WUbOWe(@L578C!uYjNLscZdHpqqzxR>}yWzOP5~ zZpFpBp!XHyI{X%B*V{_2U$GG@fEWYN`+}|Y@?*7_Yw8=7#<~?#VGleC>fW}Jxap->rBCld8B#w$VGYBKt+rQxg2&9Q{{e#RVRx%}=2o9>C?1DAx9mS_ZuM$D%l)^$ zQNP!+b+feSoxr_Tqp*LE{-P0oxrpcG#3o*^9u#%Ee%(kCGwSUnC0k$i>t%9#6nh7- zH(@RDMyXi9<}xF$9zrqPoxt79xTSU7?go;~Wkz&8?PKV>fqosMXY%D6)b87T?_PJG zKY|imFG|o&guusDl25ow;&SPSaR<3d(&uiIy=apg?2_o%1W&wCo^phyLu_=6p&Xxd zl_OKYf{2l@ie)adjoH1P*10iRDpxOsffok5`;qHwolm*Sk*Re=IEPg%bD6PqJo9Ob zC{;HxA_l$t_8Hji9>tGh^n992(skrXuF|Bev%@IOOZNR=6*u`Xw z(8q-Kc}C-{7`-_o-`Mk@r99*BN8P@_Xr5>$3$|ABb5s`#frQK^}RKY z8%AE`LF`R=B7GT%Uu48cJXbEHl-2zXAZ=x&R@9f12dgh-{pNSsFU7HxpC}hzk9$4Z z4!qkEc*+N50h-Hf>#sf|vpr_r+y}fbC-5xymI3N|&FxRA;zfcF^I-L*^dgVcZ2~J6x5zu+7NEJz zHd1}>rgyvWY#*orvx<-n*Vm@o1#UF>(t_%Gyy$Nh$7kd1Xw!Q_tnf6e1!XQX*2=S5 z-)oSRSJ>pw7Um z9*ALC;l~!Fxy)EQPfLE?LJT7w3_$mzBxO#21+{z7!ion|Sdd+h6yFo|Aq!J_)nLXW zP$L(frw6|w@SH&)7Noh%)`NX1&(yD?Rd;GcXQa46+Q3Nlyo)`oQKPXd7M!`vSVzzL zvP+}IzUN~wy04w@Ik#Kl*`e|ll)21UGfzAANThiDy@9YsYDP5A=-iV;(}6-c5JQ($ z%zkGdPp?FbofNRZx}NPm8>~;DdE%QaU~`$RU474peuZm?PMQ3#?bzHaup(hu7L>Wn zSgVx10q(m2g%pkWG6)-}mj~^U5KV8maDYS}v_8-N!#5RL@~lWM#FV{Fev|!{8&O8V zS)k@JV-Kc08+a#TpT@KT>`eaM_n&X>Ju0!%56f7<<}zCyeeZdX30%Z-#Nz@Dh&76` z;q`hfroj-;`dUv8tiBYiuc7}62Fn%Ama;y{RK zN7Lp(^Y!Av5G@+1n+wk~FUB=qGz!>)GnW~A&tqjjuF+xv#s;JNzVo%_A&nOcUe1N* zY0U{6Pc3Ot6T={9Y)y}aF&U!8W3CO#wQbL-C}McBF&Ca^hxM?=v%|tUB+~*kml<0$ z#hT$a-DwwI7=~_;Hqfe`S{~7;@ep?l&|GG$rRV886XGSJ=M9Y2#2FDiHJsIm@xc5X zc)qu#IU7%%Y_*`ef9`t5%u$2oI8TrV)%R37W}}8@6>_1a)RC?H;~LF62ayZQ^Okl( zW0??joUzD**5|R*PDarp=Qna;dfwAc3Cxt!%@(M+%r*mkGvWz}DZW=O4lGBv>bsv2 zp4om{U^$Mom0h!BeBg6OhxFm2~2iOcs_pRuA16dY` z(SvZY5P_~oh;Kiq;=r>$@L*NbTxM)n&r|fQ3ss%zGdSJ1tS^S*ty;a&AT7=#z}$;lS{eqXpaj7)n`X_${aw!Ifs1IYF5V)w4HH zSE%tXe0*GZ4TTp!`I!sP^S1u9jVB)!>QreSMBfVD6o}Cit9h_|W3{EQ(oVzX!u8mi z?GQJ1($)erm)YjNFIupp@XT3V>kzL2>V6$ac{*~;#`y&1HQ6oqtmmsC;{V$ddy zp#;9I(%Y znDUm({^}Rph`C3pZ`@poW6C2^`NoaMBk*DjPkqI}YEpBVZIt@v;7bxs#FAf|{_~yG zc{z!e{P=>Yo;5YI)zr6d_lm&Q-*2!!rw|RlzNTx=s}W4=n-O{H=ove&Nj&=-VR_dZ z&usj563u*(EKdzR&*1M!Ovh)=EWqyj&{NCrCJ?O;bXcI~GXGfpUKG 0) { + time = audio_math::rint32((audio_sample)(p_seconds * 1000.0)); + if (time == 0) time = 1; + } else if (p_seconds < 0) { + time = INFINITE; + } + return time; + } + + //! Returns true when signaled, false on timeout + static bool g_wait_for(HANDLE p_event,double p_timeout_seconds) { + SetLastError(NO_ERROR); + DWORD status = WaitForSingleObject(p_event,g_calculate_wait_time(p_timeout_seconds)); + switch(status) { + case WAIT_FAILED: + throw exception_win32(GetLastError()); + default: + throw pfc::exception_bug_check(); + case WAIT_OBJECT_0: + return true; + case WAIT_TIMEOUT: + return false; + } + } + + void set_state(bool p_state) { + PFC_ASSERT(m_handle != NULL); + if (p_state) SetEvent(m_handle); + else ResetEvent(m_handle); + } + +private: + win32_event(const win32_event&) {throw pfc::exception_not_implemented();} + const win32_event & operator=(const win32_event &) {throw pfc::exception_not_implemented();} + + HANDLE m_handle; +}; + +static void uSleepSeconds(double p_time,bool p_alertable) { + SleepEx(win32_event::g_calculate_wait_time(p_time),p_alertable ? TRUE : FALSE); +} + + + + +class win32_icon { +public: + win32_icon(HICON p_initval) : m_icon(p_initval) {} + win32_icon() : m_icon(NULL) {} + ~win32_icon() {release();} + + void release() { + HICON temp = detach(); + if (temp != NULL) DestroyIcon(temp); + } + + void set(HICON p_icon) {release(); m_icon = p_icon;} + HICON get() const {return m_icon;} + HICON detach() {return pfc::replace_t(m_icon,(HICON)NULL);} + + bool is_valid() const {return m_icon != NULL;} + +private: + win32_icon(const win32_icon&) {throw pfc::exception_not_implemented();} + const win32_icon & operator=(const win32_icon &) {throw pfc::exception_not_implemented();} + + HICON m_icon; +}; + +class win32_accelerator { +public: + win32_accelerator() : m_accel(NULL) {} + ~win32_accelerator() {release();} + HACCEL get() const {return m_accel;} + + void load(HINSTANCE p_inst,const TCHAR * p_id) { + release(); + SetLastError(NO_ERROR); + m_accel = LoadAccelerators(p_inst,p_id); + if (m_accel == NULL) { + throw exception_win32(GetLastError()); + } + } + + void release() { + if (m_accel != NULL) { + DestroyAcceleratorTable(m_accel); + m_accel = NULL; + } + } +private: + HACCEL m_accel; + PFC_CLASS_NOT_COPYABLE(win32_accelerator,win32_accelerator); +}; + + +class SelectObjectScope { +public: + SelectObjectScope(HDC p_dc,HGDIOBJ p_obj) throw() : m_dc(p_dc), m_obj(SelectObject(p_dc,p_obj)) {} + ~SelectObjectScope() throw() {SelectObject(m_dc,m_obj);} +private: + PFC_CLASS_NOT_COPYABLE_EX(SelectObjectScope) + HDC m_dc; + HGDIOBJ m_obj; +}; + +class OffsetWindowOrgScope { +public: + OffsetWindowOrgScope(HDC dc, const POINT & pt) throw() : m_dc(dc), m_pt(pt) { + OffsetWindowOrgEx(m_dc, m_pt.x, m_pt.y, NULL); + } + ~OffsetWindowOrgScope() throw() { + OffsetWindowOrgEx(m_dc, -m_pt.x, -m_pt.y, NULL); + } + +private: + const HDC m_dc; + const POINT m_pt; +}; +class DCStateScope { +public: + DCStateScope(HDC p_dc) throw() : m_dc(p_dc) { + m_state = SaveDC(m_dc); + } + ~DCStateScope() throw() { + RestoreDC(m_dc,m_state); + } +private: + const HDC m_dc; + int m_state; +}; + + +class exception_com : public std::exception { +public: + exception_com(HRESULT p_code) : std::exception(format_win32_error(p_code)), m_code(p_code) {} + HRESULT get_code() const {return m_code;} +private: + HRESULT m_code; +}; + +// Same format as _WIN32_WINNT macro. +static WORD GetWindowsVersionCode() throw() { + const DWORD ver = GetVersion(); + return (WORD)HIBYTE(LOWORD(ver)) | ((WORD)LOBYTE(LOWORD(ver)) << 8); +} + +//! Simple implementation of a COM reference counter. The initial reference count is zero, so it can be used with pfc::com_ptr_t<> with plain operator=/constructor rather than attach(). +template class ImplementCOMRefCounter : public TBase { +public: + TEMPLATE_CONSTRUCTOR_FORWARD_FLOOD(ImplementCOMRefCounter,TBase) + ULONG STDMETHODCALLTYPE AddRef() { + return ++m_refcounter; + } + ULONG STDMETHODCALLTYPE Release() { + long val = --m_refcounter; + if (val == 0) delete this; + return val; + } +protected: + virtual ~ImplementCOMRefCounter() {} +private: + pfc::refcounter m_refcounter; +}; diff --git a/tools/vio2sf/src/foobar/pfc/alloc.h b/tools/vio2sf/src/foobar/pfc/alloc.h new file mode 100644 index 000000000..b40aa092c --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/alloc.h @@ -0,0 +1,422 @@ +namespace pfc { + + static void * raw_malloc(t_size p_size) { + return p_size > 0 ? new_ptr_check_t(malloc(p_size)) : NULL; + } + + static void raw_free(void * p_block) throw() {free(p_block);} + + static void* raw_realloc(void * p_ptr,t_size p_size) { + if (p_size == 0) {raw_free(p_ptr); return NULL;} + else if (p_ptr == NULL) return raw_malloc(p_size); + else return pfc::new_ptr_check_t(::realloc(p_ptr,p_size)); + } + + static bool raw_realloc_inplace(void * p_block,t_size p_size) throw() { + if (p_block == NULL) return p_size == 0; +#ifdef _MSC_VER + if (p_size == 0) return false; + return _expand(p_block,p_size) != NULL; +#else + return false; +#endif + } + + template + t_size calc_array_width(t_size p_width) { + return pfc::mul_safe_t(p_width,sizeof(T)); + } + + template + T * __raw_malloc_t(t_size p_size) { + return reinterpret_cast(raw_malloc(calc_array_width(p_size))); + } + + template + void __raw_free_t(T * p_block) throw() { + raw_free(reinterpret_cast(p_block)); + } + + template + T * __raw_realloc_t(T * p_block,t_size p_size) { + return reinterpret_cast(raw_realloc(p_block,calc_array_width(p_size))); + } + + template + bool __raw_realloc_inplace_t(T * p_block,t_size p_size) { + return raw_realloc_inplace(p_block,calc_array_width(p_size)); + } + + + template + inline t_int safe_shift_left_t(t_int p_val,t_size p_shift = 1) { + t_int newval = p_val << p_shift; + if (newval >> p_shift != p_val) throw t_exception(); + return newval; + } + + template class alloc_dummy { + private: typedef alloc_dummy t_self; + public: + alloc_dummy() {} + void set_size(t_size p_size) {throw pfc::exception_not_implemented();} + t_size get_size() const {throw pfc::exception_not_implemented();} + const t_item & operator[](t_size p_index) const {throw pfc::exception_not_implemented();} + t_item & operator[](t_size p_index) {throw pfc::exception_not_implemented();} + + bool is_ptr_owned(const void * p_item) const {return false;} + + //set to true when we prioritize speed over memory usage + enum { alloc_prioritizes_speed = false }; + + //not mandatory + const t_item * get_ptr() const {throw pfc::exception_not_implemented();} + t_item * get_ptr() {throw pfc::exception_not_implemented();} + void prealloc(t_size) {throw pfc::exception_not_implemented();} + void force_reset() {throw pfc::exception_not_implemented();} + private: + const t_self & operator=(const t_self &) {throw pfc::exception_not_implemented();} + alloc_dummy(const t_self&) {throw pfc::exception_not_implemented();} + }; + + template + bool is_pointer_in_range(const t_item * p_buffer,t_size p_buffer_size,const void * p_pointer) { + return p_pointer >= reinterpret_cast(p_buffer) && p_pointer < reinterpret_cast(p_buffer + p_buffer_size); + } + + + //! Simple inefficient fully portable allocator. + template class alloc_simple { + private: typedef alloc_simple t_self; + public: + alloc_simple() : m_data(NULL), m_size(0) {} + void set_size(t_size p_size) { + if (p_size != m_size) { + t_item * l_data = NULL; + if (p_size > 0) l_data = new t_item[p_size]; + try { + pfc::memcpy_t(l_data,m_data,pfc::min_t(m_size,p_size)); + } catch(...) { + delete[] l_data; + throw; + } + delete[] m_data; + m_data = l_data; + m_size = p_size; + } + } + t_size get_size() const {return m_size;} + const t_item & operator[](t_size p_index) const {PFC_ASSERT(p_index < m_size); return m_data[p_index];} + t_item & operator[](t_size p_index) {PFC_ASSERT(p_index < m_size); return m_data[p_index];} + bool is_ptr_owned(const void * p_item) const {return is_pointer_in_range(get_ptr(),get_size(),p_item);} + + enum { alloc_prioritizes_speed = false }; + + t_item * get_ptr() {return m_data;} + const t_item * get_ptr() const {return m_data;} + + void prealloc(t_size) {} + void force_reset() {set_size(0);} + + ~alloc_simple() {delete[] m_data;} + private: + const t_self & operator=(const t_self &) {throw pfc::exception_not_implemented();} + alloc_simple(const t_self&) {throw pfc::exception_not_implemented();} + + t_item * m_data; + t_size m_size; + }; + + template class __array_fast_helper_t { + private: + typedef __array_fast_helper_t t_self; + public: + __array_fast_helper_t() : m_buffer(NULL), m_size_total(0), m_size(0) {} + + + void set_size(t_size p_size,t_size p_size_total) { + PFC_ASSERT(p_size <= p_size_total); + PFC_ASSERT(m_size <= m_size_total); + if (p_size_total > m_size_total) { + resize_storage(p_size_total); + resize_content(p_size); + } else { + resize_content(p_size); + resize_storage(p_size_total); + } + } + + + + t_size get_size() const {return m_size;} + t_size get_size_total() const {return m_size_total;} + const t_item & operator[](t_size p_index) const {PFC_ASSERT(p_index < m_size); return m_buffer[p_index];} + t_item & operator[](t_size p_index) {PFC_ASSERT(p_index < m_size); return m_buffer[p_index];} + ~__array_fast_helper_t() { + set_size(0,0); + } + t_item * get_ptr() {return m_buffer;} + const t_item * get_ptr() const {return m_buffer;} + bool is_ptr_owned(const void * p_item) const {return is_pointer_in_range(m_buffer,m_size_total,p_item);} + private: + const t_self & operator=(const t_self &) {throw pfc::exception_not_implemented();} + __array_fast_helper_t(const t_self &) {throw pfc::exception_not_implemented();} + + + void resize_content(t_size p_size) { + if (traits_t::needs_constructor || traits_t::needs_destructor) { + if (p_size > m_size) {//expand + do { + __unsafe__in_place_constructor_t(m_buffer[m_size]); + m_size++; + } while(m_size < p_size); + } else if (p_size < m_size) { + __unsafe__in_place_destructor_array_t(m_buffer + p_size, m_size - p_size); + m_size = p_size; + } + } else { + m_size = p_size; + } + } + + void resize_storage(t_size p_size) { + PFC_ASSERT( m_size <= m_size_total ); + PFC_ASSERT( m_size <= p_size ); + if (m_size_total != p_size) { + if (pfc::traits_t::realloc_safe) { + m_buffer = pfc::__raw_realloc_t(m_buffer,p_size); + m_size_total = p_size; + } else if (__raw_realloc_inplace_t(m_buffer,p_size)) { + //success + m_size_total = p_size; + } else { + t_item * newbuffer = pfc::__raw_malloc_t(p_size); + try { + pfc::__unsafe__in_place_constructor_array_copy_t(newbuffer,m_size,m_buffer); + } catch(...) { + pfc::__raw_free_t(newbuffer); + throw; + } + pfc::__unsafe__in_place_destructor_array_t(m_buffer,m_size); + pfc::__raw_free_t(m_buffer); + m_buffer = newbuffer; + m_size_total = p_size; + } + } + } + + t_item * m_buffer; + t_size m_size,m_size_total; + }; + + template class alloc_standard { + private: typedef alloc_standard t_self; + public: + alloc_standard() {} + void set_size(t_size p_size) {m_content.set_size(p_size,p_size);} + + t_size get_size() const {return m_content.get_size();} + + const t_item & operator[](t_size p_index) const {return m_content[p_index];} + t_item & operator[](t_size p_index) {return m_content[p_index];} + + const t_item * get_ptr() const {return m_content.get_ptr();} + t_item * get_ptr() {return m_content.get_ptr();} + + bool is_ptr_owned(const void * p_item) const {return m_content.is_ptr_owned(p_item);} + void prealloc(t_size p_size) {} + void force_reset() {set_size(0);} + + enum { alloc_prioritizes_speed = false }; + private: + alloc_standard(const t_self &) {throw pfc::exception_not_implemented();} + const t_self & operator=(const t_self&) {throw pfc::exception_not_implemented();} + + __array_fast_helper_t m_content; + }; + + template class alloc_fast { + private: typedef alloc_fast t_self; + public: + alloc_fast() {} + + void set_size(t_size p_size) { + t_size size_base = m_data.get_size_total(); + if (size_base == 0) size_base = 1; + while(size_base < p_size) { + size_base = safe_shift_left_t(size_base,1); + } + while(size_base >> 2 > p_size) { + size_base >>= 1; + } + m_data.set_size(p_size,size_base); + } + + t_size get_size() const {return m_data.get_size();} + const t_item & operator[](t_size p_index) const {return m_data[p_index];} + t_item & operator[](t_size p_index) {return m_data[p_index];} + + const t_item * get_ptr() const {return m_data.get_ptr();} + t_item * get_ptr() {return m_data.get_ptr();} + bool is_ptr_owned(const void * p_item) const {return m_data.is_ptr_owned(p_item);} + void prealloc(t_size) {} + void force_reset() {m_data.set_size(0,0);} + + enum { alloc_prioritizes_speed = true }; + private: + alloc_fast(const t_self &) {throw pfc::exception_not_implemented();} + const t_self & operator=(const t_self&) {throw pfc::exception_not_implemented();} + __array_fast_helper_t m_data; + }; + + template class alloc_fast_aggressive { + private: typedef alloc_fast_aggressive t_self; + public: + alloc_fast_aggressive() {} + + void set_size(t_size p_size) { + t_size size_base = m_data.get_size_total(); + if (size_base == 0) size_base = 1; + while(size_base < p_size) { + size_base = safe_shift_left_t(size_base,1); + } + m_data.set_size(p_size,size_base); + } + + void prealloc(t_size p_size) { + if (p_size > 0) { + t_size size_base = m_data.get_size_total(); + if (size_base == 0) size_base = 1; + while(size_base < p_size) { + size_base = safe_shift_left_t(size_base,1); + } + m_data.set_size(m_data.get_size(),size_base); + } + } + + t_size get_size() const {return m_data.get_size();} + const t_item & operator[](t_size p_index) const {;return m_data[p_index];} + t_item & operator[](t_size p_index) {return m_data[p_index];} + + const t_item * get_ptr() const {return m_data.get_ptr();} + t_item * get_ptr() {return m_data.get_ptr();} + bool is_ptr_owned(const void * p_item) const {return m_data.is_ptr_owned(p_item);} + void force_reset() {m_data.set_size(0,0);} + + enum { alloc_prioritizes_speed = true }; + private: + alloc_fast_aggressive(const t_self &) {throw pfc::exception_not_implemented();} + const t_self & operator=(const t_self&) {throw pfc::exception_not_implemented();} + __array_fast_helper_t m_data; + }; + + template class alloc_fixed { + public: + template class alloc { + private: typedef alloc t_self; + public: + alloc() : m_size(0) {} + + void set_size(t_size p_size) { + static_assert(); + + if (p_size > p_width) throw pfc::exception_overflow(); + else if (p_size > m_size) { + __unsafe__in_place_constructor_array_t(get_ptr()+m_size,p_size-m_size); + m_size = p_size; + } else if (p_size < m_size) { + __unsafe__in_place_destructor_array_t(get_ptr()+p_size,m_size-p_size); + m_size = p_size; + } + } + + ~alloc() { + if (pfc::traits_t::needs_destructor) set_size(0); + } + + t_size get_size() const {return m_size;} + + t_item * get_ptr() {return reinterpret_cast(&m_array);} + const t_item * get_ptr() const {return reinterpret_cast(&m_array);} + + const t_item & operator[](t_size n) const {return get_ptr()[n];} + t_item & operator[](t_size n) {return get_ptr()[n];} + bool is_ptr_owned(const void * p_item) const {return is_pointer_in_range(get_ptr(),p_width,p_item);} + void prealloc(t_size) {} + void force_reset() {set_size(0);} + + enum { alloc_prioritizes_speed = false }; + private: + alloc(const t_self&) {throw pfc::exception_not_implemented();} + const t_self& operator=(const t_self&) {throw pfc::exception_not_implemented();} + + t_uint8 m_array[sizeof(t_item[p_width])]; + t_size m_size; + }; + }; + + template class t_alloc = alloc_standard > class alloc_hybrid { + public: + template class alloc { + private: typedef alloc t_self; + public: + alloc() {} + + void set_size(t_size p_size) { + if (p_size > p_width) { + m_fixed.set_size(p_width); + m_variable.set_size(p_size - p_width); + } else { + m_fixed.set_size(p_size); + m_variable.set_size(0); + } + } + + t_item & operator[](t_size p_index) { + PFC_ASSERT(p_index < get_size()); + if (p_index < p_width) return m_fixed[p_index]; + else return m_variable[p_index - p_width]; + } + + const t_item & operator[](t_size p_index) const { + PFC_ASSERT(p_index < get_size()); + if (p_index < p_width) return m_fixed[p_index]; + else return m_variable[p_index - p_width]; + } + + t_size get_size() const {return m_fixed.get_size() + m_variable.get_size();} + bool is_ptr_owned(const void * p_item) const {return m_fixed.is_ptr_owned(p_item) || m_variable.is_ptr_owned(p_item);} + void prealloc(t_size p_size) { + if (p_size > p_width) m_variable.prealloc(p_size - p_width); + } + void force_reset() { + m_fixed.force_reset(); m_variable.force_reset(); + } + enum { alloc_prioritizes_speed = t_alloc::alloc_prioritizes_speed }; + private: + alloc(const t_self&) {throw pfc::exception_not_implemented();} + const t_self& operator=(const t_self&) {throw pfc::exception_not_implemented();} + + typename alloc_fixed::template alloc m_fixed; + t_alloc m_variable; + }; + }; + + template class traits_t > : public traits_default_movable {}; + template class traits_t<__array_fast_helper_t > : public traits_default_movable {}; + template class traits_t > : public pfc::traits_t<__array_fast_helper_t > {}; + template class traits_t > : public pfc::traits_t<__array_fast_helper_t > {}; + template class traits_t > : public pfc::traits_t<__array_fast_helper_t > {}; + +#if 0//not working (compiler bug?) + template class traits_t::template alloc > : public pfc::traits_t { + public: + enum { + needs_constructor = true, + }; + }; + + template class t_alloc,typename t_item> + class traits_t::template alloc > : public traits_combined::template alloc > {}; +#endif +}; diff --git a/tools/vio2sf/src/foobar/pfc/array.h b/tools/vio2sf/src/foobar/pfc/array.h new file mode 100644 index 000000000..c643cb652 --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/array.h @@ -0,0 +1,239 @@ +#ifndef _PFC_ARRAY_H_ +#define _PFC_ARRAY_H_ + +namespace pfc { + + template class t_alloc = alloc_standard> class array_t; + + + //! Special simplififed version of array class that avoids stepping on landmines with classes without public copy operators/constructors. + template + class array_staticsize_t { + public: typedef _t_item t_item; + private: typedef array_staticsize_t t_self; + public: + array_staticsize_t() : m_size(0), m_array(NULL) {} + array_staticsize_t(t_size p_size) : m_array(new t_item[p_size]), m_size(p_size) {} + ~array_staticsize_t() {__release();} + + //! Copy constructor nonfunctional when data type is not copyable. + array_staticsize_t(const t_self & p_source) : m_size(0), m_array(NULL) { + *this = p_source; + } + + //! Copy operator nonfunctional when data type is not copyable. + const t_self & operator=(const t_self & p_source) { + __release(); + + //m_array = pfc::malloc_copy_t(p_source.get_size(),p_source.get_ptr()); + const t_size newsize = p_source.get_size(); + m_array = new t_item[newsize]; + m_size = newsize; + for(t_size n = 0; n < newsize; n++) m_array[n] = p_source[n]; + return *this; + } + + void set_size_discard(t_size p_size) { + __release(); + if (p_size > 0) { + m_array = new t_item[p_size]; + m_size = p_size; + } + } + + t_size get_size() const {return m_size;} + const t_item * get_ptr() const {return m_array;} + t_item * get_ptr() {return m_array;} + + const t_item & operator[](t_size p_index) const {PFC_ASSERT(p_index < get_size());return m_array[p_index];} + t_item & operator[](t_size p_index) {PFC_ASSERT(p_index < get_size());return m_array[p_index];} + + template bool is_owned(const t_source & p_item) {return pfc::is_pointer_in_range(get_ptr(),get_size(),&p_item);} + private: + void __release() { + m_size = 0; + delete[] pfc::replace_null_t(m_array); + } + t_item * m_array; + t_size m_size; + }; + + template + inline void copy_array_t(t_to & p_to,const t_from & p_from) { + const t_size size = array_size_t(p_from); + if (p_to.has_owned_items(p_from)) {//avoid landmines with actual array data overlapping, or p_from being same as p_to + array_staticsize_t temp; + temp.set_size_discard(size); + pfc::copy_array_loop_t(temp,p_from,size); + p_to.set_size(size); + pfc::copy_array_loop_t(p_to,temp,size); + } else { + p_to.set_size(size); + pfc::copy_array_loop_t(p_to,p_from,size); + } + } + + template + inline void fill_array_t(t_array & p_array,const t_value & p_value) { + const t_size size = array_size_t(p_array); + for(t_size n=0;n class t_alloc> class array_t { + public: typedef _t_item t_item; + private: typedef array_t t_self; + public: + array_t() {} + array_t(const t_self & p_source) {copy_array_t(*this,p_source);} + template array_t(const t_source & p_source) {copy_array_t(*this,p_source);} + const t_self & operator=(const t_self & p_source) {copy_array_t(*this,p_source); return *this;} + template const t_self & operator=(const t_source & p_source) {copy_array_t(*this,p_source); return *this;} + + void set_size(t_size p_size) {m_alloc.set_size(p_size);} + void set_count(t_size p_count) {m_alloc.set_size(p_count);} + t_size get_size() const {return m_alloc.get_size();} + t_size get_count() const {return m_alloc.get_size();} + void force_reset() {m_alloc.force_reset();} + + const t_item & operator[](t_size p_index) const {PFC_ASSERT(p_index < get_size());return m_alloc[p_index];} + t_item & operator[](t_size p_index) {PFC_ASSERT(p_index < get_size());return m_alloc[p_index];} + + //! Warning: buffer pointer must not point to buffer allocated by this array (fixme). + template + void set_data_fromptr(const t_source * p_buffer,t_size p_count) { + + set_size(p_count); + pfc::copy_array_loop_t(*this,p_buffer,p_count); + } + + template + void append(const t_array & p_source) { + if (has_owned_items(p_source)) append(array_t(p_source)); + else { + const t_size source_size = array_size_t(p_source); + const t_size base = get_size(); + increase_size(source_size); + for(t_size n=0;n + void insert_multi(const t_insert & value, t_size base, t_size count) { + const t_size oldSize = get_size(); + if (base > oldSize) base = oldSize; + increase_size(count); + pfc::memmove_t(get_ptr() + base + count, get_ptr() + base, oldSize - base); + pfc::fill_ptr_t(get_ptr() + base, count, value); + } + template void append_multi(const t_append & value, t_size count) {insert_multi(value,~0,count);} + + //! Warning: buffer pointer must not point to buffer allocated by this array (fixme). + template + void append_fromptr(const t_append * p_buffer,t_size p_count) { + PFC_ASSERT( !is_owned(&p_buffer[0]) ); + t_size base = get_size(); + increase_size(p_count); + for(t_size n=0;n + void append_single(const t_append & p_item) { + if (is_owned(p_item)) append_single(t_append(p_item)); + else { + const t_size base = get_size(); + increase_size(1); + m_alloc[base] = p_item; + } + } + + template + void fill(const t_filler & p_filler) { + const t_size max = get_size(); + for(t_size n=0;n get_size()) set_size(p_size); + } + + //not supported by some allocs + const t_item * get_ptr() const {return m_alloc.get_ptr();} + t_item * get_ptr() {return m_alloc.get_ptr();} + + void prealloc(t_size p_size) {m_alloc.prealloc(p_size);} + + template + bool has_owned_items(const t_array & p_source) { + if (array_size_t(p_source) == 0) return false; + + //how the hell would we properly check if any of source items is owned by us, in case source array implements some weird mixing of references of items from different sources? + //the most obvious way means evil bottleneck here (whether it matters or not from caller's point of view which does something O(n) already is another question) + //at least this will work fine with all standard classes which don't crossreference anyhow and always use own storage + //perhaps we'll traitify this someday later + return is_owned(p_source[0]); + } + + template + bool is_owned(const t_source & p_item) { + return m_alloc.is_ptr_owned(&p_item); + } + + template + void set_single(const t_item & p_item) { + set_size(1); + (*this)[0] = p_item; + } + + template + void enumerate(t_callback & p_callback) const { + for(t_size n = 0; n < get_size(); n++ ) { + p_callback((*this)[n]); + } + } + + private: + t_alloc m_alloc; + }; + + template class t_alloc = alloc_standard > + class array_hybrid_t : public array_t::template alloc > + {}; + + + template class traits_t > : public traits_default_movable {}; + template class t_alloc> class traits_t > : public pfc::traits_t > {}; + + + template + class comparator_array { + public: + template + static int compare(const t_array1 & p_array1, const t_array2 & p_array2) { + t_size walk = 0; + for(;;) { + if (walk >= p_array1.get_size() && walk >= p_array2.get_size()) return 0; + else if (walk >= p_array1.get_size()) return -1; + else if (walk >= p_array2.get_size()) return 1; + else { + int state = t_comparator::compare(p_array1[walk],p_array2[walk]); + if (state != 0) return state; + } + ++walk; + } + } + }; +} + + +#endif //_PFC_ARRAY_H_ diff --git a/tools/vio2sf/src/foobar/pfc/avltree.h b/tools/vio2sf/src/foobar/pfc/avltree.h new file mode 100644 index 000000000..c1575c318 --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/avltree.h @@ -0,0 +1,537 @@ +namespace pfc { + + template + class _avltree_node : public _list_node { + public: + typedef _list_node t_node; + typedef _avltree_node t_self; + template _avltree_node(t_param const& param) : t_node(param), m_left(), m_right(), m_depth() {} + + typedef refcounted_object_ptr_t t_ptr; + typedef t_self* t_rawptr; + + t_ptr m_left, m_right; + t_rawptr m_parent; + + t_size m_depth; + + void link_left(t_self* ptr) throw() { + m_left = ptr; + if (ptr != NULL) ptr->m_parent = this; + } + void link_right(t_self* ptr) throw() { + m_right = ptr; + if (ptr != NULL) ptr->m_parent = this; + } + + void link_child(bool which,t_self* ptr) throw() { + (which ? m_right : m_left) = ptr; + if (ptr != NULL) ptr->m_parent = this; + } + + void unlink() throw() { + m_left.release(); m_right.release(); m_parent = NULL; m_depth = 0; + } + + inline void add_ref() throw() {this->refcount_add_ref();} + inline void release() throw() {this->refcount_release();} + + inline t_rawptr child(bool which) const throw() {return which ? &*m_right : &*m_left;} + inline bool which_child(const t_self* ptr) const throw() {return ptr == &*m_right;} + + + + t_rawptr step(bool direction) throw() { + t_self* walk = this; + for(;;) { + t_self* t = walk->child(direction); + if (t != NULL) return t->peakchild(!direction); + for(;;) { + t = walk->m_parent; + if (t == NULL) return NULL; + if (t->which_child(walk) != direction) return t; + walk = t; + } + } + } + t_rawptr peakchild(bool direction) throw() { + t_self* walk = this; + for(;;) { + t_rawptr next = walk->child(direction); + if (next == NULL) return walk; + walk = next; + } + } + t_node * prev() throw() {return step(false);} + t_node * next() throw() {return step(true);} + private: + ~_avltree_node() throw() {} + }; + + + template + class avltree_t { + public: + typedef avltree_t t_self; + typedef pfc::const_iterator const_iterator; + typedef pfc::iterator iterator; + typedef t_storage t_item; + private: + typedef _avltree_node t_node; +#if 1//MSVC8 bug fix + typedef refcounted_object_ptr_t t_nodeptr; + typedef t_node * t_noderawptr; +#else + typedef typename t_node::t_ptr t_nodeptr; + typedef typename t_node::t_rawptr t_noderawptr; +#endif + + + template + inline static int compare(const t_item1 & p_item1, const t_item2 & p_item2) { + return t_comparator::compare(p_item1,p_item2); + } + + t_nodeptr m_root; + + static t_size calc_depth(const t_nodeptr & ptr) + { + return ptr.is_valid() ? 1+ptr->m_depth : 0; + } + + static void recalc_depth(t_nodeptr const& ptr) { + ptr->m_depth = pfc::max_t(calc_depth(ptr->m_left), calc_depth(ptr->m_right)); + } + + static void assert_children(t_nodeptr ptr) { + PFC_ASSERT(ptr->m_depth == pfc::max_t(calc_depth(ptr->m_left),calc_depth(ptr->m_right)) ); + } + + static t_ssize test_depth(t_nodeptr const& ptr) + { + if (ptr==0) return 0; + else return calc_depth(ptr->m_right) - calc_depth(ptr->m_left); + } + + static t_nodeptr extract_left_leaf(t_nodeptr & p_base) { + if (p_base->m_left != NULL) { + t_nodeptr ret = extract_left_leaf(p_base->m_left); + recalc_depth(p_base); + g_rebalance(p_base); + return ret; + } else { + t_nodeptr node = p_base; + p_base = node->m_right; + if (p_base.is_valid()) p_base->m_parent = node->m_parent; + node->m_right.release(); + node->m_depth = 0; + node->m_parent = NULL; + return node; + } + } + + static t_nodeptr extract_right_leaf(t_nodeptr & p_base) { + if (p_base->m_right != NULL) { + t_nodeptr ret = extract_right_leaf(p_base->m_right); + recalc_depth(p_base); + g_rebalance(p_base); + return ret; + } else { + t_nodeptr node = p_base; + p_base = node->m_left; + if (p_base.is_valid()) p_base->m_parent = node->m_parent; + node->m_left.release(); + node->m_depth = 0; + node->m_parent = NULL; + return node; + } + } + + static void remove_internal(t_nodeptr & p_node) { + t_nodeptr oldval = p_node; + if (p_node->m_left.is_empty()) { + p_node = p_node->m_right; + if (p_node.is_valid()) p_node->m_parent = oldval->m_parent; + } else if (p_node->m_right.is_empty()) { + p_node = p_node->m_left; + if (p_node.is_valid()) p_node->m_parent = oldval->m_parent; + } else { + t_nodeptr swap = extract_left_leaf(p_node->m_right); + + swap->link_left(&*oldval->m_left); + swap->link_right(&*oldval->m_right); + swap->m_parent = oldval->m_parent; + recalc_depth(swap); + p_node = swap; + } + oldval->unlink(); + } + + template + static void __enum_items_recur(t_nodewalk * p_node,t_callback & p_callback) { + if (p_node != NULL) { + __enum_items_recur(&*p_node->m_left,p_callback); + p_callback (p_node->m_content); + __enum_items_recur(&*p_node->m_right,p_callback); + } + } + template + static t_node * g_find_or_add_node(t_nodeptr & p_base,t_node * parent,t_search const & p_search,bool & p_new) + { + if (p_base.is_empty()) { + p_base = new t_node(p_search); + p_base->m_parent = parent; + p_new = true; + return p_base.get_ptr(); + } + + PFC_ASSERT( p_base->m_parent == parent ); + + int result = compare(p_base->m_content,p_search); + if (result > 0) { + t_node * ret = g_find_or_add_node(p_base->m_left,&*p_base,p_search,p_new); + if (p_new) { + recalc_depth(p_base); + g_rebalance(p_base); + } + return ret; + } else if (result < 0) { + t_node * ret = g_find_or_add_node(p_base->m_right,&*p_base,p_search,p_new); + if (p_new) { + recalc_depth(p_base); + g_rebalance(p_base); + } + return ret; + } else { + p_new = false; + return p_base.get_ptr(); + } + } + + + + template + static t_storage * g_find_or_add(t_nodeptr & p_base,t_node * parent,t_search const & p_search,bool & p_new) { + return &g_find_or_add_node(p_base,parent,p_search,p_new)->m_content; + } + + + static void g_rotate_right(t_nodeptr & p_node) { + t_nodeptr oldroot = p_node; + t_nodeptr newroot = oldroot->m_right; + oldroot->link_child(true, &*newroot->m_left); + newroot->m_left = oldroot; + newroot->m_parent = oldroot->m_parent; + oldroot->m_parent = &*newroot; + recalc_depth(oldroot); + recalc_depth(newroot); + p_node = newroot; + } + + static void g_rotate_left(t_nodeptr & p_node) { + t_nodeptr oldroot = p_node; + t_nodeptr newroot = oldroot->m_left; + oldroot->link_child(false, &*newroot->m_right); + newroot->m_right = oldroot; + newroot->m_parent = oldroot->m_parent; + oldroot->m_parent = &*newroot; + recalc_depth(oldroot); + recalc_depth(newroot); + p_node = newroot; + } + + static void g_rebalance(t_nodeptr & p_node) { + t_ssize balance = test_depth(p_node); + if (balance > 1) { + //right becomes root + if (test_depth(p_node->m_right) < 0) { + g_rotate_left(p_node->m_right); + } + g_rotate_right(p_node); + } else if (balance < -1) { + //left becomes root + if (test_depth(p_node->m_left) > 0) { + g_rotate_right(p_node->m_left); + } + g_rotate_left(p_node); + } + selftest(p_node); + } + + template + static bool g_remove(t_nodeptr & p_node,t_search const & p_search) { + if (p_node.is_empty()) return false; + + int result = compare(p_node->m_content,p_search); + if (result == 0) { + remove_internal(p_node); + if (p_node != NULL) { + recalc_depth(p_node); + g_rebalance(p_node); + } + return true; + } else { + if (g_remove(result > 0 ? p_node->m_left : p_node->m_right,p_search)) { + recalc_depth(p_node); + g_rebalance(p_node); + return true; + } else { + return false; + } + } + } + + static void selftest(t_nodeptr const& p_node) { + #if 0 //def _DEBUG//SLOW! + if (p_node != NULL) { + selftest(p_node->m_left); + selftest(p_node->m_right); + assert_children(p_node); + t_ssize delta = test_depth(p_node); + PFC_ASSERT(delta >= -1 && delta <= 1); + + if (p_node->m_left.is_valid()) { + PFC_ASSERT( p_node.get_ptr() == p_node->m_left->m_parent ); + } + if (p_node->m_right.is_valid()) { + PFC_ASSERT( p_node.get_ptr() == p_node->m_right->m_parent ); + } + + if (p_node->m_parent != NULL) { + PFC_ASSERT(p_node == p_node->m_parent->m_left || p_node == p_node->m_parent->m_right); + } + } + #endif + } + + + static t_size calc_count(const t_node * p_node) throw() { + if (p_node != NULL) { + return 1 + calc_count(&*p_node->m_left) + calc_count(&*p_node->m_right); + } else { + return 0; + } + } + + template + t_storage * __find_item_ptr(t_param const & p_item) const { + t_node* ptr = &*m_root; + while(ptr != NULL) { + int result = compare(ptr->m_content,p_item); + if (result > 0) ptr=&*ptr->m_left; + else if (result < 0) ptr=&*ptr->m_right; + else return &ptr->m_content; + } + return NULL; + } + + template t_storage * __find_nearest(const t_search & p_search) const { + t_node * ptr = &*m_root; + t_storage * found = NULL; + while(ptr != NULL) { + int result = compare(ptr->m_content,p_search); + if (above) result = -result; + if (inclusive && result == 0) { + //direct hit + found = &ptr->m_content; + break; + } else if (result < 0) { + //match + found = &ptr->m_content; + ptr = ptr->child(!above); + } else { + //mismatch + ptr = ptr->child(above); + } + } + return found; + } + public: + avltree_t() : m_root(NULL) {} + ~avltree_t() {reset();} + const t_self & operator=(const t_self & p_other) {__copy(p_other);return *this;} + avltree_t(const t_self & p_other) : m_root(NULL) {try{__copy(p_other);} catch(...) {remove_all(); throw;}} + + template const t_self & operator=(const t_other & p_other) {copy_list_enumerated(*this,p_other);return *this;} + template avltree_t(const t_other & p_other) : m_root(NULL) {try{copy_list_enumerated(*this,p_other);}catch(...){remove_all(); throw;}} + + + template const t_storage * find_nearest_item(const t_search & p_search) const { + return __find_nearest(p_search); + } + + template t_storage * find_nearest_item(const t_search & p_search) { + return __find_nearest(p_search); + } + + template + t_storage & add_item(t_param const & p_item) { + bool dummy; + return add_item_ex(p_item,dummy); + } + + template + t_self & operator+=(const t_param & p_item) {add_item(p_item);return *this;} + + template + t_self & operator-=(const t_param & p_item) {remove_item(p_item);return *this;} + + //! Returns true when the list has been altered, false when the item was already present before. + template + bool add_item_check(t_param const & item) { + bool isNew = false; + g_find_or_add(m_root,NULL,item,isNew); + selftest(m_root); + return isNew; + } + template + t_storage & add_item_ex(t_param const & p_item,bool & p_isnew) { + t_storage * ret = g_find_or_add(m_root,NULL,p_item,p_isnew); + selftest(m_root); + return *ret; + } + + template + void set_item(const t_param & p_item) { + bool isnew; + t_storage & found = add_item_ex(p_item,isnew); + if (isnew) found = p_item; + } + + template + const t_storage * find_item_ptr(t_param const & p_item) const { + return __find_item_ptr(p_item); + } + + //! WARNING: caller must not alter the item in a way that changes the sort order. + template + t_storage * find_item_ptr(t_param const & p_item) { + return __find_item_ptr(p_item); + } + + template + bool contains(const t_param & p_item) const { + return find_item_ptr(p_item) != NULL; + } + + //! Same as contains(). + template + bool have_item(const t_param & p_item) const {return contains(p_item);} + + void remove_all() throw() { + _unlink_recur(m_root); + m_root.release(); + } + + bool remove(const_iterator const& iter) { + PFC_ASSERT(iter.is_valid()); + return remove_item(*iter);//OPTIMIZEME + //should never return false unless there's a bug in calling code + } + + template + bool remove_item(t_param const & p_item) { + bool ret = g_remove(m_root,p_item); + selftest(m_root); + return ret; + } + + t_size get_count() const throw() { + return calc_count(&*m_root); + } + + template + void enumerate(t_callback & p_callback) const { + __enum_items_recur(&*m_root,p_callback); + } + + //! Allows callback to modify the tree content. + //! WARNING: items must not be altered in a way that changes their sort order. + template + void _enumerate_var(t_callback & p_callback) { __enum_items_recur(&*m_root,p_callback); } + + template iterator insert(const t_param & p_item) { + bool isNew; + t_node * ret = g_find_or_add_node(m_root,NULL,p_item,isNew); + selftest(m_root); + return ret; + } + + //deprecated backwards compatibility method wrappers + template t_storage & add(const t_param & p_item) {return add_item(p_item);} + template t_storage & add_ex(const t_param & p_item,bool & p_isnew) {return add_item_ex(p_item,p_isnew);} + template const t_storage * find_ptr(t_param const & p_item) const {return find_item_ptr(p_item);} + template t_storage * find_ptr(t_param const & p_item) {return find_item_ptr(p_item);} + template bool exists(t_param const & p_item) const {return have_item(p_item);} + void reset() {remove_all();} + + + + + const_iterator first() const throw() {return _firstlast(false);} + const_iterator last() const throw() {return _firstlast(true);} + //Unsafe! Caller must not modify items in a way that changes sort order! + iterator _first_var() { return _firstlast(false); } + //Unsafe! Caller must not modify items in a way that changes sort order! + iterator _last_var() { return _firstlast(true); } + + template bool get_first(t_param & p_item) const throw() { + const_iterator iter = first(); + if (!iter.is_valid()) return false; + p_item = *iter; + return true; + } + template bool get_last(t_param & p_item) const throw() { + const_iterator iter = last(); + if (!iter.is_valid()) return false; + p_item = *iter; + return true; + } + + static bool equals(const t_self & v1, const t_self & v2) { + return listEquals(v1,v2); + } + bool operator==(const t_self & other) const {return equals(*this,other);} + bool operator!=(const t_self & other) const {return !equals(*this,other);} + + private: + static void _unlink_recur(t_nodeptr & node) { + if (node.is_valid()) { + _unlink_recur(node->m_left); + _unlink_recur(node->m_right); + node->unlink(); + } + } + t_node* _firstlast(bool which) const throw() { + if (m_root.is_empty()) return NULL; + for(t_node * walk = &*m_root; ; ) { + t_node * next = walk->child(which); + if (next == NULL) return walk; + PFC_ASSERT( next->m_parent == walk ); + walk = next; + } + } + static t_nodeptr __copy_recur(t_node * p_source,t_node * parent) { + if (p_source == NULL) { + return NULL; + } else { + t_nodeptr newnode = new t_node(p_source->m_content); + newnode->m_depth = p_source->m_depth; + newnode->m_left = __copy_recur(&*p_source->m_left,&*newnode); + newnode->m_right = __copy_recur(&*p_source->m_right,&*newnode); + newnode->m_parent = parent; + return newnode; + } + } + + void __copy(const t_self & p_other) { + reset(); + m_root = __copy_recur(&*p_other.m_root,NULL); + selftest(m_root); + } + }; + + + template + class traits_t > : public traits_default_movable {}; +} diff --git a/tools/vio2sf/src/foobar/pfc/binary_search.h b/tools/vio2sf/src/foobar/pfc/binary_search.h new file mode 100644 index 000000000..5b15889fe --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/binary_search.h @@ -0,0 +1,81 @@ +namespace pfc { + class comparator_default; + + template + class binarySearch { + public: + + template + static bool run(const t_container & p_container,t_size p_base,t_size p_count,const t_param & p_param,t_size & p_result) { + t_size max = p_base + p_count; + t_size min = p_base; + while(min> 1); + int state = t_comparator::compare(p_param,p_container[ptr]); + if (state > 0) min = ptr + 1; + else if (state < 0) max = ptr; + else { + p_result = ptr; + return true; + } + } + p_result = min; + return false; + } + + + template + static bool runGroupBegin(const t_container & p_container,t_size p_base,t_size p_count,const t_param & p_param,t_size & p_result) { + t_size max = p_base + p_count; + t_size min = p_base; + bool found = false; + while(min> 1); + int state = t_comparator::compare(p_param,p_container[ptr]); + if (state > 0) min = ptr + 1; + else if (state < 0) max = ptr; + else { + found = true; max = ptr; + } + } + p_result = min; + return found; + } + + template + static bool runGroupEnd(const t_container & p_container,t_size p_base,t_size p_count,const t_param & p_param,t_size & p_result) { + t_size max = p_base + p_count; + t_size min = p_base; + bool found = false; + while(min> 1); + int state = t_comparator::compare(p_param,p_container[ptr]); + if (state > 0) min = ptr + 1; + else if (state < 0) max = ptr; + else { + found = true; min = ptr + 1; + } + } + p_result = min; + return found; + } + + template + static bool runGroup(const t_container & p_container,t_size p_base,t_size p_count,const t_param & p_param,t_size & p_result,t_size & p_resultCount) { + if (!runGroupBegin(p_container,p_base,p_count,p_param,p_result)) { + p_resultCount = 0; + return false; + } + t_size groupEnd; + if (!runGroupEnd(p_container,p_result,p_count - p_result,p_param,groupEnd)) { + //should not happen.. + PFC_ASSERT(0); + p_resultCount = 0; + return false; + } + PFC_ASSERT(groupEnd > p_result); + p_resultCount = groupEnd - p_result; + return true; + } + }; +}; diff --git a/tools/vio2sf/src/foobar/pfc/bit_array.h b/tools/vio2sf/src/foobar/pfc/bit_array.h new file mode 100644 index 000000000..3e84216ad --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/bit_array.h @@ -0,0 +1,59 @@ +#ifndef _PFC_BIT_ARRAY_H_ +#define _PFC_BIT_ARRAY_H_ + +class NOVTABLE bit_array { +public: + virtual bool get(t_size n) const = 0; + virtual t_size find(bool val,t_size start,t_ssize count) const//can be overridden for improved speed; returns first occurance of val between start and start+count (excluding start+count), or start+count if not found; count may be negative if we're searching back + { + t_ssize d, todo, ptr = start; + if (count==0) return start; + else if (count<0) {d = -1; todo = -count;} + else {d = 1; todo = count;} + while(todo>0 && get(ptr)!=val) {ptr+=d;todo--;} + return ptr; + } + inline bool operator[](t_size n) const {return get(n);} + + t_size calc_count(bool val,t_size start,t_size count,t_size count_max = ~0) const//counts number of vals for start<=n +class bit_array_table_t : public bit_array +{ + const T * data; + t_size count; + bool after; +public: + inline bit_array_table_t(const T * p_data,t_size p_count,bool p_after = false) + : data(p_data), count(p_count), after(p_after) + { + } + + bool get(t_size n) const + { + if (n +class bit_array_var_table_t : public bit_array_var +{ + T * data; + t_size count; + bool after; +public: + inline bit_array_var_table_t(T * p_data,t_size p_count,bool p_after = false) + : data(p_data), count(p_count), after(p_after) + { + } + + bool get(t_size n) const { + if (n bit_array_table; +typedef bit_array_var_table_t bit_array_var_table; + +class bit_array_range : public bit_array +{ + t_size begin,end; + bool state; +public: + bit_array_range(t_size first,t_size count,bool p_state = true) : begin(first), end(first+count), state(p_state) {} + + bool get(t_size n) const + { + bool rv = n>=begin && n0) + return (val>=start && valstart+count) ? val : start+count; + } + else + { + if (start == val) return count>0 ? start+1 : start-1; + else return start; + } + } +}; + +class bit_array_bittable : public bit_array_var +{ + pfc::array_t m_data; + t_size m_count; +public: + //helpers + template + inline static bool g_get(const t_array & p_array,t_size idx) + { + return !! (p_array[idx>>3] & (1<<(idx&7))); + } + + template + inline static void g_set(t_array & p_array,t_size idx,bool val) + { + unsigned char & dst = p_array[idx>>3]; + unsigned char mask = 1<<(idx&7); + dst = val ? dst|mask : dst&~mask; + } + + inline static t_size g_estimate_size(t_size p_count) {return (p_count+7)>>3;} + + void resize(t_size p_count) + { + t_size old_bytes = g_estimate_size(m_count); + m_count = p_count; + t_size bytes = g_estimate_size(m_count); + m_data.set_size(bytes); + if (bytes > old_bytes) pfc::memset_null_t(m_data.get_ptr()+old_bytes,bytes-old_bytes); + } + + bit_array_bittable(t_size p_count) : m_count(0) {resize(p_count);} + + void set(t_size n,bool val) + { + if (n + class bsearch_callback_impl_simple_t : public bsearch_callback { + public: + int test(t_size p_index) const { + return m_compare(m_container[p_index],m_param); + } + bsearch_callback_impl_simple_t(const t_container & p_container,t_compare p_compare,const t_param & p_param) + : m_container(p_container), m_compare(p_compare), m_param(p_param) + { + } + private: + const t_container & m_container; + t_compare m_compare; + const t_param & m_param; + }; + + template + class bsearch_callback_impl_permutation_t : public bsearch_callback { + public: + int test(t_size p_index) const { + return m_compare(m_container[m_permutation[p_index]],m_param); + } + bsearch_callback_impl_permutation_t(const t_container & p_container,t_compare p_compare,const t_param & p_param,const t_permutation & p_permutation) + : m_container(p_container), m_compare(p_compare), m_param(p_param), m_permutation(p_permutation) + { + } + private: + const t_container & m_container; + t_compare m_compare; + const t_param & m_param; + const t_permutation & m_permutation; + }; + + + template + bool bsearch_t(t_size p_count,const t_container & p_container,t_compare p_compare,const t_param & p_param,t_size & p_index) { + return bsearch( + p_count, + bsearch_callback_impl_simple_t(p_container,p_compare,p_param), + p_index); + } + + template + bool bsearch_permutation_t(t_size p_count,const t_container & p_container,t_compare p_compare,const t_param & p_param,const t_permutation & p_permutation,t_size & p_index) { + t_size index; + if (bsearch( + p_count, + bsearch_callback_impl_permutation_t(p_container,p_compare,p_param,p_permutation), + index)) + { + p_index = p_permutation[index]; + return true; + } else { + return false; + } + } + + template + bool bsearch_range_t(const t_size p_count,const t_container & p_container,t_compare p_compare,const t_param & p_param,t_size & p_range_base,t_size & p_range_count) + { + t_size probe; + if (!bsearch( + p_count, + bsearch_callback_impl_simple_t(p_container,p_compare,p_param), + probe)) return false; + + t_size base = probe, count = 1; + while(base > 0 && p_compare(p_container[base-1],p_param) == 0) {base--; count++;} + while(base + count < p_count && p_compare(p_container[base+count],p_param) == 0) {count++;} + p_range_base = base; + p_range_count = count; + return true; + } + +} diff --git a/tools/vio2sf/src/foobar/pfc/bsearch_inline.h b/tools/vio2sf/src/foobar/pfc/bsearch_inline.h new file mode 100644 index 000000000..272a275a6 --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/bsearch_inline.h @@ -0,0 +1,48 @@ +namespace pfc { + + //deprecated + +template +inline bool bsearch_inline_t(t_size p_count, const t_callback & p_callback,t_size & p_result) +{ + t_size max = p_count; + t_size min = 0; + t_size ptr; + while(min> 1); + int result = p_callback.test(ptr); + if (result<0) min = ptr + 1; + else if (result>0) max = ptr; + else + { + p_result = ptr; + return true; + } + } + p_result = min; + return false; +} + +template +inline bool bsearch_simple_inline_t(const t_buffer & p_buffer,t_size p_count,t_value const & p_value,t_size & p_result) +{ + t_size max = p_count; + t_size min = 0; + t_size ptr; + while(min> 1); + if (p_value > p_buffer[ptr]) min = ptr + 1; + else if (p_value < p_buffer[ptr]) max = ptr; + else + { + p_result = ptr; + return true; + } + } + p_result = min; + return false; +} + +} diff --git a/tools/vio2sf/src/foobar/pfc/byte_order_helper.h b/tools/vio2sf/src/foobar/pfc/byte_order_helper.h new file mode 100644 index 000000000..778d44316 --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/byte_order_helper.h @@ -0,0 +1,232 @@ +#ifndef _PFC_BYTE_ORDER_HELPER_ +#define _PFC_BYTE_ORDER_HELPER_ + +namespace pfc { + void byteswap_raw(void * p_buffer,t_size p_bytes); + + template T byteswap_t(T p_source); + + template<> inline char byteswap_t(char p_source) {return p_source;} + template<> inline unsigned char byteswap_t(unsigned char p_source) {return p_source;} + +#ifdef _MSC_VER//does this even help with performance/size? + template<> inline wchar_t byteswap_t(wchar_t p_source) {return _byteswap_ushort(p_source);} + + template<> inline short byteswap_t(short p_source) {return _byteswap_ushort(p_source);} + template<> inline unsigned short byteswap_t(unsigned short p_source) {return _byteswap_ushort(p_source);} + + template<> inline int byteswap_t(int p_source) {return _byteswap_ulong(p_source);} + template<> inline unsigned int byteswap_t(unsigned int p_source) {return _byteswap_ulong(p_source);} + + template<> inline long byteswap_t(long p_source) {return _byteswap_ulong(p_source);} + template<> inline unsigned long byteswap_t(unsigned long p_source) {return _byteswap_ulong(p_source);} + + template<> inline long long byteswap_t(long long p_source) {return _byteswap_uint64(p_source);} + template<> inline unsigned long long byteswap_t(unsigned long long p_source) {return _byteswap_uint64(p_source);} +#else + template<> inline t_uint16 byteswap_t(t_uint16 p_source) {return ((p_source & 0xFF00) >> 8) | ((p_source & 0x00FF) << 8);} + template<> inline t_int16 byteswap_t(t_int16 p_source) {return byteswap_t(p_source);} + + template<> inline t_uint32 byteswap_t(t_uint32 p_source) {return ((p_source & 0xFF000000) >> 24) | ((p_source & 0x00FF0000) >> 8) | ((p_source & 0x0000FF00) << 8) | ((p_source & 0x000000FF) << 24);} + template<> inline t_int32 byteswap_t(t_int32 p_source) {return byteswap_t(p_source);} + + template<> inline t_uint64 byteswap_t(t_uint64 p_source) { + //optimizeme + byteswap_raw(&p_source,sizeof(p_source)); + return p_source; + } + template<> inline t_int64 byteswap_t(t_int64 p_source) {return byteswap_t(p_source);} + + template<> inline wchar_t byteswap_t(wchar_t p_source) { + return byteswap_t::t_unsigned>(p_source); + } +#endif + + template<> inline float byteswap_t(float p_source) { + float ret; + *(t_uint32*) &ret = byteswap_t(*(const t_uint32*)&p_source ); + return ret; + } + + template<> inline double byteswap_t(double p_source) { + double ret; + *(t_uint64*) &ret = byteswap_t(*(const t_uint64*)&p_source ); + return ret; + } + + //blargh at GUID byteswap issue + template<> inline GUID byteswap_t(GUID p_guid) { + GUID ret; + ret.Data1 = pfc::byteswap_t(p_guid.Data1); + ret.Data2 = pfc::byteswap_t(p_guid.Data2); + ret.Data3 = pfc::byteswap_t(p_guid.Data3); + ret.Data4[0] = p_guid.Data4[0]; + ret.Data4[1] = p_guid.Data4[1]; + ret.Data4[2] = p_guid.Data4[2]; + ret.Data4[3] = p_guid.Data4[3]; + ret.Data4[4] = p_guid.Data4[4]; + ret.Data4[5] = p_guid.Data4[5]; + ret.Data4[6] = p_guid.Data4[6]; + ret.Data4[7] = p_guid.Data4[7]; + return ret; + } + + + +}; + +#ifdef _MSC_VER + +#if defined(_M_IX86) || defined(_M_X64) +#define PFC_BYTE_ORDER_IS_BIG_ENDIAN 0 +#endif + +#else//_MSC_VER + +#include +#if __BYTE_ORDER == __LITTLE_ENDIAN +#define PFC_BYTE_ORDER_IS_BIG_ENDIAN 0 +#else +#define PFC_BYTE_ORDER_IS_BIG_ENDIAN 1 +#endif + +#endif//_MSC_VER + +#ifdef PFC_BYTE_ORDER_IS_BIG_ENDIAN +#define PFC_BYTE_ORDER_IS_LITTLE_ENDIAN (!(PFC_BYTE_ORDER_IS_BIG_ENDIAN)) +#else +#error please update byte order #defines +#endif + + +namespace pfc { + enum { + byte_order_is_big_endian = PFC_BYTE_ORDER_IS_BIG_ENDIAN, + byte_order_is_little_endian = PFC_BYTE_ORDER_IS_LITTLE_ENDIAN, + }; + + template T byteswap_if_be_t(T p_param) {return byte_order_is_big_endian ? byteswap_t(p_param) : p_param;} + template T byteswap_if_le_t(T p_param) {return byte_order_is_little_endian ? byteswap_t(p_param) : p_param;} +} + +namespace byte_order { + +#if PFC_BYTE_ORDER_IS_BIG_ENDIAN//big endian + template inline void order_native_to_le_t(T& param) {param = pfc::byteswap_t(param);} + template inline void order_native_to_be_t(T& param) {} + template inline void order_le_to_native_t(T& param) {param = pfc::byteswap_t(param);} + template inline void order_be_to_native_t(T& param) {} +#else//little endian + template inline void order_native_to_le_t(T& param) {} + template inline void order_native_to_be_t(T& param) {param = pfc::byteswap_t(param);} + template inline void order_le_to_native_t(T& param) {} + template inline void order_be_to_native_t(T& param) {param = pfc::byteswap_t(param);} +#endif +}; + + + +namespace pfc { + template + class __EncodeIntHelper { + public: + inline static void Run(TInt p_value,t_uint8 * p_out) { + *p_out = (t_uint8)(p_value); + __EncodeIntHelper::Run(p_value >> 8,p_out + (IsBigEndian ? -1 : 1)); + } + }; + + template + class __EncodeIntHelper { + public: + inline static void Run(TInt p_value,t_uint8* p_out) { + *p_out = (t_uint8)(p_value); + } + }; + template + class __EncodeIntHelper { + public: + inline static void Run(TInt,t_uint8*) {} + }; + + template + inline void encode_little_endian(t_uint8 * p_buffer,TInt p_value) { + __EncodeIntHelper::Run(p_value,p_buffer); + } + template + inline void encode_big_endian(t_uint8 * p_buffer,TInt p_value) { + __EncodeIntHelper::Run(p_value,p_buffer + (sizeof(TInt) - 1)); + } + + + template + class __DecodeIntHelper { + public: + inline static TInt Run(const t_uint8 * p_in) { + return (__DecodeIntHelper::Run(p_in + (IsBigEndian ? -1 : 1)) << 8) + *p_in; + } + }; + + template + class __DecodeIntHelper { + public: + inline static TInt Run(const t_uint8* p_in) {return *p_in;} + }; + + template + class __DecodeIntHelper { + public: + inline static TInt Run(const t_uint8*) {return 0;} + }; + + template + inline void decode_little_endian(TInt & p_out,const t_uint8 * p_buffer) { + p_out = __DecodeIntHelper::Run(p_buffer); + } + + template + inline void decode_big_endian(TInt & p_out,const t_uint8 * p_buffer) { + p_out = __DecodeIntHelper::Run(p_buffer + (sizeof(TInt) - 1)); + } + + template + inline TInt decode_little_endian(const t_uint8 * p_buffer) { + TInt temp; + decode_little_endian(temp,p_buffer); + return temp; + } + + template + inline TInt decode_big_endian(const t_uint8 * p_buffer) { + TInt temp; + decode_big_endian(temp,p_buffer); + return temp; + } + + template + inline void decode_endian(TInt & p_out,const t_uint8 * p_buffer) { + if (IsBigEndian) decode_big_endian(p_out,p_buffer); + else decode_little_endian(p_out,p_buffer); + } + template + inline void encode_endian(t_uint8 * p_buffer,TInt p_in) { + if (IsBigEndian) encode_big_endian(p_in,p_value); + else encode_little_endian(p_in,p_value); + } + + + + template + inline static void reverse_bytes(t_uint8 * p_buffer) { + pfc::swap_t(p_buffer[0],p_buffer[width-1]); + reverse_bytes(p_buffer+1); + } + + template<> inline static void reverse_bytes<1>(t_uint8 * p_buffer) { } + template<> inline static void reverse_bytes<0>(t_uint8 * p_buffer) { } + +} + + + +#endif diff --git a/tools/vio2sf/src/foobar/pfc/chain_list_v2.h b/tools/vio2sf/src/foobar/pfc/chain_list_v2.h new file mode 100644 index 000000000..a6d6b64f7 --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/chain_list_v2.h @@ -0,0 +1,264 @@ +namespace pfc { + + template + class __chain_list_elem : public _list_node { + public: + typedef _list_node t_node; + TEMPLATE_CONSTRUCTOR_FORWARD_FLOOD_WITH_INITIALIZER(__chain_list_elem,t_node, {m_prev = m_next = NULL;}); + + typedef __chain_list_elem t_self; + + t_self * m_prev, * m_next; + + t_node * prev() throw() {return m_prev;} + t_node * next() throw() {return m_next;} + + //helper wrappers + void add_ref() throw() {this->refcount_add_ref();} + void release() throw() {this->refcount_release();} + //workaround for cross-list-relinking case - never actually deletes p_elem + void __release_temporary() throw() {this->_refcount_release_temporary();} + }; + + //! Differences between chain_list_v2_t<> and old chain_list_t<>: \n + //! Iterators pointing to removed items as well as to items belonging to no longer existing list objects remain valid but they're no longer walkable - as if the referenced item was the only item in the list. The old class invalidated iterators on deletion instead. + template + class chain_list_v2_t { + public: + typedef _t_item t_item; + typedef chain_list_v2_t t_self; + typedef ::pfc::iterator iterator; + typedef ::pfc::const_iterator const_iterator; + typedef __chain_list_elem t_elem; + + chain_list_v2_t() : m_first(), m_last(), m_count() {} + chain_list_v2_t(const t_self & p_source) : m_first(), m_last(), m_count() { + try { + *this = p_source; + } catch(...) { + remove_all(); + throw; + } + } + const t_self & operator=(const t_self & p_other) { + remove_all(); + for(t_elem * walk = p_other.m_first; walk != NULL; walk = walk->m_next) { + add_item(walk->m_content); + } + return *this; + } + + t_size get_count() const {return m_count;} + + iterator first() {return iterator(m_first);} + iterator last() {return iterator(m_last);} + const_iterator first() const {return const_iterator(m_first);} + const_iterator last() const {return const_iterator(m_last);} + + void remove_single(const_iterator const & p_iter) { + PFC_ASSERT(p_iter.is_valid()); + __unlink(_elem(p_iter)); + } + + void remove(const_iterator const & p_iter) { + PFC_ASSERT(p_iter.is_valid()); + __unlink(_elem(p_iter)); + } + + void remove_all() throw() { + while(m_first != NULL) __unlink(m_first); + PFC_ASSERT(m_count == 0); + } + void remove_range(const_iterator const & p_from,const_iterator const & p_to) { + for(t_elem * walk = _elem(p_from);;) { + if (walk == NULL) {PFC_ASSERT(!"Should not get here"); break;}//should not happen unless there is a bug in calling code + t_elem * next = walk->m_next; + __unlink(walk); + if (walk == _elem(p_to)) break; + walk = next; + } + } + + template void enumerate(t_callback & p_callback) const {__enumerate_chain(m_first,p_callback);} + template void enumerate(t_callback & p_callback) {__enumerate_chain(m_first,p_callback);} + + template bool remove_item(const t_source & p_item) { + t_elem * elem; + if (__find(elem,p_item)) { + __unlink(elem); + return true; + } else { + return false; + } + } + + ~chain_list_v2_t() {remove_all();} + + template + inline void add_item(const t_source & p_source) { + __link_last(new t_elem(p_source)); + } + template + inline t_self & operator+=(const t_source & p_source) { + add_item(p_source); return *this; + } + iterator insert_last() {return __link_last(new t_elem);} + iterator insert_first() {return __link_first(new t_elem);} + iterator insert_after(const_iterator const & p_iter) {return __link_next(_elem(p_iter),new t_elem);} + iterator insert_before(const_iterator const & p_iter) {return __link_prev(_elem(p_iter),new t_elem);} + template iterator insert_last(const t_source & p_source) {return __link_last(new t_elem(p_source));} + template iterator insert_first(const t_source & p_source) {return __link_first(new t_elem(p_source));} + template iterator insert_after(const_iterator const & p_iter,const t_source & p_source) {return __link_next(_elem(p_iter),new t_elem(p_source));} + template iterator insert_before(const_iterator const & p_iter,const t_source & p_source) {return __link_prev(_elem(p_iter),new t_elem(p_source));} + + template const_iterator find_item(const t_source & p_item) const { + t_elem * elem; + if (!__find(elem,p_item)) return const_iterator(); + return const_iterator(elem); + } + + template iterator find_item(const t_source & p_item) { + t_elem * elem; + if (!__find(elem,p_item)) return iterator(); + return iterator(elem); + } + + template bool have_item(const t_source & p_item) const { + t_elem * dummy; + return __find(dummy,p_item); + } + template void set_single(const t_source & p_item) { + remove_all(); add_item(p_item); + } + + //! Slow! + const_iterator by_index(t_size p_index) const {return __by_index(p_index);} + //! Slow! + iterator by_index(t_size p_index) {return __by_index(p_index);} + + t_self & operator<<(t_self & p_other) { + while(p_other.m_first != NULL) { + __link_last( p_other.__unlink_temporary(p_other.m_first) ); + } + return *this; + } + t_self & operator>>(t_self & p_other) { + while(m_last != NULL) { + p_other.__link_first(__unlink_temporary(m_last)); + } + return p_other; + } + //! Links an object that has been unlinked from another list. Unsafe. + void _link_last(const_iterator const& iter) { + PFC_ASSERT(iter.is_valid()); + PFC_ASSERT( _elem(iter)->m_prev == NULL && _elem(iter)->m_next == NULL ); + __link_last(_elem(iter)); + } + //! Links an object that has been unlinked from another list. Unsafe. + void _link_first(const_iterator const& iter) { + PFC_ASSERT(iter.is_valid()); + PFC_ASSERT( _elem(iter)->m_prev == NULL && _elem(iter)->m_next == NULL ); + __link_first(_elem(iter)); + } + private: + static t_elem * _elem(const_iterator const & iter) { + return static_cast(iter._node()); + } + t_elem * __by_index(t_size p_index) const { + t_elem * walk = m_first; + while(p_index > 0 && walk != NULL) { + p_index--; + walk = walk->m_next; + } + return walk; + } + template + static void __enumerate_chain(t_elemwalk * p_elem,t_callback & p_callback) { + t_elemwalk * walk = p_elem; + while(walk != NULL) { + p_callback(walk->m_content); + walk = walk->m_next; + } + } + + template bool __find(t_elem * & p_elem,const t_source & p_item) const { + for(t_elem * walk = m_first; walk != NULL; walk = walk->m_next) { + if (walk->m_content == p_item) { + p_elem = walk; return true; + } + } + return false; + } + + void __unlink_helper(t_elem * p_elem) throw() { + (p_elem->m_prev == NULL ? m_first : p_elem->m_prev->m_next) = p_elem->m_next; + (p_elem->m_next == NULL ? m_last : p_elem->m_next->m_prev) = p_elem->m_prev; + p_elem->m_next = p_elem->m_prev = NULL; + } + + //workaround for cross-list-relinking case - never actually deletes p_elem + t_elem * __unlink_temporary(t_elem * p_elem) throw() { + __unlink_helper(p_elem); + --m_count; p_elem->__release_temporary(); + return p_elem; + } + + t_elem * __unlink(t_elem * p_elem) throw() { + __unlink_helper(p_elem); + --m_count; p_elem->release(); + return p_elem; + } + void __on_link(t_elem * p_elem) throw() { + p_elem->add_ref(); ++m_count; + } + t_elem * __link_first(t_elem * p_elem) throw() { + __on_link(p_elem); + p_elem->m_next = m_first; + p_elem->m_prev = NULL; + (m_first == NULL ? m_last : m_first->m_prev) = p_elem; + m_first = p_elem; + return p_elem; + } + t_elem * __link_last(t_elem * p_elem) throw() { + __on_link(p_elem); + p_elem->m_prev = m_last; + p_elem->m_next = NULL; + (m_last == NULL ? m_first : m_last->m_next) = p_elem; + m_last = p_elem; + return p_elem; + } + t_elem * __link_next(t_elem * p_prev,t_elem * p_elem) throw() { + __on_link(p_elem); + p_elem->m_prev = p_prev; + p_elem->m_next = p_prev->m_next; + (p_prev->m_next != NULL ? p_prev->m_next->m_prev : m_last) = p_elem; + p_prev->m_next = p_elem; + return p_elem; + } + t_elem * __link_prev(t_elem * p_next,t_elem * p_elem) throw() { + __on_link(p_elem); + p_elem->m_next = p_next; + p_elem->m_prev = p_next->m_prev; + (p_next->m_prev != NULL ? p_next->m_prev->m_next : m_first) = p_elem; + p_next->m_prev = p_elem; + return p_elem; + } + t_elem * m_first, * m_last; + t_size m_count; + }; + + + template class traits_t > : public traits_default_movable {}; + + class __chain_list_iterator_traits : public traits_default_movable { + public: + enum { + constructor_may_fail = false + }; + }; + + template class traits_t > : public traits_t > > {}; + + template class traits_t > : public traits_t > {}; + +}//namespace pfc diff --git a/tools/vio2sf/src/foobar/pfc/com_ptr_t.h b/tools/vio2sf/src/foobar/pfc/com_ptr_t.h new file mode 100644 index 000000000..2a309513e --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/com_ptr_t.h @@ -0,0 +1,82 @@ +#ifdef _WIN32 +namespace pfc { + + static void _COM_AddRef(IUnknown * ptr) { + if (ptr != NULL) ptr->AddRef(); + } + static void _COM_Release(IUnknown * ptr) { + if (ptr != NULL) ptr->Release(); + } + + template + class com_ptr_t { + public: + typedef com_ptr_t t_self; + + inline com_ptr_t() throw() : m_ptr() {} + template inline com_ptr_t(source * p_ptr) throw() : m_ptr(p_ptr) {_COM_AddRef(m_ptr);;} + inline com_ptr_t(const t_self & p_source) throw() : m_ptr(p_source.m_ptr) {_COM_AddRef(m_ptr);} + template inline com_ptr_t(const com_ptr_t & p_source) throw() : m_ptr(p_source.get_ptr()) {_COM_AddRef(m_ptr);} + + inline ~com_ptr_t() throw() {_COM_Release(m_ptr);} + + inline void copy(T * p_ptr) throw() { + _COM_Release(m_ptr); + m_ptr = p_ptr; + _COM_AddRef(m_ptr); + } + + template inline void copy(const com_ptr_t & p_source) throw() {copy(p_source.get_ptr());} + + inline void attach(T * p_ptr) throw() { + _COM_Release(m_ptr); + m_ptr = p_ptr; + } + + inline const t_self & operator=(const t_self & p_source) throw() {copy(p_source); return *this;} + inline const t_self & operator=(T* p_source) throw() {copy(p_source); return *this;} + template inline const t_self & operator=(const com_ptr_t & p_source) throw() {copy(p_source); return *this;} + template inline const t_self & operator=(source * p_ptr) throw() {copy(p_ptr); return *this;} + + inline void release() throw() { + _COM_Release(m_ptr); + m_ptr = NULL; + } + + + inline T* operator->() const throw() {assert(m_ptr);return m_ptr;} + + inline T* get_ptr() const throw() {return m_ptr;} + + inline T* duplicate_ptr() const throw() //should not be used ! temporary ! + { + _COM_AddRef(m_ptr); + return m_ptr; + } + + inline T* detach() throw() { + return replace_null_t(m_ptr); + } + + inline bool is_valid() const throw() {return m_ptr != 0;} + inline bool is_empty() const throw() {return m_ptr == 0;} + + inline bool operator==(const com_ptr_t & p_item) const throw() {return m_ptr == p_item.m_ptr;} + inline bool operator!=(const com_ptr_t & p_item) const throw() {return m_ptr != p_item.m_ptr;} + inline bool operator>(const com_ptr_t & p_item) const throw() {return m_ptr > p_item.m_ptr;} + inline bool operator<(const com_ptr_t & p_item) const throw() {return m_ptr < p_item.m_ptr;} + + inline static void g_swap(com_ptr_t & item1, com_ptr_t & item2) throw() { + pfc::swap_t(item1.m_ptr,item2.m_ptr); + } + + inline T** receive_ptr() throw() {release();return &m_ptr;} + + inline t_self & operator<<(t_self & p_source) throw() {attach(p_source.detach());return *this;} + inline t_self & operator>>(t_self & p_dest) throw() {p_dest.attach(detach());return *this;} + private: + T* m_ptr; + }; + +} +#endif diff --git a/tools/vio2sf/src/foobar/pfc/guid.cpp b/tools/vio2sf/src/foobar/pfc/guid.cpp new file mode 100644 index 000000000..ed0fc0208 --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/guid.cpp @@ -0,0 +1,144 @@ +#include "pfc.h" + +namespace pfc { +/* +6B29FC40-CA47-1067-B31D-00DD010662DA +. +typedef struct _GUID { // size is 16 + DWORD Data1; + WORD Data2; + WORD Data3; + BYTE Data4[8]; +} GUID; + +// {B296CF59-4D51-466f-8E0B-E57D3F91D908} +static const GUID <> = +{ 0xb296cf59, 0x4d51, 0x466f, { 0x8e, 0xb, 0xe5, 0x7d, 0x3f, 0x91, 0xd9, 0x8 } }; + +*/ + +unsigned GUID_from_text::read_hex(char c) +{ + if (c>='0' && c<='9') return (unsigned)c - '0'; + else if (c>='a' && c<='f') return 0xa + (unsigned)c - 'a'; + else if (c>='A' && c<='F') return 0xa + (unsigned)c - 'A'; + else return 0; +} + +unsigned GUID_from_text::read_byte(const char * ptr) +{ + return (read_hex(ptr[0])<<4) | read_hex(ptr[1]); +} +unsigned GUID_from_text::read_word(const char * ptr) +{ + return (read_byte(ptr)<<8) | read_byte(ptr+2); +} + +unsigned GUID_from_text::read_dword(const char * ptr) +{ + return (read_word(ptr)<<16) | read_word(ptr+4); +} + +void GUID_from_text::read_bytes(BYTE * out,unsigned num,const char * ptr) +{ + for(;num;num--) + { + *out = read_byte(ptr); + out++;ptr+=2; + } +} + + +GUID_from_text::GUID_from_text(const char * text) +{ + if (*text=='{') text++; + const char * max; + + { + const char * t = strchr(text,'}'); + if (t) max = t; + else max = text + strlen(text); + } + + (GUID)*this = pfc::guid_null; + + + do { + if (text+8>max) break; + Data1 = read_dword(text); + text += 8; + while(*text=='-') text++; + if (text+4>max) break; + Data2 = read_word(text); + text += 4; + while(*text=='-') text++; + if (text+4>max) break; + Data3 = read_word(text); + text += 4; + while(*text=='-') text++; + if (text+4>max) break; + read_bytes(Data4,2,text); + text += 4; + while(*text=='-') text++; + if (text+12>max) break; + read_bytes(Data4+2,6,text); + } while(false); +} + + +static inline char print_hex_digit(unsigned val) +{ + static const char table[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; + assert((val & ~0xF) == 0); + return table[val]; +} + +static void print_hex(unsigned val,char * &out,unsigned bytes) +{ + unsigned n; + for(n=0;n> ((bytes - 1 - n) << 3)) & 0xFF); + *(out++) = print_hex_digit( c >> 4 ); + *(out++) = print_hex_digit( c & 0xF ); + } + *out = 0; +} + + +print_guid::print_guid(const GUID & p_guid) +{ + char * out = m_data; + print_hex(p_guid.Data1,out,4); + *(out++) = '-'; + print_hex(p_guid.Data2,out,2); + *(out++) = '-'; + print_hex(p_guid.Data3,out,2); + *(out++) = '-'; + print_hex(p_guid.Data4[0],out,1); + print_hex(p_guid.Data4[1],out,1); + *(out++) = '-'; + print_hex(p_guid.Data4[2],out,1); + print_hex(p_guid.Data4[3],out,1); + print_hex(p_guid.Data4[4],out,1); + print_hex(p_guid.Data4[5],out,1); + print_hex(p_guid.Data4[6],out,1); + print_hex(p_guid.Data4[7],out,1); + *out = 0; +} + + +void print_hex_raw(const void * buffer,unsigned bytes,char * p_out) +{ + char * out = p_out; + const unsigned char * in = (const unsigned char *) buffer; + unsigned n; + for(n=0;n inline int compare_t(const GUID & p_item1,const GUID & p_item2) {return guid_compare(p_item1,p_item2);} + + extern const GUID guid_null; + + void print_hex_raw(const void * buffer,unsigned bytes,char * p_out); + + static GUID makeGUID(t_uint32 Data1, t_uint16 Data2, t_uint16 Data3, t_uint8 Data4_1, t_uint8 Data4_2, t_uint8 Data4_3, t_uint8 Data4_4, t_uint8 Data4_5, t_uint8 Data4_6, t_uint8 Data4_7, t_uint8 Data4_8) { + GUID guid = { Data1, Data2, Data3, {Data4_1, Data4_2, Data4_3, Data4_4, Data4_5, Data4_6, Data4_7, Data4_8 } }; + return guid; + } + static GUID xorGUID(const GUID & v1, const GUID & v2) { + GUID temp; memxor(&temp, &v1, &v1, sizeof(GUID)); return temp; + } +} + + +#endif diff --git a/tools/vio2sf/src/foobar/pfc/instance_tracker.h b/tools/vio2sf/src/foobar/pfc/instance_tracker.h new file mode 100644 index 000000000..fb3bb3b99 --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/instance_tracker.h @@ -0,0 +1,49 @@ +namespace pfc { + template + class instance_tracker_server_t { + public: + void add(t_object * p_object) { + m_list.add_item(p_object); + } + void remove(t_object * p_object) { + m_list.remove_item(p_object); + } + + t_size get_count() const {return m_list.get_count();} + t_object * get_item(t_size p_index) {return m_list[p_index];} + t_object * operator[](t_size p_index) {return m_list[p_index];} + + private: + ptr_list_hybrid_t m_list; + }; + + + template & p_server> + class instance_tracker_client_t { + public: + instance_tracker_client_t(t_object* p_ptr) : m_ptr(NULL), m_added(false) {initialize(p_ptr);} + instance_tracker_client_t() : m_ptr(NULL), m_added(false) {} + + void initialize(t_object * p_ptr) { + uninitialize(); + p_server.add(p_ptr); + m_ptr = p_ptr; + m_added = true; + } + + void uninitialize() { + if (m_added) { + p_server.remove(m_ptr); + m_ptr = NULL; + m_added = false; + } + } + + ~instance_tracker_client_t() { + uninitialize(); + } + private: + bool m_added; + t_object * m_ptr; + }; +} \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/pfc/int_types.h b/tools/vio2sf/src/foobar/pfc/int_types.h new file mode 100644 index 000000000..4d2c4af71 --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/int_types.h @@ -0,0 +1,120 @@ +#if !defined(_MSC_VER) && !defined(_EVC_VER) +#include +typedef int64_t t_int64; +typedef uint64_t t_uint64; +typedef int32_t t_int32; +typedef uint32_t t_uint32; +typedef int16_t t_int16; +typedef uint16_t t_uint16; +typedef int8_t t_int8; +typedef uint8_t t_uint8; +#else +typedef __int64 t_int64; +typedef unsigned __int64 t_uint64; +typedef __int32 t_int32; +typedef unsigned __int32 t_uint32; +typedef __int16 t_int16; +typedef unsigned __int16 t_uint16; +typedef __int8 t_int8; +typedef unsigned __int8 t_uint8; +#endif + +typedef int t_int; +typedef unsigned int t_uint; + +typedef float t_float32; +typedef double t_float64; + + + +#if defined(_WIN32) && !defined(_WIN64) +#define __PFC_WP64 __w64 +#else +#define __PFC_WP64 +#endif + + +namespace pfc { + template + class sized_int_t; + + template<> class sized_int_t<1> { + public: + typedef t_uint8 t_unsigned; + typedef t_int8 t_signed; + }; + + template<> class sized_int_t<2> { + public: + typedef t_uint16 t_unsigned; + typedef t_int16 t_signed; + }; + + template<> class sized_int_t<4> { + public: + typedef t_uint32 t_unsigned; + typedef t_int32 t_signed; + }; + + template<> class sized_int_t<8> { + public: + typedef t_uint64 t_unsigned; + typedef t_int64 t_signed; + }; +} + + +typedef pfc::sized_int_t::t_unsigned __PFC_WP64 t_size; +typedef pfc::sized_int_t::t_signed __PFC_WP64 t_ssize; + + +#define infinite (~0) + +const t_uint16 infinite16 = (t_uint16)(~0); +const t_uint32 infinite32 = (t_uint32)(~0); +const t_uint64 infinite64 = (t_uint64)(~0); +const t_size infinite_size = (t_size)(~0); + + +#if defined(_WIN32) && !defined(_WIN64) +inline t_size MulDiv_Size(t_size x,t_size y,t_size z) {return (t_size) ( ((t_uint64)x * (t_uint64)y) / (t_uint64)z );} +#elif defined(_WIN64) +inline t_size MulDiv_Size(t_size x,t_size y,t_size z) {return (x*y)/z;} +#else +#error portme +#endif + + +namespace pfc { + template class int_specs_t; + + template + class int_specs_signed_t { + public: + inline static T get_min() {return ((T)1<<(sizeof(T)*8-1));} + inline static T get_max() {return ~((T)1<<(sizeof(T)*8-1));} + enum {is_signed = true}; + }; + + template + class int_specs_unsigned_t { + public: + inline static T get_min() {return (T)0;} + inline static T get_max() {return (T)~0;} + enum {is_signed = false}; + }; + + template<> class int_specs_t : public int_specs_signed_t {}; + template<> class int_specs_t : public int_specs_unsigned_t {}; + template<> class int_specs_t : public int_specs_signed_t {}; + template<> class int_specs_t : public int_specs_unsigned_t {}; + template<> class int_specs_t : public int_specs_signed_t {}; + template<> class int_specs_t : public int_specs_unsigned_t {}; + template<> class int_specs_t : public int_specs_signed_t {}; + template<> class int_specs_t : public int_specs_unsigned_t {}; + template<> class int_specs_t : public int_specs_signed_t {}; + template<> class int_specs_t : public int_specs_unsigned_t {}; + + template<> class int_specs_t : public int_specs_unsigned_t {}; + +}; diff --git a/tools/vio2sf/src/foobar/pfc/iterators.h b/tools/vio2sf/src/foobar/pfc/iterators.h new file mode 100644 index 000000000..5455990cc --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/iterators.h @@ -0,0 +1,113 @@ +namespace pfc { + //! Base class for list nodes. Implemented by list implementers. + template class _list_node : public refcounted_object_root { + public: + typedef _list_node t_self; + + TEMPLATE_CONSTRUCTOR_FORWARD_FLOOD(_list_node,m_content) + + t_item m_content; + + virtual t_self * prev() throw() {return NULL;} + virtual t_self * next() throw() {return NULL;} + + t_self * walk(bool forward) throw() {return forward ? next() : prev();} + }; + + template class const_iterator { + public: + typedef _list_node t_node; + typedef refcounted_object_ptr_t t_nodeptr; + typedef const_iterator t_self; + + bool is_empty() const throw() {return m_content.is_empty();} + bool is_valid() const throw() {return m_content.is_valid();} + void invalidate() throw() {m_content = NULL;} + + void walk(bool forward) throw() {m_content = m_content->walk(forward);} + void prev() throw() {m_content = m_content->prev();} + void next() throw() {m_content = m_content->next();} + + //! For internal use / list implementations only! Do not call! + t_node* _node() const throw() {return m_content.get_ptr();} + + const_iterator() {} + const_iterator(t_node* source) : m_content(source) {} + const_iterator(t_nodeptr const & source) : m_content(source) {} + + const t_item& operator*() const throw() {return m_content->m_content;} + const t_item* operator->() const throw() {return &m_content->m_content;} + + const t_self & operator++() throw() {this->next(); return *this;} + const t_self & operator--() throw() {this->prev(); return *this;} + t_self operator++(int) throw() {t_self old = *this; this->next(); return old;} + t_self operator--(int) throw() {t_self old = *this; this->prev(); return old;} + + bool operator==(const t_self & other) const throw() {return this->m_content == other.m_content;} + bool operator!=(const t_self & other) const throw() {return this->m_content != other.m_content;} + bool operator> (const t_self & other) const throw() {return this->m_content > other.m_content;} + bool operator< (const t_self & other) const throw() {return this->m_content < other.m_content;} + bool operator>=(const t_self & other) const throw() {return this->m_content >= other.m_content;} + bool operator<=(const t_self & other) const throw() {return this->m_content <= other.m_content;} + protected: + t_nodeptr m_content; + }; + template class iterator : public const_iterator { + public: + typedef const_iterator t_selfConst; + typedef iterator t_self; + typedef _list_node t_node; + typedef refcounted_object_ptr_t t_nodeptr; + + iterator() {} + iterator(t_node* source) : t_selfConst(source) {} + iterator(t_nodeptr const & source) : t_selfConst(source) {} + + t_item& operator*() const throw() {return this->m_content->m_content;} + t_item* operator->() const throw() {return &this->m_content->m_content;} + + const t_self & operator++() throw() {this->next(); return *this;} + const t_self & operator--() throw() {this->prev(); return *this;} + t_self operator++(int) throw() {t_self old = *this; this->next(); return old;} + t_self operator--(int) throw() {t_self old = *this; this->prev(); return old;} + + bool operator==(const t_self & other) const throw() {return this->m_content == other.m_content;} + bool operator!=(const t_self & other) const throw() {return this->m_content != other.m_content;} + bool operator> (const t_self & other) const throw() {return this->m_content > other.m_content;} + bool operator< (const t_self & other) const throw() {return this->m_content < other.m_content;} + bool operator>=(const t_self & other) const throw() {return this->m_content >= other.m_content;} + bool operator<=(const t_self & other) const throw() {return this->m_content <= other.m_content;} + }; + + template + class comparator_list { + public: + template + static int compare(const t_list1 & p_list1, const t_list2 p_list2) { + typename t_list1::const_iterator iter1 = p_list1.first(); + typename t_list2::const_iterator iter2 = p_list2.first(); + for(;;) { + if (iter1.is_empty() && iter2.is_empty()) return 0; + else if (iter1.is_empty()) return -1; + else if (iter2.is_empty()) return 1; + else { + int state = t_comparator::compare(*iter1,*iter2); + if (state != 0) return state; + } + ++iter1; ++iter2; + } + } + }; + + template + static bool listEquals(const t_list1 & p_list1, const t_list2 & p_list2) { + typename t_list1::const_iterator iter1 = p_list1.first(); + typename t_list2::const_iterator iter2 = p_list2.first(); + for(;;) { + if (iter1.is_empty() && iter2.is_empty()) return true; + else if (iter1.is_empty() || iter2.is_empty()) return false; + else if (*iter1 != *iter2) return false; + ++iter1; ++iter2; + } + } +} diff --git a/tools/vio2sf/src/foobar/pfc/license.txt b/tools/vio2sf/src/foobar/pfc/license.txt new file mode 100644 index 000000000..55dc500fb --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/license.txt @@ -0,0 +1,10 @@ +Copyright (c) 2001-2008, Peter Pawlowski +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. +Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/tools/vio2sf/src/foobar/pfc/list.h b/tools/vio2sf/src/foobar/pfc/list.h new file mode 100644 index 000000000..7b243b875 --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/list.h @@ -0,0 +1,591 @@ +#ifndef _PFC_LIST_H_ +#define _PFC_LIST_H_ + +namespace pfc { + +template +class NOVTABLE list_base_const_t { +private: typedef list_base_const_t t_self; +public: + typedef T t_item; + virtual t_size get_count() const = 0; + virtual void get_item_ex(T& p_out, t_size n) const = 0; + + inline t_size get_size() const {return get_count();} + + inline T get_item(t_size n) const {T temp; get_item_ex(temp,n); return temp;} + inline T operator[](t_size n) const {T temp; get_item_ex(temp,n); return temp;} + + template + t_size find_duplicates_sorted_t(t_compare p_compare,bit_array_var & p_out) const + { + return pfc::find_duplicates_sorted_t const &,t_compare>(*this,get_count(),p_compare,p_out); + } + + template + t_size find_duplicates_sorted_permutation_t(t_compare p_compare,t_permutation const & p_permutation,bit_array_var & p_out) + { + return pfc::find_duplicates_sorted_permutation_t const &,t_compare,t_permutation>(*this,get_count(),p_compare,p_permutation,p_out); + } + + template + t_size find_item(const t_search & p_item) const//returns index of first occurance, infinite if not found + { + t_size n,max = get_count(); + for(n=0;n + inline bool have_item(const t_search & p_item) const {return find_item(p_item)!=~0;} + + + template + bool bsearch_t(t_compare p_compare,t_param const & p_param,t_size &p_index) const { + return pfc::bsearch_t(get_count(),*this,p_compare,p_param,p_index); + } + + template + bool bsearch_permutation_t(t_compare p_compare,t_param const & p_param,const t_permutation & p_permutation,t_size & p_index) const { + return pfc::bsearch_permutation_t(get_count(),*this,p_compare,p_param,p_permutation,p_index); + } + + template + void sort_get_permutation_t(t_compare p_compare,t_permutation const & p_permutation) const { + pfc::sort_get_permutation_t,t_compare,t_permutation>(*this,p_compare,get_count(),p_permutation); + } + + template + void sort_stable_get_permutation_t(t_compare p_compare,t_permutation const & p_permutation) const { + pfc::sort_stable_get_permutation_t,t_compare,t_permutation>(*this,p_compare,get_count(),p_permutation); + } + + template + void enumerate(t_callback & p_callback) const { + for(t_size n = 0, m = get_count(); n < m; ++n ) { + p_callback( (*this)[n] ); + } + } + + static bool g_equals(const t_self & item1, const t_self & item2) { + const t_size count = item1.get_count(); + if (count != item2.get_count()) return false; + for(t_size walk = 0; walk < count; ++walk) if (item1[walk] != item2[walk]) return false; + return true; + } + bool operator==(const t_self & item2) const {return g_equals(*this,item2);} + bool operator!=(const t_self & item2) const {return !g_equals(*this,item2);} + +protected: + list_base_const_t() {} + ~list_base_const_t() {} +private: + const t_self & operator=(const t_self &) {throw pfc::exception_not_implemented();} +}; + + +template +class list_single_ref_t : public list_base_const_t +{ +public: + list_single_ref_t(const T & p_item,t_size p_count = 1) : m_item(p_item), m_count(p_count) {} + t_size get_count() const {return m_count;} + void get_item_ex(T& p_out,t_size n) const {PFC_ASSERT(n +class list_partial_ref_t : public list_base_const_t +{ +public: + list_partial_ref_t(const list_base_const_t & p_list,t_size p_base,t_size p_count) + : m_list(p_list), m_base(p_base), m_count(p_count) + { + PFC_ASSERT(m_base + m_count <= m_list.get_count()); + } + +private: + const list_base_const_t & m_list; + t_size m_base,m_count; + + t_size get_count() const {return m_count;} + void get_item_ex(T & p_out,t_size n) const {m_list.get_item_ex(p_out,n+m_base);} +}; + +template +class list_const_array_t : public list_base_const_t +{ +public: + inline list_const_array_t(A p_data,t_size p_count) : m_data(p_data), m_count(p_count) {} + t_size get_count() const {return m_count;} + void get_item_ex(T & p_out,t_size n) const {p_out = m_data[n];} +private: + A m_data; + t_size m_count; +}; + +template +class list_const_cast_t : public list_base_const_t +{ +public: + list_const_cast_t(const list_base_const_t & p_from) : m_from(p_from) {} + t_size get_count() const {return m_from.get_count();} + void get_item_ex(to & p_out,t_size n) const + { + from temp; + m_from.get_item_ex(temp,n); + p_out = temp; + } +private: + const list_base_const_t & m_from; +}; + +template +class ptr_list_const_array_t : public list_base_const_t +{ +public: + inline ptr_list_const_array_t(A p_data,t_size p_count) : m_data(p_data), m_count(p_count) {} + t_size get_count() const {return m_count;} + void get_item_ex(T* & p_out,t_size n) const {p_out = &m_data[n];} +private: + A m_data; + t_size m_count; +}; +template +class list_const_ptr_t : public list_base_const_t +{ +public: + inline list_const_ptr_t(const T * p_data,t_size p_count) : m_data(p_data), m_count(p_count) {} + t_size get_count() const {return m_count;} + void get_item_ex(T & p_out,t_size n) const {p_out = m_data[n];} +private: + const T * m_data; + t_size m_count; +}; + +template +class NOVTABLE list_base_t : public list_base_const_t { +private: + typedef list_base_t t_self; + typedef const list_base_const_t t_self_const; +public: + class NOVTABLE sort_callback + { + public: + virtual int compare(const T& p_item1,const T& p_item2) = 0; + }; + + virtual void filter_mask(const bit_array & mask) = 0; + virtual t_size insert_items(const list_base_const_t & items,t_size base) = 0; + virtual void reorder_partial(t_size p_base,const t_size * p_data,t_size p_count) = 0; + virtual void sort(sort_callback & p_callback) = 0; + virtual void sort_stable(sort_callback & p_callback) = 0; + virtual void replace_item(t_size p_index,const T& p_item) = 0; + virtual void swap_item_with(t_size p_index,T & p_item) = 0; + virtual void swap_items(t_size p_index1,t_size p_index2) = 0; + + inline void reorder(const t_size * p_data) {reorder_partial(0,p_data,this->get_count());} + + inline t_size insert_item(const T & item,t_size base) {return insert_items(list_single_ref_t(item),base);} + t_size insert_items_repeat(const T & item,t_size num,t_size base) {return insert_items(list_single_ref_t(item,num),base);} + inline t_size add_items_repeat(T item,t_size num) {return insert_items_repeat(item,num,this->get_count());} + t_size insert_items_fromptr(const T* source,t_size num,t_size base) {return insert_items(list_const_ptr_t(source,num),base);} + inline t_size add_items_fromptr(const T* source,t_size num) {return insert_items_fromptr(source,num,this->get_count());} + + inline t_size add_items(const list_base_const_t & items) {return insert_items(items,this->get_count());} + inline t_size add_item(const T& item) {return insert_item(item,this->get_count());} + + inline void remove_mask(const bit_array & mask) {filter_mask(bit_array_not(mask));} + inline void remove_all() {filter_mask(bit_array_false());} + inline void truncate(t_size val) {if (val < this->get_count()) remove_mask(bit_array_range(val,this->get_count()-val,true));} + + inline T replace_item_ex(t_size p_index,const T & p_item) {T ret = p_item;swap_item_with(p_index,ret);return ret;} + + inline T operator[](t_size n) const {return this->get_item(n);} + + template + class sort_callback_impl_t : public sort_callback + { + public: + sort_callback_impl_t(t_compare p_compare) : m_compare(p_compare) {} + int compare(const T& p_item1,const T& p_item2) {return m_compare(p_item1,p_item2);} + private: + t_compare m_compare; + }; + + class sort_callback_auto : public sort_callback + { + public: + int compare(const T& p_item1,const T& p_item2) {return pfc::compare_t(p_item1,p_item2);} + }; + + void sort() {sort(sort_callback_auto());} + template void sort_t(t_compare p_compare) {sort(sort_callback_impl_t(p_compare));} + template void sort_stable_t(t_compare p_compare) {sort_stable(sort_callback_impl_t(p_compare));} + + template void sort_remove_duplicates_t(t_compare p_compare) + { + sort_t(p_compare); + bit_array_bittable array(this->get_count()); + if (this->template find_duplicates_sorted_t(p_compare,array) > 0) + remove_mask(array); + } + + template void sort_stable_remove_duplicates_t(t_compare p_compare) + { + sort_stable_t(p_compare); + bit_array_bittable array(this->get_count()); + if (this->template find_duplicates_sorted_t(p_compare,array) > 0) + remove_mask(array); + } + + + template void remove_duplicates_t(t_compare p_compare) + { + order_helper order(this->get_count()); + sort_get_permutation_t(p_compare,order); + bit_array_bittable array(this->get_count()); + if (this->template find_duplicates_sorted_permutation_t(p_compare,order,array) > 0) + remove_mask(array); + } + + template + void for_each(t_func p_func) { + t_size n,max=this->get_count(); + for(n=0;nget_item(n)); + } + + template + void for_each(t_func p_func,const bit_array & p_mask) { + t_size n,max=this->get_count(); + for(n=p_mask.find(true,0,max);nget_item(n)); + } + } + + template + void remove_mask_ex(const bit_array & p_mask,t_releasefunc p_func) { + this->template for_each(p_func,p_mask); + remove_mask(p_mask); + } + + template + void remove_all_ex(t_releasefunc p_func) { + this->template for_each(p_func); + remove_all(); + } + + const t_self & operator=(const t_self & p_source) {remove_all(); add_items(p_source);return *this;} + const t_self & operator=(t_self_const & source) {remove_all(); add_items(source); return *this;} + const t_self & operator+=(t_self_const & p_source) {add_items(p_source); return *this;} + +protected: + list_base_t() {} + ~list_base_t() {} +}; + + +template +class list_impl_t : public list_base_t +{ +public: + list_impl_t() {} + list_impl_t(const list_impl_t & p_source) { *this = p_source; } + + void prealloc(t_size count) {m_buffer.prealloc(count);} + + void set_count(t_size p_count) {m_buffer.set_size(p_count);} + void set_size(t_size p_count) {m_buffer.set_size(p_count);} + + t_size insert_item(const T& item,t_size idx) + { + t_size max = m_buffer.get_size(); + if (idx > max) idx = max; + max++; + m_buffer.set_size(max); + t_size n; + for(n=max-1;n>idx;n--) + m_buffer[n]=m_buffer[n-1]; + m_buffer[idx]=item; + return idx; + } + + T remove_by_idx(t_size idx) + { + T ret = m_buffer[idx]; + t_size n; + t_size max = m_buffer.get_size(); + for(n=idx+1;n=0); + PFC_ASSERT(n=0); + PFC_ASSERT(n= 0); + PFC_ASSERT(n < get_count() ); + return m_buffer[n]; + }; + + inline t_size get_count() const {return m_buffer.get_size();} + inline t_size get_size() const {return get_count();} + + inline const T & operator[](t_size n) const + { + PFC_ASSERT(n>=0); + PFC_ASSERT(n & source,t_size base) + { + t_size count = get_count(); + if (base>count) base = count; + t_size num = source.get_count(); + m_buffer.set_size(count+num); + if (count > base) + { + t_size n; + for(n=count-1;(int)n>=(int)base;n--) + { + pfc::swap_t(m_buffer[n+num],m_buffer[n]); + } + } + + { + t_size n; + for(n=0;n & out,const bit_array & mask) + { + t_size n,count = get_count(); + for_each_bit_array(n,mask,true,0,count) + out.add_item(m_buffer[n]); + } + + void filter_mask(const bit_array & mask) + { + t_size n,count = get_count(), total = 0; + + n = total = mask.find(false,0,count); + + if (n=0); + PFC_ASSERT(idx wrapper(m_buffer); + pfc::sort(wrapper,get_count()); + } + + template + void sort_t(t_compare p_compare) + { + pfc::sort_callback_impl_simple_wrap_t wrapper(m_buffer,p_compare); + pfc::sort(wrapper,get_count()); + } + + template + void sort_stable_t(t_compare p_compare) + { + pfc::sort_callback_impl_simple_wrap_t wrapper(m_buffer,p_compare); + pfc::sort_stable(wrapper,get_count()); + } + inline void reorder_partial(t_size p_base,const t_size * p_order,t_size p_count) + { + PFC_ASSERT(p_base+p_count<=get_count()); + pfc::reorder_partial_t(m_buffer,p_base,p_order,p_count); + } + + template + t_size find_duplicates_sorted_t(t_compare p_compare,bit_array_var & p_out) const + { + return pfc::find_duplicates_sorted_t const &,t_compare>(*this,get_count(),p_compare,p_out); + } + + template + t_size find_duplicates_sorted_permutation_t(t_compare p_compare,t_permutation p_permutation,bit_array_var & p_out) + { + return pfc::find_duplicates_sorted_permutation_t const &,t_compare,t_permutation>(*this,get_count(),p_compare,p_permutation,p_out); + } + + +private: + class sort_callback_wrapper + { + public: + explicit inline sort_callback_wrapper(sort_callback & p_callback) : m_callback(p_callback) {} + inline int operator()(const T& item1,const T& item2) const {return m_callback.compare(item1,item2);} + private: + sort_callback & m_callback; + }; +public: + void sort(sort_callback & p_callback) + { + sort_t(sort_callback_wrapper(p_callback)); + } + + void sort_stable(sort_callback & p_callback) + { + sort_stable_t(sort_callback_wrapper(p_callback)); + } + + void remove_mask(const bit_array & mask) {filter_mask(bit_array_not(mask));} + + void remove_mask(const bool * mask) {remove_mask(bit_array_table(mask,get_count()));} + void filter_mask(const bool * mask) {filter_mask(bit_array_table(mask,get_count()));} + + t_size add_item(const T& item) + { + t_size idx = get_count(); + insert_item(item,idx); + return idx; + } + + void remove_all() {remove_mask(bit_array_true());} + + void remove_item(const T& item) + { + t_size n,max = get_count(); + bit_array_bittable mask(max); + for(n=0;n & p_item1,list_impl_t & p_item2) + { + pfc::swap_t(p_item1.m_buffer,p_item2.m_buffer); + } + + template + t_size find_item(const t_search & p_item) const//returns index of first occurance, infinite if not found + { + t_size n,max = get_count(); + for(n=0;n + inline bool have_item(const t_search & p_item) const {return this->template find_item(p_item)!=~0;} + +protected: + t_storage m_buffer; +}; + +template class t_alloc = pfc::alloc_fast > +class list_t : public list_impl_t > { }; + +template class t_alloc = pfc::alloc_fast > +class list_hybrid_t : public list_impl_t > {}; + +template +class ptr_list_const_cast_t : public list_base_const_t +{ +public: + inline ptr_list_const_cast_t(const list_base_const_t & p_param) : m_param(p_param) {} + t_size get_count() const {return m_param.get_count();} + void get_item_ex(const T * & p_out,t_size n) const {T* temp; m_param.get_item_ex(temp,n); p_out = temp;} +private: + const list_base_const_t & m_param; + +}; + + +template +class list_const_permutation_t : public list_base_const_t +{ +public: + inline list_const_permutation_t(const list_base_const_t & p_list,P p_permutation) : m_list(p_list), m_permutation(p_permutation) {} + t_size get_count() const {return m_list.get_count();} + void get_item_ex(T & p_out,t_size n) const {m_list.get_item_ex(p_out,m_permutation[n]);} +private: + P m_permutation; + const list_base_const_t & m_list; +}; + + +template +class list_permutation_t : public list_base_const_t +{ +public: + t_size get_count() const {return m_count;} + void get_item_ex(T & p_out,t_size n) const {m_base.get_item_ex(p_out,m_order[n]);} + list_permutation_t(const list_base_const_t & p_base,const t_size * p_order,t_size p_count) + : m_base(p_base), m_order(p_order), m_count(p_count) + { + PFC_ASSERT(m_base.get_count() >= m_count); + } +private: + const list_base_const_t & m_base; + const t_size * m_order; + t_size m_count; +}; + +} +#endif //_PFC_LIST_H_ diff --git a/tools/vio2sf/src/foobar/pfc/map.h b/tools/vio2sf/src/foobar/pfc/map.h new file mode 100644 index 000000000..95d7cc718 --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/map.h @@ -0,0 +1,235 @@ +#ifndef _MAP_T_H_INCLUDED_ +#define _MAP_T_H_INCLUDED_ + +namespace pfc { + PFC_DECLARE_EXCEPTION(exception_map_entry_not_found,exception,"Map entry not found"); + + template class __map_overwrite_wrapper { + public: + __map_overwrite_wrapper(t_destination & p_destination) : m_destination(p_destination) {} + template void operator() (const t_key & p_key,const t_value & p_value) {m_destination.set(p_key,p_value);} + private: + t_destination & m_destination; + }; + + template + class map_t { + private: + typedef map_t t_self; + public: + typedef t_storage_key t_key; typedef t_storage_value t_value; + template + void set(const _t_key & p_key, const _t_value & p_value) { + bool isnew; + t_storage & storage = m_data.add_ex(t_search_set<_t_key,_t_value>(p_key,p_value), isnew); + if (!isnew) storage.m_value = p_value; + } + + template + t_storage_value & find_or_add(_t_key const & p_key) { + return m_data.add(t_search_query<_t_key>(p_key)).m_value; + } + + template + t_storage_value & find_or_add_ex(_t_key const & p_key,bool & p_isnew) { + return m_data.add_ex(t_search_query<_t_key>(p_key),p_isnew).m_value; + } + + template + bool have_item(const _t_key & p_key) const { + return m_data.have_item(t_search_query<_t_key>(p_key)); + } + + template + bool query(const _t_key & p_key,_t_value & p_value) const { + const t_storage * storage = m_data.find_ptr(t_search_query<_t_key>(p_key)); + if (storage == NULL) return false; + p_value = storage->m_value; + return true; + } + + template + const t_storage_value & operator[] (const _t_key & p_key) const { + const t_storage_value * ptr = query_ptr(p_key); + if (ptr == NULL) throw exception_map_entry_not_found(); + return *ptr; + } + + template + t_storage_value & operator[] (const _t_key & p_key) { + return find_or_add(p_key); + } + + template + const t_storage_value * query_ptr(const _t_key & p_key) const { + const t_storage * storage = m_data.find_ptr(t_search_query<_t_key>(p_key)); + if (storage == NULL) return NULL; + return &storage->m_value; + } + + template + t_storage_value * query_ptr(const _t_key & p_key) { + t_storage * storage = m_data.find_ptr(t_search_query<_t_key>(p_key)); + if (storage == NULL) return NULL; + return &storage->m_value; + } + + template + const t_storage_value * query_nearest_ptr(_t_key & p_key) const { + const t_storage * storage = m_data.find_nearest_item(t_search_query<_t_key>(p_key)); + if (storage == NULL) return NULL; + p_key = storage->m_key; + return &storage->m_value; + } + + template + t_storage_value * query_nearest_ptr(_t_key & p_key) { + t_storage * storage = m_data.find_nearest_item(t_search_query<_t_key>(p_key)); + if (storage == NULL) return NULL; + p_key = storage->m_key; + return &storage->m_value; + } + + template + bool query_nearest(_t_key & p_key,_t_value & p_value) const { + const t_storage * storage = m_data.find_nearest_item(t_search_query<_t_key>(p_key)); + if (storage == NULL) return false; + p_key = storage->m_key; + p_value = storage->m_value; + return true; + } + + + template + bool remove(const _t_key & p_key) { + return m_data.remove_item(t_search_query<_t_key>(p_key)); + } + + template + void enumerate(t_callback & p_callback) const { + m_data.enumerate(enumeration_wrapper(p_callback)); + } + + template + void enumerate(t_callback & p_callback) { + m_data._enumerate_var(enumeration_wrapper_var(p_callback)); + } + + + t_size get_count() const throw() {return m_data.get_count();} + + void remove_all() throw() {m_data.remove_all();} + + template + void overwrite(const t_source & p_source) { + __map_overwrite_wrapper wrapper(*this); + p_source.enumerate(wrapper); + } + + //backwards compatibility method wrappers + template bool exists(const _t_key & p_key) const {return have_item(p_key);} + + + template bool get_first(_t_key & p_out) const { + return m_data.get_first(t_retrieve_key<_t_key>(p_out)); + } + + template bool get_last(_t_key & p_out) const { + return m_data.get_last(t_retrieve_key<_t_key>(p_out)); + } + + private: + template + struct t_retrieve_key { + typedef t_retrieve_key<_t_key> t_self; + t_retrieve_key(_t_key & p_key) : m_key(p_key) {} + template const t_self & operator=(const t_what & p_what) {m_key = p_what.m_key; return *this;} + _t_key & m_key; + }; + template + struct t_search_query { + t_search_query(const _t_key & p_key) : m_key(p_key) {} + _t_key const & m_key; + }; + template + struct t_search_set { + t_search_set(const _t_key & p_key, const _t_value & p_value) : m_key(p_key), m_value(p_value) {} + + _t_key const & m_key; + _t_value const & m_value; + }; + + struct t_storage { + const t_storage_key m_key; + t_storage_value m_value; + + template + t_storage(t_search_query<_t_key> const & p_source) : m_key(p_source.m_key), m_value() {} + + template + t_storage(t_search_set<_t_key,_t_value> const & p_source) : m_key(p_source.m_key), m_value(p_source.m_value) {} + + static bool equals(const t_storage & v1, const t_storage & v2) {return v1.m_key == v2.m_key && v1.m_value == v2.m_value;} + bool operator==(const t_storage & other) const {return equals(*this,other);} + bool operator!=(const t_storage & other) const {return !equals(*this,other);} + }; + + class comparator_wrapper { + public: + template + inline static int compare(const t1 & p_item1,const t2 & p_item2) { + return t_comparator::compare(p_item1.m_key,p_item2.m_key); + } + }; + + template + class enumeration_wrapper { + public: + enumeration_wrapper(t_callback & p_callback) : m_callback(p_callback) {} + void operator()(const t_storage & p_item) {m_callback(p_item.m_key,p_item.m_value);} + private: + t_callback & m_callback; + }; + + template + class enumeration_wrapper_var { + public: + enumeration_wrapper_var(t_callback & p_callback) : m_callback(p_callback) {} + void operator()(t_storage & p_item) {m_callback(safe_cast(p_item.m_key),p_item.m_value);} + private: + t_callback & m_callback; + }; + + typedef avltree_t t_content; + + t_content m_data; + public: + typedef traits_t traits; + typedef typename t_content::const_iterator const_iterator; + typedef typename t_content::iterator iterator; + + iterator first() throw() {return m_data._first_var();} + iterator last() throw() {return m_data._last_var();} + const_iterator first() const throw() {return m_data.first();} + const_iterator last() const throw() {return m_data.last();} + + static bool equals(const t_self & v1, const t_self & v2) { + return t_content::equals(v1.m_data,v2.m_data); + } + bool operator==(const t_self & other) const {return equals(*this,other);} + bool operator!=(const t_self & other) const {return !equals(*this,other);} + + bool remove(iterator const& iter) { + PFC_ASSERT(iter.is_valid()); + return m_data.remove(iter); + //should never return false unless there's a bug in calling code + } + bool remove(const_iterator const& iter) { + PFC_ASSERT(iter.is_valid()); + return m_data.remove(iter); + //should never return false unless there's a bug in calling code + } + }; +} + +#endif //_MAP_T_H_INCLUDED_ diff --git a/tools/vio2sf/src/foobar/pfc/mem_block_mgr.h b/tools/vio2sf/src/foobar/pfc/mem_block_mgr.h new file mode 100644 index 000000000..daaead013 --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/mem_block_mgr.h @@ -0,0 +1,71 @@ +#ifndef _MEM_BLOCK_MGR_H_ +#define _MEM_BLOCK_MGR_H_ + +#error DEPRECATED + + +template +class mem_block_manager +{ + struct entry + { + mem_block_t block; + bool used; + }; + ptr_list_t list; +public: + T * copy(const T* ptr,int size) + { + int n; + int found_size = -1,found_index = -1; + for(n=0;nused) + { + int block_size = list[n]->block.get_size(); + if (found_size<0) + { + found_index=n; found_size = block_size; + } + else if (found_sizefound_size) + { + found_index=n; found_size = block_size; + } + } + else if (found_size>size) + { + if (block_size>=size && block_size=0) + { + list[found_index]->used = true; + return list[found_index]->block.copy(ptr,size); + } + entry * new_entry = new entry; + new_entry->used = true; + list.add_item(new_entry); + return new_entry->block.copy(ptr,size); + } + + void mark_as_free() + { + int n; + for(n=0;nused = false; + } + } + + ~mem_block_manager() {list.delete_all();} +}; + +#endif \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/pfc/order_helper.h b/tools/vio2sf/src/foobar/pfc/order_helper.h new file mode 100644 index 000000000..111ffcf9e --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/order_helper.h @@ -0,0 +1,83 @@ +namespace pfc { + PFC_DECLARE_EXCEPTION( exception_invalid_permutation, exception_invalid_params, "Invalid permutation" ); + t_size permutation_find_reverse(t_size const * order, t_size count, t_size value); + + //! For critical sanity checks. Speed: O(n), allocates memory. + bool permutation_is_valid(t_size const * order, t_size count); + //! For critical sanity checks. Speed: O(n), allocates memory. + void permutation_validate(t_size const * order, t_size count); + + //! Creates a permutation that moves selected items in a list box by the specified delta-offset. + void create_move_items_permutation(t_size * p_output,t_size p_count,const class ::bit_array & p_selection,int p_delta); +} + +class order_helper +{ + pfc::array_t m_data; +public: + order_helper(t_size p_size) { + m_data.set_size(p_size); + for(t_size n=0;n + static void g_fill(t_int * p_order,const t_size p_count) { + t_size n; for(n=0;n + static void g_fill(t_array & p_array) { + t_size n; const t_size max = pfc::array_size_t(p_array); + for(n=0;n + static bool guess_reorder_pattern(pfc::array_t & out, const t_list & from, const t_list & to) { + typedef typename t_list::t_item t_item; + const t_size count = from.get_size(); + if (count != to.get_size()) return false; + out.set_size(count); + for(t_size walk = 0; walk < count; ++walk) out[walk] = walk; + //required output: to[n] = from[out[n]]; + typedef pfc::chain_list_v2_t t_queue; + pfc::map_t content; + for(t_size walk = 0; walk < count; ++walk) { + content.find_or_add(from[walk]).add_item(walk); + } + for(t_size walk = 0; walk < count; ++walk) { + t_queue * q = content.query_ptr(to[walk]); + if (q == NULL) return false; + if (q->get_count() == 0) return false; + out[walk] = *q->first(); + q->remove(q->first()); + } + return true; + } +} diff --git a/tools/vio2sf/src/foobar/pfc/other.cpp b/tools/vio2sf/src/foobar/pfc/other.cpp new file mode 100644 index 000000000..4db4b5901 --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/other.cpp @@ -0,0 +1,137 @@ +#include "pfc.h" + +#include + +namespace pfc { + bool permutation_is_valid(t_size const * order, t_size count) { + bit_array_bittable found(count); + for(t_size walk = 0; walk < count; ++walk) { + if (order[walk] >= count) return false; + if (found[walk]) return false; + found.set(walk,true); + } + return true; + } + void permutation_validate(t_size const * order, t_size count) { + if (!permutation_is_valid(order,count)) throw exception_invalid_permutation(); + } + + t_size permutation_find_reverse(t_size const * order, t_size count, t_size value) { + if (value >= count) return ~0; + for(t_size walk = 0; walk < count; ++walk) { + if (order[walk] == value) return walk; + } + return ~0; + } + + void create_move_items_permutation(t_size * p_output,t_size p_count,const bit_array & p_selection,int p_delta) { + t_size * const order = p_output; + const t_size count = p_count; + + pfc::array_t selection; selection.set_size(p_count); + + for(t_size walk = 0; walk < count; ++walk) { + order[walk] = walk; + selection[walk] = p_selection[walk]; + } + + if (p_delta<0) + { + for(;p_delta<0;p_delta++) + { + t_size idx; + for(idx=1;idx0;p_delta--) + { + t_size idx; + for(idx=count-2;(int)idx>=0;idx--) + { + if (selection[idx] && !selection[idx+1]) + { + pfc::swap_t(order[idx],order[idx+1]); + pfc::swap_t(selection[idx],selection[idx+1]); + } + } + } + } + } +} + +void order_helper::g_swap(t_size * data,t_size ptr1,t_size ptr2) +{ + t_size temp = data[ptr1]; + data[ptr1] = data[ptr2]; + data[ptr2] = temp; +} + + +t_size order_helper::g_find_reverse(const t_size * order,t_size val) +{ + t_size prev = val, next = order[val]; + while(next != val) + { + prev = next; + next = order[next]; + } + return prev; +} + + +void order_helper::g_reverse(t_size * order,t_size base,t_size count) +{ + t_size max = count>>1; + t_size n; + t_size base2 = base+count-1; + for(n=0;n>1;n++) swap_t(ptr[n],ptr[p_bytes-n-1]); +} + +#if defined(_DEBUG) && defined(_WIN32) +void pfc::myassert(const wchar_t * _Message, const wchar_t *_File, unsigned _Line) { + if (IsDebuggerPresent()) pfc::crash(); + _wassert(_Message,_File,_Line); +} +#endif + + +t_uint64 pfc::pow_int(t_uint64 base, t_uint64 exp) { + t_uint64 mul = base; + t_uint64 val = 1; + t_uint64 mask = 1; + while(exp != 0) { + if (exp & mask) { + val *= mul; + exp ^= mask; + } + mul = mul * mul; + mask <<= 1; + } + return val; +} diff --git a/tools/vio2sf/src/foobar/pfc/other.h b/tools/vio2sf/src/foobar/pfc/other.h new file mode 100644 index 000000000..ace7e266a --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/other.h @@ -0,0 +1,207 @@ +#ifndef _PFC_OTHER_H_ +#define _PFC_OTHER_H_ + +namespace pfc { + template + class vartoggle_t { + T oldval; T & var; + public: + vartoggle_t(T & p_var,const T & val) : var(p_var) { + oldval = var; + var = val; + } + ~vartoggle_t() {var = oldval;} + }; + + typedef vartoggle_t booltoggle; +}; + +#ifdef _MSC_VER + +class fpu_control +{ + unsigned old_val; + unsigned mask; +public: + inline fpu_control(unsigned p_mask,unsigned p_val) + { + mask = p_mask; + _controlfp_s(&old_val,p_val,mask); + } + inline ~fpu_control() + { + unsigned dummy; + _controlfp_s(&dummy,old_val,mask); + } +}; + +class fpu_control_roundnearest : private fpu_control +{ +public: + fpu_control_roundnearest() : fpu_control(_MCW_RC,_RC_NEAR) {} +}; + +class fpu_control_flushdenormal : private fpu_control +{ +public: + fpu_control_flushdenormal() : fpu_control(_MCW_DN,_DN_FLUSH) {} +}; + +class fpu_control_default : private fpu_control +{ +public: + fpu_control_default() : fpu_control(_MCW_DN|_MCW_RC,_DN_FLUSH|_RC_NEAR) {} +}; + +#ifdef _M_IX86 +class sse_control { +public: + sse_control(unsigned p_mask,unsigned p_val) : m_mask(p_mask) { + __control87_2(p_val,p_mask,NULL,&m_oldval); + } + ~sse_control() { + __control87_2(m_oldval,m_mask,NULL,&m_oldval); + } +private: + unsigned m_mask,m_oldval; +}; +class sse_control_flushdenormal : private sse_control { +public: + sse_control_flushdenormal() : sse_control(_MCW_DN,_DN_FLUSH) {} +}; +#endif + +#endif + +namespace pfc { + + class releaser_delete { + public: + template static void release(T* p_ptr) {delete p_ptr;} + }; + class releaser_delete_array { + public: + template static void release(T* p_ptr) {delete[] p_ptr;} + }; + class releaser_free { + public: + static void release(void * p_ptr) {free(p_ptr);} + }; + + //! Assumes t_freefunc to never throw exceptions. + template + class ptrholder_t { + private: + typedef ptrholder_t t_self; + public: + inline ptrholder_t(T* p_ptr) : m_ptr(p_ptr) {} + inline ptrholder_t() : m_ptr(NULL) {} + inline ~ptrholder_t() {t_releaser::release(m_ptr);} + inline bool is_valid() const {return m_ptr != NULL;} + inline bool is_empty() const {return m_ptr == NULL;} + inline T* operator->() const {return m_ptr;} + inline T* get_ptr() const {return m_ptr;} + inline void release() {t_releaser::release(replace_null_t(m_ptr));;} + inline void attach(T * p_ptr) {release(); m_ptr = p_ptr;} + inline const t_self & operator=(T * p_ptr) {set(p_ptr);return *this;} + inline T* detach() {return pfc::replace_null_t(m_ptr);} + inline T& operator*() const {return *m_ptr;} + + inline t_self & operator<<(t_self & p_source) {attach(p_source.detach());return *this;} + inline t_self & operator>>(t_self & p_dest) {p_dest.attach(detach());return *this;} + + //deprecated + inline void set(T * p_ptr) {attach(p_ptr);} + private: + ptrholder_t(const t_self &) {throw pfc::exception_not_implemented();} + const t_self & operator=(const t_self & ) {throw pfc::exception_not_implemented();} + + T* m_ptr; + }; + + //avoid "void&" breakage + template + class ptrholder_t { + private: + typedef void T; + typedef ptrholder_t t_self; + public: + inline ptrholder_t(T* p_ptr) : m_ptr(p_ptr) {} + inline ptrholder_t() : m_ptr(NULL) {} + inline ~ptrholder_t() {t_releaser::release(m_ptr);} + inline bool is_valid() const {return m_ptr != NULL;} + inline bool is_empty() const {return m_ptr == NULL;} + inline T* operator->() const {return m_ptr;} + inline T* get_ptr() const {return m_ptr;} + inline void release() {t_releaser::release(replace_null_t(m_ptr));;} + inline void attach(T * p_ptr) {release(); m_ptr = p_ptr;} + inline const t_self & operator=(T * p_ptr) {set(p_ptr);return *this;} + inline T* detach() {return pfc::replace_null_t(m_ptr);} + + inline t_self & operator<<(t_self & p_source) {attach(p_source.detach());return *this;} + inline t_self & operator>>(t_self & p_dest) {p_dest.attach(detach());return *this;} + + //deprecated + inline void set(T * p_ptr) {attach(p_ptr);} + private: + ptrholder_t(const t_self &) {throw pfc::exception_not_implemented();} + const t_self & operator=(const t_self & ) {throw pfc::exception_not_implemented();} + + T* m_ptr; + }; + + void crash(); + + template + class int_container_helper { + public: + int_container_helper() : m_val(p_initval) {} + t_type m_val; + }; + + + + //warning: not multi-thread-safe + template + class instanceTracker : public t_base { + private: + typedef instanceTracker t_self; + public: + TEMPLATE_CONSTRUCTOR_FORWARD_FLOOD_WITH_INITIALIZER(instanceTracker,t_base,{g_list += this;}); + + instanceTracker(const t_self & p_other) : t_base( (const t_base &)p_other) {g_list += this;} + ~instanceTracker() {g_list -= this;} + + typedef pfc::avltree_t t_list; + static const t_list & instanceList() {return g_list;} + template static void forEach(t_callback & p_callback) {instanceList().enumerate(p_callback);} + private: + static t_list g_list; + }; + + template + typename instanceTracker::t_list instanceTracker::g_list; + + + //warning: not multi-thread-safe + template + class instanceTrackerV2 { + private: + typedef instanceTrackerV2 t_self; + public: + instanceTrackerV2(const t_self & p_other) {g_list += static_cast(this);} + instanceTrackerV2() {g_list += static_cast(this);} + ~instanceTrackerV2() {g_list -= static_cast(this);} + + typedef pfc::avltree_t t_instanceList; + static const t_instanceList & instanceList() {return g_list;} + template static void forEach(t_callback & p_callback) {instanceList().enumerate(p_callback);} + private: + static t_instanceList g_list; + }; + + template + typename instanceTrackerV2::t_instanceList instanceTrackerV2::g_list; +} + +#endif \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/pfc/pathUtils.cpp b/tools/vio2sf/src/foobar/pfc/pathUtils.cpp new file mode 100644 index 000000000..fdd723340 --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/pathUtils.cpp @@ -0,0 +1,164 @@ +#include "pfc.h" + +namespace pfc { namespace io { namespace path { + +static const string g_pathSeparators ("\\/|"); + +string getFileName(string path) { + t_size split = path.lastIndexOfAnyChar(g_pathSeparators); + if (split == ~0) return path; + else return path.subString(split+1); +} +string getFileNameWithoutExtension(string path) { + string fn = getFileName(path); + t_size split = path.lastIndexOf('.'); + if (split == ~0) return fn; + else return fn.subString(0,split); +} +string getFileExtension(string path) { + string fn = getFileName(path); + t_size split = fn.lastIndexOf('.'); + if (split == ~0) return ""; + else return fn.subString(split); +} +string getDirectory(string filePath) {return getParent(filePath);} + +string getParent(string filePath) { + t_size split = filePath.lastIndexOfAnyChar(g_pathSeparators); + if (split == ~0) return ""; +#ifdef _WINDOWS + if (split > 0 && getIllegalNameChars().contains(filePath[split-1])) { + if (split + 1 < filePath.length()) return filePath.subString(0,split+1); + else return ""; + } +#endif + return filePath.subString(0,split); +} +string combine(string basePath,string fileName) { + if (basePath.length() > 0) { + if (!isSeparator(basePath.lastChar())) { + basePath += getDefaultSeparator(); + } + return basePath + fileName; + } else { + //todo? + return fileName; + } +} + +bool isSeparator(char c) { + return g_pathSeparators.indexOf(c) != ~0; +} +string getSeparators() { + return g_pathSeparators; +} + +static string replaceIllegalChar(char c) { + switch(c) { + case '*': + return "x"; + case '\"': + return "\'\'"; + default: + return "_"; + } +} +string replaceIllegalPathChars(string fn) { + string illegal = getIllegalNameChars(); + string separators = getSeparators(); + string_formatter output; + for(t_size walk = 0; walk < fn.length(); ++walk) { + const char c = fn[walk]; + if (separators.contains(c)) { + output.add_byte(getDefaultSeparator()); + } else if (string::isNonTextChar(c) || illegal.contains(c)) { + string replacement = replaceIllegalChar(c); + if (replacement.containsAnyChar(illegal)) /*per-OS weirdness security*/ replacement = "_"; + output << replacement.ptr(); + } else { + output.add_byte(c); + } + } + return output.toString(); +} + +string replaceIllegalNameChars(string fn) { + const string illegal = getIllegalNameChars(); + string_formatter output; + for(t_size walk = 0; walk < fn.length(); ++walk) { + const char c = fn[walk]; + if (string::isNonTextChar(c) || illegal.contains(c)) { + string replacement = replaceIllegalChar(c); + if (replacement.containsAnyChar(illegal)) /*per-OS weirdness security*/ replacement = "_"; + output << replacement.ptr(); + } else { + output.add_byte(c); + } + } + return output.toString(); +} + +bool isInsideDirectory(pfc::string directory, pfc::string inside) { + //not very efficient + string walk = inside; + for(;;) { + walk = getParent(walk); + if (walk == "") return false; + if (equals(directory,walk)) return true; + } +} +bool isDirectoryRoot(string path) { + return getParent(path).isEmpty(); +} +//OS-dependant part starts here + + +char getDefaultSeparator() { +#ifdef _WINDOWS + return '\\'; +#else +#error PORTME +#endif +} + +static const string g_illegalNameChars(g_pathSeparators + +#ifdef _WINDOWS + ":<>*?\"" +#else +#error PORTME +#endif + ); + +string getIllegalNameChars() { + return g_illegalNameChars; +} + +static bool isIllegalTrailingChar(char c) { + return c == ' ' || c == '.'; +} + +string validateFileName(string name) { + while(name.endsWith('?')) name = name.subString(0, name.length() - 1); +#ifdef _WINDOWS + name = replaceIllegalNameChars(name); + if (name.length() > 0) { + t_size end = name.length(); + while(end > 0) { + if (!isIllegalTrailingChar(name[end-1])) break; + --end; + } + t_size begin = 0; + while(begin < end) { + if (!isIllegalTrailingChar(name[begin])) break; + ++begin; + } + if (end < name.length() || begin > 0) name = name.subString(begin,end - begin); + } + if (name.isEmpty()) name = "_"; + return name; +#else + return replaceIllegalNameChars(name); +#endif +} + +}}} diff --git a/tools/vio2sf/src/foobar/pfc/pathUtils.h b/tools/vio2sf/src/foobar/pfc/pathUtils.h new file mode 100644 index 000000000..34354a6ce --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/pathUtils.h @@ -0,0 +1,29 @@ +namespace pfc { + namespace io { + namespace path { + string getFileName(string path); + string getFileNameWithoutExtension(string path); + string getFileExtension(string path); + string getParent(string filePath); + string getDirectory(string filePath);//same as getParent() + string combine(string basePath,string fileName); + char getDefaultSeparator(); + string getSeparators(); + bool isSeparator(char c); + string getIllegalNameChars(); + string replaceIllegalNameChars(string fn); + string replaceIllegalPathChars(string fn); + bool isInsideDirectory(pfc::string directory, pfc::string inside); + bool isDirectoryRoot(string path); + string validateFileName(string name);//removes various illegal things from the name, exact effect depends on the OS, includes removal of the invalid characters + + template bool equals(const t1 & v1, const t2 & v2) {return comparator::compare(v1,v2) == 0;} + +#ifdef _WINDOWS + typedef string::comparatorCaseInsensitive comparator; +#else +#error PORTME +#endif + } + } +} diff --git a/tools/vio2sf/src/foobar/pfc/pfc.h b/tools/vio2sf/src/foobar/pfc/pfc.h new file mode 100644 index 000000000..edb538eb0 --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/pfc.h @@ -0,0 +1,166 @@ +#ifndef ___PFC_H___ +#define ___PFC_H___ + +#if !defined(_WINDOWS) && (defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) || defined(_WIN32_WCE)) +#define _WINDOWS +#endif + + +#define PFC_DLL_EXPORT + +#ifdef _WINDOWS + +#ifndef STRICT +#define STRICT +#endif + +#ifndef _SYS_GUID_OPERATOR_EQ_ +#define _NO_SYS_GUID_OPERATOR_EQ_ //fix retarded warning with operator== on GUID returning int +#endif + +#ifndef _WIN32_WINNT +#define _WIN32_WINNT 0x500 +#endif + +#include + +#ifndef _SYS_GUID_OPERATOR_EQ_ +__inline bool __InlineIsEqualGUID(REFGUID rguid1, REFGUID rguid2) +{ + return ( + ((unsigned long *) &rguid1)[0] == ((unsigned long *) &rguid2)[0] && + ((unsigned long *) &rguid1)[1] == ((unsigned long *) &rguid2)[1] && + ((unsigned long *) &rguid1)[2] == ((unsigned long *) &rguid2)[2] && + ((unsigned long *) &rguid1)[3] == ((unsigned long *) &rguid2)[3]); +} + +inline bool operator==(REFGUID guidOne, REFGUID guidOther) {return __InlineIsEqualGUID(guidOne,guidOther);} +inline bool operator!=(REFGUID guidOne, REFGUID guidOther) {return !__InlineIsEqualGUID(guidOne,guidOther);} +#endif + +#include + +#elif defined(__GNUC__) && (defined __unix__ || defined __POSIX__) +#include +#include +typedef struct { + uint32_t Data1; + uint16_t Data2; + uint16_t Data3; + uint8_t Data4[ 8 ]; + } GUID; //same as win32 GUID + +inline bool operator==(const GUID & p_item1,const GUID & p_item2) { + return memcmp(&p_item1,&p_item2,sizeof(GUID)) == 0; +} + +inline bool operator!=(const GUID & p_item1,const GUID & p_item2) { + return memcmp(&p_item1,&p_item2,sizeof(GUID)) != 0; +} + +#else + +#error Only win32 or unix target supported. + +#endif + + + +#define PFC_MEMORY_SPACE_LIMIT ((t_uint64)1<<(sizeof(void*)*8-1)) + +#define PFC_ALLOCA_LIMIT (4096) + +#define INDEX_INVALID ((unsigned)(-1)) + + +#include +#include +#include + +#include + +#include + +#include + +#include +#include + +#define _PFC_WIDESTRING(_String) L ## _String +#define PFC_WIDESTRING(_String) _PFC_WIDESTRING(_String) + +#ifndef _DEBUG +#define PFC_ASSERT(_Expression) ((void)0) +#define PFC_ASSERT_SUCCESS(_Expression) (void)( (_Expression), 0) +#define PFC_ASSERT_NO_EXCEPTION(_Expression) { _Expression; } +#else + +#ifdef _WIN32 +namespace pfc { void myassert(const wchar_t * _Message, const wchar_t *_File, unsigned _Line); } +#define PFC_ASSERT(_Expression) (void)( (!!(_Expression)) || (pfc::myassert(PFC_WIDESTRING(#_Expression), PFC_WIDESTRING(__FILE__), __LINE__), 0) ) +#define PFC_ASSERT_SUCCESS(_Expression) PFC_ASSERT(_Expression) +#else +#define PFC_ASSERT(_Expression) assert(_Expression) +#define PFC_ASSERT_SUCCESS(_Expression) (void)( (_Expression), 0) //FIXME +#endif + +#define PFC_ASSERT_NO_EXCEPTION(_Expression) { try { _Expression; } catch(...) { PFC_ASSERT(!"Should not get here - unexpected exception"); } } +#endif + +#ifdef _MSC_VER + +#ifdef _DEBUG +#define NOVTABLE +#else +#define NOVTABLE _declspec(novtable) +#endif + +#ifdef _DEBUG +#define ASSUME(X) PFC_ASSERT(X) +#else +#define ASSUME(X) __assume(X) +#endif + +#define PFC_DEPRECATE(X) __declspec(deprecated(X)) +#else + +#define NOVTABLE +#define ASSUME(X) assert(X) +#define PFC_DEPRECATE(X) + +#endif + +#include "int_types.h" +#include "traits.h" +#include "bit_array.h" +#include "primitives.h" +#include "alloc.h" +#include "array.h" +#include "bit_array_impl.h" +#include "binary_search.h" +#include "bsearch_inline.h" +#include "bsearch.h" +#include "sort.h" +#include "order_helper.h" +#include "list.h" +#include "ptr_list.h" +#include "string.h" +#include "string_list.h" +#include "ref_counter.h" +#include "iterators.h" +#include "avltree.h" +#include "map.h" +#include "profiler.h" +#include "guid.h" +#include "byte_order_helper.h" +#include "other.h" +#include "chain_list_v2.h" +#include "rcptr.h" +#include "com_ptr_t.h" +#include "string_conv.h" +#include "stringNew.h" +#include "pathUtils.h" +#include "instance_tracker.h" +#include "threads.h" + +#endif //___PFC_H___ diff --git a/tools/vio2sf/src/foobar/pfc/pfc.vcproj b/tools/vio2sf/src/foobar/pfc/pfc.vcproj new file mode 100644 index 000000000..4dc422bfa --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/pfc.vcproj @@ -0,0 +1,802 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/vio2sf/src/foobar/pfc/primitives.h b/tools/vio2sf/src/foobar/pfc/primitives.h new file mode 100644 index 000000000..eb1cff41a --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/primitives.h @@ -0,0 +1,783 @@ +#define tabsize(x) ((size_t)(sizeof(x)/sizeof(*x))) +#define PFC_TABSIZE(x) ((size_t)(sizeof(x)/sizeof(*x))) + +#define TEMPLATE_CONSTRUCTOR_FORWARD_FLOOD_WITH_INITIALIZER(THISCLASS,MEMBER,INITIALIZER) \ + THISCLASS() : MEMBER() INITIALIZER \ + template THISCLASS(const t_param1 & p_param1) : MEMBER(p_param1) INITIALIZER \ + template THISCLASS(const t_param1 & p_param1,const t_param2 & p_param2) : MEMBER(p_param1,p_param2) INITIALIZER \ + template THISCLASS(const t_param1 & p_param1,const t_param2 & p_param2,const t_param3 & p_param3) : MEMBER(p_param1,p_param2,p_param3) INITIALIZER \ + template THISCLASS(const t_param1 & p_param1,const t_param2 & p_param2,const t_param3 & p_param3,const t_param4 & p_param4) : MEMBER(p_param1,p_param2,p_param3,p_param4) INITIALIZER \ + template THISCLASS(const t_param1 & p_param1,const t_param2 & p_param2,const t_param3 & p_param3,const t_param4 & p_param4,const t_param5 & p_param5) : MEMBER(p_param1,p_param2,p_param3,p_param4,p_param5) INITIALIZER \ + template THISCLASS(const t_param1 & p_param1,const t_param2 & p_param2,const t_param3 & p_param3,const t_param4 & p_param4,const t_param5 & p_param5,const t_param6 & p_param6) : MEMBER(p_param1,p_param2,p_param3,p_param4,p_param5,p_param6) INITIALIZER \ + template THISCLASS(const t_param1 & p_param1,const t_param2 & p_param2,const t_param3 & p_param3,const t_param4 & p_param4,const t_param5 & p_param5,const t_param6 & p_param6,const t_param7 & p_param7) : MEMBER(p_param1,p_param2,p_param3,p_param4,p_param5,p_param6,p_param7) INITIALIZER + +#define TEMPLATE_CONSTRUCTOR_FORWARD_FLOOD(THISCLASS,MEMBER) TEMPLATE_CONSTRUCTOR_FORWARD_FLOOD_WITH_INITIALIZER(THISCLASS,MEMBER,{}) + + +#ifdef _MSC_VER + +//Bah. I noticed the fact that std::exception carrying a custom message is MS-specific *after* making exception classes a part of ABI. To be nuked next time fb2k component backwards compatibility is axed. + +#define PFC_DECLARE_EXCEPTION(NAME,BASECLASS,DEFAULTMSG) \ +class NAME : public BASECLASS { \ +public: \ + static const char * g_what() {return DEFAULTMSG;} \ + NAME() : BASECLASS(DEFAULTMSG,0) {} \ + NAME(const char * p_msg) : BASECLASS(p_msg) {} \ + NAME(const char * p_msg,int) : BASECLASS(p_msg,0) {} \ + NAME(const NAME & p_source) : BASECLASS(p_source) {} \ +}; + +namespace pfc { + template inline void throw_exception_with_message(const char * p_message) { + throw t_exception(p_message); + } +} + +#else + +#define PFC_DECLARE_EXCEPTION(NAME,BASECLASS,DEFAULTMSG) \ +class NAME : public BASECLASS { \ +public: \ + static const char * g_what() {return DEFAULTMSG;} \ + const char* what() const throw() {return DEFAULTMSG;} \ +}; + +namespace pfc { + template class __exception_with_message_t : public t_base { + private: typedef __exception_with_message_t t_self; + public: + __exception_with_message_t(const char * p_message) : m_message(NULL) { + set_message(p_message); + } + __exception_with_message_t() : m_message(NULL) {} + __exception_with_message_t(const t_self & p_source) : m_message(NULL) {set_message(p_source.m_message);} + + const char* what() const throw() {return m_message != NULL ? m_message : "unnamed exception";} + + const t_self & operator=(const t_self & p_source) {set_message(p_source.m_message);} + + ~__exception_with_message_t() throw() {cleanup();} + + private: + void set_message(const char * p_message) throw() { + cleanup(); + if (p_message != NULL) m_message = strdup(p_message); + } + void cleanup() throw() { + if (m_message != NULL) {free(m_message); m_message = NULL;} + } + char * m_message; + }; + template void throw_exception_with_message(const char * p_message) { + throw __exception_with_message_t(p_message); + } +} +#endif + +namespace pfc { + + template class assert_same_type; + template class assert_same_type {}; + + template + class is_same_type { public: enum {value = false}; }; + + template + class is_same_type { public: enum {value = true}; }; + + template class static_assert; + template<> class static_assert {}; + + template class static_assert_t; + template<> class static_assert_t {}; + +#define PFC_STATIC_ASSERT(X) { pfc::static_assert<(X)>(); } + + template + void assert_raw_type() {static_assert< !traits_t::needs_constructor && !traits_t::needs_destructor >();} + + template class assert_byte_type; + template<> class assert_byte_type {}; + template<> class assert_byte_type {}; + + + template void __unsafe__memcpy_t(t_type * p_dst,const t_type * p_src,t_size p_count) { + ::memcpy(reinterpret_cast(p_dst), reinterpret_cast(p_src), p_count * sizeof(t_type)); + } + + template void __unsafe__in_place_destructor_t(t_type & p_item) throw() { + if (traits_t::needs_destructor) try{ p_item.~t_type(); } catch(...) {} + } + + template void __unsafe__in_place_constructor_t(t_type & p_item) { + if (traits_t::needs_constructor) { + t_type * ret = new(&p_item) t_type; + PFC_ASSERT(ret == &p_item); + } + } + + template void __unsafe__in_place_destructor_array_t(t_type * p_items, t_size p_count) throw() { + if (traits_t::needs_destructor) { + t_type * walk = p_items; + for(t_size n=p_count;n;--n) __unsafe__in_place_destructor_t(*(walk++)); + } + } + + template t_type * __unsafe__in_place_constructor_array_t(t_type * p_items,t_size p_count) { + if (traits_t::needs_constructor) { + t_size walkptr = 0; + try { + for(walkptr=0;walkptr t_type * __unsafe__in_place_resize_array_t(t_type * p_items,t_size p_from,t_size p_to) { + if (p_from < p_to) __unsafe__in_place_constructor_array_t(p_items + p_from, p_to - p_from); + else if (p_from > p_to) __unsafe__in_place_destructor_array_t(p_items + p_to, p_from - p_to); + return p_items; + } + + template void __unsafe__in_place_constructor_copy_t(t_type & p_item,const t_copy & p_copyfrom) { + if (traits_t::needs_constructor) { + t_type * ret = new(&p_item) t_type(p_copyfrom); + PFC_ASSERT(ret == &p_item); + } else { + p_item = p_copyfrom; + } + } + + template t_type * __unsafe__in_place_constructor_array_copy_t(t_type * p_items,t_size p_count, const t_copy * p_copyfrom) { + t_size walkptr = 0; + try { + for(walkptr=0;walkptr t_type * __unsafe__in_place_constructor_array_copy_partial_t(t_type * p_items,t_size p_count, const t_copy * p_copyfrom,t_size p_copyfrom_count) { + if (p_copyfrom_count > p_count) p_copyfrom_count = p_count; + __unsafe__in_place_constructor_array_copy_t(p_items,p_copyfrom_count,p_copyfrom); + try { + __unsafe__in_place_constructor_array_t(p_items + p_copyfrom_count,p_count - p_copyfrom_count); + } catch(...) { + __unsafe__in_place_destructor_array_t(p_items,p_copyfrom_count); + throw; + } + return p_items; + } + + template inline t_ret safe_cast(t_ret val) {return val;} + + template + t_ret * safe_ptr_cast(t_param * p_param) { + if (pfc::is_same_type::value) return p_param; + else { + if (p_param == NULL) return NULL; + else return p_param; + } + } + + typedef std::exception exception; + + PFC_DECLARE_EXCEPTION(exception_overflow,exception,"Overflow"); + PFC_DECLARE_EXCEPTION(exception_bug_check,exception,"Bug check"); + PFC_DECLARE_EXCEPTION(exception_invalid_params,exception_bug_check,"Invalid parameters"); + PFC_DECLARE_EXCEPTION(exception_unexpected_recursion,exception_bug_check,"Unexpected recursion"); + PFC_DECLARE_EXCEPTION(exception_not_implemented,exception_bug_check,"Feature not implemented"); + PFC_DECLARE_EXCEPTION(exception_dynamic_assert,exception_bug_check,"dynamic_assert failure"); + + template + t_ret downcast_guarded(const t_param & p_param) { + t_ret temp = (t_ret) p_param; + if ((t_param) temp != p_param) throw exception_overflow(); + return temp; + } + + template + t_ret downcast_guarded_ex(const t_param & p_param) { + t_ret temp = (t_ret) p_param; + if ((t_param) temp != p_param) throw t_exception(); + return temp; + } + + template + void accumulate_guarded(t_acc & p_acc, const t_add & p_add) { + t_acc delta = downcast_guarded(p_add); + delta += p_acc; + if (delta < p_acc) throw exception_overflow(); + p_acc = delta; + } + + //deprecated + inline void bug_check_assert(bool p_condition, const char * p_msg) { + if (!p_condition) { + PFC_ASSERT(0); + throw_exception_with_message(p_msg); + } + } + //deprecated + inline void bug_check_assert(bool p_condition) { + if (!p_condition) { + PFC_ASSERT(0); + throw exception_bug_check(); + } + } + + inline void dynamic_assert(bool p_condition, const char * p_msg) { + if (!p_condition) { + PFC_ASSERT(0); + throw_exception_with_message(p_msg); + } + } + inline void dynamic_assert(bool p_condition) { + if (!p_condition) { + PFC_ASSERT(0); + throw exception_dynamic_assert(); + } + } + + template + inline void swap_multi_t(T * p_buffer1,T * p_buffer2,t_size p_size) { + T * walk1 = p_buffer1, * walk2 = p_buffer2; + for(t_size n=p_size;n;--n) { + T temp (* walk1); + *walk1 = *walk2; + *walk2 = temp; + walk1++; walk2++; + } + } + + template + inline void swap_multi_t(T * p_buffer1,T * p_buffer2) { + T * walk1 = p_buffer1, * walk2 = p_buffer2; + for(t_size n=p_size;n;--n) { + T temp (* walk1); + *walk1 = *walk2; + *walk2 = temp; + walk1++; walk2++; + } + } + + + template + inline void __unsafe__swap_raw_t(void * p_object1, void * p_object2) { + if (p_size % sizeof(t_size) == 0) { + swap_multi_t(reinterpret_cast(p_object1),reinterpret_cast(p_object2)); + } else { + swap_multi_t(reinterpret_cast(p_object1),reinterpret_cast(p_object2)); + } + } + + template + inline void swap_t(T & p_item1, T & p_item2) { + if (traits_t::realloc_safe) { + __unsafe__swap_raw_t( reinterpret_cast( &p_item1 ), reinterpret_cast( &p_item2 ) ); + } else { + T temp(p_item2); + p_item2 = p_item1; + p_item1 = temp; + } + } + + template + t_size array_size_t(const t_array & p_array) {return p_array.get_size();} + + template + t_size array_size_t(const t_item (&p_array)[p_width]) {return p_width;} + + + template + inline void fill_t(t_array & p_buffer,const t_size p_count, const t_filler & p_filler) { + for(t_size n=0;n + inline void fill_ptr_t(t_array * p_buffer,const t_size p_count, const t_filler & p_filler) { + for(t_size n=0;n + inline int compare_t(const t_item1 & p_item1, const t_item2 & p_item2) { + if (p_item1 < p_item2) return -1; + else if (p_item1 > p_item2) return 1; + else return 0; + } + + //! For use with avltree/map etc. + class comparator_default { + public: + template + inline static int compare(const t_item1 & p_item1,const t_item2 & p_item2) {return pfc::compare_t(p_item1,p_item2);} + }; + + template class comparator_pointer { public: + template static int compare(const t_item1 & p_item1,const t_item2 & p_item2) {return t_comparator::compare(*p_item1,*p_item2);} + }; + + template class comparator_dual { public: + template static int compare(const t_item1 & p_item1,const t_item2 & p_item2) { + int state = t_primary::compare(p_item1,p_item2); + if (state != 0) return state; + return t_secondary::compare(p_item1,p_item2); + } + }; + + class comparator_memcmp { + public: + template + inline static int compare(const t_item1 & p_item1,const t_item2 & p_item2) { + static_assert(); + return memcmp(&p_item1,&p_item2,sizeof(t_item1)); + } + }; + + template + t_size subtract_sorted_lists_calculate_count(const t_source1 & p_source1, const t_source2 & p_source2) { + t_size walk1 = 0, walk2 = 0, walk_out = 0; + const t_size max1 = p_source1.get_size(), max2 = p_source2.get_size(); + for(;;) { + int state; + if (walk1 < max1 && walk2 < max2) { + state = pfc::compare_t(p_source1[walk1],p_source2[walk2]); + } else if (walk1 < max1) { + state = -1; + } else if (walk2 < max2) { + state = 1; + } else { + break; + } + if (state < 0) walk_out++; + if (state <= 0) walk1++; + if (state >= 0) walk2++; + } + return walk_out; + } + + //! Subtracts p_source2 contents from p_source1 and stores result in p_destination. Both source lists must be sorted. + //! Note: duplicates will be carried over (and ignored for p_source2). + template + void subtract_sorted_lists(t_destination & p_destination,const t_source1 & p_source1, const t_source2 & p_source2) { + p_destination.set_size(subtract_sorted_lists_calculate_count(p_source1,p_source2)); + t_size walk1 = 0, walk2 = 0, walk_out = 0; + const t_size max1 = p_source1.get_size(), max2 = p_source2.get_size(); + for(;;) { + int state; + if (walk1 < max1 && walk2 < max2) { + state = pfc::compare_t(p_source1[walk1],p_source2[walk2]); + } else if (walk1 < max1) { + state = -1; + } else if (walk2 < max2) { + state = 1; + } else { + break; + } + + + if (state < 0) p_destination[walk_out++] = p_source1[walk1]; + if (state <= 0) walk1++; + if (state >= 0) walk2++; + } + } + + template + t_size merge_sorted_lists_calculate_count(const t_source1 & p_source1, const t_source2 & p_source2) { + t_size walk1 = 0, walk2 = 0, walk_out = 0; + const t_size max1 = p_source1.get_size(), max2 = p_source2.get_size(); + for(;;) { + int state; + if (walk1 < max1 && walk2 < max2) { + state = pfc::compare_t(p_source1[walk1],p_source2[walk2]); + } else if (walk1 < max1) { + state = -1; + } else if (walk2 < max2) { + state = 1; + } else { + break; + } + if (state <= 0) walk1++; + if (state >= 0) walk2++; + walk_out++; + } + return walk_out; + } + + //! Merges p_source1 and p_source2, storing content in p_destination. Both source lists must be sorted. + //! Note: duplicates will be carried over. + template + void merge_sorted_lists(t_destination & p_destination,const t_source1 & p_source1, const t_source2 & p_source2) { + p_destination.set_size(merge_sorted_lists_calculate_count(p_source1,p_source2)); + t_size walk1 = 0, walk2 = 0, walk_out = 0; + const t_size max1 = p_source1.get_size(), max2 = p_source2.get_size(); + for(;;) { + int state; + if (walk1 < max1 && walk2 < max2) { + state = pfc::compare_t(p_source1[walk1],p_source2[walk2]); + } else if (walk1 < max1) { + state = -1; + } else if (walk2 < max2) { + state = 1; + } else { + break; + } + if (state < 0) { + p_destination[walk_out] = p_source1[walk1++]; + } else if (state > 0) { + p_destination[walk_out] = p_source2[walk2++]; + } else { + p_destination[walk_out] = p_source1[walk1]; + walk1++; walk2++; + } + walk_out++; + } + } + + + + template + inline t_size append_t(t_array & p_array,const T & p_item) + { + t_size old_count = p_array.get_size(); + p_array.set_size(old_count + 1); + p_array[old_count] = p_item; + return old_count; + } + + template + inline t_size append_swap_t(t_array & p_array,T & p_item) + { + t_size old_count = p_array.get_size(); + p_array.set_size(old_count + 1); + swap_t(p_array[old_count],p_item); + return old_count; + } + + template + inline t_size insert_t(t_array & p_array,const T & p_item,t_size p_index) + { + t_size old_count = p_array.get_size(); + if (p_index > old_count) p_index = old_count; + p_array.set_size(old_count + 1); + for(t_size n=old_count;n>p_index;n--) + p_array[n] = p_array[n-1]; + p_array[p_index] = p_item; + return p_index; + } + template + inline t_size insert_default_t(t_array & p_array,t_size p_index) + { + t_size old_count = p_array.get_size(); + if (p_index > old_count) p_index = old_count; + p_array.set_size(old_count + 1); + for(t_size n=old_count;n>p_index;n--) + p_array[n] = p_array[n-1]; + /*p_array[p_index] = p_item;*/ + return p_index; + } + + template + inline t_size insert_swap_t(t_array & p_array,T & p_item,t_size p_index) + { + t_size old_count = p_array.get_size(); + if (p_index > old_count) p_index = old_count; + p_array.set_size(old_count + 1); + for(t_size n=old_count;n>p_index;n--) + swap_t(p_array[n],p_array[n-1]); + swap_t(p_array[p_index],p_item); + return p_index; + } + + + template + inline T max_t(const T & item1, const T & item2) {return item1 > item2 ? item1 : item2;}; + + template + inline T min_t(const T & item1, const T & item2) {return item1 < item2 ? item1 : item2;}; + + template + inline T abs_t(T item) {return item<0 ? -item : item;} + + template + inline T sqr_t(T item) {return item * item;} + + template + inline T clip_t(const T & p_item, const T & p_min, const T & p_max) { + if (p_item < p_min) return p_min; + else if (p_item <= p_max) return p_item; + else return p_max; + } + + + + + + template + inline void delete_t(T* ptr) {delete ptr;} + + template + inline void delete_array_t(T* ptr) {delete[] ptr;} + + template + inline T* clone_t(T* ptr) {return new T(*ptr);} + + + template + inline t_int mul_safe_t(t_int p_val1,t_int p_val2) { + if (p_val1 == 0 || p_val2 == 0) return 0; + t_int temp = (t_int) (p_val1 * p_val2); + if (temp / p_val1 != p_val2) throw t_exception(); + return temp; + } + template + t_int multiply_guarded(t_int v1, t_int v2) { + return mul_safe_t(v1, v2); + } + + template + void memcpy_t(t_dst* p_dst,const t_src* p_src,t_size p_count) { + for(t_size n=0;n + void copy_array_loop_t(t_dst & p_dst,const t_src & p_src,t_size p_count) { + for(t_size n=0;n + void memcpy_backwards_t(t_dst * p_dst,const t_src * p_src,t_size p_count) { + p_dst += p_count; p_src += p_count; + for(t_size n=0;n + void memset_t(T * p_buffer,const t_val & p_val,t_size p_count) { + for(t_size n=0;n + void memset_t(T &p_buffer,const t_val & p_val) { + const t_size width = pfc::array_size_t(p_buffer); + for(t_size n=0;n + void memset_null_t(T * p_buffer,t_size p_count) { + for(t_size n=0;n + void memset_null_t(T &p_buffer) { + const t_size width = pfc::array_size_t(p_buffer); + for(t_size n=0;n + void memmove_t(T* p_dst,const T* p_src,t_size p_count) { + if (p_dst == p_src) {/*do nothing*/} + else if (p_dst > p_src && p_dst < p_src + p_count) memcpy_backwards_t(p_dst,p_src,p_count); + else memcpy_t(p_dst,p_src,p_count); + } + + template void memxor_t(TVal * out, const TVal * s1, const TVal * s2, t_size count) { + for(t_size walk = 0; walk < count; ++walk) out[walk] = s1[walk] ^ s2[walk]; + } + static void memxor(void * target, const void * source1, const void * source2, t_size size) { + memxor_t( reinterpret_cast(target), reinterpret_cast(source1), reinterpret_cast(source2), size); + } + + template + T* new_ptr_check_t(T* p_ptr) { + if (p_ptr == NULL) throw std::bad_alloc(); + return p_ptr; + } + + template + int sgn_t(const T & p_val) { + if (p_val < 0) return -1; + else if (p_val > 0) return 1; + else return 0; + } + + template const T* empty_string_t(); + + template<> inline const char * empty_string_t() {return "";} + template<> inline const wchar_t * empty_string_t() {return L"";} + + + template + t_type replace_t(t_type & p_var,const t_newval & p_newval) { + t_type oldval = p_var; + p_var = p_newval; + return oldval; + } + template + t_type replace_null_t(t_type & p_var) { + t_type ret = p_var; + p_var = NULL; + return ret; + } + + template + inline bool is_ptr_aligned_t(const void * p_ptr) { + static_assert< (p_size_pow2 & (p_size_pow2 - 1)) == 0 >(); + return ( ((t_size)p_ptr) & (p_size_pow2-1) ) == 0; + } + + + template + void array_rangecheck_t(const t_array & p_array,t_size p_index) { + if (p_index >= pfc::array_size_t(p_array)) throw pfc::exception_overflow(); + } + + template + void array_rangecheck_t(const t_array & p_array,t_size p_from,t_size p_to) { + if (p_from > p_to) throw pfc::exception_overflow(); + array_rangecheck_t(p_array,p_from); array_rangecheck_t(p_array,p_to); + } + + inline t_int32 rint32(double p_val) {return (t_int32) floor(p_val + 0.5);} + inline t_int64 rint64(double p_val) {return (t_int64) floor(p_val + 0.5);} + + + + + template + inline t_size remove_mask_t(t_array & p_array,const bit_array & p_mask)//returns amount of items left + { + t_size n,count = p_array.get_size(), total = 0; + + n = total = p_mask.find(true,0,count); + + if (n + t_size find_duplicates_sorted_t(t_array p_array,t_size p_count,t_compare p_compare,bit_array_var & p_out) { + t_size ret = 0; + t_size n; + if (p_count > 0) + { + p_out.set(0,false); + for(n=1;n + t_size find_duplicates_sorted_permutation_t(t_array p_array,t_size p_count,t_compare p_compare,t_permutation const & p_permutation,bit_array_var & p_out) { + t_size ret = 0; + t_size n; + if (p_count > 0) { + p_out.set(p_permutation[0],false); + for(n=1;n + t_size strlen_t(const t_char * p_string,t_size p_length = infinite) { + for(t_size walk = 0;;walk++) { + if (walk >= p_length || p_string[walk] == 0) return walk; + } + } + + + template + class __list_to_array_enumerator { + public: + __list_to_array_enumerator(t_array & p_array) : m_array(p_array), m_walk(0) {} + template + void operator() (const t_item & p_item) { + PFC_ASSERT(m_walk < m_array.get_size()); + m_array[m_walk++] = p_item; + } + void finalize() { + PFC_ASSERT(m_walk == m_array.get_size()); + } + private: + t_size m_walk; + t_array & m_array; + }; + + template + void list_to_array(t_array & p_array,const t_list & p_list) { + p_array.set_size(p_list.get_count()); + __list_to_array_enumerator enumerator(p_array); + p_list.enumerate(enumerator); + enumerator.finalize(); + } + + template + class enumerator_add_item { + public: + enumerator_add_item(t_receiver & p_receiver) : m_receiver(p_receiver) {} + template void operator() (const t_item & p_item) {m_receiver.add_item(p_item);} + private: + t_receiver & m_receiver; + }; + + template + void overwrite_list_enumerated(t_receiver & p_receiver,const t_giver & p_giver) { + enumerator_add_item wrapper(p_receiver); + p_giver.enumerate(wrapper); + } + + template + void copy_list_enumerated(t_receiver & p_receiver,const t_giver & p_giver) { + p_receiver.remove_all(); + overwrite_list_enumerated(p_receiver,p_giver); + } + + inline bool lxor(bool p_val1,bool p_val2) { + return p_val1 == !p_val2; + } + + template + inline void min_acc(t_val & p_acc,const t_val & p_val) { + if (p_val < p_acc) p_acc = p_val; + } + + template + inline void max_acc(t_val & p_acc,const t_val & p_val) { + if (p_val > p_acc) p_acc = p_val; + } + + t_uint64 pow_int(t_uint64 base, t_uint64 exp); +}; + + +#define PFC_CLASS_NOT_COPYABLE(THISCLASSNAME,THISTYPE) \ + private: \ + THISCLASSNAME(const THISTYPE&) {throw pfc::exception_bug_check();} \ + const THISTYPE & operator=(const THISTYPE &) {throw pfc::exception_bug_check();} + +#define PFC_CLASS_NOT_COPYABLE_EX(THISTYPE) PFC_CLASS_NOT_COPYABLE(THISTYPE,THISTYPE) \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/pfc/printf.cpp b/tools/vio2sf/src/foobar/pfc/printf.cpp new file mode 100644 index 000000000..cdfa6a5cf --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/printf.cpp @@ -0,0 +1,117 @@ +#include "pfc.h" + +//implementations of deprecated string_printf methods, with a pragma to disable warnings when they reference other deprecated methods. + +#pragma warning(disable:4996) + +namespace pfc { + +void string_printf::run(const char * fmt,va_list list) {g_run(*this,fmt,list);} + +string_printf_va::string_printf_va(const char * fmt,va_list list) {string_printf::g_run(*this,fmt,list);} + +void string_printf::g_run(string_base & out,const char * fmt,va_list list) +{ + out.reset(); + while(*fmt) + { + if (*fmt=='%') + { + fmt++; + if (*fmt=='%') + { + out.add_char('%'); + fmt++; + } + else + { + bool force_sign = false; + if (*fmt=='+') + { + force_sign = true; + fmt++; + } + char padchar = (*fmt == '0') ? '0' : ' '; + t_size pad = 0; + while(*fmt>='0' && *fmt<='9') + { + pad = pad * 10 + (*fmt - '0'); + fmt++; + } + + if (*fmt=='s' || *fmt=='S') + { + const char * ptr = va_arg(list,const char*); + t_size len = strlen(ptr); + if (pad>len) out.add_chars(padchar,pad-len); + out.add_string(ptr); + fmt++; + + } + else if (*fmt=='i' || *fmt=='I' || *fmt=='d' || *fmt=='D') + { + char temp[8*sizeof(int)]; + int val = va_arg(list,int); + if (force_sign && val>0) out.add_char('+'); + _itoa_s(val,temp,10); + t_size len = strlen(temp); + if (pad>len) out.add_chars(padchar,pad-len); + out.add_string(temp); + fmt++; + } + else if (*fmt=='u' || *fmt=='U') + { + char temp[8*sizeof(int)]; + int val = va_arg(list,int); + if (force_sign && val>0) out.add_char('+'); + _ultoa_s(val,temp,10); + t_size len = strlen(temp); + if (pad>len) out.add_chars(padchar,pad-len); + out.add_string(temp); + fmt++; + } + else if (*fmt=='x' || *fmt=='X') + { + char temp[8*sizeof(int)]; + int val = va_arg(list,int); + if (force_sign && val>0) out.add_char('+'); + _ultoa_s(val,temp,16); + if (*fmt=='X') + { + char * t = temp; + while(*t) + { + if (*t>='a' && *t<='z') + *t += 'A' - 'a'; + t++; + } + } + t_size len = strlen(temp); + if (pad>len) out.add_chars(padchar,pad-len); + out.add_string(temp); + fmt++; + } + else if (*fmt=='c' || *fmt=='C') + { + out.add_char(va_arg(list,char)); + fmt++; + } + } + } + else + { + out.add_char(*(fmt++)); + } + } +} + +string_printf::string_printf(const char * fmt,...) +{ + va_list list; + va_start(list,fmt); + run(fmt,list); + va_end(list); +} + + +} \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/pfc/profiler.cpp b/tools/vio2sf/src/foobar/pfc/profiler.cpp new file mode 100644 index 000000000..3ec7ae578 --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/profiler.cpp @@ -0,0 +1,34 @@ +#include "pfc.h" + +#ifdef _WINDOWS +namespace pfc { + +profiler_static::profiler_static(const char * p_name) +{ + name = p_name; + total_time = 0; + num_called = 0; +} + +profiler_static::~profiler_static() +{ + try { + pfc::string_fixed_t<511> message; + message << "profiler: " << pfc::format_pad_left >(48,' ',name) << " - " << + pfc::format_pad_right >(16,' ',pfc::format_uint(total_time) ) << " cycles"; + + if (num_called > 0) { + message << " (executed " << num_called << " times, " << (total_time / num_called) << " average)"; + } + message << "\n"; + OutputDebugStringA(message); + } catch(...) { + //should never happen + OutputDebugString(_T("unexpected profiler failure\n")); + } +} + +} +#else +//PORTME +#endif diff --git a/tools/vio2sf/src/foobar/pfc/profiler.h b/tools/vio2sf/src/foobar/pfc/profiler.h new file mode 100644 index 000000000..11715d3a5 --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/profiler.h @@ -0,0 +1,100 @@ +#ifndef _PFC_PROFILER_H_ +#define _PFC_PROFILER_H_ + +#ifdef _WINDOWS + +#include +namespace pfc { +class profiler_static { +public: + profiler_static(const char * p_name); + ~profiler_static(); + void add_time(t_int64 delta) {total_time+=delta;num_called++;} +private: + const char * name; + t_uint64 total_time,num_called; +}; + +class profiler_local { +public: + profiler_local(profiler_static * p_owner) { + owner = p_owner; + start = __rdtsc(); + } + ~profiler_local() { + t_int64 end = __rdtsc(); + owner->add_time(end-start); + } +private: + t_int64 start; + profiler_static * owner; +}; + +#define profiler(name) \ + static pfc::profiler_static profiler_static_##name(#name); \ + pfc::profiler_local profiler_local_##name(&profiler_static_##name); + + +class hires_timer { +public: + void start() { + m_start = g_query(); + } + double query() const { + return _query( g_query() ); + } + double query_reset() { + t_uint64 current = g_query(); + double ret = _query(current); + m_start = current; + return ret; + } +private: + double _query(t_uint64 p_val) const { + return (double)( p_val - m_start ) / (double) g_query_freq(); + } + static t_uint64 g_query() { + LARGE_INTEGER val; + if (!QueryPerformanceCounter(&val)) throw pfc::exception_not_implemented(); + return val.QuadPart; + } + static t_uint64 g_query_freq() { + LARGE_INTEGER val; + if (!QueryPerformanceFrequency(&val)) throw pfc::exception_not_implemented(); + return val.QuadPart; + } + t_uint64 m_start; +}; + +class lores_timer { +public: + void start() { + _start(GetTickCount()); + } + + double query() const { + return _query(GetTickCount()); + } + double query_reset() { + t_uint32 time = GetTickCount(); + double ret = _query(time); + _start(time); + return ret; + } +private: + void _start(t_uint32 p_time) {m_last_seen = m_start = p_time;} + double _query(t_uint32 p_time) const { + t_uint64 time = p_time; + if (time < (m_last_seen & 0xFFFFFFFF)) time += 0x100000000; + m_last_seen = (m_last_seen & 0xFFFFFFFF00000000) + time; + return (double)(m_last_seen - m_start) / 1000.0; + } + t_uint64 m_start; + mutable t_uint64 m_last_seen; +}; +} +#else +//PORTME +#endif + +#endif diff --git a/tools/vio2sf/src/foobar/pfc/ptr_list.h b/tools/vio2sf/src/foobar/pfc/ptr_list.h new file mode 100644 index 000000000..8762799cd --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/ptr_list.h @@ -0,0 +1,45 @@ +#ifndef __PFC_PTR_LIST_H_ +#define __PFC_PTR_LIST_H_ + +namespace pfc { + + template > + class ptr_list_t : public B + { + public: + ptr_list_t() {} + ptr_list_t(const ptr_list_t & p_source) {*this = p_source;} + + void free_by_idx(t_size n) {free_mask(bit_array_one(n));} + void free_all() {this->remove_all_ex(free);} + void free_mask(const bit_array & p_mask) {this->remove_mask_ex(p_mask,free);} + + void delete_item(T* ptr) {delete_by_idx(find_item(ptr));} + + void delete_by_idx(t_size p_index) { + delete_mask(bit_array_one(p_index)); + } + + void delete_all() { + this->remove_all_ex(pfc::delete_t); + } + + void delete_mask(const bit_array & p_mask) { + this->remove_mask_ex(p_mask,pfc::delete_t); + } + + T * operator[](t_size n) const {return this->get_item(n);} + }; + + template + class ptr_list_hybrid_t : public ptr_list_t > { + public: + ptr_list_hybrid_t() {} + ptr_list_hybrid_t(const ptr_list_hybrid_t & p_source) {*this = p_source;} + }; + + typedef ptr_list_t ptr_list; +} + + +#endif //__PFC_PTR_LIST_H_ diff --git a/tools/vio2sf/src/foobar/pfc/rcptr.h b/tools/vio2sf/src/foobar/pfc/rcptr.h new file mode 100644 index 000000000..5a55cb02b --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/rcptr.h @@ -0,0 +1,250 @@ +namespace pfc { + + class rc_container_base { + public: + long add_ref() throw() { + return ++m_counter; + } + long release() throw() { + long ret = --m_counter; + if (ret == 0) PFC_ASSERT_NO_EXCEPTION( delete this ); + return ret; + } + protected: + virtual ~rc_container_base() {} + private: + refcounter m_counter; + }; + + template + class rc_container_t : public rc_container_base { + public: + TEMPLATE_CONSTRUCTOR_FORWARD_FLOOD(rc_container_t,m_object) + + t_object m_object; + }; + + template + class rcptr_t { + private: + typedef rcptr_t t_self; + typedef rc_container_base t_container; + typedef rc_container_t t_container_impl; + public: + rcptr_t() throw() {__init();} + rcptr_t(const t_self & p_source) throw() {__init(p_source);} + t_self const & operator=(const t_self & p_source) throw() {__copy(p_source); return *this;} + + template + rcptr_t(const rcptr_t & p_source) throw() {__init(p_source);} + template + const t_self & operator=(const rcptr_t & p_source) throw() {__copy(p_source); return *this;} + +/* template + operator rcptr_t() const throw() { + rcptr_t temp; + if (is_valid()) temp.__set_from_cast(this->m_container,this->m_ptr); + return temp; + }*/ + + + template + bool operator==(const rcptr_t & p_other) const throw() { + return m_container == p_other.__container(); + } + + template + bool operator!=(const rcptr_t & p_other) const throw() { + return m_container != p_other.__container(); + } + + void __set_from_cast(t_container * p_container,t_object * p_ptr) throw() { + //addref first because in rare cases this is the same pointer as the one we currently own + if (p_container != NULL) p_container->add_ref(); + release(); + m_container = p_container; + m_ptr = p_ptr; + } + + bool is_valid() const throw() {return m_container != NULL;} + bool is_empty() const throw() {return m_container == NULL;} + + + ~rcptr_t() throw() {release();} + + void release() throw() { + t_container * temp = m_container; + m_ptr = NULL; + m_container = NULL; + if (temp != NULL) temp->release(); + } + + + template + rcptr_t static_cast_t() const throw() { + rcptr_t temp; + if (is_valid()) temp.__set_from_cast(this->m_container,static_cast(this->m_ptr)); + return temp; + } + + void new_t() { + on_new(new t_container_impl()); + } + + template + void new_t(t_param1 const & p_param1) { + on_new(new t_container_impl(p_param1)); + } + + template + void new_t(t_param1 const & p_param1, t_param2 const & p_param2) { + on_new(new t_container_impl(p_param1,p_param2)); + } + + template + void new_t(t_param1 const & p_param1, t_param2 const & p_param2,t_param3 const & p_param3) { + on_new(new t_container_impl(p_param1,p_param2,p_param3)); + } + + template + void new_t(t_param1 const & p_param1, t_param2 const & p_param2,t_param3 const & p_param3,t_param4 const & p_param4) { + on_new(new t_container_impl(p_param1,p_param2,p_param3,p_param4)); + } + + template + void new_t(t_param1 const & p_param1, t_param2 const & p_param2,t_param3 const & p_param3,t_param4 const & p_param4,t_param5 const & p_param5) { + on_new(new t_container_impl(p_param1,p_param2,p_param3,p_param4,p_param5)); + } + + template + void new_t(t_param1 const & p_param1, t_param2 const & p_param2,t_param3 const & p_param3,t_param4 const & p_param4,t_param5 const & p_param5,t_param6 const & p_param6) { + on_new(new t_container_impl(p_param1,p_param2,p_param3,p_param4,p_param5,p_param6)); + } + + static t_self g_new_t() { + t_self temp; + temp.new_t(); + return temp; + } + + template + static t_self g_new_t(t_param1 const & p_param1) { + t_self temp; + temp.new_t(p_param1); + return temp; + } + + template + static t_self g_new_t(t_param1 const & p_param1,t_param2 const & p_param2) { + t_self temp; + temp.new_t(p_param1,p_param2); + return temp; + } + + template + static t_self g_new_t(t_param1 const & p_param1,t_param2 const & p_param2,t_param3 const & p_param3) { + t_self temp; + temp.new_t(p_param1,p_param2,p_param3); + return temp; + } + + template + static t_self g_new_t(t_param1 const & p_param1,t_param2 const & p_param2,t_param3 const & p_param3,t_param4 const & p_param4) { + t_self temp; + temp.new_t(p_param1,p_param2,p_param3,p_param4); + return temp; + } + + template + static t_self g_new_t(t_param1 const & p_param1,t_param2 const & p_param2,t_param3 const & p_param3,t_param4 const & p_param4,t_param5 const & p_param5) { + t_self temp; + temp.new_t(p_param1,p_param2,p_param3,p_param4,p_param5); + return temp; + } + + t_object & operator*() const throw() {return *this->m_ptr;} + + t_object * operator->() const throw() {return this->m_ptr;} + + + t_container * __container() const throw() {return m_container;} + private: + void __init() throw() {m_container = NULL; m_ptr = NULL;} + + template + void __init(const rcptr_t & p_source) throw() { + m_container = p_source.__container(); + m_ptr = &*p_source; + if (m_container != NULL) m_container->add_ref(); + } + template + void __copy(const rcptr_t & p_source) throw() { + __set_from_cast(p_source.__container(),&*p_source); + } + void on_new(t_container_impl * p_container) throw() { + this->release(); + p_container->add_ref(); + this->m_ptr = &p_container->m_object; + this->m_container = p_container; + } + + t_container * m_container; + t_object * m_ptr; + }; + + template + rcptr_t rcnew_t() { + rcptr_t temp; + temp.new_t(); + return temp; + } + + template + rcptr_t rcnew_t(t_param1 const & p_param1) { + rcptr_t temp; + temp.new_t(p_param1); + return temp; + } + + template + rcptr_t rcnew_t(t_param1 const & p_param1,t_param2 const & p_param2) { + rcptr_t temp; + temp.new_t(p_param1,p_param2); + return temp; + } + + template + rcptr_t rcnew_t(t_param1 const & p_param1,t_param2 const & p_param2,t_param3 const & p_param3) { + rcptr_t temp; + temp.new_t(p_param1,p_param2,p_param3); + return temp; + } + + template + rcptr_t rcnew_t(t_param1 const & p_param1,t_param2 const & p_param2,t_param3 const & p_param3,t_param4 const & p_param4) { + rcptr_t temp; + temp.new_t(p_param1,p_param2,p_param3,p_param4); + return temp; + } + + template + rcptr_t rcnew_t(t_param1 const & p_param1,t_param2 const & p_param2,t_param3 const & p_param3,t_param4 const & p_param4,t_param5 const & p_param5) { + rcptr_t temp; + temp.new_t(p_param1,p_param2,p_param3,p_param4,p_param5); + return temp; + } + + template + rcptr_t rcnew_t(t_param1 const & p_param1,t_param2 const & p_param2,t_param3 const & p_param3,t_param4 const & p_param4,t_param5 const & p_param5,t_param6 const & p_param6) { + rcptr_t temp; + temp.new_t(p_param1,p_param2,p_param3,p_param4,p_param5,p_param6); + return temp; + } + + class traits_rcptr : public traits_default { + public: + enum { realloc_safe = true, constructor_may_fail = false }; + }; + + template class traits_t > : public traits_rcptr {}; +} \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/pfc/ref_counter.h b/tools/vio2sf/src/foobar/pfc/ref_counter.h new file mode 100644 index 000000000..539e4bc3a --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/ref_counter.h @@ -0,0 +1,122 @@ +namespace pfc { + class counter { + public: + counter(long p_val = 0) : m_val(p_val) {} +#ifdef _WINDOWS + long operator++() throw() {return InterlockedIncrement(&m_val);} + long operator--() throw() {return InterlockedDecrement(&m_val);} + long operator++(int) throw() {return InterlockedIncrement(&m_val)-1;} + long operator--(int) throw() {return InterlockedDecrement(&m_val)+1;} +#else + long operator++() {return ++m_val;} + long operator--() {return --m_val;} + long operator++(int) {return m_val++;} + long operator--(int) {return m_val--;} +#pragma message("PORTME") +#endif + operator long() const throw() {return m_val;} + typedef long t_val; + private: + volatile long m_val; + }; + + typedef counter refcounter; + + class NOVTABLE refcounted_object_root + { + public: + void refcount_add_ref() throw() {++m_counter;} + void refcount_release() throw() {if (--m_counter == 0) delete this;} + void _refcount_release_temporary() throw() {--m_counter;}//for internal use only! + protected: + refcounted_object_root() {} + virtual ~refcounted_object_root() {} + private: + refcounter m_counter; + }; + + template + class refcounted_object_ptr_t { + private: + typedef refcounted_object_ptr_t t_self; + public: + inline refcounted_object_ptr_t() throw() : m_ptr(NULL) {} + inline refcounted_object_ptr_t(T* p_ptr) throw() : m_ptr(NULL) {copy(p_ptr);} + inline refcounted_object_ptr_t(const t_self & p_source) throw() : m_ptr(NULL) {copy(p_source);} + + template + inline refcounted_object_ptr_t(t_source * p_ptr) throw() : m_ptr(NULL) {copy(p_ptr);} + + template + inline refcounted_object_ptr_t(const refcounted_object_ptr_t & p_source) throw() : m_ptr(NULL) {copy(p_source);} + + inline ~refcounted_object_ptr_t() throw() {if (m_ptr != NULL) m_ptr->refcount_release();} + + template + inline void copy(t_source * p_ptr) throw() { + T* torel = pfc::replace_t(m_ptr,pfc::safe_ptr_cast(p_ptr)); + if (m_ptr != NULL) m_ptr->refcount_add_ref(); + if (torel != NULL) torel->refcount_release(); + + } + + template + inline void copy(const refcounted_object_ptr_t & p_source) throw() {copy(p_source.get_ptr());} + + + inline const t_self & operator=(const t_self & p_source) throw() {copy(p_source); return *this;} + inline const t_self & operator=(T * p_ptr) throw() {copy(p_ptr); return *this;} + + template inline t_self & operator=(const refcounted_object_ptr_t & p_source) throw() {copy(p_source); return *this;} + template inline t_self & operator=(t_source * p_ptr) throw() {copy(p_ptr); return *this;} + + inline void release() throw() { + T * temp = pfc::replace_t(m_ptr,(T*)NULL); + if (temp != NULL) temp->refcount_release(); + } + + + inline T& operator*() const throw() {return *m_ptr;} + + inline T* operator->() const throw() {PFC_ASSERT(m_ptr != NULL);return m_ptr;} + + inline T* get_ptr() const throw() {return m_ptr;} + + inline bool is_valid() const throw() {return m_ptr != NULL;} + inline bool is_empty() const throw() {return m_ptr == NULL;} + + inline bool operator==(const t_self & p_item) const throw() {return m_ptr == p_item.get_ptr();} + inline bool operator!=(const t_self & p_item) const throw() {return m_ptr != p_item.get_ptr();} + inline bool operator>(const t_self & p_item) const throw() {return m_ptr > p_item.get_ptr();} + inline bool operator<(const t_self & p_item) const throw() {return m_ptr < p_item.get_ptr();} + + + inline T* __unsafe_duplicate() const throw()//should not be used ! temporary ! + { + if (m_ptr) m_ptr->refcount_add_ref(); + return m_ptr; + } + + inline T* detach() throw() {//should not be used ! temporary ! + T* ret = m_ptr; + m_ptr = 0; + return ret; + } + + inline void attach(T * p_ptr) throw() {//should not be used ! temporary ! + release(); + m_ptr = p_ptr; + } + inline t_self & operator<<(t_self & p_source) throw() {attach(p_source.detach());return *this;} + inline t_self & operator>>(t_self & p_dest) throw() {p_dest.attach(detach());return *this;} + private: + T* m_ptr; + }; + + template + class traits_t > : public traits_default { + public: + enum { realloc_safe = true, constructor_may_fail = false}; + }; + +}; \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/pfc/selftest.cpp b/tools/vio2sf/src/foobar/pfc/selftest.cpp new file mode 100644 index 000000000..ed2271c37 --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/selftest.cpp @@ -0,0 +1,29 @@ +#include "pfc.h" + +static void selftest() //never called, testing done at compile time +{ + pfc::static_assert_t(); + pfc::static_assert_t(); + pfc::static_assert_t(); + pfc::static_assert_t(); + + pfc::static_assert_t(); + pfc::static_assert_t(); + pfc::static_assert_t(); + pfc::static_assert_t(); + + pfc::static_assert_t(); + pfc::static_assert_t(); + + pfc::static_assert_t(); + pfc::static_assert_t(); + + pfc::static_assert_t(); + + pfc::static_assert_t(); + + /*typedef pfc::avltree_t t_asdf; + t_asdf asdf; asdf.add_item(1); + t_asdf::iterator iter = asdf._first_var(); + t_asdf::const_iterator iter2 = asdf._first_var();*/ +} \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/pfc/sort.cpp b/tools/vio2sf/src/foobar/pfc/sort.cpp new file mode 100644 index 000000000..2849992b6 --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/sort.cpp @@ -0,0 +1,263 @@ +#include "pfc.h" + +#if defined(_M_IX86) || defined(_M_IX64) +#include +#define PFC_HAVE_RDTSC +#endif + +namespace pfc { + +void swap_void(void * item1,void * item2,t_size width) +{ + unsigned char * ptr1 = (unsigned char*)item1, * ptr2 = (unsigned char*)item2; + t_size n; + unsigned char temp; + for(n=0;n done; + done.set_size(done_size); + pfc::memset_t(done,(unsigned char)0); + t_size n; + for(n=0;nn); + assert(n done; + done.set_size(done_size); + pfc::memset_t(done,(unsigned char)0); + t_size n; + for(n=0;nn); + assert(n 0) pfc::swap_t(p_elem1,p_elem2); +} + + +#ifdef PFC_HAVE_RDTSC +static inline t_uint64 uniqueVal() {return __rdtsc();} +#else +static counter::t_val uniqueVal() { + static counter c; return ++c; +} +#endif + +static t_size myrand(t_size count) { + static_assert(); + + t_uint64 val; + val = (t_uint64) rand() | (t_uint64)( (t_uint32)rand() << 16 ); + + val ^= uniqueVal(); + + return (t_size)(val % count); +} + +inline static t_size __pivot_helper(pfc::sort_callback & p_callback,t_size const p_base,t_size const p_count) { + PFC_ASSERT(p_count > 2); + + //t_size val1 = p_base, val2 = p_base + (p_count / 2), val3 = p_base + (p_count - 1); + + t_size val1 = myrand(p_count), val2 = myrand(p_count-1), val3 = myrand(p_count-2); + if (val2 >= val1) val2++; + if (val3 >= val1) val3++; + if (val3 >= val2) val3++; + + val1 += p_base; val2 += p_base; val3 += p_base; + + __sort_2elem_helper(p_callback,val1,val2); + __sort_2elem_helper(p_callback,val1,val3); + __sort_2elem_helper(p_callback,val2,val3); + + return val2; +} + +static void newsort(pfc::sort_callback & p_callback,t_size const p_base,t_size const p_count) { + if (p_count <= 4) { + squaresort(p_callback,p_base,p_count); + return; + } + + t_size pivot = __pivot_helper(p_callback,p_base,p_count); + + { + const t_size target = p_base + p_count - 1; + if (pivot != target) { + p_callback.swap(pivot,target); pivot = target; + } + } + + + t_size partition = p_base; + { + bool asdf = false; + for(t_size walk = p_base; walk < pivot; ++walk) { + const int comp = p_callback.compare(walk,pivot); + bool trigger = false; + if (comp == 0) { + trigger = asdf; + asdf = !asdf; + } else if (comp < 0) { + trigger = true; + } + if (trigger) { + if (partition != walk) p_callback.swap(partition,walk); + partition++; + } + } + } + if (pivot != partition) { + p_callback.swap(pivot,partition); pivot = partition; + } + + newsort(p_callback,p_base,pivot-p_base); + newsort(p_callback,pivot+1,p_count-(pivot+1-p_base)); +} + +void sort(pfc::sort_callback & p_callback,t_size p_num) { + srand((unsigned int)(uniqueVal() ^ p_num)); + newsort(p_callback,0,p_num); +} + + +void sort_void(void * base,t_size num,t_size width,int (*comp)(const void *, const void *) ) +{ + sort_void_ex(base,num,width,comp,swap_void); +} + + + + +sort_callback_stabilizer::sort_callback_stabilizer(sort_callback & p_chain,t_size p_count) +: m_chain(p_chain) +{ + m_order.set_size(p_count); + t_size n; + for(n=0;n + class reorder_callback_impl_t : public reorder_callback + { + public: + reorder_callback_impl_t(t_container & p_data) : m_data(p_data) {} + void swap(t_size p_index1,t_size p_index2) + { + pfc::swap_t(m_data[p_index1],m_data[p_index2]); + } + private: + t_container & m_data; + }; + + class reorder_callback_impl_delta : public reorder_callback + { + public: + reorder_callback_impl_delta(reorder_callback & p_data,t_size p_delta) : m_data(p_data), m_delta(p_delta) {} + void swap(t_size p_index1,t_size p_index2) + { + m_data.swap(p_index1+m_delta,p_index2+m_delta); + } + private: + reorder_callback & m_data; + t_size m_delta; + }; + + template + void reorder_t(t_container & p_data,const t_size * p_order,t_size p_count) + { + reorder(reorder_callback_impl_t(p_data),p_order,p_count); + } + + template + void reorder_partial_t(t_container & p_data,t_size p_base,const t_size * p_order,t_size p_count) + { + reorder(reorder_callback_impl_delta(reorder_callback_impl_t(p_data),p_base),p_order,p_count); + } + + template + class reorder_callback_impl_ptr_t : public reorder_callback + { + public: + reorder_callback_impl_ptr_t(T * p_data) : m_data(p_data) {} + void swap(t_size p_index1,t_size p_index2) + { + pfc::swap_t(m_data[p_index1],m_data[p_index2]); + } + private: + T* m_data; + }; + + + template + void reorder_ptr_t(T* p_data,const t_size * p_order,t_size p_count) + { + reorder(reorder_callback_impl_ptr_t(p_data),p_order,p_count); + } + + + + class NOVTABLE sort_callback + { + public: + virtual int compare(t_size p_index1, t_size p_index2) const = 0; + virtual void swap(t_size p_index1, t_size p_index2) = 0; + void swap_check(t_size p_index1, t_size p_index2) {if (compare(p_index1,p_index2) > 0) swap(p_index1,p_index2);} + }; + + class sort_callback_stabilizer : public sort_callback + { + public: + sort_callback_stabilizer(sort_callback & p_chain,t_size p_count); + virtual int compare(t_size p_index1, t_size p_index2) const; + virtual void swap(t_size p_index1, t_size p_index2); + private: + sort_callback & m_chain; + array_t m_order; + }; + + void sort(sort_callback & p_callback,t_size p_count); + void sort_stable(sort_callback & p_callback,t_size p_count); + + void sort_void_ex(void *base,t_size num,t_size width, int (*comp)(const void *, const void *),void (*swap)(void *, void *, t_size) ); + void sort_void(void * base,t_size num,t_size width,int (*comp)(const void *, const void *) ); + + template + class sort_callback_impl_simple_wrap_t : public sort_callback + { + public: + sort_callback_impl_simple_wrap_t(t_container & p_data, t_compare p_compare) : m_data(p_data), m_compare(p_compare) {} + int compare(t_size p_index1, t_size p_index2) const + { + return m_compare(m_data[p_index1],m_data[p_index2]); + } + + void swap(t_size p_index1, t_size p_index2) + { + swap_t(m_data[p_index1],m_data[p_index2]); + } + private: + t_container & m_data; + t_compare m_compare; + }; + + template + class sort_callback_impl_auto_wrap_t : public sort_callback + { + public: + sort_callback_impl_auto_wrap_t(t_container & p_data) : m_data(p_data) {} + int compare(t_size p_index1, t_size p_index2) const + { + return compare_t(m_data[p_index1],m_data[p_index2]); + } + + void swap(t_size p_index1, t_size p_index2) + { + swap_t(m_data[p_index1],m_data[p_index2]); + } + private: + t_container & m_data; + }; + + template + class sort_callback_impl_permutation_wrap_t : public sort_callback + { + public: + sort_callback_impl_permutation_wrap_t(const t_container & p_data, t_compare p_compare,t_permutation const & p_permutation) : m_data(p_data), m_compare(p_compare), m_permutation(p_permutation) {} + int compare(t_size p_index1, t_size p_index2) const + { + return m_compare(m_data[m_permutation[p_index1]],m_data[m_permutation[p_index2]]); + } + + void swap(t_size p_index1, t_size p_index2) + { + swap_t(m_permutation[p_index1],m_permutation[p_index2]); + } + private: + const t_container & m_data; + t_compare m_compare; + t_permutation const & m_permutation; + }; + + template + static void sort_t(t_container & p_data,t_compare p_compare,t_size p_count) + { + sort(sort_callback_impl_simple_wrap_t(p_data,p_compare),p_count); + } + + template + static void sort_stable_t(t_container & p_data,t_compare p_compare,t_size p_count) + { + sort_stable(sort_callback_impl_simple_wrap_t(p_data,p_compare),p_count); + } + + template + static void sort_get_permutation_t(const t_container & p_data,t_compare p_compare,t_size p_count,t_permutation const & p_permutation) + { + sort(sort_callback_impl_permutation_wrap_t(p_data,p_compare,p_permutation),p_count); + } + + template + static void sort_stable_get_permutation_t(const t_container & p_data,t_compare p_compare,t_size p_count,t_permutation const & p_permutation) + { + sort_stable(sort_callback_impl_permutation_wrap_t(p_data,p_compare,p_permutation),p_count); + } + +} diff --git a/tools/vio2sf/src/foobar/pfc/stdafx.cpp b/tools/vio2sf/src/foobar/pfc/stdafx.cpp new file mode 100644 index 000000000..72044fc8b --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/stdafx.cpp @@ -0,0 +1,2 @@ +//cpp used to generate precompiled header +#include "pfc.h" \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/pfc/string.cpp b/tools/vio2sf/src/foobar/pfc/string.cpp new file mode 100644 index 000000000..14c086a59 --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/string.cpp @@ -0,0 +1,850 @@ +#include "pfc.h" + +namespace pfc { + +void string_receiver::add_char(t_uint32 p_char) +{ + char temp[8]; + t_size len = utf8_encode_char(p_char,temp); + if (len>0) add_string(temp,len); +} + +void string_base::skip_trailing_char(unsigned skip) +{ + const char * str = get_ptr(); + t_size ptr,trunc; + bool need_trunc = false; + for(ptr=0;str[ptr];) + { + unsigned c; + t_size delta = utf8_decode_char(str+ptr,c); + if (delta==0) break; + if (c==skip) + { + need_trunc = true; + trunc = ptr; + } + else + { + need_trunc = false; + } + ptr += delta; + } + if (need_trunc) truncate(trunc); +} + +format_time::format_time(t_uint64 p_seconds) { + t_uint64 length = p_seconds; + unsigned weeks,days,hours,minutes,seconds; + + weeks = (unsigned)( ( length / (60*60*24*7) ) ); + days = (unsigned)( ( length / (60*60*24) ) % 7 ); + hours = (unsigned) ( ( length / (60 * 60) ) % 24); + minutes = (unsigned) ( ( length / (60 ) ) % 60 ); + seconds = (unsigned) ( ( length ) % 60 ); + + if (weeks) { + m_buffer << weeks << "wk "; + } + if (days || weeks) { + m_buffer << days << "d "; + } + if (hours || days || weeks) { + m_buffer << hours << ":" << format_uint(minutes,2) << ":" << format_uint(seconds,2); + } else { + m_buffer << minutes << ":" << format_uint(seconds,2); + } +} + +bool is_path_separator(unsigned c) +{ + return c=='\\' || c=='/' || c=='|' || c==':'; +} + +bool is_path_bad_char(unsigned c) +{ +#ifdef _WINDOWS + return c=='\\' || c=='/' || c=='|' || c==':' || c=='*' || c=='?' || c=='\"' || c=='>' || c=='<'; +#else +#error portme +#endif +} + + + +char * strdup_n(const char * src,t_size len) +{ + len = strlen_max(src,len); + char * ret = (char*)malloc(len+1); + if (ret) + { + memcpy(ret,src,len); + ret[len]=0; + } + return ret; +} + +string_filename::string_filename(const char * fn) +{ + fn += pfc::scan_filename(fn); + const char * ptr=fn,*dot=0; + while(*ptr && *ptr!='?') + { + if (*ptr=='.') dot=ptr; + ptr++; + } + + if (dot && dot>fn) set_string(fn,dot-fn); + else set_string(fn); +} + +string_filename_ext::string_filename_ext(const char * fn) +{ + fn += pfc::scan_filename(fn); + const char * ptr = fn; + while(*ptr && *ptr!='?') ptr++; + set_string(fn,ptr-fn); +} + +string_extension::string_extension(const char * src) +{ + buffer[0]=0; + const char * start = src + pfc::scan_filename(src); + const char * end = start + strlen(start); + const char * ptr = end-1; + while(ptr>start && *ptr!='.') + { + if (*ptr=='?') end=ptr; + ptr--; + } + + if (ptr>=start && *ptr=='.') + { + ptr++; + t_size len = end-ptr; + if (len temp; + t_size outptr; + + if (out_max == 0) return; + out_max--;//for null terminator + + outptr = 0; + + if (outptr == out_max) {out[outptr]=0;return;} + + if (val<0) {out[outptr++] = '-'; val = -val;} + else if (b_sign) {out[outptr++] = '+';} + + if (outptr == out_max) {out[outptr]=0;return;} + + + { + double powval = pow((double)10.0,(double)precision); + temp << (t_int64)floor(val * powval + 0.5); + //_i64toa(blargh,temp,10); + } + + const t_size temp_len = temp.length(); + if (temp_len <= precision) + { + out[outptr++] = '0'; + if (outptr == out_max) {out[outptr]=0;return;} + out[outptr++] = '.'; + if (outptr == out_max) {out[outptr]=0;return;} + t_size d; + for(d=precision-temp_len;d;d--) + { + out[outptr++] = '0'; + if (outptr == out_max) {out[outptr]=0;return;} + } + for(d=0;d='0' && *src<='9') + { + int d = *src - '0'; + val = val * 10 + d; + if (got_dot) div--; + src++; + } + else if (*src=='.' || *src==',') + { + if (got_dot) break; + got_dot = true; + src++; + } + else if (*src=='E' || *src=='e') + { + src++; + div += atoi(src); + break; + } + else break; + } + if (neg) val = -val; + return (double) val * pow(10.0,(double)div); +} + +double string_to_float(const char * src,t_size max) { + //old function wants an oldstyle nullterminated string, and i don't currently care enough to rewrite it as it works appropriately otherwise + char blargh[128]; + if (max > 127) max = 127; + t_size walk; + for(walk = 0; walk < max && src[walk]; walk++) blargh[walk] = src[walk]; + blargh[walk] = 0; + return pfc_string_to_float_internal(blargh); +} + + + +void string_base::convert_to_lower_ascii(const char * src,char replace) +{ + reset(); + PFC_ASSERT(replace>0); + while(*src) + { + unsigned c; + t_size delta = utf8_decode_char(src,c); + if (delta==0) {c = replace; delta = 1;} + else if (c>=0x80) c = replace; + add_byte((char)c); + src += delta; + } +} + +void convert_to_lower_ascii(const char * src,t_size max,char * out,char replace) +{ + t_size ptr = 0; + PFC_ASSERT(replace>0); + while(ptr=0x80) c = replace; + *(out++) = (char)c; + ptr += delta; + } + *out = 0; +} + +t_size strstr_ex(const char * p_string,t_size p_string_len,const char * p_substring,t_size p_substring_len) throw() +{ + p_string_len = strlen_max(p_string,p_string_len); + p_substring_len = strlen_max(p_substring,p_substring_len); + t_size index = 0; + while(index + p_substring_len <= p_string_len) + { + if (memcmp(p_string+index,p_substring,p_substring_len) == 0) return index; + t_size delta = utf8_char_len(p_string+index,p_string_len - index); + if (delta == 0) break; + index += delta; + } + return ~0; +} + +unsigned atoui_ex(const char * p_string,t_size p_string_len) +{ + unsigned ret = 0; t_size ptr = 0; + while(ptr= '0' && c <= '9' ) ) break; + ret = ret * 10 + (unsigned)( c - '0' ); + ptr++; + } + return ret; +} + +int strcmp_ex(const char* p1,t_size n1,const char* p2,t_size n2) +{ + t_size idx = 0; + n1 = strlen_max(p1,n1); n2 = strlen_max(p2,n2); + for(;;) + { + if (idx == n1 && idx == n2) return 0; + else if (idx == n1) return -1;//end of param1 + else if (idx == n2) return 1;//end of param2 + + char c1 = p1[idx], c2 = p2[idx]; + if (c1c2) return 1; + + idx++; + } +} + +t_uint64 atoui64_ex(const char * src,t_size len) { + len = strlen_max(src,len); + t_uint64 ret = 0, mul = 1; + t_size ptr = len; + t_size start = 0; +// start += skip_spacing(src+start,len-start); + + while(ptr>start) + { + char c = src[--ptr]; + if (c>='0' && c<='9') + { + ret += (c-'0') * mul; + mul *= 10; + } + else + { + ret = 0; + mul = 1; + } + } + return ret; +} + + +t_int64 atoi64_ex(const char * src,t_size len) +{ + len = strlen_max(src,len); + t_int64 ret = 0, mul = 1; + t_size ptr = len; + t_size start = 0; + bool neg = false; +// start += skip_spacing(src+start,len-start); + if (start < len && src[start] == '-') {neg = true; start++;} +// start += skip_spacing(src+start,len-start); + + while(ptr>start) + { + char c = src[--ptr]; + if (c>='0' && c<='9') + { + ret += (c-'0') * mul; + mul *= 10; + } + else + { + ret = 0; + mul = 1; + } + } + return neg ? -ret : ret; +} + +int stricmp_ascii_ex(const char * const s1,t_size const len1,const char * const s2,t_size const len2) throw() { + t_size walk1 = 0, walk2 = 0; + for(;;) { + char c1 = (walk1 < len1) ? s1[walk1] : 0; + char c2 = (walk2 < len2) ? s2[walk2] : 0; + c1 = ascii_tolower(c1); c2 = ascii_tolower(c2); + if (c1c2) return 1; + else if (c1 == 0) return 0; + walk1++; + walk2++; + } + +} +int stricmp_ascii(const char * s1,const char * s2) throw() { + for(;;) { + char c1 = ascii_tolower(*s1), c2 = ascii_tolower(*s2); + if (c1c2) return 1; + else if (c1 == 0) return 0; + s1++; + s2++; + } +} + +format_float::format_float(double p_val,unsigned p_width,unsigned p_prec) +{ + char temp[64]; + float_to_string(temp,64,p_val,p_prec,false); + temp[63] = 0; + t_size len = strlen(temp); + if (len < p_width) + m_buffer.add_chars(' ',p_width-len); + m_buffer += temp; +} + +static char format_hex_char(unsigned p_val) +{ + PFC_ASSERT(p_val < 16); + return (p_val < 10) ? p_val + '0' : p_val - 10 + 'A'; +} + +format_hex::format_hex(t_uint64 p_val,unsigned p_width) +{ + if (p_width > 16) p_width = 16; + else if (p_width == 0) p_width = 1; + char temp[16]; + unsigned n; + for(n=0;n<16;n++) + { + temp[15-n] = format_hex_char((unsigned)(p_val & 0xF)); + p_val >>= 4; + } + + for(n=0;n<16 && temp[n] == '0';n++) {} + + if (n > 16 - p_width) n = 16 - p_width; + + char * out = m_buffer; + for(;n<16;n++) + *(out++) = temp[n]; + *out = 0; +} + +static char format_hex_char_lowercase(unsigned p_val) +{ + PFC_ASSERT(p_val < 16); + return (p_val < 10) ? p_val + '0' : p_val - 10 + 'a'; +} + +format_hex_lowercase::format_hex_lowercase(t_uint64 p_val,unsigned p_width) +{ + if (p_width > 16) p_width = 16; + else if (p_width == 0) p_width = 1; + char temp[16]; + unsigned n; + for(n=0;n<16;n++) + { + temp[15-n] = format_hex_char_lowercase((unsigned)(p_val & 0xF)); + p_val >>= 4; + } + + for(n=0;n<16 && temp[n] == '0';n++) {} + + if (n > 16 - p_width) n = 16 - p_width; + + char * out = m_buffer; + for(;n<16;n++) + *(out++) = temp[n]; + *out = 0; +} + +format_uint::format_uint(t_uint64 val,unsigned p_width,unsigned p_base) +{ + + enum {max_width = tabsize(m_buffer) - 1}; + + if (p_width > max_width) p_width = max_width; + else if (p_width == 0) p_width = 1; + + char temp[max_width]; + + unsigned n; + for(n=0;n max_width - p_width) n = max_width - p_width; + + char * out = m_buffer; + + for(;n max_width) p_width = max_width; + else if (p_width == 0) p_width = 1; + + if (neg && p_width > 1) p_width --; + + char temp[max_width]; + + unsigned n; + for(n=0;n max_width - p_width) n = max_width - p_width; + + char * out = m_buffer; + + if (neg) *(out++) = '-'; + + for(;n 0 && p_spacing != 0) m_formatter << p_spacing; + m_formatter << format_hex_lowercase(buffer[n],2); + } +} + +format_hexdump::format_hexdump(const void * p_buffer,t_size p_bytes,const char * p_spacing) +{ + t_size n; + const t_uint8 * buffer = (const t_uint8*)p_buffer; + for(n=0;n 0 && p_spacing != 0) m_formatter << p_spacing; + m_formatter << format_hex(buffer[n],2); + } +} + + + +string_replace_extension::string_replace_extension(const char * p_path,const char * p_ext) +{ + m_data = p_path; + t_size dot = m_data.find_last('.'); + if (dot < m_data.scan_filename()) + {//argh + m_data += "."; + m_data += p_ext; + } + else + { + m_data.truncate(dot+1); + m_data += p_ext; + } +} + +string_directory::string_directory(const char * p_path) +{ + t_size ptr = scan_filename(p_path); + if (ptr > 0) m_data.set_string(p_path,ptr-1); +} + +t_size scan_filename(const char * ptr) +{ + t_size n; + t_size _used = strlen(ptr); + for(n=_used-1;n!=~0;n--) + { + if (is_path_separator(ptr[n])) return n+1; + } + return 0; +} + + + +t_size string_find_first(const char * p_string,char p_tofind,t_size p_start) { + return string_find_first_ex(p_string,infinite,&p_tofind,1,p_start); +} +t_size string_find_last(const char * p_string,char p_tofind,t_size p_start) { + return string_find_last_ex(p_string,infinite,&p_tofind,1,p_start); +} +t_size string_find_first(const char * p_string,const char * p_tofind,t_size p_start) { + return string_find_first_ex(p_string,infinite,p_tofind,infinite,p_start); +} +t_size string_find_last(const char * p_string,const char * p_tofind,t_size p_start) { + return string_find_last_ex(p_string,infinite,p_tofind,infinite,p_start); +} + +t_size string_find_first_ex(const char * p_string,t_size p_string_length,char p_tofind,t_size p_start) { + return string_find_first_ex(p_string,p_string_length,&p_tofind,1,p_start); +} +t_size string_find_last_ex(const char * p_string,t_size p_string_length,char p_tofind,t_size p_start) { + return string_find_last_ex(p_string,p_string_length,&p_tofind,1,p_start); +} +t_size string_find_first_ex(const char * p_string,t_size p_string_length,const char * p_tofind,t_size p_tofind_length,t_size p_start) { + p_string_length = strlen_max(p_string,p_string_length); p_tofind_length = strlen_max(p_tofind,p_tofind_length); + if (p_string_length >= p_tofind_length) { + t_size max = p_string_length - p_tofind_length; + for(t_size walk = p_start; walk <= max; walk++) { + if (_strcmp_partial_ex(p_string+walk,p_string_length-walk,p_tofind,p_tofind_length) == 0) return walk; + } + } + return infinite; +} +t_size string_find_last_ex(const char * p_string,t_size p_string_length,const char * p_tofind,t_size p_tofind_length,t_size p_start) { + p_string_length = strlen_max(p_string,p_string_length); p_tofind_length = strlen_max(p_tofind,p_tofind_length); + if (p_string_length >= p_tofind_length) { + t_size max = min_t(p_string_length - p_tofind_length,p_start); + for(t_size walk = max; walk != (t_size)(-1); walk--) { + if (_strcmp_partial_ex(p_string+walk,p_string_length-walk,p_tofind,p_tofind_length) == 0) return walk; + } + } + return infinite; +} + + +bool string_is_numeric(const char * p_string,t_size p_length) throw() { + bool retval = false; + for(t_size walk = 0; walk < p_length && p_string[walk] != 0; walk++) { + if (!char_is_numeric(p_string[walk])) {retval = false; break;} + retval = true; + } + return retval; +} + + +void string_base::fix_dir_separator(char p_char) { + t_size length = get_length(); + if (length == 0 || get_ptr()[length-1] != p_char) add_byte(p_char); +} + +bool is_multiline(const char * p_string,t_size p_len) { + for(t_size n = 0; n < p_len && p_string[n]; n++) { + switch(p_string[n]) { + case '\r': + case '\n': + return true; + } + } + return false; +} + +static t_uint64 pow10_helper(unsigned p_extra) { + t_uint64 ret = 1; + for(unsigned n = 0; n < p_extra; n++ ) ret *= 10; + return ret; +} + +format_time_ex::format_time_ex(double p_seconds,unsigned p_extra) { + t_uint64 pow10 = pow10_helper(p_extra); + t_uint64 ticks = pfc::rint64(pow10 * p_seconds); + + m_buffer << pfc::format_time(ticks / pow10); + if (p_extra>0) { + m_buffer << "." << pfc::format_uint(ticks % pow10, p_extra); + } +} + +t_uint32 charLower(t_uint32 param) +{ + if (param<128) + { + if (param>='A' && param<='Z') param += 'a' - 'A'; + return param; + } +#ifdef WIN32 + else if (param<0x10000) + { + unsigned ret; +#ifdef UNICODE + ret = (unsigned)CharLowerW((WCHAR*)param); +#else +#error Nein! Verboten! +#endif + return ret; + } + else return param; +#else + else + { + setlocale(LC_CTYPE,""); + return towlower(param); + } +#endif +} + +t_uint32 charUpper(t_uint32 param) +{ + if (param<128) + { + if (param>='a' && param<='z') param += 'A' - 'a'; + return param; + } +#ifdef WIN32 + else if (param<0x10000) + { + unsigned ret; +#ifdef UNICODE + ret = (unsigned)CharUpperW((WCHAR*)param); +#else +#error Nein! Verboten! +#endif + return ret; + } + else return param; +#else + else + { + setlocale(LC_CTYPE,""); + return towupper(param); + } +#endif +} + +void stringToUpperAppend(string_base & out, const char * src, t_size len) { + while(len && *src) { + unsigned c; t_size d; + d = utf8_decode_char(src,c,len); + if (d==0 || d>len) break; + out.add_char(charUpper(c)); + src+=d; + len-=d; + } +} +void stringToLowerAppend(string_base & out, const char * src, t_size len) { + while(len && *src) { + unsigned c; t_size d; + d = utf8_decode_char(src,c,len); + if (d==0 || d>len) break; + out.add_char(charLower(c)); + src+=d; + len-=d; + } +} + +int stringCompareCaseInsensitive(const char * s1, const char * s2) { + for(;;) { + unsigned c1, c2; t_size d1, d2; + d1 = utf8_decode_char(s1,c1); + d2 = utf8_decode_char(s2,c2); + if (d1 == 0 && d2 == 0) return 0; + else if (d1 == 0) return -1; + else if (d2 == 0) return 1; + else { + c1 = charLower(c1); c2 = charLower(c2); + if (c1 < c2) return -1; + else if (c1 > c2) return 1; + } + s1 += d1; s2 += d2; + } +} + +format_file_size_short::format_file_size_short(t_uint64 size) { + t_uint64 scale = 1; + const char * unit = "B"; + const char * const unitTable[] = {"B","KB","MB","GB","TB"}; + for(t_size walk = 1; walk < tabsize(unitTable); ++walk) { + t_uint64 next = scale * 1024; + if (size < next) break; + scale = next; unit = unitTable[walk]; + } + *this << ( size / scale ); + + if (scale > 1 && length() < 3) { + t_size digits = 3 - length(); + const t_uint64 mask = pow_int(10,digits); + t_uint64 remaining = ( (size * mask / scale) % mask ); + while(digits > 0 && (remaining % 10) == 0) { + remaining /= 10; --digits; + } + if (digits > 0) { + *this << "." << format_uint(remaining, (t_uint32)digits); + } + } + *this << unit; + m_scale = scale; +} + +bool string_base::truncate_eol(t_size start) +{ + const char * ptr = get_ptr() + start; + for(t_size n=start;*ptr;n++) + { + if (*ptr==10 || *ptr==13) + { + truncate(n); + return true; + } + ptr++; + } + return false; +} + +bool string_base::fix_eol(const char * append,t_size start) +{ + const bool rv = truncate_eol(start); + if (rv) add_string(append); + return rv; +} + +bool string_base::limit_length(t_size length_in_chars,const char * append) +{ + bool rv = false; + const char * base = get_ptr(), * ptr = base; + while(length_in_chars && utf8_advance(ptr)) length_in_chars--; + if (length_in_chars==0) + { + truncate(ptr-base); + add_string(append); + rv = true; + } + return rv; +} + +} //namespace pfc diff --git a/tools/vio2sf/src/foobar/pfc/string.h b/tools/vio2sf/src/foobar/pfc/string.h new file mode 100644 index 000000000..f7ae3cc4a --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/string.h @@ -0,0 +1,854 @@ +#ifndef _PFC_STRING_H_ +#define _PFC_STRING_H_ + +namespace pfc { + + class NOVTABLE string_receiver { + public: + virtual void add_string(const char * p_string,t_size p_string_size = infinite) = 0; + + void add_char(t_uint32 c);//adds unicode char to the string + void add_byte(char c) {add_string(&c,1);} + void add_chars(t_uint32 p_char,t_size p_count) {for(;p_count;p_count--) add_char(p_char);} + protected: + string_receiver() {} + ~string_receiver() {} + }; + + t_size scan_filename(const char * ptr); + + bool is_path_separator(unsigned c); + bool is_path_bad_char(unsigned c); + bool is_valid_utf8(const char * param,t_size max = infinite); + bool is_lower_ascii(const char * param); + bool is_multiline(const char * p_string,t_size p_len = infinite); + bool has_path_bad_chars(const char * param); + void recover_invalid_utf8(const char * src,char * out,unsigned replace);//out must be enough to hold strlen(char) + 1, or appropiately bigger if replace needs multiple chars + void convert_to_lower_ascii(const char * src,t_size max,char * out,char replace = '?');//out should be at least strlen(src)+1 long + + inline char ascii_tolower(char c) {if (c >= 'A' && c <= 'Z') c += 'a' - 'A'; return c;} + inline char ascii_toupper(char c) {if (c >= 'a' && c <= 'z') c += 'A' - 'a'; return c;} + + t_size string_find_first(const char * p_string,char p_tofind,t_size p_start = 0); //returns infinite if not found + t_size string_find_last(const char * p_string,char p_tofind,t_size p_start = ~0); //returns infinite if not found + t_size string_find_first(const char * p_string,const char * p_tofind,t_size p_start = 0); //returns infinite if not found + t_size string_find_last(const char * p_string,const char * p_tofind,t_size p_start = ~0); //returns infinite if not found + + t_size string_find_first_ex(const char * p_string,t_size p_string_length,char p_tofind,t_size p_start = 0); //returns infinite if not found + t_size string_find_last_ex(const char * p_string,t_size p_string_length,char p_tofind,t_size p_start = ~0); //returns infinite if not found + t_size string_find_first_ex(const char * p_string,t_size p_string_length,const char * p_tofind,t_size p_tofind_length,t_size p_start = 0); //returns infinite if not found + t_size string_find_last_ex(const char * p_string,t_size p_string_length,const char * p_tofind,t_size p_tofind_length,t_size p_start = ~0); //returns infinite if not found + + + template + t_size strlen_max_t(const t_char * ptr,t_size max) { + if (ptr == NULL) return 0; + t_size n = 0; + while(n= '0' && p_char <= '9';} + inline bool char_is_ascii_alpha_upper(char p_char) throw() {return p_char >= 'A' && p_char <= 'Z';} + inline bool char_is_ascii_alpha_lower(char p_char) throw() {return p_char >= 'a' && p_char <= 'z';} + inline bool char_is_ascii_alpha(char p_char) throw() {return char_is_ascii_alpha_lower(p_char) || char_is_ascii_alpha_upper(p_char);} + inline bool char_is_ascii_alphanumeric(char p_char) throw() {return char_is_ascii_alpha(p_char) || char_is_numeric(p_char);} + + unsigned atoui_ex(const char * ptr,t_size max); + t_int64 atoi64_ex(const char * ptr,t_size max); + t_uint64 atoui64_ex(const char * ptr,t_size max); + + t_size strlen_utf8(const char * s,t_size num = ~0) throw();//returns number of characters in utf8 string; num - no. of bytes (optional) + t_size utf8_char_len(const char * s,t_size max = ~0) throw();//returns size of utf8 character pointed by s, in bytes, 0 on error + t_size utf8_char_len_from_header(char c) throw(); + t_size utf8_chars_to_bytes(const char * string,t_size count) throw(); + + t_size strcpy_utf8_truncate(const char * src,char * out,t_size maxbytes); + + t_size utf8_decode_char(const char * src,unsigned & out,t_size src_bytes) throw();//returns length in bytes + t_size utf8_decode_char(const char * src,unsigned & out) throw();//returns length in bytes + + t_size utf8_encode_char(unsigned c,char * out) throw();//returns used length in bytes, max 6 + t_size utf16_decode_char(const wchar_t * p_source,unsigned * p_out,t_size p_source_length = ~0) throw(); + t_size utf16_encode_char(unsigned c,wchar_t * out) throw(); + + + t_size strstr_ex(const char * p_string,t_size p_string_len,const char * p_substring,t_size p_substring_len) throw(); + + + t_size skip_utf8_chars(const char * ptr,t_size count) throw(); + char * strdup_n(const char * src,t_size len); + int stricmp_ascii(const char * s1,const char * s2) throw(); + int stricmp_ascii_ex(const char * s1,t_size len1,const char * s2,t_size len2) throw(); + + int strcmp_ex(const char* p1,t_size n1,const char* p2,t_size n2) throw(); + + unsigned utf8_get_char(const char * src); + + inline bool utf8_advance(const char * & var) throw() { + t_size delta = utf8_char_len(var); + var += delta; + return delta>0; + } + + inline bool utf8_advance(char * & var) throw() { + t_size delta = utf8_char_len(var); + var += delta; + return delta>0; + } + + inline const char * utf8_char_next(const char * src) throw() {return src + utf8_char_len(src);} + inline char * utf8_char_next(char * src) throw() {return src + utf8_char_len(src);} + + class NOVTABLE string_base : public pfc::string_receiver { + public: + virtual const char * get_ptr() const = 0; + virtual void add_string(const char * p_string,t_size p_length = ~0) = 0;//same as string_receiver method + virtual void set_string(const char * p_string,t_size p_length = ~0) {reset();add_string(p_string,p_length);} + virtual void truncate(t_size len)=0; + virtual t_size get_length() const {return strlen(get_ptr());} + virtual char * lock_buffer(t_size p_requested_length) = 0; + virtual void unlock_buffer() = 0; + + inline const char * toString() const {return get_ptr();} + + //! For compatibility with old conventions. + inline t_size length() const {return get_length();} + + inline void reset() {truncate(0);} + + inline bool is_empty() const {return *get_ptr()==0;} + + void skip_trailing_char(unsigned c = ' '); + + bool is_valid_utf8() const {return pfc::is_valid_utf8(get_ptr());} + + void convert_to_lower_ascii(const char * src,char replace = '?'); + + inline const string_base & operator= (const char * src) {set_string(src);return *this;} + inline const string_base & operator+= (const char * src) {add_string(src);return *this;} + inline const string_base & operator= (const string_base & src) {set_string(src);return *this;} + inline const string_base & operator+= (const string_base & src) {add_string(src);return *this;} + + bool operator==(const string_base & p_other) const {return strcmp(*this,p_other) == 0;} + bool operator!=(const string_base & p_other) const {return strcmp(*this,p_other) != 0;} + bool operator>(const string_base & p_other) const {return strcmp(*this,p_other) > 0;} + bool operator<(const string_base & p_other) const {return strcmp(*this,p_other) < 0;} + bool operator>=(const string_base & p_other) const {return strcmp(*this,p_other) >= 0;} + bool operator<=(const string_base & p_other) const {return strcmp(*this,p_other) <= 0;} + + inline operator const char * () const {return get_ptr();} + + t_size scan_filename() const {return pfc::scan_filename(get_ptr());} + + t_size find_first(char p_char,t_size p_start = 0) const {return pfc::string_find_first(get_ptr(),p_char,p_start);} + t_size find_last(char p_char,t_size p_start = ~0) const {return pfc::string_find_last(get_ptr(),p_char,p_start);} + t_size find_first(const char * p_string,t_size p_start = 0) const {return pfc::string_find_first(get_ptr(),p_string,p_start);} + t_size find_last(const char * p_string,t_size p_start = ~0) const {return pfc::string_find_last(get_ptr(),p_string,p_start);} + + void fix_dir_separator(char p_char); + + bool truncate_eol(t_size start = 0); + bool fix_eol(const char * append = " (...)",t_size start = 0); + bool limit_length(t_size length_in_chars,const char * append = " (...)"); + + protected: + string_base() {} + ~string_base() {} + }; + + template + class string_fixed_t : public pfc::string_base { + public: + inline string_fixed_t() {init();} + inline string_fixed_t(const string_fixed_t & p_source) {init(); *this = p_source;} + inline string_fixed_t(const char * p_source) {init(); set_string(p_source);} + + inline const string_fixed_t & operator=(const string_fixed_t & p_source) {set_string(p_source);return *this;} + inline const string_fixed_t & operator=(const char * p_source) {set_string(p_source);return *this;} + + char * lock_buffer(t_size p_requested_length) { + if (p_requested_length >= max_length) return NULL; + memset(m_data,0,sizeof(m_data)); + return m_data; + } + void unlock_buffer() { + m_length = strlen(m_data); + } + + inline operator const char * () const {return m_data;} + + const char * get_ptr() const {return m_data;} + + void add_string(const char * ptr,t_size len) { + len = strlen_max(ptr,len); + if (m_length + len < m_length || m_length + len > max_length) throw pfc::exception_overflow(); + for(t_size n=0;n max_length) len = max_length; + if (m_length > len) { + m_length = len; + m_data[len] = 0; + } + } + t_size get_length() const {return m_length;} + private: + inline void init() { + pfc::static_assert<(max_length>1)>(); + m_length = 0; m_data[0] = 0; + } + t_size m_length; + char m_data[max_length+1]; + }; + + template class t_alloc> + class string8_t : public pfc::string_base { + private: + typedef string8_t t_self; + protected: + pfc::array_t m_data; + t_size used; + + inline void makespace(t_size s) { + if (t_alloc::alloc_prioritizes_speed) { + m_data.set_size(s); + } else { + const t_size old_size = m_data.get_size(); + if (old_size < s) + m_data.set_size(s + 16); + else if (old_size > s + 32) + m_data.set_size(s); + } + } + + inline const char * _get_ptr() const throw() {return used > 0 ? m_data.get_ptr() : "";} + + public: + inline const t_self & operator= (const char * src) {set_string(src);return *this;} + inline const t_self & operator+= (const char * src) {add_string(src);return *this;} + inline const t_self & operator= (const string_base & src) {set_string(src);return *this;} + inline const t_self & operator+= (const string_base & src) {add_string(src);return *this;} + inline const t_self & operator= (const t_self & src) {set_string(src);return *this;} + inline const t_self & operator+= (const t_self & src) {add_string(src);return *this;} + + inline operator const char * () const throw() {return _get_ptr();} + + string8_t() : used(0) {} + string8_t(const char * p_string) : used(0) {set_string(p_string);} + string8_t(const char * p_string,t_size p_length) : used(0) {set_string(p_string,p_length);} + string8_t(const t_self & p_string) : used(0) {set_string(p_string);} + string8_t(const string_base & p_string) : used(0) {set_string(p_string);} + + void prealloc(t_size p_size) {m_data.prealloc(p_size+1);} + + const char * get_ptr() const throw() {return _get_ptr();} + + void add_string(const char * p_string,t_size p_length = ~0); + void set_string(const char * p_string,t_size p_length = ~0); + + void truncate(t_size len) + { + if (used>len) {used=len;m_data[len]=0;makespace(used+1);} + } + + t_size get_length() const throw() {return used;} + + + void set_char(unsigned offset,char c); + + t_size replace_nontext_chars(char p_replace = '_'); + t_size replace_char(unsigned c1,unsigned c2,t_size start = 0); + t_size replace_byte(char c1,char c2,t_size start = 0); + void fix_filename_chars(char def = '_',char leave=0);//replace "bad" characters, leave parameter can be used to keep eg. path separators + void remove_chars(t_size first,t_size count); //slow + void insert_chars(t_size first,const char * src, t_size count);//slow + void insert_chars(t_size first,const char * src); + + //for string_buffer class + char * lock_buffer(t_size n) + { + if (n + 1 == 0) throw exception_overflow(); + makespace(n+1); + pfc::memset_t(m_data,(char)0); + return m_data.get_ptr();; + } + + void unlock_buffer() { + if (m_data.get_size() > 0) { + used=strlen(m_data.get_ptr()); + makespace(used+1); + } + } + + void force_reset() {used=0;m_data.force_reset();} + + inline static void g_swap(t_self & p_item1,t_self & p_item2) { + pfc::swap_t(p_item1.m_data,p_item2.m_data); + pfc::swap_t(p_item1.used,p_item2.used); + } + }; + + typedef string8_t string8; + typedef string8_t string8_fast; + typedef string8_t string8_fast_aggressive; + //for backwards compatibility + typedef string8_t string8_fastalloc; + + + template class t_alloc> class traits_t > : public pfc::combine_traits > > { + public: + enum { + needs_constructor = true, + }; + }; +} + + + +#include "string8_impl.h" + +#define PFC_DEPRECATE_PRINTF PFC_DEPRECATE("Use string8/string_fixed_t with operator<< overloads instead.") + +namespace pfc { + + class string_buffer { + private: + string_base & m_owner; + char * m_buffer; + public: + explicit string_buffer(string_base & p_string,t_size p_requeted_length) : m_owner(p_string) {m_buffer = m_owner.lock_buffer(p_requeted_length);} + ~string_buffer() {m_owner.unlock_buffer();} + operator char* () {return m_buffer;} + }; + + class PFC_DEPRECATE_PRINTF string_printf : public string8_fastalloc { + public: + static void g_run(string_base & out,const char * fmt,va_list list); + void run(const char * fmt,va_list list); + + explicit string_printf(const char * fmt,...); + }; + + class PFC_DEPRECATE_PRINTF string_printf_va : public string8_fastalloc { + public: + string_printf_va(const char * fmt,va_list list); + }; + + class format_time { + public: + format_time(t_uint64 p_seconds); + const char * get_ptr() const {return m_buffer;} + operator const char * () const {return m_buffer;} + protected: + string_fixed_t<127> m_buffer; + }; + + + class format_time_ex { + public: + format_time_ex(double p_seconds,unsigned p_extra = 3); + const char * get_ptr() const {return m_buffer;} + operator const char * () const {return m_buffer;} + private: + string_fixed_t<127> m_buffer; + }; + + + + + class string_filename : public string8 { + public: + explicit string_filename(const char * fn); + }; + + class string_filename_ext : public string8 { + public: + explicit string_filename_ext(const char * fn); + }; + + class string_extension + { + char buffer[32]; + public: + inline const char * get_ptr() const {return buffer;} + inline t_size length() const {return strlen(buffer);} + inline operator const char * () const {return buffer;} + inline const char * toString() const {return buffer;} + explicit string_extension(const char * src); + }; + + + class string_replace_extension + { + public: + string_replace_extension(const char * p_path,const char * p_ext); + inline operator const char*() const {return m_data;} + private: + string8 m_data; + }; + + class string_directory + { + public: + string_directory(const char * p_path); + inline operator const char*() const {return m_data;} + private: + string8 m_data; + }; + + void float_to_string(char * out,t_size out_max,double val,unsigned precision,bool force_sign = false);//doesnt add E+X etc, has internal range limits, useful for storing float numbers as strings without having to bother with international coma/dot settings BS + double string_to_float(const char * src,t_size len = infinite); + + template<> + inline void swap_t(string8 & p_item1,string8 & p_item2) + { + string8::g_swap(p_item1,p_item2); + } + + class format_float + { + public: + format_float(double p_val,unsigned p_width = 0,unsigned p_prec = 7); + format_float(const format_float & p_source) {*this = p_source;} + + inline const char * get_ptr() const {return m_buffer.get_ptr();} + inline const char * toString() const {return m_buffer.get_ptr();} + inline operator const char*() const {return m_buffer.get_ptr();} + private: + string8 m_buffer; + }; + + class format_int + { + public: + format_int(t_int64 p_val,unsigned p_width = 0,unsigned p_base = 10); + format_int(const format_int & p_source) {*this = p_source;} + inline const char * get_ptr() const {return m_buffer;} + inline const char * toString() const {return m_buffer;} + inline operator const char*() const {return m_buffer;} + private: + char m_buffer[64]; + }; + + + class format_uint { + public: + format_uint(t_uint64 p_val,unsigned p_width = 0,unsigned p_base = 10); + format_uint(const format_uint & p_source) {*this = p_source;} + inline const char * get_ptr() const {return m_buffer;} + inline const char * toString() const {return m_buffer;} + inline operator const char*() const {return m_buffer;} + private: + char m_buffer[64]; + }; + + class format_hex + { + public: + format_hex(t_uint64 p_val,unsigned p_width = 0); + format_hex(const format_hex & p_source) {*this = p_source;} + inline const char * get_ptr() const {return m_buffer;} + inline const char * toString() const {return m_buffer;} + inline operator const char*() const {return m_buffer;} + private: + char m_buffer[17]; + }; + + class format_hex_lowercase + { + public: + format_hex_lowercase(t_uint64 p_val,unsigned p_width = 0); + format_hex_lowercase(const format_hex_lowercase & p_source) {*this = p_source;} + inline const char * get_ptr() const {return m_buffer;} + inline operator const char*() const {return m_buffer;} + inline const char * toString() const {return m_buffer;} + private: + char m_buffer[17]; + }; + + + typedef string8_fastalloc string_formatter; + + class format_hexdump_ex { + public: + template format_hexdump_ex(const TWord * buffer, t_size bufLen, const char * spacing = " ") { + for(t_size n = 0; n < bufLen; n++) { + if (n > 0 && spacing != NULL) m_formatter << spacing; + m_formatter << format_hex(buffer[n],sizeof(TWord) * 2); + } + } + inline const char * get_ptr() const {return m_formatter;} + inline operator const char * () const {return m_formatter;} + inline const char * toString() const {return m_formatter;} + private: + string_formatter m_formatter; + }; + + class format_hexdump + { + public: + format_hexdump(const void * p_buffer,t_size p_bytes,const char * p_spacing = " "); + + inline const char * get_ptr() const {return m_formatter;} + inline operator const char * () const {return m_formatter;} + inline const char * toString() const {return m_formatter;} + private: + string_formatter m_formatter; + }; + + class format_hexdump_lowercase + { + public: + format_hexdump_lowercase(const void * p_buffer,t_size p_bytes,const char * p_spacing = " "); + + inline const char * get_ptr() const {return m_formatter;} + inline operator const char * () const {return m_formatter;} + inline const char * toString() const {return m_formatter;} + + private: + string_formatter m_formatter; + }; + + class format_fixedpoint + { + public: + format_fixedpoint(t_int64 p_val,unsigned p_point); + inline const char * get_ptr() const {return m_buffer;} + inline operator const char*() const {return m_buffer;} + inline const char * toString() const {return m_buffer;} + private: + string_formatter m_buffer; + }; + + class format_char { + public: + format_char(char p_char) {m_buffer[0] = p_char; m_buffer[1] = 0;} + inline const char * get_ptr() const {return m_buffer;} + inline operator const char*() const {return m_buffer;} + inline const char * toString() const {return m_buffer;} + private: + char m_buffer[2]; + }; + + template + class format_pad_left { + public: + format_pad_left(t_size p_chars,t_uint32 p_padding /* = ' ' */,const char * p_string,t_size p_string_length = infinite) { + t_size source_len = 0, source_walk = 0; + + while(source_walk < p_string_length && source_len < p_chars) { + unsigned dummy; + t_size delta = pfc::utf8_decode_char(p_string + source_walk, dummy, p_string_length - source_walk); + if (delta == 0) break; + source_len++; + source_walk += delta; + } + + m_buffer.add_string(p_string,source_walk); + m_buffer.add_chars(p_padding,p_chars - source_len); + } + inline const char * get_ptr() const {return m_buffer;} + inline operator const char*() const {return m_buffer;} + inline const char * toString() const {return m_buffer;} + private: + t_stringbuffer m_buffer; + }; + + template + class format_pad_right { + public: + format_pad_right(t_size p_chars,t_uint32 p_padding /* = ' ' */,const char * p_string,t_size p_string_length = infinite) { + t_size source_len = 0, source_walk = 0; + + while(source_walk < p_string_length && source_len < p_chars) { + unsigned dummy; + t_size delta = pfc::utf8_decode_char(p_string + source_walk, dummy, p_string_length - source_walk); + if (delta == 0) break; + source_len++; + source_walk += delta; + } + + m_buffer.add_chars(p_padding,p_chars - source_len); + m_buffer.add_string(p_string,source_walk); + } + inline const char * get_ptr() const {return m_buffer;} + inline operator const char*() const {return m_buffer;} + inline const char * toString() const {return m_buffer;} + private: + t_stringbuffer m_buffer; + }; + + class format_array : public string_formatter { + public: + template format_array(t_source const & source, const char * separator = ", ") { + const t_size count = array_size_t(source); + if (count > 0) { + *this << source[0]; + for(t_size walk = 1; walk < count; ++walk) *this << separator << source[walk]; + } + } + }; + + + class format_file_size_short : public string_formatter { + public: + format_file_size_short(t_uint64 size); + t_uint64 get_used_scale() const {return m_scale;} + private: + t_uint64 m_scale; + }; + +} + +inline pfc::string_base & operator<<(pfc::string_base & p_fmt,const char * p_source) {p_fmt.add_string(p_source); return p_fmt;} +inline pfc::string_base & operator<<(pfc::string_base & p_fmt,t_int32 p_val) {return p_fmt << pfc::format_int(p_val);} +inline pfc::string_base & operator<<(pfc::string_base & p_fmt,t_uint32 p_val) {return p_fmt << pfc::format_uint(p_val);} +inline pfc::string_base & operator<<(pfc::string_base & p_fmt,t_int64 p_val) {return p_fmt << pfc::format_int(p_val);} +inline pfc::string_base & operator<<(pfc::string_base & p_fmt,t_uint64 p_val) {return p_fmt << pfc::format_uint(p_val);} +inline pfc::string_base & operator<<(pfc::string_base & p_fmt,double p_val) {return p_fmt << pfc::format_float(p_val);} + +inline pfc::string_base & operator<<(pfc::string_base & p_fmt,std::exception const & p_exception) {return p_fmt << p_exception.what();} + + + + + + +namespace pfc { + template + class string_simple_t { + private: + typedef string_simple_t t_self; + public: + t_size length(t_size p_limit = infinite) const {return pfc::strlen_t(get_ptr(),p_limit);} + bool is_empty() const {return length(1) == 0;} + void set_string(const t_char * p_source,t_size p_length = infinite) { + t_size length = pfc::strlen_t(p_source,p_length); + m_buffer.set_size(length + 1); + pfc::memcpy_t(m_buffer.get_ptr(),p_source,length); + m_buffer[length] = 0; + } + string_simple_t() {} + string_simple_t(const t_char * p_source,t_size p_length = infinite) {set_string(p_source,p_length);} + const t_self & operator=(const t_char * p_source) {set_string(p_source);return *this;} + operator const t_char* () const {return get_ptr();} + const t_char * get_ptr() const {return m_buffer.get_size() > 0 ? m_buffer.get_ptr() : pfc::empty_string_t();} + private: + pfc::array_t m_buffer; + }; + + typedef string_simple_t string_simple; + + template class traits_t > : public traits_t > {}; +} + + +namespace pfc { + class comparator_strcmp { + public: + inline static int compare(const char * p_item1,const char * p_item2) {return strcmp(p_item1,p_item2);} + inline static int compare(const wchar_t * item1, const wchar_t * item2) {return wcscmp(item1, item2);} + }; + + class comparator_stricmp_ascii { + public: + inline static int compare(const char * p_item1,const char * p_item2) {return pfc::stricmp_ascii(p_item1,p_item2);} + }; + + + + + template + void splitStringEx(t_output & p_output, const t_splitCheck & p_check, const char * p_string, t_size p_stringLen = infinite) { + t_size walk = 0, splitBase = 0; + const t_size max = strlen_max(p_string,p_stringLen); + for(;walk < max;) { + t_size delta = p_check(p_string + walk,p_stringLen - walk); + if (delta > 0) { + if (walk > splitBase) p_output(p_string + splitBase, walk - splitBase); + splitBase = walk + delta; + } else { + delta = utf8_char_len(p_string + walk, p_stringLen - walk); + if (delta == 0) break; + } + walk += delta; + } + if (walk > splitBase) p_output(p_string + splitBase, walk - splitBase); + } + + class __splitStringSimple_calculateSubstringCount { + public: + __splitStringSimple_calculateSubstringCount() : m_count() {} + void operator() (const char *, t_size) {++m_count;} + t_size get() const {return m_count;} + private: + t_size m_count; + }; + class __splitStringSimple_check { + public: + __splitStringSimple_check(const char * p_chars) { + m_chars.set_size(strlen_utf8(p_chars)); + for(t_size walk = 0, ptr = 0; walk < m_chars.get_size(); ++walk) { + ptr += utf8_decode_char(p_chars + ptr,m_chars[walk]); + } + } + t_size operator()(const char * p_string, t_size p_stringLen) const { + t_uint32 c; + t_size delta = utf8_decode_char(p_string, c, p_stringLen); + if (delta > 0) { + for(t_size walk = 0; walk < m_chars.get_size(); ++walk) { + if (m_chars[walk] == c) return delta; + } + } + return 0; + } + private: + array_t m_chars; + }; + template + class __splitStringSimple_arrayWrapper { + public: + __splitStringSimple_arrayWrapper(t_array & p_array) : m_walk(), m_array(p_array) {} + void operator()(const char * p_string, t_size p_stringLen) { + m_array[m_walk++].set_string(p_string,p_stringLen); + } + private: + t_size m_walk; + t_array & m_array; + }; + template + class __splitStringSimple_listWrapper { + public: + __splitStringSimple_listWrapper(t_list & p_list) : m_list(p_list) {} + void operator()(const char * p_string, t_size p_stringLen) { + m_temp.set_string(p_string,p_stringLen); + m_list.add_item(m_temp); + } + private: + string8_fastalloc m_temp; + t_list & m_list; + }; + + template + void splitStringSimple_toArray(t_array & p_output, const char * p_splitChars, const char * p_string, t_size p_stringLen = infinite) { + __splitStringSimple_check check(p_splitChars); + + { + __splitStringSimple_calculateSubstringCount wrapper; + splitStringEx(wrapper,check,p_string,p_stringLen); + p_output.set_size(wrapper.get()); + } + + { + __splitStringSimple_arrayWrapper wrapper(p_output); + splitStringEx(wrapper,check,p_string,p_stringLen); + } + } + template + void splitStringSimple_toList(t_list & p_output, const char * p_splitChars, const char * p_string, t_size p_stringLen = infinite) { + __splitStringSimple_check check(p_splitChars); + + __splitStringSimple_listWrapper wrapper(p_output); + splitStringEx(wrapper,check,p_string,p_stringLen); + } + + template void splitStringByLines(t_out & out, const char * str) { + for(;;) { + const char * next = strchr(str, '\n'); + if (next == NULL) { + out.insert_last()->set_string(str); break; + } + const char * walk = next; + while(walk > str && walk[-1] == '\r') --walk; + out.insert_last()->set_string(str, walk - str); + str = next + 1; + } + } + + void stringToUpperAppend(string_base & p_out, const char * p_source, t_size p_sourceLen); + void stringToLowerAppend(string_base & p_out, const char * p_source, t_size p_sourceLen); + int stringCompareCaseInsensitive(const char * s1, const char * s2); + t_uint32 charLower(t_uint32 param); + t_uint32 charUpper(t_uint32 param); + + template inline const char * stringToPtr(T const& val) {return val.get_ptr();} + inline const char * stringToPtr(const char* val) {return val;} + + + + class string_base_ref : public string_base { + public: + string_base_ref(const char * ptr) : m_ptr(ptr), m_len(strlen(ptr)) {} + const char * get_ptr() const {return m_ptr;} + t_size get_length() const {return m_len;} + private: + void add_string(const char * p_string,t_size p_length = ~0) {throw pfc::exception_not_implemented();} + void set_string(const char * p_string,t_size p_length = ~0) {throw pfc::exception_not_implemented();} + void truncate(t_size len) {throw pfc::exception_not_implemented();} + char * lock_buffer(t_size p_requested_length) {throw pfc::exception_not_implemented();} + void unlock_buffer() {throw pfc::exception_not_implemented();} + private: + const char * const m_ptr; + t_size const m_len; + }; + + //! Writes a string to a fixed-size buffer. Truncates the string if necessary. Always writes a null terminator. + template + void stringToBuffer(TChar (&buffer)[len], const TSource & source) { + pfc::static_assert<(len>0)>(); + t_size walk; + for(walk = 0; walk < len - 1 && source[walk] != 0; ++walk) { + buffer[walk] = source[walk]; + } + buffer[walk] = 0; + } + + //! Same as stringToBuffer() but throws exception_overflow() if the string could not be fully written, including null terminator. + template + void stringToBufferGuarded(TChar (&buffer)[len], const TSource & source) { + t_size walk; + for(walk = 0; source[walk] != 0; ++walk) { + if (walk >= len) throw exception_overflow(); + buffer[walk] = source[walk]; + } + if (walk >= len) throw exception_overflow(); + buffer[walk] = 0; + } + + + template int _strcmp_partial_ex(const t_char * p_string,t_size p_string_length,const t_char * p_substring,t_size p_substring_length) throw() { + for(t_size walk=0;walk=p_string_length ? 0 : p_string[walk]); + t_char substringchar = p_substring[walk]; + int result = compare_t(stringchar,substringchar); + if (result != 0) return result; + } + return 0; + } + + template int strcmp_partial_ex_t(const t_char * p_string,t_size p_string_length,const t_char * p_substring,t_size p_substring_length) throw() { + p_string_length = strlen_max_t(p_string,p_string_length); p_substring_length = strlen_max_t(p_substring,p_substring_length); + return _strcmp_partial_ex(p_string,p_string_length,p_substring,p_substring_length); + } + + template + int strcmp_partial_t(const t_char * p_string,const t_char * p_substring) throw() {return strcmp_partial_ex_t(p_string,infinite,p_substring,infinite);} + + static int strcmp_partial_ex(const char * str, t_size strLen, const char * substr, t_size substrLen) throw() {return strcmp_partial_ex(str, strLen, substr, substrLen); } + static int strcmp_partial(const char * str, const char * substr) throw() {return strcmp_partial_t(str, substr); } + +} + +#endif //_PFC_STRING_H_ diff --git a/tools/vio2sf/src/foobar/pfc/string8_impl.h b/tools/vio2sf/src/foobar/pfc/string8_impl.h new file mode 100644 index 000000000..968798637 --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/string8_impl.h @@ -0,0 +1,123 @@ +namespace pfc { + +template class t_alloc> +void string8_t::add_string(const char * ptr,t_size len) +{ + if (m_data.is_owned(ptr)) { + add_string(string8(ptr,len)); + } else { + len = strlen_max(ptr,len); + makespace(used+len+1); + pfc::memcpy_t(m_data.get_ptr() + used,ptr,len); + used+=len; + m_data[used]=0; + } +} + +template class t_alloc> +void string8_t::set_string(const char * ptr,t_size len) { + if (m_data.is_owned(ptr)) { + set_string(string8(ptr,len)); + } else { + len = strlen_max(ptr,len); + makespace(len+1); + pfc::memcpy_t(m_data.get_ptr(),ptr,len); + used=len; + m_data[used]=0; + } +} + +template class t_alloc> +void string8_t::set_char(unsigned offset,char c) +{ + if (!c) truncate(offset); + else if (offset class t_alloc> +void string8_t::fix_filename_chars(char def,char leave)//replace "bad" characters, leave parameter can be used to keep eg. path separators +{ + t_size n; + for(n=0;n class t_alloc> +void string8_t::remove_chars(t_size first,t_size count) +{ + if (first>used) first = used; + if (first+count>used) count = used-first; + if (count>0) + { + t_size n; + for(n=first+count;n<=used;n++) + m_data[n-count]=m_data[n]; + used -= count; + makespace(used+1); + } +} + +template class t_alloc> +void string8_t::insert_chars(t_size first,const char * src, t_size count) +{ + if (first > used) first = used; + + makespace(used+count+1); + t_size n; + for(n=used;(int)n>=(int)first;n--) + m_data[n+count] = m_data[n]; + for(n=0;n class t_alloc> +void string8_t::insert_chars(t_size first,const char * src) {insert_chars(first,src,strlen(src));} + + +template class t_alloc> +t_size string8_t::replace_nontext_chars(char p_replace) +{ + t_size ret = 0; + for(t_size n=0;n class t_alloc> +t_size string8_t::replace_byte(char c1,char c2,t_size start) +{ + PFC_ASSERT(c1 != 0); PFC_ASSERT(c2 != 0); + t_size n, ret = 0; + for(n=start;n class t_alloc> +t_size string8_t::replace_char(unsigned c1,unsigned c2,t_size start) +{ + if (c1 < 128 && c2 < 128) return replace_byte((char)c1,(char)c2,start); + + string8 temp(get_ptr()+start); + truncate(start); + const char * ptr = temp; + t_size rv = 0; + while(*ptr) + { + unsigned test; + t_size delta = utf8_decode_char(ptr,test); + if (delta==0 || test==0) break; + if (test == c1) {test = c2;rv++;} + add_char(test); + ptr += delta; + } + return rv; +} + +} diff --git a/tools/vio2sf/src/foobar/pfc/stringNew.cpp b/tools/vio2sf/src/foobar/pfc/stringNew.cpp new file mode 100644 index 000000000..f6652ee5f --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/stringNew.cpp @@ -0,0 +1,82 @@ +#include "pfc.h" + +namespace pfc { + +t_size string::indexOf(char c,t_size base) const { + return pfc::string_find_first(ptr(),c,base); +} +t_size string::lastIndexOf(char c,t_size base) const { + return pfc::string_find_last(ptr(),c,base); +} +t_size string::indexOf(stringp s,t_size base) const { + return pfc::string_find_first(ptr(),s.ptr(),base); +} +t_size string::lastIndexOf(stringp s,t_size base) const { + return pfc::string_find_last(ptr(),s.ptr(),base); +} +t_size string::indexOfAnyChar(stringp _s,t_size base) const { + string s ( _s ); + const t_size len = length(); + const char* content = ptr(); + for(t_size walk = 0; walk < len; ++walk) { + if (s.contains(content[walk])) return walk; + } + return ~0; +} +t_size string::lastIndexOfAnyChar(stringp _s,t_size base) const { + string s ( _s ); + const char* content = ptr(); + for(t_size _walk = length(); _walk > 0; --_walk) { + const t_size walk = _walk-1; + if (s.contains(content[walk])) return walk; + } + return ~0; +} +bool string::startsWith(char c) const { + return (*this)[0] == c; +} +bool string::startsWith(string s) const { + const char * walk = ptr(); + const char * subWalk = s.ptr(); + for(;;) { + if (*subWalk == 0) return true; + if (*walk != *subWalk) return false; + walk++; subWalk++; + } +} +bool string::endsWith(char c) const { + const t_size len = length(); + if (len == 0) return false; + return ptr()[len-1] == c; +} +bool string::endsWith(string s) const { + const t_size len = length(), subLen = s.length(); + if (subLen > len) return false; + return subString(len - subLen) == s; +} + +char string::firstChar() const { + return (*this)[0]; +} +char string::lastChar() const { + const t_size len = length(); + return len > 0 ? (*this)[len-1] : (char)0; +} + +string string::replace(stringp strOld, stringp strNew) const { + t_size walk = 0; + string ret; + for(;;) { + t_size next = indexOf(strOld, walk); + if (next == ~0) { + ret += subString(walk); break; + } + ret += subString(walk,next-walk) + strNew; + walk = next + strOld.length(); + } + return ret; +} +bool string::contains(char c) const {return indexOf(c) != ~0;} +bool string::contains(stringp s) const {return indexOf(s) != ~0;} +bool string::containsAnyChar(stringp s) const {return indexOfAnyChar(s) != ~0;} +} diff --git a/tools/vio2sf/src/foobar/pfc/stringNew.h b/tools/vio2sf/src/foobar/pfc/stringNew.h new file mode 100644 index 000000000..218f59910 --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/stringNew.h @@ -0,0 +1,220 @@ +namespace pfc { + //helper, const methods only + class __stringEmpty : public string_base { + public: + const char * get_ptr() const {return "";} + void add_string(const char * p_string,t_size p_length = ~0) {throw exception_not_implemented();} + void set_string(const char * p_string,t_size p_length = ~0) {throw exception_not_implemented();} + void truncate(t_size len) {throw exception_not_implemented();} + t_size get_length() const {return 0;} + char * lock_buffer(t_size p_requested_length) {throw exception_not_implemented();} + void unlock_buffer() {throw exception_not_implemented();} + }; + + class stringp; + + //! New EXPERIMENTAL string class, allowing efficient copies and returning from functions. \n + //! Does not implement the string_base interface so you still need string8 in many cases. \n + //! Safe to pass between DLLs, but since a reference is used, objects possibly created by other DLLs must be released before owning DLLs are unloaded. + class string { + public: + typedef rcptr_t t_data; + typedef rcptr_t t_dataImpl; + + string() : m_content(rcnew_t<__stringEmpty>()) {} + string(const char * p_source) : m_content(rcnew_t(p_source)) {} + string(const char * p_source, t_size p_sourceLen) : m_content(rcnew_t(p_source,p_sourceLen)) {} + string(t_data const & p_source) : m_content(p_source) {} + template string(const TSource & p_source); + + string const & toString() const {return *this;} + + //warning, not length-checked anymore! + static string g_concatenateRaw(const char * item1, t_size len1, const char * item2, t_size len2) { + t_dataImpl impl; impl.new_t(); + char * buffer = impl->lock_buffer(len1+len2); + memcpy_t(buffer,item1,len1); + memcpy_t(buffer+len1,item2,len2); + impl->unlock_buffer(); + return string(t_data(impl)); + } + + string operator+(const string& p_item2) const { + return g_concatenateRaw(ptr(),length(),p_item2.ptr(),p_item2.length()); + } + string operator+(const char * p_item2) const { + return g_concatenateRaw(ptr(),length(),p_item2,strlen(p_item2)); + } + + template string operator+(const TSource & p_item2) const; + + template + const string & operator+=(const TSource & p_item) { + *this = *this + p_item; + return *this; + } + + string subString(t_size base) const { + if (base > length()) throw exception_overflow(); + return string(ptr() + base); + } + string subString(t_size base, t_size count) const { + return string(ptr() + base,count); + } + + string toLower() const { + pfc::string8_fastalloc temp; temp.prealloc(128); + stringToLowerAppend(temp,ptr(),~0); + return string(temp.get_ptr()); + } + string toUpper() const { + pfc::string8_fastalloc temp; temp.prealloc(128); + stringToUpperAppend(temp,ptr(),~0); + return string(temp.get_ptr()); + } + + string clone() const {return string(ptr());} + + //! @returns ~0 if not found. + t_size indexOf(char c,t_size base = 0) const; + //! @returns ~0 if not found. + t_size lastIndexOf(char c,t_size base = ~0) const; + //! @returns ~0 if not found. + t_size indexOf(stringp s,t_size base = 0) const; + //! @returns ~0 if not found. + t_size lastIndexOf(stringp s,t_size base = ~0) const; + //! @returns ~0 if not found. + t_size indexOfAnyChar(stringp s,t_size base = 0) const; + //! @returns ~0 if not found. + t_size lastIndexOfAnyChar(stringp s,t_size base = ~0) const; + + bool contains(char c) const; + bool contains(stringp s) const; + + bool containsAnyChar(stringp s) const; + + bool startsWith(char c) const; + bool startsWith(string s) const; + bool endsWith(char c) const; + bool endsWith(string s) const; + + char firstChar() const; + char lastChar() const; + + string replace(stringp strOld, stringp strNew) const; + + static int g_compare(const string & p_item1, const string & p_item2) {return strcmp(p_item1.ptr(),p_item2.ptr());} + bool operator==(const string& p_other) const {return g_compare(*this,p_other) == 0;} + bool operator!=(const string& p_other) const {return g_compare(*this,p_other) != 0;} + bool operator<(const string& p_other) const {return g_compare(*this,p_other) < 0;} + bool operator>(const string& p_other) const {return g_compare(*this,p_other) > 0;} + bool operator<=(const string& p_other) const {return g_compare(*this,p_other) <= 0;} + bool operator>=(const string& p_other) const {return g_compare(*this,p_other) >= 0;} + + const char * ptr() const {return m_content->get_ptr();} + const char * get_ptr() const {return m_content->get_ptr();} + t_size length() const {return m_content->get_length();} + t_size get_length() const {return m_content->get_length();} + + void set_string(const char * ptr, t_size len = ~0) { + *this = string(ptr, len); + } + + static bool isNonTextChar(char c) {return c >= 0 && c < 32;} + + char operator[](t_size p_index) const { + PFC_ASSERT(p_index < length()); + return ptr()[p_index]; + } + bool isEmpty() const {return length() == 0;} + + class comparatorCaseSensitive { + public: + template + static int compare(T1 const& v1, T2 const& v2) { + return strcmp(stringToPtr(v1),stringToPtr(v2)); + } + static int compare_ex(const char * v1, t_size l1, const char * v2, t_size l2) { + return strcmp_ex(v1, l1, v2, l2); + } + + }; + class comparatorCaseInsensitive { + public: + template + static int compare(T1 const& v1, T2 const& v2) { + return stringCompareCaseInsensitive(stringToPtr(v1),stringToPtr(v2)); + } + }; + class comparatorCaseInsensitiveASCII { + public: + template + static int compare(T1 const& v1, T2 const& v2) { + return stricmp_ascii(stringToPtr(v1),stringToPtr(v2)); + } + + static int compare_ex(const char * v1, t_size l1, const char * v2, t_size l2) { + return stricmp_ascii_ex(v1, l1, v2, l2); + } + }; + + static bool g_equals(const string & p_item1, const string & p_item2) {return p_item1 == p_item2;} + static bool g_equalsCaseInsensitive(const string & p_item1, const string & p_item2) {return comparatorCaseInsensitive::compare(p_item1,p_item2) == 0;} + + t_data _content() const {return m_content;} + private: + t_data m_content; + }; + + template inline string toString(T const& val) {return val.toString();} + template<> inline string toString(t_int64 const& val) {return format_int(val).get_ptr();} + template<> inline string toString(t_int32 const& val) {return format_int(val).get_ptr();} + template<> inline string toString(t_int16 const& val) {return format_int(val).get_ptr();} + template<> inline string toString(t_uint64 const& val) {return format_uint(val).get_ptr();} + template<> inline string toString(t_uint32 const& val) {return format_uint(val).get_ptr();} + template<> inline string toString(t_uint16 const& val) {return format_uint(val).get_ptr();} + template<> inline string toString(float const& val) {return format_float(val).get_ptr();} + template<> inline string toString(double const& val) {return format_float(val).get_ptr();} + template<> inline string toString(char const& val) {return string(&val,1);} + inline const char * toString(std::exception const& val) {return val.what();} + + template string::string(const TSource & p_source) { + *this = pfc::toString(p_source); + } + template string string::operator+(const TSource & p_item2) const { + return *this + pfc::toString(p_item2); + } + + //! "String parameter" helper class, to use in function parameters, allowing functions to take any type of string as a parameter (const char*, string_base, string). + class stringp { + public: + stringp(const char * ptr) : m_ptr(ptr) {} + stringp(pfc::string const &s) : m_ptr(s.ptr()), m_s(s._content()) {} + stringp(pfc::string_base const &s) : m_ptr(s.get_ptr()) {} + template stringp(const TWhat& in) : m_ptr(in.toString()) {} + + operator const char*() const {return m_ptr;} + const char * ptr() const {return m_ptr;} + const char * get_ptr() const {return m_ptr;} + pfc::string str() const {return m_s.is_valid() ? pfc::string(m_s) : pfc::string(m_ptr);} + operator pfc::string() const {return str();} + pfc::string toString() const {return str();} + t_size length() const {return m_s.is_valid() ? m_s->length() : strlen(m_ptr);} + private: + const char * const m_ptr; + pfc::string::t_data m_s; + }; + + template + string stringCombineList(const TList & list, stringp separator) { + typename TList::const_iterator iter = list.first(); + string acc; + if (iter.is_valid()) { + acc = *iter; + for(++iter; iter.is_valid(); ++iter) { + acc = acc + separator + *iter; + } + } + return acc; + } +} diff --git a/tools/vio2sf/src/foobar/pfc/string_conv.cpp b/tools/vio2sf/src/foobar/pfc/string_conv.cpp new file mode 100644 index 000000000..77b2deed5 --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/string_conv.cpp @@ -0,0 +1,216 @@ +#include "pfc.h" + + +#ifdef _WINDOWS + +namespace { + template + class string_writer_t { + public: + string_writer_t(t_char * p_buffer,t_size p_size) : m_buffer(p_buffer), m_size(p_size), m_writeptr(0) {} + + void write(t_char p_char) { + if (isChecked) { + if (m_writeptr < m_size) { + m_buffer[m_writeptr++] = p_char; + } + } else { + m_buffer[m_writeptr++] = p_char; + } + } + void write_multi(const t_char * p_buffer,t_size p_count) { + if (isChecked) { + const t_size delta = pfc::min_t(p_count,m_size-m_writeptr); + for(t_size n=0;n(m_writeptr,m_size-1); + m_buffer[terminator] = 0; + return terminator; + } else { + m_buffer[m_writeptr] = 0; + return m_writeptr; + } + } + bool is_overrun() const { + return m_writeptr >= m_size; + } + private: + t_char * m_buffer; + t_size m_size; + t_size m_writeptr; + }; + + + +}; + +namespace pfc { + namespace stringcvt { + + + t_size convert_utf8_to_wide(wchar_t * p_out,t_size p_out_size,const char * p_in,t_size p_in_size) { + const t_size insize = p_in_size; + t_size inptr = 0; + string_writer_t writer(p_out,p_out_size); + + while(inptr < insize && !writer.is_overrun()) { + unsigned newchar = 0; + t_size delta = utf8_decode_char(p_in + inptr,newchar,insize - inptr); + if (delta == 0 || newchar == 0) break; + PFC_ASSERT(inptr + delta <= insize); + inptr += delta; + writer.write_as_wide(newchar); + } + + return writer.finalize(); + } + + t_size convert_utf8_to_wide_unchecked(wchar_t * p_out,const char * p_in) { + t_size inptr = 0; + string_writer_t writer(p_out,~0); + + while(!writer.is_overrun()) { + unsigned newchar = 0; + t_size delta = utf8_decode_char(p_in + inptr,newchar); + if (delta == 0 || newchar == 0) break; + inptr += delta; + writer.write_as_wide(newchar); + } + + return writer.finalize(); + } + + t_size convert_wide_to_utf8(char * p_out,t_size p_out_size,const wchar_t * p_in,t_size p_in_size) { + const t_size insize = p_in_size; + t_size inptr = 0; + string_writer_t writer(p_out,p_out_size); + + while(inptr < insize && !writer.is_overrun()) { + unsigned newchar = 0; + t_size delta = utf16_decode_char(p_in + inptr,&newchar,insize - inptr); + if (delta == 0 || newchar == 0) break; + PFC_ASSERT(inptr + delta <= insize); + inptr += delta; + writer.write_as_utf8(newchar); + } + + return writer.finalize(); + } + + t_size estimate_utf8_to_wide(const char * p_in) { + t_size inptr = 0; + t_size retval = 1;//1 for null terminator + for(;;) { + unsigned newchar = 0; + t_size delta = utf8_decode_char(p_in + inptr,newchar); + if (delta == 0 || newchar == 0) break; + inptr += delta; + + { + wchar_t temp[2]; + retval += utf16_encode_char(newchar,temp); + } + } + return retval; + } + + t_size estimate_utf8_to_wide(const char * p_in,t_size p_in_size) { + const t_size insize = p_in_size; + t_size inptr = 0; + t_size retval = 1;//1 for null terminator + while(inptr < insize) { + unsigned newchar = 0; + t_size delta = utf8_decode_char(p_in + inptr,newchar,insize - inptr); + if (delta == 0 || newchar == 0) break; + PFC_ASSERT(inptr + delta <= insize); + inptr += delta; + + { + wchar_t temp[2]; + retval += utf16_encode_char(newchar,temp); + } + } + return retval; + } + + t_size estimate_wide_to_utf8(const wchar_t * p_in,t_size p_in_size) { + const t_size insize = p_in_size; + t_size inptr = 0; + t_size retval = 1;//1 for null terminator + while(inptr < insize) { + unsigned newchar = 0; + t_size delta = utf16_decode_char(p_in + inptr,&newchar,insize - inptr); + if (delta == 0 || newchar == 0) break; + PFC_ASSERT(inptr + delta <= insize); + inptr += delta; + + { + char temp[6]; + delta = utf8_encode_char(newchar,temp); + if (delta == 0) break; + retval += delta; + } + } + return retval; + } + + + t_size convert_codepage_to_wide(unsigned p_codepage,wchar_t * p_out,t_size p_out_size,const char * p_source,t_size p_source_size) { + if (p_out_size == 0) return 0; + memset(p_out,0,p_out_size * sizeof(*p_out)); + MultiByteToWideChar(p_codepage,0,p_source,p_source_size,p_out,p_out_size); + p_out[p_out_size-1] = 0; + return wcslen(p_out); + } + + t_size convert_wide_to_codepage(unsigned p_codepage,char * p_out,t_size p_out_size,const wchar_t * p_source,t_size p_source_size) { + if (p_out_size == 0) return 0; + memset(p_out,0,p_out_size * sizeof(*p_out)); + WideCharToMultiByte(p_codepage,0,p_source,p_source_size,p_out,p_out_size,0,FALSE); + p_out[p_out_size-1] = 0; + return strlen(p_out); + } + + t_size estimate_codepage_to_wide(unsigned p_codepage,const char * p_source,t_size p_source_size) { + return MultiByteToWideChar(p_codepage,0,p_source,strlen_max(p_source,p_source_size),0,0) + 1; + } + t_size estimate_wide_to_codepage(unsigned p_codepage,const wchar_t * p_source,t_size p_source_size) { + return WideCharToMultiByte(p_codepage,0,p_source,wcslen_max(p_source,p_source_size),0,0,0,FALSE) + 1; + } + } + +} + +#endif //_WINDOWS + diff --git a/tools/vio2sf/src/foobar/pfc/string_conv.h b/tools/vio2sf/src/foobar/pfc/string_conv.h new file mode 100644 index 000000000..21a31e173 --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/string_conv.h @@ -0,0 +1,410 @@ +namespace pfc { + + namespace stringcvt { + +#ifdef _WINDOWS + enum { + codepage_system = CP_ACP, + codepage_ascii = 20127, + codepage_iso_8859_1 = 28591, + }; + + //! Converts UTF-8 characters to wide character. + //! @param p_out Output buffer, receives converted string, with null terminator. + //! @param p_out_size Size of output buffer, in characters. If converted string is too long, it will be truncated. Null terminator is always written, unless p_out_size is zero. + //! @param p_source String to convert. + //! @param p_source_size Number of characters to read from p_source. If reading stops if null terminator is encountered earlier. + //! @returns Number of characters written, not counting null terminator. + t_size convert_utf8_to_wide(wchar_t * p_out,t_size p_out_size,const char * p_source,t_size p_source_size); + + + //! Estimates buffer size required to convert specified UTF-8 string to widechar. + //! @param p_source String to be converted. + //! @param p_source_size Number of characters to read from p_source. If reading stops if null terminator is encountered earlier. + //! @returns Number of characters to allocate, including space for null terminator. + t_size estimate_utf8_to_wide(const char * p_source,t_size p_source_size); + + t_size estimate_utf8_to_wide(const char * p_source); + + //! Converts wide character string to UTF-8. + //! @param p_out Output buffer, receives converted string, with null terminator. + //! @param p_out_size Size of output buffer, in characters. If converted string is too long, it will be truncated. Null terminator is always written, unless p_out_size is zero. + //! @param p_source String to convert. + //! @param p_source_size Number of characters to read from p_source. If reading stops if null terminator is encountered earlier. + //! @returns Number of characters written, not counting null terminator. + t_size convert_wide_to_utf8(char * p_out,t_size p_out_size,const wchar_t * p_source,t_size p_source_size); + + //! Estimates buffer size required to convert specified wide character string to UTF-8. + //! @param p_source String to be converted. + //! @param p_source_size Number of characters to read from p_source. If reading stops if null terminator is encountered earlier. + //! @returns Number of characters to allocate, including space for null terminator. + t_size estimate_wide_to_utf8(const wchar_t * p_source,t_size p_source_size); + + + + //! Converts string from specified codepage to wide character. + //! @param p_out Output buffer, receives converted string, with null terminator. + //! @param p_codepage Codepage ID of source string. + //! @param p_source String to convert. + //! @param p_source_size Number of characters to read from p_source. If reading stops if null terminator is encountered earlier. + //! @param p_out_size Size of output buffer, in characters. If converted string is too long, it will be truncated. Null terminator is always written, unless p_out_size is zero. + //! @returns Number of characters written, not counting null terminator. + t_size convert_codepage_to_wide(unsigned p_codepage,wchar_t * p_out,t_size p_out_size,const char * p_source,t_size p_source_size); + + //! Estimates buffer size required to convert specified string from specified codepage to wide character. + //! @param p_codepage Codepage ID of source string. + //! @param p_source String to be converted. + //! @param p_source_size Number of characters to read from p_source. If reading stops if null terminator is encountered earlier. + //! @returns Number of characters to allocate, including space for null terminator. + t_size estimate_codepage_to_wide(unsigned p_codepage,const char * p_source,t_size p_source_size); + + //! Converts string from wide character to specified codepage. + //! @param p_codepage Codepage ID of source string. + //! @param p_out Output buffer, receives converted string, with null terminator. + //! @param p_out_size Size of output buffer, in characters. If converted string is too long, it will be truncated. Null terminator is always written, unless p_out_size is zero. + //! @param p_source String to convert. + //! @param p_source_size Number of characters to read from p_source. If reading stops if null terminator is encountered earlier. + //! @returns Number of characters written, not counting null terminator. + t_size convert_wide_to_codepage(unsigned p_codepage,char * p_out,t_size p_out_size,const wchar_t * p_source,t_size p_source_size); + + //! Estimates buffer size required to convert specified wide character string to specified codepage. + //! @param p_codepage Codepage ID of source string. + //! @param p_source String to be converted. + //! @param p_source_size Number of characters to read from p_source. If reading stops if null terminator is encountered earlier. + //! @returns Number of characters to allocate, including space for null terminator. + t_size estimate_wide_to_codepage(unsigned p_codepage,const wchar_t * p_source,t_size p_source_size); + + + //! Converts string from system codepage to wide character. + //! @param p_out Output buffer, receives converted string, with null terminator. + //! @param p_source String to convert. + //! @param p_source_size Number of characters to read from p_source. If reading stops if null terminator is encountered earlier. + //! @param p_out_size Size of output buffer, in characters. If converted string is too long, it will be truncated. Null terminator is always written, unless p_out_size is zero. + //! @returns Number of characters written, not counting null terminator. + inline t_size convert_ansi_to_wide(wchar_t * p_out,t_size p_out_size,const char * p_source,t_size p_source_size) { + return convert_codepage_to_wide(codepage_system,p_out,p_out_size,p_source,p_source_size); + } + + //! Estimates buffer size required to convert specified system codepage string to wide character. + //! @param p_source String to be converted. + //! @param p_source_size Number of characters to read from p_source. If reading stops if null terminator is encountered earlier. + //! @returns Number of characters to allocate, including space for null terminator. + inline t_size estimate_ansi_to_wide(const char * p_source,t_size p_source_size) { + return estimate_codepage_to_wide(codepage_system,p_source,p_source_size); + } + + //! Converts string from wide character to system codepage. + //! @param p_out Output buffer, receives converted string, with null terminator. + //! @param p_out_size Size of output buffer, in characters. If converted string is too long, it will be truncated. Null terminator is always written, unless p_out_size is zero. + //! @param p_source String to convert. + //! @param p_source_size Number of characters to read from p_source. If reading stops if null terminator is encountered earlier. + //! @returns Number of characters written, not counting null terminator. + inline t_size convert_wide_to_ansi(char * p_out,t_size p_out_size,const wchar_t * p_source,t_size p_source_size) { + return convert_wide_to_codepage(codepage_system,p_out,p_out_size,p_source,p_source_size); + } + + //! Estimates buffer size required to convert specified wide character string to system codepage. + //! @param p_source String to be converted. + //! @param p_source_size Number of characters to read from p_source. If reading stops if null terminator is encountered earlier. + //! @returns Number of characters to allocate, including space for null terminator. + inline t_size estimate_wide_to_ansi(const wchar_t * p_source,t_size p_source_size) { + return estimate_wide_to_codepage(codepage_system,p_source,p_source_size); + } + + + //! estimate_utf8_to_wide_quick() functions use simple math to determine buffer size required for the conversion. The result is not accurate length of output string - it's just a safe estimate of required buffer size, possibly bigger than what's really needed. \n + //! These functions are meant for scenarios when speed is more important than memory usage. + inline t_size estimate_utf8_to_wide_quick(t_size sourceLen) { + return sourceLen + 1; + } + inline t_size estimate_utf8_to_wide_quick(const char * source) { + return estimate_utf8_to_wide_quick(strlen(source)); + } + inline t_size estimate_utf8_to_wide_quick(const char * source, t_size sourceLen) { + return estimate_utf8_to_wide_quick(strlen_max(source, sourceLen)); + } + t_size convert_utf8_to_wide_unchecked(wchar_t * p_out,const char * p_source); + + template const t_char * null_string_t(); + template<> inline const char * null_string_t() {return "";} + template<> inline const wchar_t * null_string_t() {return L"";} + + template t_size strlen_t(const t_char * p_string,t_size p_string_size = ~0) { + for(t_size n=0;n bool string_is_empty_t(const t_char * p_string,t_size p_string_size = ~0) { + if (p_string_size == 0) return true; + return p_string[0] == 0; + } + + template class t_alloc = pfc::alloc_standard> class char_buffer_t { + public: + char_buffer_t() {} + char_buffer_t(const char_buffer_t & p_source) : m_buffer(p_source.m_buffer) {} + void set_size(t_size p_count) {m_buffer.set_size(p_count);} + t_char * get_ptr_var() {return m_buffer.get_ptr();} + const t_char * get_ptr() const { + return m_buffer.get_size() > 0 ? m_buffer.get_ptr() : null_string_t(); + } + private: + pfc::array_t m_buffer; + }; + + template class t_alloc = pfc::alloc_standard> + class string_utf8_from_wide_t { + public: + string_utf8_from_wide_t() {} + string_utf8_from_wide_t(const wchar_t * p_source,t_size p_source_size = ~0) {convert(p_source,p_source_size);} + + void convert(const wchar_t * p_source,t_size p_source_size = ~0) { + t_size size = estimate_wide_to_utf8(p_source,p_source_size); + m_buffer.set_size(size); + convert_wide_to_utf8( m_buffer.get_ptr_var(),size,p_source,p_source_size); + } + + operator const char * () const {return get_ptr();} + const char * get_ptr() const {return m_buffer.get_ptr();} + const char * toString() const {return get_ptr();} + bool is_empty() const {return string_is_empty_t(get_ptr());} + t_size length() const {return strlen_t(get_ptr());} + + private: + char_buffer_t m_buffer; + }; + typedef string_utf8_from_wide_t<> string_utf8_from_wide; + + template class t_alloc = pfc::alloc_standard> + class string_wide_from_utf8_t { + public: + string_wide_from_utf8_t() {} + string_wide_from_utf8_t(const char* p_source) {convert(p_source);} + string_wide_from_utf8_t(const char* p_source,t_size p_source_size) {convert(p_source,p_source_size);} + + void convert(const char* p_source,t_size p_source_size) { + const t_size size = estimate_size(p_source, p_source_size); + m_buffer.set_size(size); + convert_utf8_to_wide( m_buffer.get_ptr_var(),size,p_source,p_source_size ); + } + void convert(const char * p_source) { + m_buffer.set_size( estimate_size(p_source) ); + convert_utf8_to_wide_unchecked(m_buffer.get_ptr_var(), p_source); + } + + operator const wchar_t * () const {return get_ptr();} + const wchar_t * get_ptr() const {return m_buffer.get_ptr();} + bool is_empty() const {return string_is_empty_t(get_ptr());} + t_size length() const {return strlen_t(get_ptr());} + + enum { alloc_prioritizes_speed = t_alloc::alloc_prioritizes_speed }; + private: + + inline t_size estimate_size(const char * source, t_size sourceLen) { + return alloc_prioritizes_speed ? estimate_utf8_to_wide_quick(source, sourceLen) : estimate_utf8_to_wide(source,sourceLen); + } + inline t_size estimate_size(const char * source) { + return alloc_prioritizes_speed ? estimate_utf8_to_wide_quick(source) : estimate_utf8_to_wide(source,~0); + } + char_buffer_t m_buffer; + }; + typedef string_wide_from_utf8_t<> string_wide_from_utf8; + typedef string_wide_from_utf8_t string_wide_from_utf8_fast; + + template class t_alloc = pfc::alloc_standard> + class string_wide_from_codepage_t { + public: + string_wide_from_codepage_t() {} + string_wide_from_codepage_t(const string_wide_from_codepage_t & p_source) : m_buffer(p_source.m_buffer) {} + string_wide_from_codepage_t(unsigned p_codepage,const char * p_source,t_size p_source_size = ~0) {convert(p_codepage,p_source,p_source_size);} + + void convert(unsigned p_codepage,const char * p_source,t_size p_source_size = ~0) { + t_size size = estimate_codepage_to_wide(p_codepage,p_source,p_source_size); + m_buffer.set_size(size); + convert_codepage_to_wide(p_codepage, m_buffer.get_ptr_var(),size,p_source,p_source_size); + } + + operator const wchar_t * () const {return get_ptr();} + const wchar_t * get_ptr() const {return m_buffer.get_ptr();} + bool is_empty() const {return string_is_empty_t(get_ptr());} + t_size length() const {return strlen_t(get_ptr());} + + private: + char_buffer_t m_buffer; + }; + typedef string_wide_from_codepage_t<> string_wide_from_codepage; + + + template class t_alloc = pfc::alloc_standard> + class string_codepage_from_wide_t { + public: + string_codepage_from_wide_t() {} + string_codepage_from_wide_t(const string_codepage_from_wide_t & p_source) : m_buffer(p_source.m_buffer) {} + string_codepage_from_wide_t(unsigned p_codepage,const wchar_t * p_source,t_size p_source_size = ~0) {convert(p_codepage,p_source,p_source_size);} + + void convert(unsigned p_codepage,const wchar_t * p_source,t_size p_source_size = ~0) { + t_size size = estimate_wide_to_codepage(p_codepage,p_source,p_source_size); + m_buffer.set_size(size); + convert_wide_to_codepage(p_codepage, m_buffer.get_ptr_var(),size,p_source,p_source_size); + } + + operator const char * () const {return get_ptr();} + const char * get_ptr() const {return m_buffer.get_ptr();} + bool is_empty() const {return string_is_empty_t(get_ptr());} + t_size length() const {return strlen_t(get_ptr());} + + private: + char_buffer_t m_buffer; + }; + typedef string_codepage_from_wide_t<> string_codepage_from_wide; + + class string_codepage_from_utf8 { + public: + string_codepage_from_utf8() {} + string_codepage_from_utf8(const string_codepage_from_utf8 & p_source) : m_buffer(p_source.m_buffer) {} + string_codepage_from_utf8(unsigned p_codepage,const char * p_source,t_size p_source_size = ~0) {convert(p_codepage,p_source,p_source_size);} + + void convert(unsigned p_codepage,const char * p_source,t_size p_source_size = ~0) { + string_wide_from_utf8 temp; + temp.convert(p_source,p_source_size); + t_size size = estimate_wide_to_codepage(p_codepage,temp,~0); + m_buffer.set_size(size); + convert_wide_to_codepage(p_codepage,m_buffer.get_ptr_var(),size,temp,~0); + } + + operator const char * () const {return get_ptr();} + const char * get_ptr() const {return m_buffer.get_ptr();} + bool is_empty() const {return string_is_empty_t(get_ptr());} + t_size length() const {return strlen_t(get_ptr());} + + private: + char_buffer_t m_buffer; + }; + + class string_utf8_from_codepage { + public: + string_utf8_from_codepage() {} + string_utf8_from_codepage(const string_utf8_from_codepage & p_source) : m_buffer(p_source.m_buffer) {} + string_utf8_from_codepage(unsigned p_codepage,const char * p_source,t_size p_source_size = ~0) {convert(p_codepage,p_source,p_source_size);} + + void convert(unsigned p_codepage,const char * p_source,t_size p_source_size = ~0) { + string_wide_from_codepage temp; + temp.convert(p_codepage,p_source,p_source_size); + t_size size = estimate_wide_to_utf8(temp,~0); + m_buffer.set_size(size); + convert_wide_to_utf8( m_buffer.get_ptr_var(),size,temp,~0); + } + + operator const char * () const {return get_ptr();} + const char * get_ptr() const {return m_buffer.get_ptr();} + bool is_empty() const {return string_is_empty_t(get_ptr());} + t_size length() const {return strlen_t(get_ptr());} + + private: + char_buffer_t m_buffer; + }; + + + class string_utf8_from_ansi { + public: + string_utf8_from_ansi() {} + string_utf8_from_ansi(const string_utf8_from_ansi & p_source) : m_buffer(p_source.m_buffer) {} + string_utf8_from_ansi(const char * p_source,t_size p_source_size = ~0) : m_buffer(codepage_system,p_source,p_source_size) {} + operator const char * () const {return get_ptr();} + const char * get_ptr() const {return m_buffer.get_ptr();} + const char * toString() const {return get_ptr();} + bool is_empty() const {return string_is_empty_t(get_ptr());} + t_size length() const {return strlen_t(get_ptr());} + void convert(const char * p_source,t_size p_source_size = ~0) {m_buffer.convert(codepage_system,p_source,p_source_size);} + + private: + string_utf8_from_codepage m_buffer; + }; + + class string_ansi_from_utf8 { + public: + string_ansi_from_utf8() {} + string_ansi_from_utf8(const string_ansi_from_utf8 & p_source) : m_buffer(p_source.m_buffer) {} + string_ansi_from_utf8(const char * p_source,t_size p_source_size = ~0) : m_buffer(codepage_system,p_source,p_source_size) {} + operator const char * () const {return get_ptr();} + const char * get_ptr() const {return m_buffer.get_ptr();} + bool is_empty() const {return string_is_empty_t(get_ptr());} + t_size length() const {return strlen_t(get_ptr());} + + void convert(const char * p_source,t_size p_source_size = ~0) {m_buffer.convert(codepage_system,p_source,p_source_size);} + + private: + string_codepage_from_utf8 m_buffer; + }; + + class string_wide_from_ansi { + public: + string_wide_from_ansi() {} + string_wide_from_ansi(const string_wide_from_ansi & p_source) : m_buffer(p_source.m_buffer) {} + string_wide_from_ansi(const char * p_source,t_size p_source_size = ~0) : m_buffer(codepage_system,p_source,p_source_size) {} + operator const wchar_t * () const {return get_ptr();} + const wchar_t * get_ptr() const {return m_buffer.get_ptr();} + bool is_empty() const {return string_is_empty_t(get_ptr());} + t_size length() const {return strlen_t(get_ptr());} + + void convert(const char * p_source,t_size p_source_size = ~0) {m_buffer.convert(codepage_system,p_source,p_source_size);} + + private: + string_wide_from_codepage m_buffer; + }; + + class string_ansi_from_wide { + public: + string_ansi_from_wide() {} + string_ansi_from_wide(const string_ansi_from_wide & p_source) : m_buffer(p_source.m_buffer) {} + string_ansi_from_wide(const wchar_t * p_source,t_size p_source_size = ~0) : m_buffer(codepage_system,p_source,p_source_size) {} + operator const char * () const {return get_ptr();} + const char * get_ptr() const {return m_buffer.get_ptr();} + bool is_empty() const {return string_is_empty_t(get_ptr());} + t_size length() const {return strlen_t(get_ptr());} + + void convert(const wchar_t * p_source,t_size p_source_size = ~0) {m_buffer.convert(codepage_system,p_source,p_source_size);} + + private: + string_codepage_from_wide m_buffer; + }; + +#ifdef UNICODE + typedef string_wide_from_utf8 string_os_from_utf8; + typedef string_utf8_from_wide string_utf8_from_os; + typedef string_wide_from_utf8_fast string_os_from_utf8_fast; +#else + typedef string_ansi_from_utf8 string_os_from_utf8; + typedef string_utf8_from_ansi string_utf8_from_os; + typedef string_ansi_from_utf8 string_os_from_utf8_fast; +#endif + + class string_utf8_from_os_ex { + public: + template string_utf8_from_os_ex(const t_source * source, t_size sourceLen = ~0) { + convert(source,sourceLen); + } + + void convert(const char * source, t_size sourceLen = ~0) { + m_buffer = string_utf8_from_ansi(source,sourceLen); + } + void convert(const wchar_t * source, t_size sourceLen = ~0) { + m_buffer = string_utf8_from_wide(source,sourceLen); + } + + operator const char * () const {return get_ptr();} + const char * get_ptr() const {return m_buffer.get_ptr();} + bool is_empty() const {return m_buffer.is_empty();} + t_size length() const {return m_buffer.length();} + const char * toString() const {return get_ptr();} + private: + string8 m_buffer; + }; + } + +#else +//PORTME +#endif +}; diff --git a/tools/vio2sf/src/foobar/pfc/string_list.h b/tools/vio2sf/src/foobar/pfc/string_list.h new file mode 100644 index 000000000..bf07cdd96 --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/string_list.h @@ -0,0 +1,58 @@ +#ifndef _PFC_STRING_LIST_H_ +#define _PFC_STRING_LIST_H_ + +namespace pfc { + + typedef list_base_const_t string_list_const; + + class string_list_impl : public string_list_const + { + public: + t_size get_count() const {return m_data.get_size();} + void get_item_ex(const char* & p_out, t_size n) const {p_out = m_data[n];} + + inline const char * operator[] (t_size n) const {return m_data[n];} + + void add_item(const char * p_string) { + t_size idx = m_data.get_size(); + m_data.set_size(idx + 1); + m_data[idx] = p_string; + } + + void add_items(const string_list_const & p_source) {_append(p_source);} + + void remove_all() + { + m_data.set_size(0); + } + + //unnecessary since pfc::array_t is in use for implementation + //~string_list_impl() {remove_all();} + + inline string_list_impl() {} + inline string_list_impl(const string_list_impl & p_source) {_copy(p_source);} + inline string_list_impl(const string_list_const & p_source) {_copy(p_source);} + inline const string_list_impl & operator=(const string_list_impl & p_source) {_copy(p_source);return *this;} + inline const string_list_impl & operator=(const string_list_const & p_source) {_copy(p_source);return *this;} + inline const string_list_impl & operator+=(const string_list_impl & p_source) {_append(p_source);return *this;} + inline const string_list_impl & operator+=(const string_list_const & p_source) {_append(p_source);return *this;} + + private: + + void _append(const string_list_const & p_source) { + const t_size toadd = p_source.get_count(), base = m_data.get_size(); + m_data.set_size(base+toadd); + for(t_size n=0;n m_data; + }; +} + +#endif //_PFC_STRING_LIST_H_ diff --git a/tools/vio2sf/src/foobar/pfc/threads.cpp b/tools/vio2sf/src/foobar/pfc/threads.cpp new file mode 100644 index 000000000..71f7f27e1 --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/threads.cpp @@ -0,0 +1,23 @@ +#include "pfc.h" + +namespace pfc { + t_size getOptimalWorkerThreadCount() { +#ifdef _WINDOWS + DWORD_PTR mask,system; + t_size ret = 0; + GetProcessAffinityMask(GetCurrentProcess(),&mask,&system); + for(t_size n=0;n(this),overridePriority ? CREATE_SUSPENDED : 0,NULL); + if (thread == NULL) throw exception_creation(); + if (overridePriority) { + SetThreadPriority(thread, priority); + ResumeThread(thread); + } + m_thread = thread; + } + bool isActive() const { + return m_thread != INVALID_HANDLE_VALUE; + } + void waitTillDone() { + close(); + } + protected: + virtual void threadProc() {PFC_ASSERT(!"Stub thread entry - should not get here");} + private: + void close() { + if (isActive()) { + WaitForSingleObject(m_thread,INFINITE); + CloseHandle(m_thread); m_thread = INVALID_HANDLE_VALUE; + } + } + + static DWORD CALLBACK g_entry(void* p_instance) { + return reinterpret_cast(p_instance)->entry(); + } + unsigned entry() { + try { + threadProc(); + } catch(...) {} + return 0; + } + HANDLE m_thread; + + PFC_CLASS_NOT_COPYABLE_EX(thread) + }; +#else +#error PORTME +#endif +} diff --git a/tools/vio2sf/src/foobar/pfc/traits.h b/tools/vio2sf/src/foobar/pfc/traits.h new file mode 100644 index 000000000..0110eb514 --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/traits.h @@ -0,0 +1,81 @@ +namespace pfc { + + class traits_default { + public: + enum { + realloc_safe = false, + needs_destructor = true, + needs_constructor = true, + constructor_may_fail = true + }; + }; + + class traits_default_movable { + public: + enum { + realloc_safe = true, + needs_destructor = true, + needs_constructor = true, + constructor_may_fail = true + }; + }; + + class traits_rawobject : public traits_default { + public: + enum { + realloc_safe = true, + needs_destructor = false, + needs_constructor = false, + constructor_may_fail = false + }; + }; + + class traits_vtable { + public: + enum { + realloc_safe = true, + needs_destructor = true, + needs_constructor = true, + constructor_may_fail = false + }; + }; + + template class traits_t : public traits_default {}; + + template + class combine_traits { + public: + enum { + realloc_safe = (traits1::realloc_safe && traits2::realloc_safe), + needs_destructor = (traits1::needs_destructor || traits2::needs_destructor), + needs_constructor = (traits1::needs_constructor || traits2::needs_constructor), + constructor_may_fail = (traits1::constructor_may_fail || traits2::constructor_may_fail), + }; + }; + + template + class traits_combined : public combine_traits,pfc::traits_t > {}; + + template class traits_t : public traits_rawobject {}; + + template<> class traits_t : public traits_rawobject {}; + template<> class traits_t : public traits_rawobject {}; + template<> class traits_t : public traits_rawobject {}; + template<> class traits_t : public traits_rawobject {}; + template<> class traits_t : public traits_rawobject {}; + template<> class traits_t : public traits_rawobject {}; + template<> class traits_t : public traits_rawobject {}; + template<> class traits_t : public traits_rawobject {}; + template<> class traits_t : public traits_rawobject {}; + template<> class traits_t : public traits_rawobject {}; + template<> class traits_t : public traits_rawobject {}; + template<> class traits_t : public traits_rawobject {}; + + template<> class traits_t : public traits_rawobject {}; + template<> class traits_t : public traits_rawobject {}; + + template<> class traits_t : public traits_rawobject {}; + + template + class traits_t : public traits_t {}; +} \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/pfc/utf8.cpp b/tools/vio2sf/src/foobar/pfc/utf8.cpp new file mode 100644 index 000000000..81b37d21b --- /dev/null +++ b/tools/vio2sf/src/foobar/pfc/utf8.cpp @@ -0,0 +1,323 @@ +#include "pfc.h" + +namespace pfc { +//utf8 stuff + +static const t_uint8 mask_tab[6]={0x80,0xE0,0xF0,0xF8,0xFC,0xFE}; + +static const t_uint8 val_tab[6]={0,0xC0,0xE0,0xF0,0xF8,0xFC}; + +t_size utf8_char_len_from_header(char p_c) throw() +{ + t_uint8 c = (t_uint8)p_c; + + t_size cnt = 0; + for(;;) + { + if ((p_c & mask_tab[cnt])==val_tab[cnt]) break; + if (++cnt>=6) return 0; + } + + return cnt + 1; + +} +t_size utf8_decode_char(const char *p_utf8,unsigned & wide) throw() { + const t_uint8 * utf8 = (const t_uint8*)p_utf8; + const t_size max = 6; + + if (utf8[0]<0x80) { + wide = utf8[0]; + return utf8[0]>0 ? 1 : 0; + } + wide = 0; + + unsigned res=0; + unsigned n; + unsigned cnt=0; + for(;;) + { + if ((*utf8&mask_tab[cnt])==val_tab[cnt]) break; + if (++cnt>=max) return 0; + } + cnt++; + + if (cnt==2 && !(*utf8&0x1E)) return 0; + + if (cnt==1) + res=*utf8; + else + res=(0xFF>>(cnt+1))&*utf8; + + for (n=1;n> (7 - cnt))) + return 0; + + res=(res<<6)|(utf8[n]&0x3F); + } + + wide = res; + + return cnt; +} + +t_size utf8_decode_char(const char *p_utf8,unsigned & wide,t_size max) throw() +{ + const t_uint8 * utf8 = (const t_uint8*)p_utf8; + + if (max==0) { + wide = 0; + return 0; + } + + if (utf8[0]<0x80) { + wide = utf8[0]; + return utf8[0]>0 ? 1 : 0; + } + if (max>6) max = 6; + wide = 0; + + unsigned res=0; + unsigned n; + unsigned cnt=0; + for(;;) + { + if ((*utf8&mask_tab[cnt])==val_tab[cnt]) break; + if (++cnt>=max) return 0; + } + cnt++; + + if (cnt==2 && !(*utf8&0x1E)) return 0; + + if (cnt==1) + res=*utf8; + else + res=(0xFF>>(cnt+1))&*utf8; + + for (n=1;n> (7 - cnt))) + return 0; + + res=(res<<6)|(utf8[n]&0x3F); + } + + wide = res; + + return cnt; +} + + +t_size utf8_encode_char(unsigned wide,char * target) throw() +{ + t_size count; + + if (wide < 0x80) + count = 1; + else if (wide < 0x800) + count = 2; + else if (wide < 0x10000) + count = 3; + else if (wide < 0x200000) + count = 4; + else if (wide < 0x4000000) + count = 5; + else if (wide <= 0x7FFFFFFF) + count = 6; + else + return 0; + //if (count>max) return 0; + + if (target == 0) + return count; + + switch (count) + { + case 6: + target[5] = 0x80 | (wide & 0x3F); + wide = wide >> 6; + wide |= 0x4000000; + case 5: + target[4] = 0x80 | (wide & 0x3F); + wide = wide >> 6; + wide |= 0x200000; + case 4: + target[3] = 0x80 | (wide & 0x3F); + wide = wide >> 6; + wide |= 0x10000; + case 3: + target[2] = 0x80 | (wide & 0x3F); + wide = wide >> 6; + wide |= 0x800; + case 2: + target[1] = 0x80 | (wide & 0x3F); + wide = wide >> 6; + wide |= 0xC0; + case 1: + target[0] = wide; + } + + return count; +} + +t_size utf16_encode_char(unsigned cur_wchar,wchar_t * out) throw() +{ + if (cur_wchar < 0x10000) { + *out = (wchar_t) cur_wchar; return 1; + } else if (cur_wchar < (1 << 20)) { + unsigned c = cur_wchar - 0x10000; + //MSDN: + //The first (high) surrogate is a 16-bit code value in the range U+D800 to U+DBFF. The second (low) surrogate is a 16-bit code value in the range U+DC00 to U+DFFF. Using surrogates, Unicode can support over one million characters. For more details about surrogates, refer to The Unicode Standard, version 2.0. + out[0] = (wchar_t)(0xD800 | (0x3FF & (c>>10)) ); + out[1] = (wchar_t)(0xDC00 | (0x3FF & c) ) ; + return 2; + } else { + *out = '?'; return 1; + } +} + +t_size utf16_decode_char(const wchar_t * p_source,unsigned * p_out,t_size p_source_length) throw() { + if (p_source_length == 0) return 0; + else if (p_source_length == 1) { + *p_out = p_source[0]; + return 1; + } else { + t_size retval = 0; + unsigned decoded = p_source[0]; + if (decoded != 0) + { + retval = 1; + if ((decoded & 0xFC00) == 0xD800) + { + unsigned low = p_source[1]; + if ((low & 0xFC00) == 0xDC00) + { + decoded = 0x10000 + ( ((decoded & 0x3FF) << 10) | (low & 0x3FF) ); + retval = 2; + } + } + } + *p_out = decoded; + return retval; + } +} + + +unsigned utf8_get_char(const char * src) +{ + unsigned rv = 0; + utf8_decode_char(src,rv); + return rv; +} + + +t_size utf8_char_len(const char * s,t_size max) throw() +{ + unsigned dummy; + return utf8_decode_char(s,dummy,max); +} + +t_size skip_utf8_chars(const char * ptr,t_size count) throw() +{ + t_size num = 0; + for(;count && ptr[num];count--) + { + t_size d = utf8_char_len(ptr+num); + if (d<=0) break; + num+=d; + } + return num; +} + +bool is_valid_utf8(const char * param,t_size max) { + t_size walk = 0; + while(walk < max && param[walk] != 0) { + t_size d; + unsigned dummy; + d = utf8_decode_char(param + walk,dummy,max - walk); + if (d==0) return false; + walk += d; + if (walk > max) { + PFC_ASSERT(0);//should not be triggerable + return false; + } + } + return true; +} + +bool is_lower_ascii(const char * param) +{ + while(*param) + { + if (*param<0) return false; + param++; + } + return true; +} + +static bool check_end_of_string(const char * ptr) +{ + __try { + return !*ptr; + } + __except(1) {return true;} +} + +unsigned strcpy_utf8_truncate(const char * src,char * out,unsigned maxbytes) +{ + unsigned rv = 0 , ptr = 0; + if (maxbytes>0) + { + maxbytes--;//for null + while(!check_end_of_string(src) && maxbytes>0) + { + __try { + t_size delta = utf8_char_len(src); + if (delta>maxbytes || delta==0) break; + do + { + out[ptr++] = *(src++); + } while(--delta); + } __except(1) { break; } + rv = ptr; + } + out[rv]=0; + } + return rv; +} + +t_size strlen_utf8(const char * p,t_size num) throw() +{ + unsigned w; + t_size d; + t_size ret = 0; + for(;num;) + { + d = utf8_decode_char(p,w); + if (w==0 || d<=0) break; + ret++; + p+=d; + num-=d; + } + return ret; +} + +t_size utf8_chars_to_bytes(const char * string,t_size count) throw() +{ + t_size bytes = 0; + while(count) + { + unsigned dummy; + t_size delta = utf8_decode_char(string+bytes,dummy); + if (delta==0) break; + bytes += delta; + count--; + } + return bytes; +} + +} \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/sdk-license.txt b/tools/vio2sf/src/foobar/sdk-license.txt new file mode 100644 index 000000000..350911121 --- /dev/null +++ b/tools/vio2sf/src/foobar/sdk-license.txt @@ -0,0 +1,14 @@ +foobar2000 0.9.5 SDK +Copyright (c) 2001-2008, Peter Pawlowski +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation or other materials provided with the distribution. + +Usage restrictions: +It is illegal to use this SDK as a part of foobar2000 components that operate outside of legally documented programming interfaces (APIs), such as using window procedure hooks to modify user interface behaviors. We believe components doing so to be harmful to our userbase by introducing compatibility issues and dependencies on undocumented behaviors of our code that may change at any time without any notice or an update to the SDK which would reflect the change. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/sdk-readme.css b/tools/vio2sf/src/foobar/sdk-readme.css new file mode 100644 index 000000000..74c0c9bc6 --- /dev/null +++ b/tools/vio2sf/src/foobar/sdk-readme.css @@ -0,0 +1 @@ +a.interwiki{background:transparent url(/wiki/lib/images/interwiki.png) 0px 1px no-repeat;padding-left:16px;}a.iw_wp{background-image:url(/wiki/lib/images/interwiki/wp.gif)}a.iw_wpde{background-image:url(/wiki/lib/images/interwiki/wpde.gif)}a.iw_wpmeta{background-image:url(/wiki/lib/images/interwiki/wpmeta.gif)}a.iw_doku{background-image:url(/wiki/lib/images/interwiki/doku.gif)}a.iw_sb{background-image:url(/wiki/lib/images/interwiki/sb.gif)}a.iw_amazon{background-image:url(/wiki/lib/images/interwiki/amazon.gif)}a.iw_amazon_de{background-image:url(/wiki/lib/images/interwiki/amazon.de.gif)}a.iw_amazon_uk{background-image:url(/wiki/lib/images/interwiki/amazon.uk.gif)}a.iw_phpfn{background-image:url(/wiki/lib/images/interwiki/phpfn.gif)}a.iw_dokubug{background-image:url(/wiki/lib/images/interwiki/dokubug.gif)}a.iw_coral{background-image:url(/wiki/lib/images/interwiki/coral.gif)}a.iw_google{background-image:url(/wiki/lib/images/interwiki/google.gif)}a.iw_meatball{background-image:url(/wiki/lib/images/interwiki/meatball.gif)}a.iw_wiki{background-image:url(/wiki/lib/images/interwiki/wiki.gif)}a.mediafile{background:transparent url(/wiki/lib/images/fileicons/file.png) 0px 1px no-repeat;padding-left:18px;padding-bottom:1px;}a.mf_jpg{background-image:url(/wiki/lib/images/fileicons/jpg.png)}a.mf_jpeg{background-image:url(/wiki/lib/images/fileicons/jpeg.png)}a.mf_gif{background-image:url(/wiki/lib/images/fileicons/gif.png)}a.mf_png{background-image:url(/wiki/lib/images/fileicons/png.png)}a.mf_tgz{background-image:url(/wiki/lib/images/fileicons/tgz.png)}a.mf_tar{background-image:url(/wiki/lib/images/fileicons/tar.png)}a.mf_gz{background-image:url(/wiki/lib/images/fileicons/gz.png)}a.mf_zip{background-image:url(/wiki/lib/images/fileicons/zip.png)}a.mf_rar{background-image:url(/wiki/lib/images/fileicons/rar.png)}a.mf_pdf{background-image:url(/wiki/lib/images/fileicons/pdf.png)}a.mf_ps{background-image:url(/wiki/lib/images/fileicons/ps.png)}a.mf_doc{background-image:url(/wiki/lib/images/fileicons/doc.png)}a.mf_xls{background-image:url(/wiki/lib/images/fileicons/xls.png)}a.mf_ppt{background-image:url(/wiki/lib/images/fileicons/ppt.png)}a.mf_rtf{background-image:url(/wiki/lib/images/fileicons/rtf.png)}a.mf_swf{background-image:url(/wiki/lib/images/fileicons/swf.png)}a.mf_rpm{background-image:url(/wiki/lib/images/fileicons/rpm.png)}a.mf_deb{background-image:url(/wiki/lib/images/fileicons/deb.png)}a.mf_sxw{background-image:url(/wiki/lib/images/fileicons/sxw.png)}a.mf_sxc{background-image:url(/wiki/lib/images/fileicons/sxc.png)}a.mf_sxi{background-image:url(/wiki/lib/images/fileicons/sxi.png)}a.mf_sxd{background-image:url(/wiki/lib/images/fileicons/sxd.png)}a.mf_odc{background-image:url(/wiki/lib/images/fileicons/odc.png)}a.mf_odf{background-image:url(/wiki/lib/images/fileicons/odf.png)}a.mf_odg{background-image:url(/wiki/lib/images/fileicons/odg.png)}a.mf_odi{background-image:url(/wiki/lib/images/fileicons/odi.png)}a.mf_odp{background-image:url(/wiki/lib/images/fileicons/odp.png)}a.mf_ods{background-image:url(/wiki/lib/images/fileicons/ods.png)}a.mf_odt{background-image:url(/wiki/lib/images/fileicons/odt.png)}div.clearer{clear:both;line-height:0px;height:0;overflow:hidden;}div.no{display:inline;margin:0;padding:0;}.hidden{display:none;}div.error{background:#fcc url(/wiki/lib/styles/../images/error.png) 0.5em 0px no-repeat;color:#000;border-bottom:1px solid #faa;font-size:90%;margin:0;padding-left:3em;overflow:hidden;}div.info{background:#ccf url(/wiki/lib/styles/../images/info.png) 0.5em 0px no-repeat;color:#000;border-bottom:1px solid #aaf;font-size:90%;margin:0;padding-left:3em;overflow:hidden;}div.success{background:#cfc url(/wiki/lib/styles/../images/success.png) 0.5em 0px no-repeat;color:#000;border-bottom:1px solid #afa;font-size:90%;margin:0;padding-left:3em;overflow:hidden;}div.notify{background:#ffc url(/wiki/lib/styles/../images/notify.png) 0.5em 0px no-repeat;color:#000;border-bottom:1px solid #ffa;font-size:90%;margin:0;padding-left:3em;overflow:hidden;}.medialeft{float:left;}.mediaright{float:right;}.mediacenter{display:block;margin-left:auto;margin-right:auto;}.leftalign{text-align:left;}.centeralign{text-align:center;}.rightalign{text-align:right;}em.u{font-style:normal;text-decoration:underline;}em em.u{font-style:italic;}.code .br0{color:#6c6;}.code .co1{color:#808080;font-style:italic;}.code .co2{color:#808080;font-style:italic;}.code .co3{color:#808080;}.code .coMULTI{color:#808080;font-style:italic;}.code .es0{color:#009;font-weight:bold;}.code .kw1{color:#b1b100;}.code .kw2{color:#000;font-weight:bold;}.code .kw3{color:#006;}.code .kw4{color:#933;}.code .kw5{color:#00f;}.code .me1{color:#060;}.code .me2{color:#060;}.code .nu0{color:#c6c;}.code .re0{color:#00f;}.code .re1{color:#00f;}.code .re2{color:#00f;}.code .re3{color:#f33;font-weight:bold;}.code .re4{color:#099;}.code .st0{color:#f00;}.code .sy0{color:#6c6;}#acl__manager label{text-align:left;font-weight:normal;display:inline;}#acl__manager table{margin-left:10%;width:80%;}#config__manager div.success,#config__manager div.error,#config__manager div.info{background-position:0.5em;padding:0.5em;text-align:center;}#config__manager fieldset{margin:1em;width:auto;margin-bottom:2em;background-color:#dee7ec;color:#000;padding:0 1em;}#config__manager legend{font-size:1.25em;}#config__manager form{}#config__manager table{margin:1em 0;width:100%;}#config__manager fieldset td{text-align:left;}#config__manager fieldset td.value{width:30em;}#config__manager td input.edit{width:30em;}#config__manager td select.edit{}#config__manager td textarea.edit{width:27.5em;height:4em;}#config__manager tr .input,#config__manager tr input,#config__manager tr textarea,#config__manager tr select{background-color:#fff;color:#000;}#config__manager tr.default .input,#config__manager tr.default input,#config__manager tr.default textarea,#config__manager tr.default select,#config__manager .selectiondefault{background-color:#cdf;color:#000;}#config__manager tr.protected .input,#config__manager tr.protected input,#config__manager tr.protected textarea,#config__manager tr.protected select,#config__manager tr.protected .selection{background-color:#fcc!important;color:#000 !important;}#config__manager td.error{background-color:red;color:#000;}#config__manager .selection{width:14.8em;float:left;margin:0 0.3em 2px 0;}#config__manager .selection label{float:right;width:14em;font-size:90%;}* html #config__manager .selection label{padding-top:2px;}#config__manager .selection input.checkbox{padding-left:0.7em;}#config__manager .other{clear:both;padding-top:0.5em;}#config__manager .other label{padding-left:2px;font-size:90%;}#plugin__manager{}#plugin__manager h2{margin-left:0;}#plugin__manager form{display:block;margin:0;padding:0;}#plugin__manager legend{display:none;}#plugin__manager fieldset{width:auto;}#plugin__manager .button{margin:0;}#plugin__manager p,#plugin__manager label{text-align:left;}#plugin__manager .hidden{display:none;}#plugin__manager .new{background:#dee7ec;}#plugin__manager input[disabled]{color:#ccc;border-color:#ccc;}#plugin__manager .pm_menu,#plugin__manager .pm_info{margin-left:0;text-align:left;}#plugin__manager .pm_menu{float:left;width:48%;}#plugin__manager .pm_info{float:right;width:50%;}#plugin__manager .common{}#plugin__manager .common form{}#plugin__manager .common fieldset{margin:0;padding:0 0 1.0em 0;text-align:left;border:none;}#plugin__manager .common label{padding:0 0 0.5em 0;}#plugin__manager .common input{}#plugin__manager .common input.edit{width:24em;margin:0.5em;}#plugin__manager .common .button{}#plugin__manager form.plugins{}#plugin__manager .plugins fieldset{color:#000;background:#fff;text-align:right;border-top:none;border-right:none;border-left:none;}#plugin__manager .plugins fieldset.protected{background:#fdd;color:#000;}#plugin__manager .plugins fieldset.disabled{background:#e0e0e0;color:#a8a8a8;}#plugin__manager .plugins .legend{color:#000;background:inherit;display:block;margin:0;padding:0;font-size:1em;line-height:1.4em;font-weight:normal;text-align:left;float:left;padding:0;clear:none;}#plugin__manager .plugins .button{font-size:95%;}#plugin__manager .plugins fieldset.buttons{border:none;}#plugin__manager .plugins fieldset.buttons .button{float:left;}#plugin__manager .pm_info h3{margin-left:0;}#plugin__manager .pm_info dl{margin:1em 0;padding:0;}#plugin__manager .pm_info dt{width:6em;float:left;clear:left;margin:0;padding:0;}#plugin__manager .pm_info dd{margin:0 0 0 7em;padding:0;background:none;}#plugin__manager .plugins .enable{float:left;width:auto;margin-right:0.5em;}#user__manager tr.disabled{color:#6f6f6f;background:#e4e4e4;}#user__manager tr.user_info{vertical-align:top;}#user__manager div.edit_user{width:46%;float:left;}#user__manager table{margin-bottom:1em;}#user__manager input.button[disabled]{color:#ccc!important;border-color:#ccc!important;}div.dokuwiki .header{padding:3px 0 0 2px;}div.dokuwiki .pagename{float:left;font-size:200%;font-weight:bolder;color:#dee7ec;text-align:left;vertical-align:middle;}div.dokuwiki .pagename a{color:#436976 !important;text-decoration:none !important;}div.dokuwiki .logo{float:right;font-size:220%;font-weight:bolder;text-align:right;vertical-align:middle;}div.dokuwiki .logo a{color:#dee7ec !important;text-decoration:none !important;font-variant:small-caps;letter-spacing:2pt;}div.dokuwiki .bar{border-top:1px solid #8cacbb;border-bottom:1px solid #8cacbb;background:#dee7ec;padding:0.1em 0.15em;clear:both;}div.dokuwiki .bar-left{float:left;}div.dokuwiki .bar-right{float:right;text-align:right;}div.dokuwiki #bar__bottom{margin-bottom:3px;}div.dokuwiki div.meta{clear:both;margin-top:1em;color:#638c9c;font-size:70%;}div.dokuwiki div.meta div.user{float:left;}div.dokuwiki div.meta div.doc{text-align:right;}*{padding:0;margin:0;}body{font:80% "Lucida Grande",Verdana,Lucida,Helvetica,Arial,sans-serif;background-color:#fff;color:#000;}div.dokuwiki div.page{margin:4px 2em 0 1em;text-align:justify;}div.dokuwiki table{font-size:100%;}div.dokuwiki tr,div.dokuwiki td,div.dokuwiki th{}div.dokuwiki img{border:0;}div.dokuwiki p,div.dokuwiki blockquote,div.dokuwiki table,div.dokuwiki pre{margin:0 0 1.0em 0;}div.dokuwiki hr{border:0px;border-top:1px solid #8cacbb;text-align:center;height:0px;}div.dokuwiki div.nothing{text-align:center;margin:2em;}div.dokuwiki form{border:none;display:inline;}div.dokuwiki label.block{display:block;text-align:right;font-weight:bold;}div.dokuwiki label.simple{display:block;text-align:left;font-weight:normal;}div.dokuwiki label.block input.edit{width:50%;}div.dokuwiki fieldset{width:300px;text-align:center;border:1px solid #8cacbb;padding:0.5em;margin:auto;}div.dokuwiki textarea.edit{font-family:monospace;font-size:14px;color:#000;background-color:#fff;border:1px solid #8cacbb;padding:0.3em 0 0 0.3em;width:100%;}html>body div.dokuwiki textarea.edit{background:#fff url(/wiki/lib/tpl/default/images/inputshadow.png) repeat-x top;}div.dokuwiki input.edit,div.dokuwiki select.edit{font-size:100%;border:1px solid #8cacbb;color:#000;background-color:#fff;vertical-align:middle;margin:1px;padding:0.20em 0.3em;display:inline;}html>body div.dokuwiki input.edit,html>body div.dokuwiki select.edit{background:#fff url(/wiki/lib/tpl/default/images/inputshadow.png) repeat-x top;}div.dokuwiki select.edit{padding:0.1em 0;}div.dokuwiki input.missing{font-size:100%;border:1px solid #8cacbb;color:#000;background-color:#fcc;vertical-align:middle;margin:1px;padding:0.20em 0.3em;display:inline;}div.dokuwiki textarea.edit[disabled],div.dokuwiki textarea.edit[readonly],div.dokuwiki input.edit[disabled],div.dokuwiki input.edit[readonly],div.dokuwiki select.edit[disabled]{background-color:#f5f5f5!important;color:#666!important;}div.dokuwiki div.toolbar,div.dokuwiki div#wiki__editbar{margin:2px 0;text-align:left;}div.dokuwiki div#size__ctl{float:right;width:60px;height:2.7em;}div.dokuwiki #size__ctl img{cursor:pointer;}div.dokuwiki div#wiki__editbar div.editButtons{float:left;padding:0 1.0em 0.7em 0;}div.dokuwiki div#wiki__editbar div.summary{float:left;}div.dokuwiki .nowrap{white-space:nowrap;}div.dokuwiki div#draft__status{float:right;color:#638c9c;}div.dokuwiki input.button,div.dokuwiki button.button{border:1px solid #8cacbb;color:#000;background-color:#fff;vertical-align:middle;text-decoration:none;font-size:100%;cursor:pointer;margin:1px;padding:0.125em 0.4em;}html>body div.dokuwiki input.button,html>body div.dokuwiki button.button{background:#fff url(/wiki/lib/tpl/default/images/buttonshadow.png) repeat-x bottom;}* html div.dokuwiki input.button,* html div.dokuwiki button.button{height:1.8em;}div.dokuwiki div.secedit input.button{border:1px solid #8cacbb;color:#000;background-color:#fff;vertical-align:middle;text-decoration:none;margin:0;padding:0;font-size:10px;cursor:pointer;float:right;display:inline;}div.dokuwiki div.pagenav{margin:1em 0 0 0;}div.dokuwiki div.pagenav-prev{text-align:right;float:left;width:49%}div.dokuwiki div.pagenav-next{text-align:left;float:right;width:49%}div.dokuwiki a:link,div.dokuwiki a:visited{color:#436976;text-decoration:none;}div.dokuwiki a:hover,div.dokuwiki a:active{color:#000;text-decoration:underline;}div.dokuwiki h1 a,div.dokuwiki h2 a,div.dokuwiki h3 a,div.dokuwiki h4 a,div.dokuwiki h5 a,div.dokuwiki a.nolink{color:#000 !important;text-decoration:none !important;}div.dokuwiki a.urlextern{background:transparent url(/wiki/lib/tpl/default/images/link_icon.gif) 0px 1px no-repeat;padding:1px 0px 1px 16px;}div.dokuwiki a.windows{background:transparent url(/wiki/lib/tpl/default/images/windows.gif) 0px 1px no-repeat;padding:1px 0px 1px 16px;}div.dokuwiki a.interwiki{}div.dokuwiki a.media{}div.dokuwiki a.urlextern:link,div.dokuwiki a.windows:link,div.dokuwiki a.interwiki:link{color:#436976;}div.dokuwiki a.urlextern:visited,div.dokuwiki a.windows:visited,div.dokuwiki a.interwiki:visited{color:purple;}div.dokuwiki a.urlextern:hover,div.dokuwiki a.urlextern:active,div.dokuwiki a.windows:hover,div.dokuwiki a.windows:active,div.dokuwiki a.interwiki:hover,div.dokuwiki a.interwiki:active{color:#000;}div.dokuwiki a.mail{background:transparent url(/wiki/lib/tpl/default/images/mail_icon.gif) 0px 1px no-repeat;padding:1px 0px 1px 16px;}div.dokuwiki a.wikilink1{color:#090 !important;}div.dokuwiki a.wikilink2{color:#f30 !important;text-decoration:none !important;border-bottom:dashed 1px #f30 !important;}div.dokuwiki div.preview{background-color:#f5f5f5;margin:0 0 0 2em;padding:4px;border:1px dashed #000;}div.dokuwiki div.breadcrumbs{background-color:#f5f5f5;color:#666;font-size:80%;padding:0 0 0 4px;}div.dokuwiki span.user{color:#ccc;font-size:90%;}div.dokuwiki li.minor{color:#666;font-style:italic;}div.dokuwiki img.media{margin:3px;}div.dokuwiki img.medialeft{border:0;float:left;margin:0 1.5em 0 0;}div.dokuwiki img.mediaright{border:0;float:right;margin:0 0 0 1.5em;}div.dokuwiki img.mediacenter{border:0;display:block;margin:0 auto;}div.dokuwiki img.middle{vertical-align:middle;}div.dokuwiki acronym{cursor:help;border-bottom:1px dotted #000;}div.dokuwiki h1,div.dokuwiki h2,div.dokuwiki h3,div.dokuwiki h4,div.dokuwiki h5{color:#000;background-color:inherit;font-size:100%;font-weight:normal;margin:0 0 1em 0;padding:0.5em 0 0 0;border-bottom:1px solid #8cacbb;clear:left;}div.dokuwiki h1{font-size:160%;margin-left:0px;font-weight:bold;}div.dokuwiki h2{font-size:150%;margin-left:20px;}div.dokuwiki h3{font-size:140%;margin-left:40px;border-bottom:none;font-weight:bold;}div.dokuwiki h4{font-size:120%;margin-left:60px;border-bottom:none;font-weight:bold;}div.dokuwiki h5{font-size:100%;margin-left:80px;border-bottom:none;font-weight:bold;}div.dokuwiki div.level1{margin-left:3px;}div.dokuwiki div.level2{margin-left:23px;}div.dokuwiki div.level3{margin-left:43px;}div.dokuwiki div.level4{margin-left:63px;}div.dokuwiki div.level5{margin-left:83px;}div.dokuwiki ul{line-height:1.5em;list-style-type:square;list-style-image:none;margin:0 0 0.5em 1.5em;color:#638c9c;}div.dokuwiki ol{line-height:1.5em;list-style-image:none;margin:0 0 0.5em 1.5em;color:#638c9c;font-weight:bold;}div.dokuwiki .li{color:#000;font-weight:normal;}div.dokuwiki ol{list-style-type:decimal}div.dokuwiki ol ol{list-style-type:upper-roman}div.dokuwiki ol ol ol{list-style-type:lower-alpha}div.dokuwiki ol ol ol ol{list-style-type:lower-greek}div.dokuwiki li.open{list-style-image:url(/wiki/lib/tpl/default/images/open.gif);}div.dokuwiki li.closed{list-style-image:url(/wiki/lib/tpl/default/images/closed.gif);}div.dokuwiki blockquote{border-left:2px solid #8cacbb;padding-left:3px;}div.dokuwiki pre{font-size:120%;padding:0.5em;border:1px dashed #8cacbb;color:#000;overflow:auto;}div.dokuwiki pre.pre{background-color:#f7f9fa;}div.dokuwiki pre.code{background-color:#f7f9fa;}div.dokuwiki code{font-size:120%;}div.dokuwiki pre.file{background-color:#dee7ec;}div.dokuwiki table.inline{background-color:#fff;border-spacing:0px;border-collapse:collapse;}div.dokuwiki table.inline th{padding:3px;border:1px solid #8cacbb;background-color:#dee7ec;}div.dokuwiki table.inline td{padding:3px;border:1px solid #8cacbb;}div.dokuwiki div.toc{margin:1.2em 0 0 2em;float:right;width:200px;font-size:80%;clear:both;}div.dokuwiki div.tocheader{border:1px solid #8cacbb;background-color:#dee7ec;text-align:left;font-weight:bold;padding:3px;margin-bottom:2px;}div.dokuwiki span.toc_open,div.dokuwiki span.toc_close{border:0.4em solid #dee7ec;float:right;display:block;margin:0.4em 3px 0 0;}div.dokuwiki span.toc_open span,div.dokuwiki span.toc_close span{display:none;}div.dokuwiki span.toc_open{margin-top:0.4em;border-top:0.4em solid #000;}div.dokuwiki span.toc_close{margin-top:0;border-bottom:0.4em solid #000;}div.dokuwiki #toc__inside{border:1px solid #8cacbb;background-color:#fff;text-align:left;padding:0.5em 0 0.7em 0;}div.dokuwiki ul.toc{list-style-type:none;list-style-image:none;line-height:1.2em;padding-left:1em;margin:0;}div.dokuwiki ul.toc li{background:transparent url(/wiki/lib/tpl/default/images/tocdot2.gif) 0 0.6em no-repeat;padding-left:0.4em;}div.dokuwiki ul.toc li.clear{background-image:none;padding-left:0.4em;}div.dokuwiki a.toc:link,div.dokuwiki a.toc:visited{color:#436976;}div.dokuwiki a.toc:hover,div.dokuwiki a.toc:active{color:#000;}div.dokuwiki table.diff{background-color:#fff;width:100%;}div.dokuwiki td.diff-blockheader{font-weight:bold;}div.dokuwiki table.diff th{border-bottom:1px solid #8cacbb;font-size:120%;width:50%;font-weight:normal;text-align:left;}div.dokuwiki table.diff td{font-family:monospace;font-size:100%;}div.dokuwiki td.diff-addedline{background-color:#dfd;}div.dokuwiki td.diff-deletedline{background-color:#ffb;}div.dokuwiki td.diff-context{background-color:#f5f5f5;}div.dokuwiki table.diff td.diff-addedline strong,div.dokuwiki table.diff td.diff-deletedline strong{color:red;}div.dokuwiki div.footnotes{clear:both;border-top:1px solid #8cacbb;padding-left:1em;margin-top:1em;}div.dokuwiki div.fn{font-size:90%;}div.dokuwiki a.fn_top{vertical-align:super;font-size:80%;}div.dokuwiki a.fn_bot{vertical-align:super;font-size:80%;font-weight:bold;}div.insitu-footnote{font-size:80%;line-height:1.2em;border:1px solid #8cacbb;background-color:#f7f9fa;text-align:left;padding:4px;max-width:40%;}* html .insitu-footnote pre.code,* html .insitu-footnote pre.file{padding-bottom:18px;}div.dokuwiki .search_result{margin-bottom:6px;padding:0 10px 0 30px;}div.dokuwiki .search_snippet{color:#ccc;font-size:12px;margin-left:20px;}div.dokuwiki .search_sep{color:#000;}div.dokuwiki .search_hit{color:#000;background-color:#ff9;}div.dokuwiki strong.search_hit{font-weight:normal;}div.dokuwiki div.search_quickresult{margin:0 0 15px 30px;padding:0 10px 10px 0;border-bottom:1px dashed #8cacbb;}div.dokuwiki div.search_quickresult h3{margin:0 0 1.0em 0;font-size:1em;font-weight:bold;}div.dokuwiki ul.search_quickhits{margin:0 0 0.5em 1.0em;}div.dokuwiki ul.search_quickhits li{margin:0 1.0em 0 1.0em;float:left;width:30%;}div.footerinc{text-align:center;}.footerinc a img{opacity:0.5;border:0;}.footerinc a:hover img{opacity:1;}div.dokuwiki div.ajax_qsearch{position:absolute;right:237px;;width:200px;opacity:0.9;display:none;font-size:80%;line-height:1.2em;border:1px solid #8cacbb;background-color:#f7f9fa;text-align:left;padding:4px;}button.toolbutton{background-color:#fff;padding:0px;margin:0 1px 0 0;border:1px solid #8cacbb;cursor:pointer;}html>body button.toolbutton{background:#fff url(/wiki/lib/tpl/default/images/buttonshadow.png) repeat-x bottom;}div.picker{width:250px;border:1px solid #8cacbb;background-color:#dee7ec;}button.pickerbutton{padding:0px;margin:0 1px 1px 0;border:0;background-color:transparent;font-size:80%;cursor:pointer;}div.dokuwiki a.spell_error{color:#f00;text-decoration:underline;}div.dokuwiki div#spell__suggest{background-color:#fff;padding:2px;border:1px solid #000;font-size:80%;display:none;}div.dokuwiki div#spell__result{border:1px solid #8cacbb;color:#000;font-size:14px;padding:3px;background-color:#f7f9fa;display:none;}div.dokuwiki span.spell_noerr{color:#093;}div.dokuwiki span.spell_wait{color:#06c;}div.dokuwiki div.img_big{float:left;margin-right:0.5em;}div.dokuwiki dl.img_tags dt{font-weight:bold;background-color:#dee7ec;}div.dokuwiki dl.img_tags dd{background-color:#f5f5f5;}div.dokuwiki div.imagemeta{color:#666;font-size:70%;line-height:95%;}div.dokuwiki div.imagemeta img.thumb{float:left;margin-right:0.1em;}#media__manager{height:100%;overflow:hidden;}#media__left{width:30%;border-right:solid 1px #8cacbb;height:100%;overflow:auto;position:absolute;left:0;}#media__right{width:69.7%;height:100%;overflow:auto;position:absolute;right:0;}#media__manager h1{margin:0;padding:0;margin-bottom:0.5em;}#media__tree img{float:left;padding:0.5em 0.3em 0 0;}#media__tree ul{list-style-type:none;list-style-image:none;}#media__tree li{clear:left;list-style-type:none;list-style-image:none;}* html #media__tree li{border:1px solid #fff;}#media__opts{padding-left:1em;margin-bottom:0.5em;}#media__opts input{float:left;position:absolute;}* html #media__opts input{position:static;}#media__opts label{display:block;float:left;margin-left:30px;}* html #media__opts label{margin-left:10px;}#media__opts br{clear:left;}#media__content img.load{margin:1em auto;}#media__content #scroll__here{border:1px dashed #8cacbb;}#media__content .odd{background-color:#f7f9fa;padding:0.4em;}#media__content .even{padding:0.4em;}#media__content a.mediafile{margin-right:1.5em;font-weight:bold;}#media__content div.detail{padding:0.3em 0 0.3em 2em;}#media__content div.detail div.thumb{float:left;width:130px;text-align:center;margin-right:0.4em;}#media__content img.btn{vertical-align:text-bottom;}#media__content div.example{color:#666;margin-left:1em;}#media__content div.upload{font-size:90%;padding:0 0.5em 0.5em 0.5em;}#media__content form.upload{display:block;border-bottom:solid 1px #8cacbb;padding:0 0.5em 1em 0.5em;}#media__content form.upload fieldset{padding:0;margin:0;border:none;width:auto;}#media__content form.upload p{clear:left;text-align:left;padding:0.25em 0;margin:0;line-height:1.0em;}#media__content form.upload label{float:left;width:30%;}#media__content form.upload label.check{float:none;width:auto;}#media__content form.upload input.check{margin-left:30%;}#media__content form.meta{display:block;padding:0 0 1em 0;}#media__content form.meta label{display:block;width:25%;float:left;font-weight:bold;margin-left:1em;clear:left;}#media__content form.meta .edit{font:100% "Lucida Grande",Verdana,Lucida,Helvetica,Arial,sans-serif;float:left;width:70%;padding-right:0;padding-left:0.2em;margin:2px;}#media__content form.meta textarea.edit{height:8em;}#media__content form.meta div.metafield{clear:left;}#media__content form.meta div.buttons{clear:left;margin-left:20%;padding-left:1em;} \ No newline at end of file diff --git a/tools/vio2sf/src/foobar/sdk-readme.html b/tools/vio2sf/src/foobar/sdk-readme.html new file mode 100644 index 000000000..e7dec6cbc --- /dev/null +++ b/tools/vio2sf/src/foobar/sdk-readme.html @@ -0,0 +1,372 @@ + + + foobar2000 0.9.5 SDK readme + + + + + +
+ + + + +

foobar2000 0.9.5 SDK readme

+
+ +
+ +

Compatibility

+
+ +

+ Components built with this SDK are compatible with foobar2000 0.9.5. They are not compatible with any earlier versions (will fail to load), and not guaranteed to be compatible with any future versions, though upcoming 0.9.X releases will aim to maintain compatibility as far as possible without crippling newly added functionality. +

+ +
+ +

New features provided by incremental updates

+
+ +

+Some of non-critical functionality provided through this SDK (flagged as such) was introduced in one of incremental 0.9.5.X updates and will not function when used with foobar2000 versions older than specified in the description of specific API. For an example: +

+
try {
+  //Attempting to use an API that was introduced in 0.9.5.1:
+  static_api_ptr_t<app_close_blocking_task_manager>()->register_task(mytask);
+} catch(exception_service_not_found) {
+  //User's foobar2000 is older than 0.9.5.1.
+  //Possible responses: ignore and disable affected functionality, complain to user about outdated install, etc.
+}
+
+ +

Basic usage

+
+ +

+ Each component must link against: +

+
    +
  • foobar2000_SDK project (contains declarations of services and various service-specific helper code)
    +
  • +
  • foobar2000_component_client project (contains DLL entrypoint)
    +
  • +
  • shared.dll (various helper code, mainly win32 function wrappers taking UTF-8 strings)
    +
  • +
  • PFC (non-OS-specific helper class library)
    +
  • +
+ +

+Optionally, components can use helper libraries with various non-critical code that is commonly reused across various foobar2000 components: +

+
    +
  • foobar2000_SDK_helpers - a library of various helper code commonly used by foobar2000 components.
    +
  • +
  • foobar2000_ATL_helpers - another library of various helper code commonly used by foobar2000 components; requires WTL. Note that it depends on foobar2000_SDK and foobar2000_SDK_helpers projects.
    +
  • +
+ +

+ Foobar2000_SDK, foobar2000_component_client and PFC are included in sourcecode form; you can link against them by adding them to your workspace and using dependencies. To link against shared.dll, you must add “shared.lib” to linker input manually. +

+ +

+Component code should include the following header files: +

+
    +
  • foobar2000.h from SDK - do not include other headers from the SDK directory directly, they're meant to be referenced by foobar2000.h only; it also includes PFC headers and shared.dll helper declaration headers.
    +
  • +
  • Optionally: helpers.h from helpers directory (foobar2000_SDK_helpers project) - a library of various helper code commonly used by foobar2000 components.
    +
  • +
  • Optionally: ATLHelpers.h from ATLHelpers directory (foobar2000_ATL_helpers project) - another library of various helper code commonly used by foobar2000 components; requires WTL. Note that ATLHelpers.h already includes SDK/foobar2000.h and helpers/helpers.h so you can replace your other include lines with a reference to ATLHelpers.h.
    +
  • +
+ +
+ +

Structure of a component

+
+ +

+ A component is a DLL that implements one or more entrypoint services and interacts with services provided by other components. +

+ +
+ +

Services

+
+ +

+ A service type is an interface class, deriving directly or indirectly from service_base class. A service type class must not have any data members; it can only provide virtual methods (to be overridden by service implementation), helper non-virtual methods built around virtual methods, static helper methods, and constants / enums. Each service interface class must have a static class_guid member, used for identification when enumerating services or querying for supported functionality. A service type declaration should declare a class with public virtual/helper/static methods, and use FB2K_MAKE_SERVICE_INTERFACE() / FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT() macro to implement standard service behaviors for the class; additionally, class_guid needs to be defined outside class declaration (e.g. const GUID someclass::class_guid = {….}; ). Note that most of components will not declare their own service types, they will only implement existing ones declared in the SDK. +

+ +

+A service implementation is a class derived from relevant service type class, implementing virtual methods declared by service type class. Note that service implementation class does not implement virtual methods declared by service_base; those are implemented by service type declaration framework (service_query) or by instantiation framework (service_add_ref / service_release). Service implementation classes are instantiated using service_factory templates in case of entrypoint services (see below), or using service_impl_t template and operator new: ”myserviceptr = new service_impl_t<myservice_impl>(params);”. +

+ +

+Each service object provides reference counter features and (service_add_ref() and service_release() methods) as well as a method to query for extended functionality (service_query() method). Those methods are implemented by service framework and should be never overridden by service implementations. These methods should also never be called directly - reference counter methods are managed by relevant autopointer templates, service_query_t function template should be used instead of calling service_query directly, to ensure type safety and correct type conversions. +

+ +
+ +

Entrypoint services

+
+ +

+ An entrypoint service type is a special case of a service type that can be registered using service_factory templates, and then accessed from any point of service system (excluding DLL startup/shutdown code, such as code inside static object constructors/destructors). An entrypoint service type class must directly derive from service_base. +

+ +

+Registered entrypoint services can be accessed using: +

+
    +
  • For services types with variable number of implementations registered: service_enum_t<T> template, service_class_helper_t<T> template, etc, e.g.
    service_enum_t<someclass> e; service_ptr_t<someclass> ptr; while(e.next(ptr)) ptr->dosomething();
    +
  • +
  • For services types with single always-present implementation registered - such as core services like playlist_manager - using static_api_ptr_t<T> template, e.g.:
    static_api_ptr_t<someclass> api; api->dosomething(); api->dosomethingelse();
    +
  • +
  • Using per-service-type defined static helper functions, e.g. someclass::g_dosomething() - those use relevant service enumeration methods internally.
    +
  • +
+ +

+ An entrypoint service type must use FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT() macro to implement standard entrypoint service behaviors, as opposed to all other service types that use FB2K_MAKE_SERVICE_INTERFACE() macro instead. +

+ +

+You can register your own entrypoint service implementations using either service_factory_t or service_factory_single_t template - the difference between the two is that the former instantiates the class on demand, while the latter keeps a single static instance and returns references to it when requested; the latter is faster but usable only for things that have no per-instance member data to maintain. Each service_factory_t / service_factory_single_t instance should be a static variable, such as: ”static service_factory_t<myclass> g_myclass_factory;”. +

+ +

+Certain service types require custom service_factory helper templates to be used instead of standard service_factory_t / service_factory_single_t templates; see documentation of specific service type for exact info about registering. +

+ +

+A typical entrypoint service implementation looks like this: +

+
class myservice_impl : public myservice {
+public:
+	void dosomething() {....};
+	void dosomethingelse(int meh) {...};
+};
+static service_factory_single_t<myservice_impl> g_myservice_impl_factory;
+
+ +

Service extensions

+
+ +

+ Additional methods can be added to any service type, by declaring a new service type class deriving from service type class you want to extend. For example: +

+
class myservice : public service_base { public: virtual void dosomething() = 0; FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(myservice); };
+class myservice_v2 : public myservice { public: virtual void dosomethingelse() = 0; FB2K_MAKE_SERVICE_INTERFACE(myservice_v2, myservice); };
+

+ In such scenario, to query whether a myservice instance is a myservice_v2 and to retrieve myservice_v2 pointer, use service_query functionality: +

+
service_ptr_t<myservice> ptr;
+(...)
+service_ptr_t<myservice_v2> ptr_ex;
+if (ptr->service_query_t(ptr_ex)) { /* ptr_ex is a valid pointer to myservice_v2 interface of our myservice instance */ (...) }
+else {/* this myservice implementation does not implement myservice_v2 */ (...) }
+
+ +

Autopointer template use

+
+ +

+ When performing most kinds of service operations, service_ptr_t<T> template should be used rather than working with service pointers directly; it automatically manages reference counter calls, ensuring that the service object is deleted when it is no longer referenced. Additionally, static_api_ptr_t<T> can be used to automatically acquire/release a pointer to single-implementation entrypoint service, such as one of standard APIs like playlist_manager. +

+ +
+ +

Exception use

+
+ +

+ Most of API functions use C++ exceptions to signal failure conditions. All used exception classes must derive from std::exception (which pfc::exception is typedef'd to); this design allows various instances of code to use single catch() line to get human-readable description of the problem to display. +

+ +

+Additionally, special subclasses of exceptions are defined for use in specific conditions, such as exception_io for I/O failures. As a result, you must provide an exception handler whenever you invoke any kind of I/O code that may fail, unless in specific case calling context already handles exceptions (e.g. input implementation code - any exceptions should be forwarded to calling context, since exceptions are a part of input API). +

+ +

+Implementations of global callback services such as playlist_callback, playback_callback or library_callback must not throw unhandled exceptions; behaviors in case they do are undefined (app termination is to be expected). +

+ +
+ +

Storing configuration

+
+ +

+ In order to create your entries in the configuration file, you must instantiate some objects that derive from cfg_var class. Those can be either predefined classes (cfg_int, cfg_string, etc) or your own classes implementing relevant methods. +

+ +

+Each cfg_var instance has a GUID assigned, to identify its configuration file entry. The GUID is passed to its constructor (which implementations must take care of, typically by providing a constructor that takes a GUID and forwards it to cfg_var constructor). +

+ +

+Note that cfg_var objects can only be instantiated statically (either directly as static objects, or as members of other static objects). Additionally, you can create configuration data objects that can be accessed by other components, by implementing config_object service. Some standard configuration variables can be also accessed using config_object interface. +

+ +
+ +

Use of global callback services

+
+ +

+ Multiple service classes presented by the SDK allow your component to receive notifications about various events: +

+
    +
  • file_operation_callback - tracking file move/copy/delete operations.
    +
  • +
  • library_callback - tracking Media Library content changes.
    +
  • +
  • metadb_io_callback - tracking tag read / write operations altering cached/displayed media information.
    +
  • +
  • play_callback - tracking playback related events.
    +
  • +
  • playback_statistics_collector - collecting information about played tracks.
    +
  • +
  • playlist_callback, playlist_callback_single - tracking playlist changes (the latter tracks only active playlist changes).
    +
  • +
  • playback_queue_callback - tracking playback queue changes.
    +
  • +
  • titleformat_config_callback - tracking changes of title formatting configuration.
    +
  • +
  • ui_drop_item_callback - filtering items dropped into the UI.
    +
  • +
+ +

+All of global callbacks operate only within main app thread, allowing easy cooperation with windows GUI - for an example, you perform playlist view window repainting directly from your playlist_callback implementation. +

+ +

+There are restrictions on things that are legal to call from within global callbacks. For an example, you can't modify playlist from inside a playlist callback, because there are other registered callbacks tracking playlist changes that haven't been notified about the change being currently processed yet. +

+ +

+IMPORTANT: You must not enter modal message loops from inside global callbacks, as those allow any unrelated code (queued messages, user input, etc.) to be executed, without being aware that a global callback is being processed. Certain global API methods such as metadb_io::load_info_multi or threaded_process::run_modal enter modal loops when called. In other words, calling tag read/write operations from within one of global callbacks is illegal and will lead to issues. Use main_thread_callback service to avoid this problem and delay execution of problematic code. +

+ +
+ +

Service class design guidelines (advanced)

+
+ +

+ This chapter describes things you should keep on your mind when designing your own service type classes. Since 99% of components will only implement existing service types rather than adding their own cross-DLL-communication protocols, you can probably skip reading this chapter. +

+ +
+ +

Cross-DLL safety

+
+ +

+ It is important that all function parameters used by virtual methods of services are cross-DLL safe (do not depend on compiler-specific or runtime-specific behaviors, so no unexpected behaviors occur when calling code is built with different compiler/runtime than callee). To achieve this, any classes passed around must be either simple objects with no structure that could possibly vary with different compilers/runtimes (i.e. make sure that any memory blocks are freed on the side that allocated them); easiest way to achieve this is to reduce all complex data objects or classes passed around to interfaces with virtual methods, with implementation details hidden from callee. For an example, use pfc::string_base& as parameter to a function that is meant to return variable-length strings. +

+ +
+ +

Entrypoint service efficiency

+
+ +

+ When designing an entrypoint service interface meant to have multiple different implementations, you should consider making it possible for all its implementations to use service_factory_single_t (i.e. no per-instance member data); by e.g. moving functionality that needs multi-instance operation to a separate service type class that is created on-demand by one of entrypoint service methods. For example: +

+
class myservice : public service_base {
+public:
+	//this method accesses per-instance member data of the implementation class
+	virtual void workerfunction(const void * p_databuffer,t_size p_buffersize) = 0;
+	//this method is used to determine which implementation can be used to process specific data stream.
+	virtual bool queryfunction(const char * p_dataformat) = 0;
+ 
+	FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(myservice);
+};
+(...)
+service_ptr_t<myservice> findservice(const char * p_dataformat) {
+	service_enum_t<myservice> e; service_ptr_t<myservice> ptr;
+	//BOTTLENECK, this dynamically instantiates the service for each query.
+	while(e.next(ptr)) {
+		if (ptr->queryfunction(p_dataformat)) return ptr;
+	}
+	throw exception_io_data();
+}
+

+.. should be changed to: +

+
//no longer an entrypoint service - use myservice::instantiate to get an instance instead.
+class myservice_instance : public service_base {
+public:
+	virtual void workerfunction(const void * p_databuffer,t_size p_buffersize) = 0;
+	FB2K_MAKE_SERVICE_INTERFACE(myservice_instance,service_base);
+};
+ 
+class myservice : public service_base {
+public:
+	//this method is used to determine which implementation can be used to process specific data stream.
+	virtual bool queryfunction(const char * p_dataformat) = 0;
+	virtual service_ptr_t<myservice_instance> instantiate() = 0;
+	FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(myservice);
+};
+ 
+template<typename t_myservice_instance_impl>
+class myservice_impl_t : public myservice {
+public:
+	//implementation of myservice_instance must provide static bool g_queryformatfunction(const char*);
+	bool queryfunction(const char * p_dataformat) {return t_myservice_instance_impl::g_queryfunction(p_dataformat);}
+	service_ptr_t<myservice_instance> instantiate() {return new service_impl_t<t_myservice_instance_impl>();}
+};
+ 
+template<typename t_myservice_instance_impl> class myservice_factory_t :
+	public service_factory_single_t<myservice_impl_t<t_myservice_instance_impl> > {};
+//usage: static myservice_factory_t<myclass> g_myclass_factory;
+ 
+(...)
+ 
+service_ptr_t<myservice_instance> findservice(const char * p_dataformat) {
+	service_enum_t<myservice> e; service_ptr_t<myservice> ptr;
+	//no more bottleneck, enumerated service does not perform inefficient operations when requesting an instance.
+	while(e.next(ptr)) {
+		//"inefficient" part is used only once, with implementation that actually supports what we request.
+		if (ptr->queryfunction(p_dataformat)) return ptr->instantiate();
+	}
+	throw exception_io_data();
+}
+
+
+ + diff --git a/tools/vio2sf/src/foobar8/foobar2000/foobar2000_component_client/foobar2000_component_client.dsp b/tools/vio2sf/src/foobar8/foobar2000/foobar2000_component_client/foobar2000_component_client.dsp new file mode 100644 index 000000000..aeaf93383 --- /dev/null +++ b/tools/vio2sf/src/foobar8/foobar2000/foobar2000_component_client/foobar2000_component_client.dsp @@ -0,0 +1,92 @@ +# Microsoft Developer Studio Project File - Name="foobar2000_component_client" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Static Library" 0x0104 + +CFG=foobar2000_component_client - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "foobar2000_component_client.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "foobar2000_component_client.mak" CFG="foobar2000_component_client - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "foobar2000_component_client - Win32 Release" (based on "Win32 (x86) Static Library") +!MESSAGE "foobar2000_component_client - Win32 Debug" (based on "Win32 (x86) Static Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "foobar2000_component_client - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Target_Dir "" +MTL=midl.exe +F90=df.exe +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX- /O1 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo + +!ELSEIF "$(CFG)" == "foobar2000_component_client - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Target_Dir "" +MTL=midl.exe +F90=df.exe +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo + +!ENDIF + +# Begin Target + +# Name "foobar2000_component_client - Win32 Release" +# Name "foobar2000_component_client - Win32 Debug" +# Begin Source File + +SOURCE=.\component_client.cpp +# End Source File +# End Target +# End Project diff --git a/tools/vio2sf/src/foobar8/pfc/ptr_list.h b/tools/vio2sf/src/foobar8/pfc/ptr_list.h new file mode 100644 index 000000000..2e58aaf80 --- /dev/null +++ b/tools/vio2sf/src/foobar8/pfc/ptr_list.h @@ -0,0 +1,201 @@ +#ifndef __PFC_PTR_LIST_H_ +#define __PFC_PTR_LIST_H_ + +class NOVTABLE ptr_list_root//base interface (avoids bloating code with templated vtables) +{ +protected: + virtual unsigned _ptr_list_get_count() const = 0; + virtual void* _ptr_list_get_item(unsigned n) const = 0; + virtual void* _ptr_list_remove_by_idx(unsigned idx) = 0; + virtual void _ptr_list_filter_mask(const bit_array & mask) = 0; + virtual void _ptr_list_insert_item(void* item,unsigned idx) = 0; +}; + +template +class NOVTABLE ptr_list_interface : public ptr_list_root//cross-dll safe interface, use this for passing data around between components; you can typecast ptr_list_t to it +{ +public: + inline unsigned get_count() const {return _ptr_list_get_count();} + inline T* get_item(unsigned idx) const {return reinterpret_cast(_ptr_list_get_item(idx));} + inline T* remove_by_idx(unsigned idx) {return reinterpret_cast(_ptr_list_remove_by_idx(idx));} + inline void filter_mask(const bit_array & mask) {_ptr_list_filter_mask(mask);} + inline void insert_item(T* item,unsigned idx) {_ptr_list_insert_item(const_cast(reinterpret_cast(item)),idx);} + + inline unsigned add_item(T* item) {unsigned idx = get_count();insert_item(item,idx);return idx;} + inline void remove_mask(const bit_array & mask) {filter_mask(bit_array_not(mask));} + inline void remove_all() {filter_mask(bit_array_false());} + + inline T* operator[](unsigned n) const {return get_item(n);} +}; + +#define ptr_list_base ptr_list_interface + +#define void_cast(blah) const_cast(reinterpret_cast(blah)) + +class ptr_list : public mem_block_list, virtual public ptr_list_root +{ +private: + virtual unsigned _ptr_list_get_count() const {return get_count();} + virtual void* _ptr_list_get_item(unsigned idx) const {return void_cast(get_item(idx));} + virtual void* _ptr_list_remove_by_idx(unsigned idx) {return void_cast(remove_by_idx(idx));} + virtual void _ptr_list_filter_mask(const bit_array & mask) {filter_mask(mask);} + virtual void _ptr_list_insert_item(void* item,unsigned idx) {insert_item(item,idx);} +public: + using mem_block_list::get_count; + using mem_block_list::get_item; + using mem_block_list::remove_by_idx; + using mem_block_list::filter_mask; + using mem_block_list::insert_item; + using mem_block_list::apply_order; + + void * operator[](unsigned n) const {return get_item(n);} + + void free_by_idx(unsigned n) + { + void * ptr = remove_by_idx(n); + assert(ptr); + free(ptr); + } + void free_all() + { + unsigned n,max=get_count(); + for(n=0;n +class ptr_list_t : public ptr_list +{ +public: + using ptr_list::get_count; + inline T* get_item(unsigned idx) const {return reinterpret_cast(ptr_list::get_item(idx));} + inline T* remove_by_idx(unsigned idx) {return reinterpret_cast(ptr_list::remove_by_idx(idx));} + using ptr_list::filter_mask; + inline void insert_item(T* item,unsigned idx) {ptr_list::insert_item(void_cast(item),idx);} + + inline unsigned add_item(T* item) {return ptr_list::add_item(void_cast(item));} + + void sort(int (__cdecl *compare )(const T * &elem1, const T* &elem2 ) ) + { + ptr_list::sort(reinterpret_cast< int (__cdecl *)(void* const*, void* const*) >(compare)); + } + + void add_items_copy(const ptr_list_t & source) + { + unsigned n; + for(n=0;n(ptr_list::replace_item(idx,void_cast(item)));} + + inline void delete_item(T* ptr) {remove_item(ptr);delete ptr;} + + inline void delete_by_idx(unsigned idx) + { + T* ptr = remove_by_idx(idx); + assert(ptr); + delete ptr; + } + + void delete_all() + { + unsigned n,max=get_count(); + for(n=0;n & source) + { + add_items_fromptr(source.get_ptr(),source.get_count()); + } + + inline void add_items_fromptr(T*const* source,unsigned num) {ptr_list::add_items_fromptr((void*const*)source,num);} + + inline T* const * get_ptr() const {return (T*const*)ptr_list::get_ptr();} + + inline void remove_item(T * item) {ptr_list::remove_item(void_cast(item));} + inline int find_item(T* item) const {return ptr_list::find_item(void_cast(item));} + inline bool have_item(T* item) const {return ptr_list::have_item(void_cast(item));} + + inline T* operator[](unsigned n) const {return get_item(n);} + + inline ptr_list_interface & get_interface() {return * static_cast * > (&ptr_list::get_interface());} + inline const ptr_list_interface & get_interface_const() const {return * static_cast * > (&ptr_list::get_interface_const());} + + inline operator ptr_list_interface & () {return get_interface();} + inline operator const ptr_list_interface & () const {return get_interface_const();} + + using ptr_list::apply_order; +}; + +#define ptr_list_simple ptr_list_t + +template +class ptr_list_autodel_t : public ptr_list_t +{ +public: + ~ptr_list_autodel_t() {delete_all();} +}; + + +template +class ptr_list_autofree_t : public ptr_list_t +{ +public: + ~ptr_list_autofree_t() {free_all();} +}; + +#endif //__PFC_PTR_LIST_H_ \ No newline at end of file diff --git a/tools/vio2sf/src/xsfc/foo_input_xsf.cpp b/tools/vio2sf/src/xsfc/foo_input_xsf.cpp index 9a7186da9..192c7fe53 100644 --- a/tools/vio2sf/src/xsfc/foo_input_xsf.cpp +++ b/tools/vio2sf/src/xsfc/foo_input_xsf.cpp @@ -1,3 +1,5 @@ +extern unsigned long dwInterpolation; + #include "leakchk.h" #include "foobar2000/SDK/foobar2000.h" @@ -72,7 +74,14 @@ public: void start(void *p, DWORD l) { if (loadDrv()) + { + if (lpif->dwInterfaceVersion >= 3) + { + lpif->SetExtendParam(1, CFGGetExtendParam1()); + lpif->SetExtendParam(2, CFGGetExtendParam2()); + } m_genok = !lpif->Start(p, l); + } skipSilenceOnStartSec = CFGGetSkipSilenceOnStartSec(); @@ -108,6 +117,10 @@ public: } if (!output) detectSilence = 0; } + if (lpif->dwInterfaceVersion >= 4) + { + lpif->SetExtendParamImmediate(EXTEND_PARAM_IMMEDIATE_INTERPOLATION,&dwInterpolation); + } while (pos < bufsize) { diff --git a/tools/vio2sf/src/xsfc/foo_input_xsf8.cpp b/tools/vio2sf/src/xsfc/foo_input_xsf8.cpp index a65f81f63..dc6c6982b 100644 --- a/tools/vio2sf/src/xsfc/foo_input_xsf8.cpp +++ b/tools/vio2sf/src/xsfc/foo_input_xsf8.cpp @@ -1,3 +1,5 @@ +extern unsigned long dwInterpolation; + #include "foobar2000/SDK/foobar2000.h" #include "../pversion.h" @@ -149,6 +151,10 @@ public: } if (!output) detectSilence = 0; } + if (lpif->dwInterfaceVersion >= 4) + { + lpif->SetExtendParamImmediate(EXTEND_PARAM_IMMEDIATE_INTERPOLATION,&dwInterpolation); + } while (pos < bufsize) { diff --git a/tools/vio2sf/src/xsfc/foo_input_xsfcfg.cpp b/tools/vio2sf/src/xsfc/foo_input_xsfcfg.cpp index 0a3f7dd43..5fd0af821 100644 --- a/tools/vio2sf/src/xsfc/foo_input_xsfcfg.cpp +++ b/tools/vio2sf/src/xsfc/foo_input_xsfcfg.cpp @@ -7,6 +7,8 @@ #include "tagget.h" #include "xsfcfg.h" +#include "xsfui.rh" + namespace { @@ -167,6 +169,13 @@ protected: { switch (id) { + case IDC_COMBO_INTERPOLATION: + if (cmd == CBN_SELCHANGE) + { + CFGUpdate(pcfg, hwndDlg); + CFGSave(pcfg); + } + break; case 0x200: case 0x201: case 0x202: case 0x203: case 0x204: case 0x205: if (initialized) diff --git a/tools/vio2sf/src/xsfc/foo_input_xsfcfg8.cpp b/tools/vio2sf/src/xsfc/foo_input_xsfcfg8.cpp index 73802e45d..67459ddd5 100644 --- a/tools/vio2sf/src/xsfc/foo_input_xsfcfg8.cpp +++ b/tools/vio2sf/src/xsfc/foo_input_xsfcfg8.cpp @@ -5,6 +5,10 @@ #include "tagget.h" #include "xsfcfg.h" +#include "xsfui.rh" + +extern unsigned long dwInterpolation; + namespace { @@ -163,6 +167,14 @@ protected: { switch (id) { + case IDC_COMBO_INTERPOLATION: + if (cmd == CBN_SELCHANGE) + { + CFGUpdate(pcfg, hwndDlg); + CFGSave(pcfg); + } + break; + case 0x200: case 0x201: case 0x202: case 0x203: case 0x204: case 0x205: if (initialized) diff --git a/tools/vio2sf/src/xsfc/in_xsfcfg.cpp b/tools/vio2sf/src/xsfc/in_xsfcfg.cpp index 51a89bf89..c6aa83b26 100644 --- a/tools/vio2sf/src/xsfc/in_xsfcfg.cpp +++ b/tools/vio2sf/src/xsfc/in_xsfcfg.cpp @@ -151,10 +151,6 @@ static BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l ::SetWindowTextA(hwndDlg, WINAMPPLUGIN_NAME); ::ShowWindow(GetDlgItem(hwndDlg, IDOK), SW_SHOWNA); ::ShowWindow(GetDlgItem(hwndDlg, IDCANCEL), SW_SHOWNA); - ComboBox_AddString(GetDlgItem(hwndDlg, IDC_COMBO_INTERPOLATION), "None"); - ComboBox_AddString(GetDlgItem(hwndDlg, IDC_COMBO_INTERPOLATION), "Linear"); - ComboBox_AddString(GetDlgItem(hwndDlg, IDC_COMBO_INTERPOLATION), "Cosine"); - ComboBox_SetCurSel(GetDlgItem(hwndDlg, IDC_COMBO_INTERPOLATION), dwInterpolation); CFGLoad(pcfg); CFGReset(pcfg, hwndDlg); return TRUE; diff --git a/tools/vio2sf/src/xsfc/xsfc.cpp b/tools/vio2sf/src/xsfc/xsfc.cpp index 50bef9b97..1d7318e2c 100644 --- a/tools/vio2sf/src/xsfc/xsfc.cpp +++ b/tools/vio2sf/src/xsfc/xsfc.cpp @@ -469,6 +469,20 @@ void TWin32::DlgAddList(void *hwndDlg, int itm, TString item) } } +void TWin32::DlgAddCombo(void *hwndDlg, int itm, TString item) +{ + try + { + if (IsUnicodeSupportedOS()) + WndMsgSend(DlgItem(hwndDlg, itm), CB_ADDSTRING, 0, item.GetW()); + else + WndMsgSend(DlgItem(hwndDlg, itm), CB_ADDSTRING, 0, TStringM(item).GetM()); + } + catch (xsfc::EShortOfMemory e) + { + } +} + int TWin32::DlgCntList(void *hwndDlg, int itm) { return (int)(INT_PTR)WndMsgSend(DlgItem(hwndDlg, itm), LB_GETCOUNT, 0, 0); @@ -479,6 +493,11 @@ int TWin32::DlgCurList(void *hwndDlg, int itm) return (int)(INT_PTR)WndMsgSend(DlgItem(hwndDlg, itm), LB_GETCURSEL, 0, 0); } +int TWin32::DlgCurCombo(void *hwndDlg, int itm) +{ + return (int)(INT_PTR)WndMsgSend(DlgItem(hwndDlg, itm), CB_GETCURSEL, 0, 0); +} + bool TWin32::DlgGetList(void *hwndDlg, int itm, int cur) { return (INT_PTR)WndMsgSend(DlgItem(hwndDlg, itm), LB_GETSEL, cur, 0) > 0; diff --git a/tools/vio2sf/src/xsfc/xsfc.h b/tools/vio2sf/src/xsfc/xsfc.h index 3364aed08..fbc7eabde 100644 --- a/tools/vio2sf/src/xsfc/xsfc.h +++ b/tools/vio2sf/src/xsfc/xsfc.h @@ -629,8 +629,10 @@ public: static void DlgSetCheck(void *hwndDlg, int itm, bool chk) throw(); static bool DlgGetCheck(void *hwndDlg, int itm) throw(); static void DlgAddList(void *hwndDlg, int itm, TString item) throw(); + static void DlgAddCombo(void *hwndDlg, int itm, TString item) throw(); static int DlgCntList(void *hwndDlg, int itm) throw(); static int DlgCurList(void *hwndDlg, int itm) throw(); + static int DlgCurCombo(void *hwndDlg, int itm) throw(); static bool DlgGetList(void *hwndDlg, int itm, int cur) throw(); // File typedef void *(*lpfnalloc)(void *pwork, size_t s); diff --git a/tools/vio2sf/src/xsfc/xsfcfg.cpp b/tools/vio2sf/src/xsfc/xsfcfg.cpp index 557cad2c0..0cf3db981 100644 --- a/tools/vio2sf/src/xsfc/xsfcfg.cpp +++ b/tools/vio2sf/src/xsfc/xsfcfg.cpp @@ -209,6 +209,9 @@ void CFGReset(LPIConfigIO pcfg, void *hwndDlg) { char buf[128]; xsfc::TWin32::DlgSetCheck(hwndDlg, 0x200, dwPlayInfinitely == 1); + xsfc::TWin32::DlgAddCombo(hwndDlg, IDC_COMBO_INTERPOLATION, xsfc::TString("No interpolation")); + xsfc::TWin32::DlgAddCombo(hwndDlg, IDC_COMBO_INTERPOLATION, xsfc::TString("Linear interpolation")); + xsfc::TWin32::DlgAddCombo(hwndDlg, IDC_COMBO_INTERPOLATION, xsfc::TString("Cosine interpolation")); ComboBox_SetCurSel(GetDlgItem((HWND)hwndDlg, IDC_COMBO_INTERPOLATION), dwInterpolation); xsfc::TWin32::DlgSetText(hwndDlg, 0x201, sDefaultLength); xsfc::TWin32::DlgSetText(hwndDlg, 0x202, sDefaultFade); @@ -254,6 +257,7 @@ void CFGUpdate(LPIConfigIO pcfg, void *hwndDlg) try { dwPlayInfinitely = xsfc::TWin32::DlgGetCheck(hwndDlg, 0x200) ? 1 : 0; + dwInterpolation = xsfc::TWin32::DlgCurCombo(hwndDlg, IDC_COMBO_INTERPOLATION); sDefaultLength = xsfc::TWin32::DlgGetText(hwndDlg, 0x201); sDefaultFade = xsfc::TWin32::DlgGetText(hwndDlg, 0x202); dwSkipSilenceOnStartSec = xsfc::TWin32::DlgGetText(hwndDlg, 0x203).GetULong(); diff --git a/tools/vio2sf/src/xsfc/xsfui.rc b/tools/vio2sf/src/xsfc/xsfui.rc index 2d6e1e335..052a4f585 100644 --- a/tools/vio2sf/src/xsfc/xsfui.rc +++ b/tools/vio2sf/src/xsfc/xsfui.rc @@ -1,4 +1,4 @@ -// Microsoft Visual C++ generated resource script. +//Microsoft Developer Studio generated resource script. // #include "xsfui.rh" @@ -27,18 +27,18 @@ LANGUAGE LANG_JAPANESE, SUBLANG_DEFAULT // TEXTINCLUDE // -1 TEXTINCLUDE +1 TEXTINCLUDE MOVEABLE PURE BEGIN "xsfui.rh\0" END -2 TEXTINCLUDE +2 TEXTINCLUDE MOVEABLE PURE BEGIN "#include ""winresx.h""\r\n" "\0" END -3 TEXTINCLUDE +3 TEXTINCLUDE MOVEABLE PURE BEGIN "\r\n" "\0" @@ -64,12 +64,13 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL // Dialog // -1 DIALOGEX 0, 0, 172, 202 -STYLE DS_SETFONT | WS_CHILD -FONT 9, "MS UI Gothic", 0, 0, 0x0 +1 DIALOG DISCARDABLE 0, 0, 172, 202 +STYLE WS_CHILD +FONT 9, "MS UI Gothic" BEGIN GROUPBOX "General",IDC_STATIC,5,5,160,90 - CONTROL "Play infinitely",512,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,15,60,10 + CONTROL "Play infinitely",512,"Button",BS_AUTOCHECKBOX | + WS_TABSTOP,10,15,60,10 EDITTEXT 513,100,30,25,12,ES_RIGHT | ES_AUTOHSCROLL LTEXT "Default play length (m:s)",IDC_STATIC,10,30,85,9 EDITTEXT 514,100,45,25,12,ES_RIGHT | ES_AUTOHSCROLL @@ -85,11 +86,13 @@ BEGIN EDITTEXT 520,65,125,25,12,ES_RIGHT | ES_AUTOHSCROLL | WS_DISABLED LTEXT "",521,10,140,50,9 EDITTEXT 522,65,140,25,12,ES_RIGHT | ES_AUTOHSCROLL | WS_DISABLED - LISTBOX 518,100,105,60,45,LBS_MULTIPLESEL | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP + LISTBOX 518,100,105,60,45,LBS_MULTIPLESEL | LBS_NOINTEGRALHEIGHT | + WS_VSCROLL | WS_TABSTOP LTEXT "Mute",IDC_STATIC,80,110,20,9 DEFPUSHBUTTON "OK",IDOK,84,181,35,15,NOT WS_VISIBLE PUSHBUTTON "Cancel",IDCANCEL,129,181,35,15,NOT WS_VISIBLE - COMBOBOX IDC_COMBO_INTERPOLATION,10,156,78,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + COMBOBOX IDC_COMBO_INTERPOLATION,10,156,78,55,CBS_DROPDOWNLIST | + WS_VSCROLL | WS_TABSTOP END @@ -99,7 +102,7 @@ END // #ifdef APSTUDIO_INVOKED -GUIDELINES DESIGNINFO +GUIDELINES DESIGNINFO MOVEABLE PURE BEGIN 1, DIALOG BEGIN