From b23b5ce25c27f27ad3cf58ef2571394de168ea2b Mon Sep 17 00:00:00 2001
From: Kai Blaschke
Date: Sun, 6 Nov 2022 14:35:45 +0100
Subject: [PATCH] Deleted all playlist-related code from libprojectM.
Note: SDL test UI won't compile after this commit. Will be fixed in a later commit, when the playlist library is done.
---
src/api/include/libprojectM/projectM.h | 313 ++-----------
src/libprojectM/CMakeLists.txt | 6 -
src/libprojectM/KeyHandler.cpp | 59 +--
.../MilkdropPresetFactory/Parser.cpp | 149 ------
src/libprojectM/PresetChooser.cpp | 14 -
src/libprojectM/PresetChooser.hpp | 257 -----------
src/libprojectM/PresetLoader.cpp | 193 --------
src/libprojectM/PresetLoader.hpp | 113 -----
src/libprojectM/ProjectM.cpp | 407 +---------------
src/libprojectM/ProjectM.hpp | 114 +----
src/libprojectM/ProjectMCWrapper.cpp | 263 +----------
src/libprojectM/ProjectMCWrapper.hpp | 18 +-
src/libprojectM/Renderer/CMakeLists.txt | 2 +
.../{ => Renderer}/FileScanner.cpp | 434 +++++++++---------
.../{ => Renderer}/FileScanner.hpp | 96 ++--
src/libprojectM/Renderer/Renderer.hpp | 10 -
src/libprojectM/TestRunner.cpp | 2 -
17 files changed, 341 insertions(+), 2109 deletions(-)
delete mode 100644 src/libprojectM/PresetChooser.cpp
delete mode 100644 src/libprojectM/PresetChooser.hpp
delete mode 100644 src/libprojectM/PresetLoader.cpp
delete mode 100644 src/libprojectM/PresetLoader.hpp
rename src/libprojectM/{ => Renderer}/FileScanner.cpp (96%)
rename src/libprojectM/{ => Renderer}/FileScanner.hpp (95%)
diff --git a/src/api/include/libprojectM/projectM.h b/src/api/include/libprojectM/projectM.h
index 07300e62d..d964ed1cd 100644
--- a/src/api/include/libprojectM/projectM.h
+++ b/src/api/include/libprojectM/projectM.h
@@ -32,7 +32,7 @@
extern "C" {
#endif
-struct projectm; //!< Opaque projectM instance type.
+struct projectm; //!< Opaque projectM instance type.
typedef struct projectm* projectm_handle; //!< A pointer to the opaque projectM instance.
/**
@@ -48,42 +48,30 @@ typedef struct projectm* projectm_handle; //!< A pointer to the opaque projectM
* projectm_free_settings() will automatically call projectm_free_string() on it. If you free it on your own, remember
* to reset the pointer to NULL after doing so!
*/
-typedef struct PROJECTM_EXPORT projectm_settings_s
-{
- int mesh_x; //!< Per-pixel mesh X resolution.
- int mesh_y; //!< Per-pixel mesh Y resolution.
- int fps; //!< Target rendering frames per second.
- int texture_size; //!< Size of the render texture. Must be a power of 2.
- int window_width; //!< Width of the rendering viewport.
- int window_height; //!< Height of the rendering viewport.
- char* preset_path; //!< Path with preset files to be loaded into the playlist. Use FLAG_DISABLE_PLAYLIST_LOAD to skip automatic loading of presets.
- char* texture_path; //!< Additional path with texture files for use in presets.
- char* data_path; //!< Path to data files like default textures and presets.
- double preset_duration; //!< Display duration for each preset in seconds.
- double soft_cut_duration; //!< Blend-over duration between two presets in seconds.
- double hard_cut_duration; //!< Minimum time in seconds a preset is displayed before a hard cut can happen.
- bool hard_cut_enabled; //!< Set to true to enable fast beat-driven preset switches.
- float hard_cut_sensitivity; //!< Beat sensitivity value that must be surpassed for a hard cut.
- float beat_sensitivity; //!< Beat sensitivity. Standard sensitivity is 1.0.
- bool aspect_correction; //!< Use aspect ration correction in presets that support it.
- float easter_egg; //!< Used as the "sigma" value for a gaussian RNG to randomize preset duration. Unused on Windows.
- bool shuffle_enabled; //!< Enable playlist shuffle, selecting a random preset on each switch instead of the next in list.
- bool soft_cut_ratings_enabled; //!< If true, use soft cut ratings on soft cuts and hard cut ratings on hard cuts. If false, the hard cut rating is always used.
+typedef struct PROJECTM_EXPORT projectm_settings_s {
+ int mesh_x; //!< Per-pixel mesh X resolution.
+ int mesh_y; //!< Per-pixel mesh Y resolution.
+ int fps; //!< Target rendering frames per second.
+ int texture_size; //!< Size of the render texture. Must be a power of 2.
+ int window_width; //!< Width of the rendering viewport.
+ int window_height; //!< Height of the rendering viewport.
+ char* texture_path; //!< Additional path with texture files for use in presets.
+ char* data_path; //!< Path to data files like default textures and presets.
+ double preset_duration; //!< Display duration for each preset in seconds.
+ double soft_cut_duration; //!< Blend-over duration between two presets in seconds.
+ double hard_cut_duration; //!< Minimum time in seconds a preset is displayed before a hard cut can happen.
+ bool hard_cut_enabled; //!< Set to true to enable fast beat-driven preset switches.
+ float hard_cut_sensitivity; //!< Beat sensitivity value that must be surpassed for a hard cut.
+ float beat_sensitivity; //!< Beat sensitivity. Standard sensitivity is 1.0.
+ bool aspect_correction; //!< Use aspect ration correction in presets that support it.
+ float easter_egg; //!< Used as the "sigma" value for a gaussian RNG to randomize preset duration. Unused on Windows.
} projectm_settings;
-/**
- * Flags that influence projectM instance creation.
- */
-typedef enum
-{
- PROJECTM_FLAG_NONE = 0, //!< No flags.
- PROJECTM_FLAG_DISABLE_PLAYLIST_LOAD = 1 << 0 //!< Set this flag to disable loading a preset playlist on startup.
-} projectm_flags;
-
/**
* For specifying audio data format.
*/
-typedef enum {
+typedef enum
+{
PROJECTM_MONO = 1,
PROJECTM_STEREO = 2
} projectm_channels;
@@ -95,7 +83,7 @@ typedef enum {
typedef enum
{
PROJECTM_HARD_CUT_RATING_TYPE, //!< Rating for hard cuts.
- PROJECTM_SOFT_CUT_RATING_TYPE //!< Rating for soft cuts.
+ PROJECTM_SOFT_CUT_RATING_TYPE //!< Rating for soft cuts.
} projectm_preset_rating_type;
/**
@@ -106,7 +94,7 @@ typedef enum
PROJECTM_CHANNEL_L = 0, //!< Left audio channel.
PROJECTM_CHANNEL_0 = 0, //!< Left audio channel.
PROJECTM_CHANNEL_R = 1, //!< Right audio channel.
- PROJECTM_CHANNEL_1 = 1 //!< Right audio channel.
+ PROJECTM_CHANNEL_1 = 1 //!< Right audio channel.
} projectm_pcm_channel;
/**
@@ -114,15 +102,15 @@ typedef enum
*/
typedef enum
{
- PROJECTM_TOUCH_TYPE_RANDOM, //!< Random waveform type.
- PROJECTM_TOUCH_TYPE_CIRCLE, //!< Draws a circular waveform.
- PROJECTM_TOUCH_TYPE_RADIAL_BLOB, //!< Draws a radial blob waveform.
- PROJECTM_TOUCH_TYPE_BLOB2,//!< Draws a blob-style waveform.
- PROJECTM_TOUCH_TYPE_BLOB3, //!< Draws another blob-style waveform.
+ PROJECTM_TOUCH_TYPE_RANDOM, //!< Random waveform type.
+ PROJECTM_TOUCH_TYPE_CIRCLE, //!< Draws a circular waveform.
+ PROJECTM_TOUCH_TYPE_RADIAL_BLOB, //!< Draws a radial blob waveform.
+ PROJECTM_TOUCH_TYPE_BLOB2, //!< Draws a blob-style waveform.
+ PROJECTM_TOUCH_TYPE_BLOB3, //!< Draws another blob-style waveform.
PROJECTM_TOUCH_TYPE_DERIVATIVE_LINE, //!< Draws a derivative-line waveform.
- PROJECTM_TOUCH_TYPE_BLOB5, //!< Draws a five-blob waveform.
- PROJECTM_TOUCH_TYPE_LINE, //!< Draws a single-line waveform.
- PROJECTM_TOUCH_TYPE_DOUBLE_LINE //!< Draws a double-line waveform.
+ PROJECTM_TOUCH_TYPE_BLOB5, //!< Draws a five-blob waveform.
+ PROJECTM_TOUCH_TYPE_LINE, //!< Draws a single-line waveform.
+ PROJECTM_TOUCH_TYPE_DOUBLE_LINE //!< Draws a double-line waveform.
} projectm_touch_type;
/**
@@ -183,7 +171,7 @@ PROJECTM_EXPORT void projectm_free_settings(const projectm_settings* settings);
* @param user_data A user-defined data pointer that was provided when registering the callback,
* e.g. context information.
*/
-typedef void(* projectm_preset_switched_event)(bool is_hard_cut, unsigned int index, void* user_data);
+typedef void (*projectm_preset_switched_event)(bool is_hard_cut, unsigned int index, void* user_data);
/**
* @brief Callback function that is executed is the shuffle setting has changed.
@@ -191,22 +179,22 @@ typedef void(* projectm_preset_switched_event)(bool is_hard_cut, unsigned int in
* @param user_data A user-defined data pointer that was provided when registering the callback,
* e.g. context information.
*/
-typedef void(* projectm_shuffle_enable_changed_event)(bool shuffle_enabled, void* user_data);
+typedef void (*projectm_shuffle_enable_changed_event)(bool shuffle_enabled, void* user_data);
/**
* @brief Callback function that is executed if a preset change failed.
*
- * The message pointer is only valid inside the callback. Make a copy if it must be kept
- * for later use.
+ * The message and filename pointers are only valid inside the callback. Make a copy if these values
+ * need to be retained for later use.
*
* @param is_hard_cut True if the preset was switched using a hard cut via beat detection.
- * @param index The playlist index of the new preset.
+ * @param preset_filename The filename of the failed preset.
* @param message The error message.
* @param user_data A user-defined data pointer that was provided when registering the callback,
* e.g. context information.
*/
-typedef void(* projectm_preset_switch_failed_event)(bool is_hard_cut, unsigned int index, const char* message,
- void* user_data);
+typedef void (*projectm_preset_switch_failed_event)(bool is_hard_cut, const char* preset_filename,
+ const char* message, void* user_data);
/**
* @brief Callback function that is executed if a preset rating has been changed.
@@ -219,30 +207,27 @@ typedef void(* projectm_preset_switch_failed_event)(bool is_hard_cut, unsigned i
* @param user_data A user-defined data pointer that was provided when registering the callback,
* e.g. context information.
*/
-typedef void(* projectm_preset_rating_changed_event)(unsigned int index, int rating,
+typedef void (*projectm_preset_rating_changed_event)(unsigned int index, int rating,
projectm_preset_rating_type rating_type, void* user_data);
-
/**
* @brief Creates a new projectM instance, reading settings from the given file.
* @param setting_file_path A path to the settings file to read the configuration from.
* If NULL or an empty path are provided, default settings will be used.
- * @param flags Any combination of values from the projectm_flags enumeration.
* @return A projectM handle for the newly created instance that must be used in subsequent API calls.
* NULL if the instance could not be created successfully.
*/
-PROJECTM_EXPORT projectm_handle projectm_create(const char* setting_file_path, int flags);
+PROJECTM_EXPORT projectm_handle projectm_create(const char* setting_file_path);
/**
* @brief Creates a new projectM instance with given settings.
* @param settings A pointer to a projectm_settings_t with the settings to be used by the new instance.
* If this pointer is NULL, default settings will be used.
- * @param flags Any combination of values from the projectm_flags enumeration.
* @return A projectM handle for the newly created instance that must be used in subsequent API calls.
* NULL if the instance could not be created successfully.
*/
-PROJECTM_EXPORT projectm_handle projectm_create_settings(const projectm_settings* settings, int flags);
+PROJECTM_EXPORT projectm_handle projectm_create_settings(const projectm_settings* settings);
/**
* @brief Destroys the given instance and frees the resources.
@@ -534,13 +519,6 @@ PROJECTM_EXPORT int32_t projectm_get_fps(projectm_handle instance);
*/
PROJECTM_EXPORT void projectm_set_fps(projectm_handle instance, int32_t fps);
-/**
- * @brief Returns the search path for presets and textures.
- * @param instance The projectM instance handle.
- * @return The path used to search for presets and textures.
- */
-PROJECTM_EXPORT const char* projectm_get_preset_path(projectm_handle instance);
-
/**
* @brief Returns the search path for additional textures.
* @param instance The projectM instance handle.
@@ -654,34 +632,6 @@ PROJECTM_EXPORT projectm_settings* projectm_get_settings(projectm_handle instanc
*/
PROJECTM_EXPORT void projectm_write_config(const char* config_file, const projectm_settings* settings);
-/**
- * @brief Selects a preset, but does not display it.
- * @param instance The projectM instance handle.
- * @param index The preset index to select.
- */
-PROJECTM_EXPORT void projectm_select_preset_position(projectm_handle instance, unsigned int index);
-
-/**
- * @brief Selects and displays the preset.
- * @param instance The projectM instance handle.
- * @param index the preset to display.
- * @param hard_cut If true, a hard cut is made, otherwise it will be blended smoothly.
- */
-PROJECTM_EXPORT void projectm_select_preset(projectm_handle instance, unsigned int index, bool hard_cut);
-
-/**
- * @brief Removes a preset from the playlist.
- * @param instance The projectM instance handle.
- * @param index The preset index to remove from the playlist.
- */
-PROJECTM_EXPORT void projectm_remove_preset(projectm_handle instance, unsigned int index);
-
-/**
- * @brief Clears the preset playlist.
- * @param instance The projectM instance handle.
- */
-PROJECTM_EXPORT void projectm_clear_playlist(projectm_handle instance);
-
/**
* @brief Locks or unlocks the current preset.
*
@@ -700,183 +650,6 @@ PROJECTM_EXPORT void projectm_lock_preset(projectm_handle instance, bool lock);
*/
PROJECTM_EXPORT bool projectm_is_preset_locked(projectm_handle instance);
-/**
- * @brief Returns the playlist index for the given preset name.
- *
- * If the preset name is found multiple times, the first matching index will be returned.
- *
- * @param instance The projectM instance handle.
- * @param preset_name The preset name to search for.
- * @return The first found playlist index of the requested preset, or 0 if the preset wasn't found.
- */
-PROJECTM_EXPORT unsigned int projectm_get_preset_index(projectm_handle instance, const char* preset_name);
-
-/**
- * @brief Displays the preset with the given name.
- * @param instance The projectM instance handle.
- * @param preset_name The preset name to search for.
- * @param hard_cut If true, the preset will be shown immediately, if false a soft transition will be rendered.
- */
-PROJECTM_EXPORT void projectm_select_preset_by_name(projectm_handle instance, const char* preset_name, bool hard_cut);
-
-/**
- * @brief Returns the currently selected preset index.
- * @param instance The projectM instance handle.
- * @param index A valid pointer to an unsigned int that will receive the preset index.
- * @return True if a preset idnex was returned, false if no preset was selected, e.g. the playlist is empty.
- */
-PROJECTM_EXPORT bool projectm_get_selected_preset_index(projectm_handle instance, unsigned int* index);
-
-/**
- * @brief Adds a new preset at the end of the playlist.
- *
- * The rating list is one rating per value of the projectm_preset_rating_type enumeration, with each actual enum
- * value used as the index. If the rating list has the wrong length, the preset will not be added.
- *
- * @param instance The projectM instance handle.
- * @param preset_url The full path and filename of the preset.
- * @param preset_name The display name of the preset.
- * @param rating_list A list with ratings for the preset, one rating per rating type.
- * @param rating_list_length Length of the preset rating list.
- */
-PROJECTM_EXPORT void projectm_add_preset_url(projectm_handle instance, const char* preset_url,
- const char* preset_name, int* rating_list,
- unsigned int rating_list_length);
-
-/**
- * @brief Adds a new preset at the given position in the playlist.
- *
- * The rating list is one rating per value of the projectm_preset_rating_type enumeration, with each actual enum
- * value used as the index. If the rating list has the wrong length, the preset will not be added.
- *
- * @param instance The projectM instance handle.
- * @param index The playlist index to insert the preset at. Must be less than or equal to the length of
- * the playlist.
- * @param preset_url The full path and filename of the preset.
- * @param preset_name The display name of the preset.
- * @param rating_list A list with ratings for the preset, one rating per rating type.
- * @param rating_list_length Length of the preset rating list.
- */
-PROJECTM_EXPORT void projectm_insert_preset_url(projectm_handle instance, unsigned int index, const char* preset_url,
- const char* preset_name, int* rating_list,
- unsigned int rating_list_length);
-
-/**
- * @brief Returns whether the currently selected preset has a valid position in the playlist.
- *
- * This function is useful to check if the currently displayed preset is still inside the bounds of
- * the current playlist, for example after the playlist was changed.
- *
- * @param instance The projectM instance handle.
- * @return True if the position is valid, false if outside bounds.
- */
-PROJECTM_EXPORT bool projectm_preset_position_valid(projectm_handle instance);
-
-/**
- * @brief Returns the path and filename of the preset at the requested playlist index.
- * @note Make sure the index is inside the playlist bounds!
- * @param instance The projectM instance handle.
- * @param index The playlist index to return the filename for.
- * @return The full path and filename of the preset at the given index.
- */
-PROJECTM_EXPORT const char* projectm_get_preset_filename(projectm_handle instance, unsigned int index);
-
-/**
- * @brief Returns the display name of the preset at the requested playlist index.
- * @note Make sure the index is inside the playlist bounds!
- * @param instance The projectM instance handle.
- * @param index The playlist index to return the display name for.
- * @return The display name of the preset at the given index.
- */
-PROJECTM_EXPORT const char* projectm_get_preset_name(projectm_handle instance, unsigned int index);
-
-/**
- * @brief Changes the display name of the given preset in the playlist.
- * @param instance The projectM instance handle.
- * @param index the playlist item index to change.
- * @param name The new display name.
- */
-PROJECTM_EXPORT void projectm_set_preset_name(projectm_handle instance, unsigned int index, const char* name);
-
-/**
- * @brief Returns the rating for the given index and transition type.
- * @param instance The projectM instance handle.
- * @param index The playlist item to retrieve the rating from.
- * @param rating_type The rating type to retrieve, either hard or soft cut.
- * @return The rating value of the requested item and type.
- */
-PROJECTM_EXPORT int projectm_get_preset_rating(projectm_handle instance, unsigned int index,
- projectm_preset_rating_type rating_type);
-
-/**
- * @brief Changes the rating or a playlist item and type.
- * @param instance The projectM instance handle.
- * @param index the playlist item to change the rating of.
- * @param rating The new rating value.
- * @param rating_type The type of the rating, either hard or soft cut.
- */
-PROJECTM_EXPORT void projectm_set_preset_rating(projectm_handle instance, unsigned int index, int rating,
- projectm_preset_rating_type rating_type);
-
-/**
- * @brief Returns the number of presets in the current playlist.
- * @param instance The projectM instance handle.
- * @return The number of presets in the currently loaded playlist.
- */
-PROJECTM_EXPORT unsigned int projectm_get_playlist_size(projectm_handle instance);
-
-/**
- * @brief Returns whether playlist shuffling is currently enabled or not.
- * @param instance The projectM instance handle.
- * @return True if shuffle is enabled, false if not.
- */
-PROJECTM_EXPORT bool projectm_get_shuffle_enabled(projectm_handle instance);
-
-/**
- * @brief Enables or disables preset playlist shuffling.
- * @param instance The projectM instance handle.
- * @param shuffle_enabled True to randomly select the next preset, false to skip to the next item in line.
- */
-PROJECTM_EXPORT void projectm_set_shuffle_enabled(projectm_handle instance, bool shuffle_enabled);
-
-/**
- * @brief Gets the index of the provided preset name in the current search result list.
- * @param instance The projectM instance handle.
- * @param name The name of the preset to return the index for.
- * @return The search result list index of the given preset name.
- */
-PROJECTM_EXPORT unsigned int projectm_get_search_index(projectm_handle instance, const char* name);
-
-/**
- * @brief Switches to the previous preset in the current playlist.
- *
- * This is unaffected by the shuffle mode and will always switch to the previous item.
- *
- * @param instance The projectM instance handle.
- * @param hard_cut True to immediately perform to the previous preset, false to do a soft transition.
- */
-PROJECTM_EXPORT void projectm_select_previous_preset(projectm_handle instance, bool hard_cut);
-
-/**
- * @brief Switches to the next preset in the current playlist.
- *
- * This is unaffected by the shuffle mode and will always switch to the next item.
- *
- * @param instance The projectM instance handle.
- * @param hard_cut True to immediately perform to the next preset, false to do a soft transition.
- */
-PROJECTM_EXPORT void projectm_select_next_preset(projectm_handle instance, bool hard_cut);
-
-/**
- * @brief Switches to a random preset in the current playlist.
- *
- * This is unaffected by the shuffle mode and will always switch to a random item.
- *
- * @param instance The projectM instance handle.
- * @param hard_cut True to immediately perform to a random preset, false to do a soft transition.
- */
-PROJECTM_EXPORT void projectm_select_random_preset(projectm_handle instance, bool hard_cut);
-
/**
* @brief Returns the current viewport size in pixels.
* @param instance The projectM instance handle.
@@ -930,7 +703,7 @@ PROJECTM_EXPORT unsigned int projectm_pcm_get_max_samples();
* Can be PROJECTM_MONO or PROJECTM_STEREO.
*/
PROJECTM_EXPORT void projectm_pcm_add_float(projectm_handle instance, const float* samples,
- unsigned int count, projectm_channels channels);
+ unsigned int count, projectm_channels channels);
/**
* @brief Adds 16-bit integer audio samples.
@@ -947,7 +720,7 @@ PROJECTM_EXPORT void projectm_pcm_add_float(projectm_handle instance, const floa
* Can be PROJECTM_MONO or PROJECTM_STEREO.
*/
PROJECTM_EXPORT void projectm_pcm_add_int16(projectm_handle instance, const int16_t* samples,
- unsigned int count, projectm_channels channels);
+ unsigned int count, projectm_channels channels);
/**
* @brief Adds 8-bit unsigned integer audio samples.
@@ -964,7 +737,7 @@ PROJECTM_EXPORT void projectm_pcm_add_int16(projectm_handle instance, const int1
* Can be PROJECTM_MONO or PROJECTM_STEREO.
*/
PROJECTM_EXPORT void projectm_pcm_add_uint8(projectm_handle instance, const uint8_t* samples,
- unsigned int count, projectm_channels channels);
+ unsigned int count, projectm_channels channels);
/**
* @brief Writes a .bmp framedump after rendering the next main texture, before shaders are applied.
diff --git a/src/libprojectM/CMakeLists.txt b/src/libprojectM/CMakeLists.txt
index b5dec2bce..c01915966 100644
--- a/src/libprojectM/CMakeLists.txt
+++ b/src/libprojectM/CMakeLists.txt
@@ -42,8 +42,6 @@ add_library(projectM_main OBJECT
fatal.h
fftsg.cpp
fftsg.h
- FileScanner.cpp
- FileScanner.hpp
glError.h
gltext.h
HungarianMethod.hpp
@@ -56,14 +54,10 @@ add_library(projectM_main OBJECT
PipelineMerger.hpp
Preset.cpp
Preset.hpp
- PresetChooser.cpp
- PresetChooser.hpp
PresetFactory.cpp
PresetFactory.hpp
PresetFactoryManager.cpp
PresetFactoryManager.hpp
- PresetLoader.cpp
- PresetLoader.hpp
ProjectM.cpp
ProjectM.hpp
projectM-opengl.h
diff --git a/src/libprojectM/KeyHandler.cpp b/src/libprojectM/KeyHandler.cpp
index 95d55622d..4f567323c 100755
--- a/src/libprojectM/KeyHandler.cpp
+++ b/src/libprojectM/KeyHandler.cpp
@@ -19,7 +19,6 @@
*
*/
-#include "PresetChooser.hpp"
#include "ProjectM.hpp"
#include "Renderer.hpp"
#include "TimeKeeper.hpp"
@@ -78,68 +77,14 @@ void ProjectM::DefaultKeyHandler(projectMEvent event, projectMKeycode keycode) {
m_beatDetect->beatSensitivity = 0;
}
break;
- case PROJECTM_K_y:
- this->SetShuffleEnabled(!this->ShuffleEnabled());
- break;
+
case PROJECTM_K_a:
m_renderer->correction = !m_renderer->correction;
break;
- case PROJECTM_K_n:
- SelectNext(true);
- break;
- case PROJECTM_K_N:
- SelectNext(false);
- break;
- case PROJECTM_K_r:
- SelectRandom(true);
- break;
- case PROJECTM_K_R:
- SelectRandom(false);
- break;
- case PROJECTM_K_p:
- SelectPrevious(true);
- break;
- case PROJECTM_K_P:
- case PROJECTM_K_BACKSPACE:
- SelectPrevious(false);
- break;
+
case PROJECTM_K_l:
SetPresetLocked(!PresetLocked());
break;
- case PROJECTM_K_i:
- break;
- case PROJECTM_K_EQUALS:
- case PROJECTM_K_PLUS:
-
- unsigned int index;
-
- if (SelectedPresetIndex(index)) {
-
- const int oldRating = PresetRating(index, HARD_CUT_RATING_TYPE);
-
- if (oldRating >= 6)
- break;
-
- const int rating = oldRating + 1;
-
- ChangePresetRating(index, rating, HARD_CUT_RATING_TYPE);
- }
-
- break;
-
- case PROJECTM_K_MINUS:
- if (SelectedPresetIndex(index)) {
-
- const int oldRating = PresetRating(index, HARD_CUT_RATING_TYPE);
-
- if (oldRating <= 1)
- break;
-
- const int rating = oldRating - 1;
-
- ChangePresetRating(index, rating, HARD_CUT_RATING_TYPE);
- }
- break;
default:
break;
diff --git a/src/libprojectM/MilkdropPresetFactory/Parser.cpp b/src/libprojectM/MilkdropPresetFactory/Parser.cpp
index fd2576f98..c1416e872 100755
--- a/src/libprojectM/MilkdropPresetFactory/Parser.cpp
+++ b/src/libprojectM/MilkdropPresetFactory/Parser.cpp
@@ -2692,152 +2692,3 @@ else
return false;
}
-
-
-
-
-
-
-
-// TESTS
-
-
-#include
-
-#ifndef NDEBUG
-
-#include
-
-#define TEST(cond) if (!verify(#cond,cond)) return false
-#define TEST2(str,cond) if (!verify(str,cond)) return false
-
-struct ParserTest : public Test
-{
- ParserTest() : Test("ParserTest")
- {}
-
- MilkdropPreset *preset;
- std::istringstream is;
- std::istringstream &ss(const char *s) { return is = std::istringstream(s); }
-
- bool eq(float a, float b)
- {
- return std::abs(a-b) < (std::abs(a)+std::abs(b) + 1)/1000.0f;
- }
-
-public:
-
- bool test_float()
- {
- float f=-1.0f;
- TEST(PROJECTM_SUCCESS == Parser::parse_float(ss("1.1"),&f));
- TEST(1.1f == f);
- TEST(PROJECTM_SUCCESS == Parser::parse_float(ss("+1.2"),&f));
- TEST(PROJECTM_SUCCESS == Parser::parse_float(ss("-1.3"),&f));
- TEST(PROJECTM_PARSE_ERROR == Parser::parse_float(ss(""),&f));
- TEST(PROJECTM_PARSE_ERROR == Parser::parse_float(ss("\n"),&f));
- TEST(PROJECTM_PARSE_ERROR == Parser::parse_float(ss("+"),&f));
- return true;
- }
-
- bool test_int()
- {
- int i=-1;
- TEST(PROJECTM_SUCCESS == Parser::parse_int(ss("1"),&i));
- TEST(1 == i);
- TEST(PROJECTM_SUCCESS == Parser::parse_int(ss("+2"),&i));
- TEST(PROJECTM_SUCCESS == Parser::parse_int(ss("-3"),&i));
- TEST(PROJECTM_PARSE_ERROR == Parser::parse_int(ss(""),&i));
- TEST(PROJECTM_PARSE_ERROR == Parser::parse_int(ss("\n"),&i));
- TEST(PROJECTM_PARSE_ERROR == Parser::parse_int(ss("+"),&i));
- return true;
- }
-
- bool eval_expr(float expected, const char *s)
- {
- float result;
- Expr *expr_parse = Parser::parse_gen_expr(ss(s),nullptr,preset);
- TEST(expr_parse != nullptr);
- // Expr doesn't really expect to run 'non-optimized' expressions any longer
- Expr *expr = Expr::optimize(expr_parse);
- expr_parse = nullptr;
- if (!ParserTest::eq(expected, result=expr->eval(-1,-1)))
- {
- std::cout << "failed: expected " << expected << " found " << result << std::endl;
- return false;
- }
- Expr::delete_expr(expr);
- return true;
- }
-
- bool test_eqn()
- {
- TEST(eval_expr(1.0f, "1.0"));
- TEST(eval_expr(-1.0f, "-(1.0)")); // unary`
- TEST(eval_expr(0.5f, "5/10.000")); // binary
- TEST(eval_expr(1.0f, "sin(3.14159/2)"));
- // emtpy expression evals to 0, NULL usually means error in this parser
- TEST(eval_expr(0.0f, ""));
- TEST(eval_expr(0.0f, " "));
- TEST(eval_expr(0.0f, "\n"));
- TEST(eval_expr(0.0f, " \n"));
- preset->presetOutputs().rot = 0.99f;
- TEST(eval_expr(0.99f, "rot"));
-
- // random other stuff to parse
- Parser::parse_gen_expr(ss("0.5 + 0.5*sin(q8*0.613 + 1);"),nullptr,preset);
- return true;
- }
-
- // test multi-line expression, and multi-expression line
- bool test_lines()
- {
- // TODO
- return true;
- }
-
- bool test_params()
- {
- // TODO
- return true;
- }
-
-
- bool _test()
- {
- bool success = true;
- success &= test_float();
- success &= test_int();
- success &= test_eqn();
- success &= test_lines();
- success &= test_params();
- return success;
- }
-
- bool test() override
- {
- // load IdlePreset
- PresetLoader *presetLoader = new PresetLoader ( 400, 400, "" );
- std::unique_ptr preset_ptr = presetLoader->loadPreset("idle://Geiss & Sperl - Feedback (projectM idle HDR mix).milk");
- preset = (MilkdropPreset *)preset_ptr.get();
-
- bool success = _test();
-
- delete presetLoader;
- return success;
- }
-};
-
-Test* Parser::test()
-{
- return new ParserTest();
-}
-
-#else
-
-Test* Parser::test()
-{
- return nullptr;
-}
-
-#endif
diff --git a/src/libprojectM/PresetChooser.cpp b/src/libprojectM/PresetChooser.cpp
deleted file mode 100644
index b2397590e..000000000
--- a/src/libprojectM/PresetChooser.cpp
+++ /dev/null
@@ -1,14 +0,0 @@
-//
-// C++ Implementation: PresetChooser
-//
-// Description:
-//
-//
-// Author: Carmelo Piccione , (C) 2007
-//
-// Copyright: See COPYING file that comes with this distribution
-//
-//
-
-#include "PresetChooser.hpp"
-
diff --git a/src/libprojectM/PresetChooser.hpp b/src/libprojectM/PresetChooser.hpp
deleted file mode 100644
index f6937603a..000000000
--- a/src/libprojectM/PresetChooser.hpp
+++ /dev/null
@@ -1,257 +0,0 @@
-#ifndef PRESET_CHOOSER_HPP
-#define PRESET_CHOOSER_HPP
-
-#include "Preset.hpp"
-
-#include "PresetLoader.hpp"
-#include "RandomNumberGenerators.hpp"
-#include
-#include
-#include
-class PresetChooser;
-
-/// A simple iterator class to traverse back and forth a preset directory
-class PresetIterator {
-
-public:
- PresetIterator() {}
-
- /// Instantiate a preset iterator at the given starting position
- PresetIterator(std::size_t start);
-
- /// Move iterator forward
- void operator++();
-
- /// Move iterator backword
- void operator--() ;
-
- /// Not equal comparator
- bool operator !=(const PresetIterator & presetPos) const ;
-
- /// Equality comparator
- bool operator ==(const PresetIterator & presetPos) const ;
-
- /// Returns an integer value representing the iterator position
- /// @bug might become internal
- /// \brief Returns the indexing value used by the current iterator.
- std::size_t operator*() const;
-
- // Return previous index.
- std::size_t lastIndex() const;
-
- /// Allocate a new preset given this iterator's associated preset name
- /// \param presetInputs the preset inputs to associate with the preset upon construction
- /// \param presetOutputs the preset outputs to associate with the preset upon construction
- /// \returns an autopointer of the newly allocated preset
- std::unique_ptr allocate();
-
- /// Set the chooser asocciated with this iterator
- void setChooser(const PresetChooser & chooser);
-
-private:
- std::size_t _currentIndex;
- const PresetChooser * _presetChooser;
-
-};
-
-/// Provides functions and iterators to select presets. Requires a preset loader upon construction
-class PresetChooser {
-
-public:
- typedef PresetIterator iterator;
-
- /// Initializes a chooser with an established preset loader.
- /// \param presetLoader an initialized preset loader to choose presets from
- /// \note The preset loader is refreshed via events or otherwise outside this class's scope
- PresetChooser(const PresetLoader & presetLoader, bool softCutRatingsEnabled);
-
- inline void setSoftCutRatingsEnabled(bool enabled) {
- _softCutRatingsEnabled = enabled;
- }
-
- /// Choose a preset via the passed in index. Must be between 0 and num valid presets in directory
- /// \param index An index lying in the interval [0, this->getNumPresets())
- /// \param presetInputs the preset inputs to associate with the preset upon construction
- /// \param presetOutputs the preset outputs to associate with the preset upon construction
- /// \returns an auto pointer of the newly allocated preset
- std::unique_ptr directoryIndex(std::size_t index) const;
-
- /// Gets the number of presets last believed to exist in the preset loader's filename collection
- /// \returns the number of presets in the collection
- std::size_t size() const;
-
- /// An STL-esque iterator to begin traversing presets from a directory
- /// \param index the index to begin iterating at. Assumed valid between [0, num presets)
- /// \returns the position of the first preset in the collection
- PresetIterator begin(unsigned int index) const;
-
- /// An STL-esque iterator to begin traversing presets from a directory
- /// \returns the position of the first preset in the collection
- PresetIterator begin();
-
- /// An STL-esque iterator to retrieve an end position from a directory
- /// \returns the end position of the collection
- PresetIterator end() const;
-
- /// Perform a weighted sample to select a preset (uses preset rating values)
- /// \returns an iterator to the randomly selected preset
- iterator weightedRandom(bool hardCut) const;
-
- /// True if no presets in directory
- bool empty() const;
-
-
- inline void nextPreset(PresetIterator & presetPos);
- inline void previousPreset(PresetIterator & presetPos);
-
-private:
- std::vector sampleWeights;
- const PresetLoader * _presetLoader;
- bool _softCutRatingsEnabled;
-};
-
-
-inline PresetChooser::PresetChooser(const PresetLoader & presetLoader, bool softCutRatingsEnabled):_presetLoader(&presetLoader), _softCutRatingsEnabled(softCutRatingsEnabled) {
-
-}
-
-inline std::size_t PresetChooser::size() const {
- return _presetLoader->size();
-}
-
-inline void PresetIterator::setChooser(const PresetChooser & chooser) {
- _presetChooser = &chooser;
-}
-
-inline std::size_t PresetIterator::operator*() const {
- return _currentIndex;
-}
-
-inline std::size_t PresetIterator::lastIndex() const {
- return _currentIndex;
-}
-
-inline PresetIterator::PresetIterator(std::size_t start):_currentIndex(start) {}
-
-inline void PresetIterator::operator++() {
- assert(_currentIndex < _presetChooser->size());
- _currentIndex++;
-}
-
-inline void PresetIterator::operator--() {
- assert(_currentIndex > 0);
- _currentIndex--;
-}
-
-inline bool PresetIterator::operator !=(const PresetIterator & presetPos) const {
- return (*presetPos != **this);
-}
-
-
-inline bool PresetIterator::operator ==(const PresetIterator & presetPos) const {
- return (*presetPos == **this);
-}
-
-inline std::unique_ptr PresetIterator::allocate() {
- return _presetChooser->directoryIndex(_currentIndex);
-}
-
-inline void PresetChooser::nextPreset(PresetIterator & presetPos) {
-
- if (this->empty()) {
- return;
- }
-
- // Case: idle preset currently running, selected first preset of chooser
- else if (presetPos == this->end())
- presetPos = this->begin();
- else
- ++(presetPos);
-
- // Case: already at last preset, loop to beginning
- if (((presetPos) == this->end())) {
- presetPos = this->begin();
- }
-
-}
-
-
-inline void PresetChooser::previousPreset(PresetIterator & presetPos) {
- if (this->empty())
- return;
-
- // Case: idle preset currently running, selected last preset of chooser
- else if (presetPos == this->end()) {
- --(presetPos);
- }
-
- else if (presetPos != this->begin()) {
- --(presetPos);
- }
-
- else {
- presetPos = this->end();
- --(presetPos);
- }
-}
-
-inline PresetIterator PresetChooser::begin() {
- PresetIterator pos(0);
- pos.setChooser(*this);
- return pos;
-}
-
-inline PresetIterator PresetChooser::begin(unsigned int index) const{
- PresetIterator pos(index);
- pos.setChooser(*this);
- return pos;
-}
-
-inline PresetIterator PresetChooser::end() const {
- PresetIterator pos(_presetLoader->size());
- pos.setChooser(*this);
- return pos;
-}
-
-
-inline bool PresetChooser::empty() const {
- return _presetLoader->size() == 0;
-}
-
-inline std::unique_ptr PresetChooser::directoryIndex(std::size_t index) const {
- return _presetLoader->loadPreset(index);
-}
-
-
-inline PresetChooser::iterator PresetChooser::weightedRandom(bool hardCut) const {
-
-
-
-
- // TODO make a sophisticated function object interface to determine why a certain rating
- // category is chosen, or weighted distribution thereover.
- const PresetRatingType ratingType = hardCut || (!_softCutRatingsEnabled) ?
- HARD_CUT_RATING_TYPE : SOFT_CUT_RATING_TYPE;
-
- const std::size_t ratingsTypeIndex = static_cast(ratingType);
-
- const std::vector & weights = _presetLoader->getPresetRatings()[ratingsTypeIndex];
-
- const auto weightsSum = _presetLoader->getPresetRatingsSums()[ratingsTypeIndex];
-
- std::size_t index;
- if (weightsSum > 0)
- {
- index = RandomNumberGenerators::weightedRandom(weights,
- _presetLoader->getPresetRatingsSums()[ratingsTypeIndex]);
- }
- else
- {
- // No ratings (all zero), so just select a random preset with a uniform distribution.
- index = RandomNumberGenerators::uniformInteger(_presetLoader->size());
- }
-
- return begin(index);
-}
-
-#endif
diff --git a/src/libprojectM/PresetLoader.cpp b/src/libprojectM/PresetLoader.cpp
deleted file mode 100644
index 542428ea3..000000000
--- a/src/libprojectM/PresetLoader.cpp
+++ /dev/null
@@ -1,193 +0,0 @@
-//
-// C++ Implementation: PresetLoader
-//
-// Description:
-//
-//
-// Author: Carmelo Piccione , (C) 2007
-//
-// Copyright: See COPYING file that comes with this distribution
-//
-//
-#include "PresetLoader.hpp"
-#include "Preset.hpp"
-#include "PresetFactory.hpp"
-#include
-#include
-#include
-#include
-#include
-#include "fatal.h"
-
-PresetLoader::PresetLoader (int gx, int gy, std::string dirname = std::string()) :_dirname ( dirname )
-{
- _presetFactoryManager.initialize(gx,gy);
-
- std::vector dirs{_dirname};
- std::vector extensions = _presetFactoryManager.extensionsHandled();
- fileScanner = FileScanner(dirs, extensions);
-
- // Do one scan
- if ( _dirname != std::string() )
- rescan();
- else
- clear();
-}
-
-PresetLoader::~PresetLoader() {}
-
-void PresetLoader::setScanDirectory ( std::string dirname )
-{
- _dirname = dirname;
-}
-
-void PresetLoader::addScannedPresetFile(const std::string &path, const std::string &name) {
- auto ext = ParseExtension(path);
- if (ext.empty())
- return;
-
- ext = "." + ext;
-
- // Verify extension is projectm or milkdrop
- if (!_presetFactoryManager.extensionHandled(ext))
- return;
-
-// std::cout << "Loading preset file " << path << std::endl;
-
- _entries.push_back(path);
- _presetNames.push_back(name + ext);
-}
-
-void PresetLoader::rescan()
-{
- // std::cerr << "Rescanning..." << std::endl;
-
- // Clear the directory entry collection
- clear();
-
- // scan for presets
- using namespace std::placeholders;
- fileScanner.scan(std::bind(&PresetLoader::addScannedPresetFile, this, _1, _2));
-
- // Give all presets equal rating of 3 - why 3? I don't know
- _ratings = std::vector(TOTAL_RATING_TYPES, RatingList( _presetNames.size(), 3 ));
- _ratingsSums = std::vector(TOTAL_RATING_TYPES, 3 *_presetNames.size());
-
- assert ( _entries.size() == _presetNames.size() );
-}
-
-std::unique_ptr PresetLoader::loadPreset ( PresetIndex index ) const
-{
- // Check that index isn't insane
- assert ( index < _entries.size() );
- return _presetFactoryManager.allocate
- ( _entries[index], _presetNames[index] );
-}
-
-std::unique_ptr PresetLoader::loadPreset ( const std::string & url ) const
-{
-// std::cout << "Loading preset " << url << std::endl;
- try {
- /// @bug probably should not use url for preset name
- return _presetFactoryManager.allocate
- (url, url);
- } catch (const std::exception & e) {
- throw PresetFactoryException(e.what());
- } catch (...) {
- throw PresetFactoryException("preset factory exception of unknown cause");
- }
- return std::unique_ptr();
-}
-
-void PresetLoader::setRating(PresetIndex index, int rating, const PresetRatingType ratingType)
-{
- const unsigned int ratingTypeIndex = static_cast(ratingType);
- assert (index < _ratings[ratingTypeIndex].size());
-
- _ratingsSums[ratingTypeIndex] -= _ratings[ratingTypeIndex][index];
-
- _ratings[ratingTypeIndex][index] = rating;
- _ratingsSums[ratingType] += rating;
-}
-
-unsigned long PresetLoader::addPresetURL ( const std::string & url, const std::string & presetName, const std::vector & ratings)
-{
- _entries.push_back(url);
- _presetNames.push_back ( presetName );
-
- assert(ratings.size() == TOTAL_RATING_TYPES);
- assert(ratings.size() == _ratings.size());
-
- for (unsigned int i = 0; i < _ratings.size(); i++)
- _ratings[i].push_back(ratings[i]);
-
- for (unsigned int i = 0; i < ratings.size(); i++)
- _ratingsSums[i] += ratings[i];
-
- return _entries.size()-1;
-}
-
-void PresetLoader::removePreset ( PresetIndex index )
-{
- _entries.erase ( _entries.begin() + index );
- _presetNames.erase ( _presetNames.begin() + index );
-
- for (unsigned int i = 0; i < _ratingsSums.size(); i++) {
- _ratingsSums[i] -= _ratings[i][index];
- _ratings[i].erase ( _ratings[i].begin() + index );
- }
-}
-
-const std::string & PresetLoader::getPresetURL ( PresetIndex index ) const
-{
- return _entries[index];
-}
-
-const std::string & PresetLoader::getPresetName ( PresetIndex index ) const
-{
- return _presetNames[index];
-}
-
-
-// Get vector of preset names
-const std::vector &PresetLoader::getPresetNames() const
-{
- return _presetNames;
-}
-
-// Get the preset index given a name
-unsigned int PresetLoader::getPresetIndex(const std::string& name) const
-{
- return find(_presetNames.begin(), _presetNames.end(), name) - _presetNames.begin();
-}
-
-int PresetLoader::getPresetRating ( PresetIndex index, const PresetRatingType ratingType ) const
-{
- return _ratings[ratingType][index];
-}
-
-const std::vector & PresetLoader::getPresetRatings () const
-{
- return _ratings;
-}
-
-const std::vector & PresetLoader::getPresetRatingsSums() const {
- return _ratingsSums;
-}
-
-void PresetLoader::setPresetName(PresetIndex index, std::string name) {
- _presetNames[index] = name;
-}
-
-void PresetLoader::insertPresetURL ( PresetIndex index, const std::string & url, const std::string & presetName, const RatingList & ratings)
-{
- _entries.insert ( _entries.begin() + index, url );
- _presetNames.insert ( _presetNames.begin() + index, presetName );
-
- for (unsigned int i = 0; i < _ratingsSums.size();i++) {
- _ratingsSums[i] += _ratings[i][index];
- _ratings[i].insert ( _ratings[i].begin() + index, ratings[i] );
- }
-
- assert ( _entries.size() == _presetNames.size() );
-}
diff --git a/src/libprojectM/PresetLoader.hpp b/src/libprojectM/PresetLoader.hpp
deleted file mode 100644
index 891546911..000000000
--- a/src/libprojectM/PresetLoader.hpp
+++ /dev/null
@@ -1,113 +0,0 @@
-#ifndef __PRESET_LOADER_HPP
-#define __PRESET_LOADER_HPP
-
-#include // used for path / filename stuff
-#include // for auto pointers
-#include
-
-#include
-#include