From 0a4cf9fa49156e4f967bbbe53bdec789229823c1 Mon Sep 17 00:00:00 2001 From: Kai Blaschke Date: Sun, 22 Aug 2021 18:40:15 +0200 Subject: [PATCH] Added getters and setters for all settings values and renamed some members. Some members and functions were named in different ways, now the naming scheme is a bit more unified. Also changed some types to size_t where negative values don't make sense. --- src/libprojectM/ProjectMCWrapper.cpp | 197 +++++++++++++--- src/libprojectM/Renderer/Renderer.cpp | 5 + src/libprojectM/Renderer/Renderer.hpp | 1 + src/libprojectM/TimeKeeper.cpp | 8 +- src/libprojectM/TimeKeeper.hpp | 11 +- src/libprojectM/projectM.cpp | 169 +++++++++++--- src/libprojectM/projectM.h | 269 ++++++++++++++++++---- src/libprojectM/projectM.hpp | 91 ++++---- src/projectM-qt/qplaylistmodel.cpp | 10 +- src/projectM-qt/qprojectm_mainwindow.cpp | 12 +- src/projectM-qt/qprojectmconfigdialog.cpp | 4 +- src/projectM-qt/qprojectmwidget.hpp | 2 +- src/projectM-sdl/pmSDL.cpp | 16 +- src/projectM-sdl/pmSDL.hpp | 4 +- src/projectM-sdl/setup.cpp | 8 +- 15 files changed, 604 insertions(+), 203 deletions(-) diff --git a/src/libprojectM/ProjectMCWrapper.cpp b/src/libprojectM/ProjectMCWrapper.cpp index a5d5cb5f2..f12f8b7a8 100644 --- a/src/libprojectM/ProjectMCWrapper.cpp +++ b/src/libprojectM/ProjectMCWrapper.cpp @@ -135,11 +135,11 @@ projectm_handle projectm_create_settings(const projectm_settings* settings, int cppSettings.titleFontURL = settings->title_font_url ? settings->title_font_url : ""; cppSettings.menuFontURL = settings->menu_font_url ? settings->menu_font_url : ""; cppSettings.datadir = settings->data_dir ? settings->data_dir : ""; - cppSettings.smoothPresetDuration = settings->smooth_preset_duration; + cppSettings.softCutDuration = settings->soft_cut_duration; cppSettings.presetDuration = settings->preset_duration; - cppSettings.hardcutEnabled = settings->hardcut_enabled; - cppSettings.hardcutDuration = settings->hardcut_duration; - cppSettings.hardcutSensitivity = settings->hardcut_sensitivity; + cppSettings.hardCutEnabled = settings->hard_cut_enabled; + cppSettings.hardCutDuration = settings->hard_cut_duration; + cppSettings.hardCutSensitivity = settings->hard_cut_sensitivity; cppSettings.beatSensitivity = settings->beat_sensitivity; cppSettings.aspectCorrection = settings->aspect_correction; cppSettings.easterEgg = settings->easter_egg; @@ -205,10 +205,16 @@ void projectm_reset_textures(projectm_handle instance) projectMInstance->projectM_resetTextures(); } +const char* projectm_get_title(projectm_handle instance) +{ + auto projectMInstance = handle_to_instance(instance); + return projectm_alloc_string_from_std_string(projectMInstance->getTitle()); +} + void projectm_set_title(projectm_handle instance, const char* title) { auto projectMInstance = handle_to_instance(instance); - projectMInstance->projectM_setTitle(title); + projectMInstance->setTitle(title); } void projectm_render_frame(projectm_handle instance) @@ -236,28 +242,136 @@ void projectm_default_key_handler(projectm_handle instance, projectMEvent event, projectMInstance->default_key_handler(event, keycode); } -void projectm_set_texture_size(projectm_handle instance, int size) +size_t projectm_get_texture_size(projectm_handle instance) { auto projectMInstance = handle_to_instance(instance); - projectMInstance->changeTextureSize(size); + return projectMInstance->getTextureSize(); } -void projectm_set_hardcut_duration(projectm_handle instance, double seconds) +void projectm_set_texture_size(projectm_handle instance, size_t size) { auto projectMInstance = handle_to_instance(instance); - projectMInstance->changeHardcutDuration(seconds); + projectMInstance->setTextureSize(size); +} + +double projectm_get_hard_cut_duration(projectm_handle instance) +{ + auto projectMInstance = handle_to_instance(instance); + return projectMInstance->getHardCutDuration(); +} + +void projectm_set_hard_cut_duration(projectm_handle instance, double seconds) +{ + auto projectMInstance = handle_to_instance(instance); + projectMInstance->setHardCutDuration(seconds); +} + +bool projectm_get_hard_cut_enabled(projectm_handle instance) +{ + auto projectMInstance = handle_to_instance(instance); + return projectMInstance->getHardCutEnabled(); +} + +void projectm_set_hard_cut_enabled(projectm_handle instance, bool enabled) +{ + auto projectMInstance = handle_to_instance(instance); + projectMInstance->setHardCutEnabled(enabled); +} + +float projectm_get_hard_cut_sensitivity(projectm_handle instance) +{ + auto projectMInstance = handle_to_instance(instance); + return projectMInstance->getHardCutSensitivity(); +} + +void projectm_set_hard_cut_sensitivity(projectm_handle instance, float sensitivity) +{ + auto projectMInstance = handle_to_instance(instance); + projectMInstance->setHardCutSensitivity(sensitivity); +} + +double projectm_get_soft_cut_duration(projectm_handle instance) +{ + auto projectMInstance = handle_to_instance(instance); + return projectMInstance->getSoftCutDuration(); +} + +void projectm_set_soft_cut_duration(projectm_handle instance, double seconds) +{ + auto projectMInstance = handle_to_instance(instance); + projectMInstance->setSoftCutDuration(seconds); } void projectm_set_preset_duration(projectm_handle instance, double seconds) { auto projectMInstance = handle_to_instance(instance); - projectMInstance->changePresetDuration(seconds); + projectMInstance->setPresetDuration(seconds); } -void projectm_get_mesh_size(projectm_handle instance, int* width, int* height) +void projectm_get_mesh_size(projectm_handle instance, size_t* width, size_t* height) { auto projectMInstance = handle_to_instance(instance); - projectMInstance->getMeshSize(width, height); + projectMInstance->getMeshSize(*width, *height); +} + +void projectm_set_mesh_size(projectm_handle instance, size_t width, size_t height) +{ + auto projectMInstance = handle_to_instance(instance); + projectMInstance->setMeshSize(width, height); +} + +size_t projectm_get_fps(projectm_handle instance) +{ + auto projectMInstance = handle_to_instance(instance); + return projectMInstance->settings().fps; +} + +const char* projectm_get_preset_path(projectm_handle instance) +{ + auto projectMInstance = handle_to_instance(instance); + return projectm_alloc_string_from_std_string(projectMInstance->settings().presetURL); +} + +const char* projectm_get_title_font_filename(projectm_handle instance) +{ + auto projectMInstance = handle_to_instance(instance); + return projectm_alloc_string_from_std_string(projectMInstance->settings().titleFontURL); +} + +const char* projectm_get_menu_font_filename(projectm_handle instance) +{ + auto projectMInstance = handle_to_instance(instance); + return projectm_alloc_string_from_std_string(projectMInstance->settings().menuFontURL); +} + +const char* projectm_get_data_dir_path(projectm_handle instance) +{ + auto projectMInstance = handle_to_instance(instance); + return projectm_alloc_string_from_std_string(projectMInstance->settings().datadir); +} + +void projectm_set_aspect_correction(projectm_handle instance, bool enabled) +{ + auto projectMInstance = handle_to_instance(instance); + projectMInstance->setAspectCorrection(enabled); +} + +bool projectm_get_aspect_correction(projectm_handle instance) +{ + auto projectMInstance = handle_to_instance(instance); + return projectMInstance->getAspectCorrection(); +} + +void projectm_set_easter_egg(projectm_handle instance, float value) +{ + auto projectMInstance = handle_to_instance(instance); + projectMInstance->setEasterEgg(value); +} + +float projectm_get_easter_egg(projectm_handle instance) +{ + auto projectMInstance = handle_to_instance(instance); + return projectMInstance->getEasterEgg(); } void projectm_touch(projectm_handle instance, float x, float y, int pressure, projectm_touch_type touch_type) @@ -322,11 +436,11 @@ projectm_settings* projectm_get_settings(projectm_handle instance) settingsStruct->title_font_url = projectm_alloc_string_from_std_string(settings.titleFontURL); settingsStruct->menu_font_url = projectm_alloc_string_from_std_string(settings.menuFontURL); settingsStruct->data_dir = projectm_alloc_string_from_std_string(settings.datadir); - settingsStruct->smooth_preset_duration = settings.smoothPresetDuration; + settingsStruct->soft_cut_duration = settings.softCutDuration; settingsStruct->preset_duration = settings.presetDuration; - settingsStruct->hardcut_enabled = settings.hardcutEnabled; - settingsStruct->hardcut_duration = settings.hardcutDuration; - settingsStruct->hardcut_sensitivity = settings.hardcutSensitivity; + settingsStruct->hard_cut_enabled = settings.hardCutEnabled; + settingsStruct->hard_cut_duration = settings.hardCutDuration; + settingsStruct->hard_cut_sensitivity = settings.hardCutSensitivity; settingsStruct->beat_sensitivity = settings.beatSensitivity; settingsStruct->aspect_correction = settings.aspectCorrection; settingsStruct->easter_egg = settings.easterEgg; @@ -349,11 +463,11 @@ void projectm_write_config(const char* config_file, const projectm_settings* set cppSettings.titleFontURL = settings->title_font_url ? settings->title_font_url : ""; cppSettings.menuFontURL = settings->menu_font_url ? settings->menu_font_url : ""; cppSettings.datadir = settings->data_dir ? settings->data_dir : ""; - cppSettings.smoothPresetDuration = settings->smooth_preset_duration; + cppSettings.softCutDuration = settings->soft_cut_duration; cppSettings.presetDuration = settings->preset_duration; - cppSettings.hardcutEnabled = settings->hardcut_enabled; - cppSettings.hardcutDuration = settings->hardcut_duration; - cppSettings.hardcutSensitivity = settings->hardcut_sensitivity; + cppSettings.hardCutEnabled = settings->hard_cut_enabled; + cppSettings.hardCutDuration = settings->hard_cut_duration; + cppSettings.hardCutSensitivity = settings->hard_cut_sensitivity; cppSettings.beatSensitivity = settings->beat_sensitivity; cppSettings.aspectCorrection = settings->aspect_correction; cppSettings.easterEgg = settings->easter_egg; @@ -433,6 +547,12 @@ void projectm_select_preset_by_name(projectm_handle instance, const char* preset return projectMInstance->selectPresetByName(preset_name, hard_cut); } +const char* projectm_get_search_text(projectm_handle instance) +{ + auto projectMInstance = handle_to_instance(instance); + return projectm_alloc_string_from_std_string(projectMInstance->getSearchText()); +} + void projectm_set_search_text(projectm_handle instance, const char* search_text) { if (!search_text) @@ -456,7 +576,7 @@ void projectm_reset_search_text(projectm_handle instance) return projectMInstance->resetSearchText(); } -bool projectm_selected_preset_index(projectm_handle instance, unsigned int* index) +bool projectm_get_selected_preset_index(projectm_handle instance, unsigned int* index) { if (!index) { @@ -515,7 +635,7 @@ bool projectm_preset_position_valid(projectm_handle instance) return projectMInstance->presetPositionValid(); } -const char* projectm_get_preset_url(projectm_handle instance, unsigned int index) +const char* projectm_get_preset_filename(projectm_handle instance, unsigned int index) { auto projectMInstance = handle_to_instance(instance); return projectm_alloc_string_from_std_string(projectMInstance->getPresetURL(index)); @@ -527,7 +647,7 @@ const char* projectm_get_preset_name(projectm_handle instance, unsigned int inde return projectm_alloc_string_from_std_string(projectMInstance->getPresetName(index)); } -void projectm_change_preset_name(projectm_handle instance, unsigned int index, const char* name) +void projectm_set_preset_name(projectm_handle instance, unsigned int index, const char* name) { auto projectMInstance = handle_to_instance(instance); projectMInstance->changePresetName(index, name); @@ -539,8 +659,8 @@ int projectm_get_preset_rating(projectm_handle instance, unsigned int index, pro return projectMInstance->getPresetRating(index, static_cast(rating_type)); } -void projectm_change_preset_rating(projectm_handle instance, unsigned int index, int rating, - projectm_preset_rating_type rating_type) +void projectm_set_preset_rating(projectm_handle instance, unsigned int index, int rating, + projectm_preset_rating_type rating_type) { auto projectMInstance = handle_to_instance(instance); projectMInstance->changePresetRating(index, rating, static_cast(rating_type)); @@ -552,52 +672,53 @@ unsigned int projectm_get_playlist_size(projectm_handle instance) return projectMInstance->getPlaylistSize(); } +bool projectm_get_shuffle_enabled(projectm_handle instance) +{ + auto projectMInstance = handle_to_instance(instance); + return projectMInstance->isShuffleEnabled(); +} + void projectm_set_shuffle_enabled(projectm_handle instance, bool shuffle_enabled) { auto projectMInstance = handle_to_instance(instance); projectMInstance->setShuffleEnabled(shuffle_enabled); } -bool projectm_is_shuffle_enabled(projectm_handle instance) -{ - auto projectMInstance = handle_to_instance(instance); - return projectMInstance->isShuffleEnabled(); -} - unsigned int projectm_get_search_index(projectm_handle instance, const char* name) { auto projectMInstance = handle_to_instance(instance); return projectMInstance->getSearchIndex(name); } -void projectm_select_previous(projectm_handle instance, bool hard_cut) +void projectm_select_previous_preset(projectm_handle instance, bool hard_cut) { auto projectMInstance = handle_to_instance(instance); projectMInstance->selectPrevious(hard_cut); } -void projectm_select_next(projectm_handle instance, bool hard_cut) +void projectm_select_next_preset(projectm_handle instance, bool hard_cut) { auto projectMInstance = handle_to_instance(instance); projectMInstance->selectNext(hard_cut); } -void projectm_select_random(projectm_handle instance, bool hard_cut) +void projectm_select_random_preset(projectm_handle instance, bool hard_cut) { auto projectMInstance = handle_to_instance(instance); projectMInstance->selectRandom(hard_cut); } -int projectm_get_window_width(projectm_handle instance) +void projectm_get_window_size(projectm_handle instance, size_t* width, size_t* height) { auto projectMInstance = handle_to_instance(instance); - return projectMInstance->getWindowWidth(); + *width = projectMInstance->getWindowWidth(); + *height = projectMInstance->getWindowHeight(); } -int projectm_get_window_height(projectm_handle instance) +void projectm_set_window_size(projectm_handle instance, size_t width, size_t height) { auto projectMInstance = handle_to_instance(instance); - return projectMInstance->getWindowHeight(); + projectMInstance->projectM_resetGL(width, height); } bool projectm_get_error_loading_current_preset(projectm_handle instance) diff --git a/src/libprojectM/Renderer/Renderer.cpp b/src/libprojectM/Renderer/Renderer.cpp index b41e2ebec..a0c72a644 100644 --- a/src/libprojectM/Renderer/Renderer.cpp +++ b/src/libprojectM/Renderer/Renderer.cpp @@ -814,6 +814,11 @@ void Renderer::toggleSearchText() { } } +std::string Renderer::getSearchText() const +{ + return m_searchText; +} + // search based on new key input void Renderer::setSearchText(const std::string& theValue) { diff --git a/src/libprojectM/Renderer/Renderer.hpp b/src/libprojectM/Renderer/Renderer.hpp index b3ec2474d..cd93b5917 100644 --- a/src/libprojectM/Renderer/Renderer.hpp +++ b/src/libprojectM/Renderer/Renderer.hpp @@ -174,6 +174,7 @@ public: bool touchedWaveform(float x, float y, std::size_t i); void setToastMessage(const std::string& theValue); + std::string getSearchText() const; void setSearchText(const std::string& theValue); void resetSearchText(); void deleteSearchText(); diff --git a/src/libprojectM/TimeKeeper.cpp b/src/libprojectM/TimeKeeper.cpp index f79e277f2..51244b7ba 100644 --- a/src/libprojectM/TimeKeeper.cpp +++ b/src/libprojectM/TimeKeeper.cpp @@ -9,9 +9,9 @@ TimeKeeper::TimeKeeper(double presetDuration, double smoothDuration, double hardcutDuration, double easterEgg) { - _smoothDuration = smoothDuration; + _softCutDuration = smoothDuration; _presetDuration = presetDuration; - _hardcutDuration = hardcutDuration; + _hardCutDuration = hardcutDuration; _easterEgg = easterEgg; #ifndef WIN32 @@ -60,12 +60,12 @@ TimeKeeper::TimeKeeper(double presetDuration, double smoothDuration, double hard bool TimeKeeper::CanHardCut() { - return ((_currentTime - _presetTimeA) > _hardcutDuration); + return ((_currentTime - _presetTimeA) > _hardCutDuration); } double TimeKeeper::SmoothRatio() { - return (_currentTime - _presetTimeB) / _smoothDuration; + return (_currentTime - _presetTimeB) / _softCutDuration; } bool TimeKeeper::IsSmoothing() { diff --git a/src/libprojectM/TimeKeeper.hpp b/src/libprojectM/TimeKeeper.hpp index 1374d5836..d57aa7333 100644 --- a/src/libprojectM/TimeKeeper.hpp +++ b/src/libprojectM/TimeKeeper.hpp @@ -40,10 +40,13 @@ public: double sampledPresetDuration(); - void ChangeHardcutDuration(int seconds) { _hardcutDuration = seconds; } + void ChangeHardCutDuration(int seconds) { _hardCutDuration = seconds; } + void ChangeHardCutDuration(double seconds) { _hardCutDuration = seconds; } + void ChangeSoftCutDuration(int seconds) { _softCutDuration = seconds; } + void ChangeSoftCutDuration(double seconds) { _softCutDuration = seconds; } void ChangePresetDuration(int seconds) { _presetDuration = seconds; } - void ChangeHardcutDuration(double seconds) { _hardcutDuration = seconds; } void ChangePresetDuration(double seconds) { _presetDuration = seconds; } + void ChangeEasterEgg(float value) { _easterEgg = value; } #ifndef WIN32 /* The first ticks value of the application */ @@ -58,8 +61,8 @@ private: double _presetDuration; double _presetDurationA; double _presetDurationB; - double _smoothDuration; - double _hardcutDuration; + double _softCutDuration; + double _hardCutDuration; double _currentTime; double _presetTimeA; diff --git a/src/libprojectM/projectM.cpp b/src/libprojectM/projectM.cpp index f166fa66c..f187238a7 100644 --- a/src/libprojectM/projectM.cpp +++ b/src/libprojectM/projectM.cpp @@ -134,7 +134,7 @@ projectM::projectM(Settings settings, int flags): } -bool projectM::writeConfig(const std::string & configFile, const Settings & settings) { +bool projectM::writeConfig(const std::string& configFile, const Settings & settings) { ConfigFile config ( configFile ); @@ -144,7 +144,7 @@ bool projectM::writeConfig(const std::string & configFile, const Settings & sett config.add("FPS", settings.fps); config.add("Window Width", settings.windowWidth); config.add("Window Height", settings.windowHeight); - config.add("Smooth Preset Duration", settings.smoothPresetDuration); + config.add("Smooth Preset Duration", settings.softCutDuration); config.add("Preset Duration", settings.presetDuration); config.add("Preset Path", settings.presetURL); config.add("Title Font", settings.titleFontURL); @@ -175,7 +175,7 @@ void projectM::readConfig (const std::string & configFile) _settings.fps = config.read ( "FPS", 35 ); _settings.windowWidth = config.read ( "Window Width", 512 ); _settings.windowHeight = config.read ( "Window Height", 512 ); - _settings.smoothPresetDuration = config.read + _settings.softCutDuration = config.read ( "Smooth Preset Duration", config.read("Smooth Transition Duration", 10)); _settings.presetDuration = config.read ( "Preset Duration", 15 ); @@ -221,11 +221,11 @@ void projectM::readConfig (const std::string & configFile) config.read ( "Soft Cut Ratings Enabled", false); // Hard Cuts are preset transitions that occur when your music becomes louder. They only occur after a hard cut duration threshold has passed. - _settings.hardcutEnabled = config.read ( "Hard Cuts Enabled", false ); + _settings.hardCutEnabled = config.read ("Hard Cuts Enabled", false ); // Hard Cut duration is the number of seconds before you become eligible for a hard cut. - _settings.hardcutDuration = config.read ( "Hard Cut Duration", 60 ); + _settings.hardCutDuration = config.read ("Hard Cut Duration", 60 ); // Hard Cut sensitivity is the volume difference before a "hard cut" is triggered. - _settings.hardcutSensitivity = config.read ( "Hard Cut Sensitivity", 1.0 ); + _settings.hardCutSensitivity = config.read ("Hard Cut Sensitivity", 1.0 ); // Beat Sensitivity impacts how reactive your visualizations are to volume, bass, mid-range, and treble. // Preset authors have developed their visualizations with the default of 1.0. @@ -258,7 +258,7 @@ void projectM::readSettings (const Settings & settings ) _settings.fps = settings.fps; _settings.windowWidth = settings.windowWidth; _settings.windowHeight = settings.windowHeight; - _settings.smoothPresetDuration = settings.smoothPresetDuration; + _settings.softCutDuration = settings.softCutDuration; _settings.presetDuration = settings.presetDuration; _settings.softCutRatingsEnabled = settings.softCutRatingsEnabled; @@ -270,9 +270,9 @@ void projectM::readSettings (const Settings & settings ) _settings.easterEgg = settings.easterEgg; - _settings.hardcutEnabled = settings.hardcutEnabled; - _settings.hardcutDuration = settings.hardcutDuration; - _settings.hardcutSensitivity = settings.hardcutSensitivity; + _settings.hardCutEnabled = settings.hardCutEnabled; + _settings.hardCutDuration = settings.hardCutDuration; + _settings.hardCutSensitivity = settings.hardCutSensitivity; _settings.beatSensitivity = settings.beatSensitivity; @@ -380,7 +380,7 @@ Pipeline * projectM::renderFrameOnlyPass1(Pipeline *pPipeline) /*pPipeline is a selectRandom(false); else selectNext(false); - } else if (settings().hardcutEnabled && (beatDetect->vol-beatDetect->vol_old>settings().hardcutSensitivity) && timeKeeper->CanHardCut()) + } else if (settings().hardCutEnabled && (beatDetect->vol - beatDetect->vol_old > settings().hardCutSensitivity) && timeKeeper->CanHardCut()) { // Hard Cuts must be enabled, must have passed the hardcut duration, and the volume must be a greater difference than the hardcut sensitivity. if (settings().shuffleEnabled) @@ -549,7 +549,7 @@ void projectM::projectM_reset() void projectM::projectM_init ( int gx, int gy, int fps, int texsize, int width, int height ) { /** Initialise start time */ - timeKeeper = new TimeKeeper(_settings.presetDuration,_settings.smoothPresetDuration, _settings.hardcutDuration, _settings.easterEgg); + timeKeeper = new TimeKeeper(_settings.presetDuration, _settings.softCutDuration, _settings.hardCutDuration, _settings.easterEgg); /** Nullify frame stash */ @@ -609,21 +609,23 @@ void projectM::projectM_resetengine() } /** Resets OpenGL state */ -void projectM::projectM_resetGL ( int w, int h ) +void projectM::projectM_resetGL(size_t width, size_t height) { - /** sanity check **/ - assert(w > 0); - assert(h > 0); - /** Stash the new dimensions */ - _settings.windowWidth = w; - _settings.windowHeight = h; - renderer->reset ( w,h ); + _settings.windowWidth = width; + _settings.windowHeight = height; + renderer->reset(width, height); } /** Sets the title to display */ -void projectM::projectM_setTitle ( std::string title ) { +std::string projectM::getTitle() const +{ + return renderer->title; +} +/** Sets the title to display */ +void projectM::setTitle(const std::string& title) +{ if ( title != renderer->title ) { renderer->title=title; @@ -1109,33 +1111,109 @@ void projectM::changePresetName ( unsigned int index, std::string name ) { } -void projectM::changeTextureSize(int size) { +void projectM::setTextureSize(size_t size) { _settings.textureSize = size; - delete renderer; - renderer = new Renderer(_settings.windowWidth, _settings.windowHeight, - _settings.meshX, _settings.meshY, - beatDetect, _settings.presetURL, - _settings.titleFontURL, _settings.menuFontURL, - _settings.datadir); + recreateRenderer(); } -void projectM::changeHardcutDuration(int seconds) { - timeKeeper->ChangeHardcutDuration(seconds); +size_t projectM::getTextureSize() const +{ + return _settings.textureSize; } -void projectM::changePresetDuration(int seconds) { + +double projectM::getSoftCutDuration() const +{ + return _settings.softCutDuration; +} + +void projectM::setSoftCutDuration(int seconds) { + _settings.softCutDuration = static_cast(seconds); + timeKeeper->ChangeSoftCutDuration(seconds); +} + +void projectM::setSoftCutDuration(double seconds) { + _settings.softCutDuration = seconds; + timeKeeper->ChangeSoftCutDuration(seconds); +} + +double projectM::getHardCutDuration() const +{ + return _settings.hardCutDuration; +} + +void projectM::setHardCutDuration(int seconds) { + _settings.hardCutDuration = seconds; + timeKeeper->ChangeHardCutDuration(seconds); +} + +void projectM::setHardCutDuration(double seconds) { + _settings.hardCutDuration = static_cast(seconds); + timeKeeper->ChangeHardCutDuration(seconds); +} + +bool projectM::getHardCutEnabled() const +{ + return _settings.hardCutEnabled; +} + +void projectM::setHardCutEnabled(bool enabled) +{ + _settings.hardCutEnabled = enabled; +} + +float projectM::getHardCutSensitivity() const +{ + return _settings.hardCutSensitivity; +} + +void projectM::setHardCutSensitivity(float sensitivity) +{ + _settings.hardCutSensitivity = sensitivity; +} + +void projectM::setPresetDuration(int seconds) { timeKeeper->ChangePresetDuration(seconds); } -void projectM::changeHardcutDuration(double seconds) { - timeKeeper->ChangeHardcutDuration(seconds); -} -void projectM::changePresetDuration(double seconds) { +void projectM::setPresetDuration(double seconds) { timeKeeper->ChangePresetDuration(seconds); } -void projectM::getMeshSize(int *w, int *h) { - *w = _settings.meshX; - *h = _settings.meshY; + +bool projectM::getAspectCorrection() const +{ + return _settings.aspectCorrection; +} + +void projectM::setAspectCorrection(bool enabled) +{ + _settings.aspectCorrection = enabled; + renderer->correction = enabled; +} + +float projectM::getEasterEgg() const +{ + return _settings.easterEgg; +} + +void projectM::setEasterEgg(float value) +{ + _settings.easterEgg = value; + timeKeeper->ChangeEasterEgg(value); +} + +void projectM::getMeshSize(size_t& w, size_t& h) const +{ + w = _settings.meshX; + h = _settings.meshY; +} + +void projectM::setMeshSize(size_t w, size_t h) +{ + _settings.meshX = w; + _settings.meshY = h; + + recreateRenderer(); } // toggleSearchText @@ -1171,6 +1249,11 @@ void projectM::selectPresetByName(std::string name, bool hardCut) { selectPreset(index); } +std::string projectM::getSearchText() const +{ + return renderer->getSearchText(); +} + // update search text based on new keystroke void projectM::setSearchText(const std::string & searchKey) { @@ -1246,3 +1329,13 @@ void projectM::setHelpText(const std::string & helpText) if ( renderer ) renderer->setHelpText(helpText); } + +void projectM::recreateRenderer() +{ + delete renderer; + renderer = new Renderer(_settings.windowWidth, _settings.windowHeight, + _settings.meshX, _settings.meshY, + beatDetect, _settings.presetURL, + _settings.titleFontURL, _settings.menuFontURL, + _settings.datadir); +} diff --git a/src/libprojectM/projectM.h b/src/libprojectM/projectM.h index e53f61f8f..b3659ff47 100644 --- a/src/libprojectM/projectM.h +++ b/src/libprojectM/projectM.h @@ -24,6 +24,8 @@ #include "projectM_export.h" #include "event.h" +#include + #ifdef __cplusplus extern "C" { #endif @@ -56,11 +58,11 @@ struct PROJECTM_EXPORT projectm_settings char* title_font_url; //!< Path to the "title" font that is used to render the preset name. char* menu_font_url; //!< Path to the "menu" font that is used to render the built-in on-screen menu. char* data_dir; //!< Path to data files like default fonts and presets. - double smooth_preset_duration; //!< Blend-over duration between two presets in seconds. double preset_duration; //!< Display duration for each preset in seconds. - bool hardcut_enabled; //!< Set to true to enable fast beat-driven preset switches. - int hardcut_duration; //!< Minimum time a preset is displayed before a hardcut can happen in seconds. - float hardcut_sensitivity; //!< Beat sensitivity value that must be surpassed for a hardcut. + 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. @@ -127,7 +129,7 @@ PROJECTM_EXPORT char* projectm_alloc_string(unsigned int length); * @brief Frees the memory of an allocated string. * *

Frees the memory allocated by a call to projectm_alloc_string() or any - * (const) char* pointers returned by an API call.

+ * (const) char* pointers returned by a projectM API call.

* *

Do not use free() to delete the pointer!

* @@ -138,7 +140,11 @@ PROJECTM_EXPORT void projectm_free_string(const char* str); /** * @brief Allocates memory for a projectm_settings struct and returns the pointer. * - * To free the allocated memory, call projectm_free_settings(). Do not use free()! + *

This will not allocate memory for the char* members in the struct. These will be set to NULL initially. + * To store a string in these members, use projectm_alloc_string() to allocate the required memory. Do not use + * malloc()!

+ * + *

To free the allocated memory, call projectm_free_settings(). Do not use free()!

* * @return A pointer to a zero-initialized projectm_settings struct. */ @@ -293,15 +299,13 @@ PROJECTM_EXPORT void projectm_set_preset_rating_changed_event_callback(projectm_ /** * @brief Reset the projectM OpenGL renderer. * - * Required if anything invalidates the state of the current OpenGL context projectM is rendering to. - * This is the case on window resizes, restoring a window from minimized state or other events that - * required recreating of OpenGL objects. + *

Required if anything invalidates the state of the current OpenGL context projectM is rendering to.

+ * + *

For resize events, it is sufficient to call projectm_set_window_size()

* * @param instance The projectM instance handle. - * @param width The rendering viewport width. - * @param height The rendering viewport height. */ -PROJECTM_EXPORT void projectm_reset_gl(projectm_handle instance, int width, int height); +PROJECTM_EXPORT void projectm_reset_gl(projectm_handle instance); /** @@ -313,6 +317,13 @@ PROJECTM_EXPORT void projectm_reset_gl(projectm_handle instance, int width, int */ PROJECTM_EXPORT void projectm_reset_textures(projectm_handle instance); +/** + * @brief Returns the current title text. + * @param instance The projectM instance handle. + * @return The currently set title text. + */ +PROJECTM_EXPORT const char* projectm_get_title(projectm_handle instance); + /** * @brief Sets the current title text and displays it. * @param instance The projectM instance handle. @@ -344,11 +355,11 @@ PROJECTM_EXPORT unsigned int projectm_init_render_to_texture(projectm_handle ins /** * @brief Key handler that processes user input. * - * This method can be used to send user input in the host application to projectM, for example - * to switch presets, display the help and search menus or change settings like beat sensitivity. + *

This method can be used to send user input in the host application to projectM, for example + * to switch presets, display the help and search menus or change settings like beat sensitivity.

* - * All actions executed by the key handler can also be run programmatically if the host application - * is not able to redirect keyboard input to projectM. + *

All actions executed by the key handler can also be run programmatically if the host application + * is not able to redirect keyboard input to projectM.

* * @param instance The projectM instance handle. * @param event The key event, valid are either PROJECTM_KEYUP or PROJECTM_KEYDOWN. @@ -361,11 +372,11 @@ PROJECTM_EXPORT void projectm_key_handler(projectm_handle instance, projectMEven /** * @brief Default key handler that processes user input. * - * This method can be used to send user input in the host application to projectM, for example - * to switch presets, display the help and search menus or change settings like beat sensitivity. + *

This method can be used to send user input in the host application to projectM, for example + * to switch presets, display the help and search menus or change settings like beat sensitivity.

* - * All actions executed by the key handler can also be run programmatically if the host application - * is not able to redirect keyboard input to projectM. + *

All actions executed by the key handler can also be run programmatically if the host application + * is not able to redirect keyboard input to projectM.

* * @param instance The projectM instance handle. * @param event The key event, valid are either PROJECTM_KEYUP or PROJECTM_KEYDOWN. @@ -373,13 +384,28 @@ PROJECTM_EXPORT void projectm_key_handler(projectm_handle instance, projectMEven */ PROJECTM_EXPORT void projectm_default_key_handler(projectm_handle instance, projectMEvent event, projectMKeycode keycode); + +/** + * @brief Returns the size of the internal render texture. + * @param instance The projectM instance handle. + * @return The size of the internal rendering texture. + */ +PROJECTM_EXPORT size_t projectm_get_texture_size(projectm_handle instance); + /** * @brief Changes the size of the internal render texture. * @note This will recreate the internal renderer. * @param instance The projectM instance handle. * @param size The new size of the render texture. Must be a power of 2. */ -PROJECTM_EXPORT void projectm_set_texture_size(projectm_handle instance, int size); +PROJECTM_EXPORT void projectm_set_texture_size(projectm_handle instance, size_t size); + +/** + * @brief Returns the minimum display time before a hard cut can happen. + * @param instance The projectM instance handle. + * @return The minimum number of seconds the preset will be displayed before a hard cut. + */ +PROJECTM_EXPORT double projectm_get_hard_cut_duration(projectm_handle instance); /** * @brief Sets the minimum display time before a hard cut can happen. @@ -392,22 +418,162 @@ PROJECTM_EXPORT void projectm_set_texture_size(projectm_handle instance, int siz * @param instance The projectM instance handle. * @param seconds Minimum number of seconds the preset will be displayed before a hard cut. */ -PROJECTM_EXPORT void projectm_set_hardcut_duration(projectm_handle instance, double seconds); +PROJECTM_EXPORT void projectm_set_hard_cut_duration(projectm_handle instance, double seconds); + +/** + * @brief Returns whether hard cuts are enabled or not. + * @param instance The projectM instance handle. + * @return True if hard cuts are enabled, false otherwise. + */ +PROJECTM_EXPORT bool projectm_get_hard_cut_enabled(projectm_handle instance); + +/** + * @brief Enables or disables hard cuts. + * + * Even if enabled, the hard cut duration must be set to a value lower than the preset duration + * to work properly. + * + * @param instance The projectM instance handle. + * @param enabled True to enable hard cuts, false to disable. + */ +PROJECTM_EXPORT void projectm_set_hard_cut_enabled(projectm_handle instance, bool enabled); + +/** + * @brief Returns the current hard cut sensitivity. + * @param instance The projectM instance handle. + * @return The current hard cut sensitivity. + */ +PROJECTM_EXPORT float projectm_get_hard_cut_sensitivity(projectm_handle instance); + +/** + * @brief Sets the hard cut volume sensitivity. + * + * The beat detection volume difference that must be surpassed to trigger a hard cut. + * + * @param instance The projectM instance handle. + * @param sensitivity The volume threshold that triggers a hard cut if surpassed. + */ +PROJECTM_EXPORT void projectm_set_hard_cut_sensitivity(projectm_handle instance, float sensitivity); + +/** + * @brief Returns the time in seconds for a soft transition between two presets. + * @param instance The projectM instance handle. + * @return Time in seconds it takes to smoothly transition from one preset to another. + */ +PROJECTM_EXPORT double projectm_get_soft_cut_duration(projectm_handle instance); + +/** + * @brief Sets the time in seconds for a soft transition between two presets. + * + * During a soft cut, both presets are rendered and slowly transitioned from one + * to the other. + * + * @param instance The projectM instance handle. + * @param seconds Time in seconds it takes to smoothly transition from one preset to another. + */ +PROJECTM_EXPORT void projectm_set_soft_cut_duration(projectm_handle instance, double seconds); /** * @brief Sets the preset display duration before switching to the next using a soft cut. + * + * This can be considered as the maximum time a preset is displayed. If this time is reached, + * a smooth cut will be initiated. A hard cut, if any, will always happen before this time. + * * @param instance The projectM instance handle. * @param seconds The number of seconds a preset will be displayed before the next is shown. */ PROJECTM_EXPORT void projectm_set_preset_duration(projectm_handle instance, double seconds); /** - * @brief returns the per-pixel equation mesh size in units. + * @brief Returns the per-pixel equation mesh size in units. * @param instance The projectM instance handle. * @param width The width of the mesh. * @param height The height of the mesh. */ -PROJECTM_EXPORT void projectm_get_mesh_size(projectm_handle instance, int* width, int* height); +PROJECTM_EXPORT void projectm_get_mesh_size(projectm_handle instance, size_t* width, size_t* height); + +/** + * @brief Sets the per-pixel equation mesh size in units. + * @note This will recreate the renderer. + * @param instance The projectM instance handle. + * @param width The new width of the mesh. + * @param height The new height of the mesh. + */ +PROJECTM_EXPORT void projectm_set_mesh_size(projectm_handle instance, size_t width, size_t height); + +/** + * @brief Returns the target frames per second count. + * @note This is not the actual FPS, but the targeted refresh framerate if the integrating application. + * @param instance The projectM instance handle. + */ +PROJECTM_EXPORT size_t projectm_get_fps(projectm_handle instance); + +/** + * @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 path and filename of the font used to render the title overlay text. + * @param instance The projectM instance handle. + * @return The path and filename of the title text font. + */ +PROJECTM_EXPORT const char* projectm_get_title_font_filename(projectm_handle instance); + +/** + * @brief Returns the path and filename of the font used to render the menu overlay text. + * @param instance The projectM instance handle. + * @return The path and filename of the menu text font. + */ +PROJECTM_EXPORT const char* projectm_get_menu_font_filename(projectm_handle instance); + +/** + * @brief Returns the path projectM uses to search for additional data. + * @param instance The projectM instance handle. + * @return The data dir path. + */ +PROJECTM_EXPORT const char* projectm_get_data_dir_path(projectm_handle instance); + +/** + * @brief Enabled or disables aspect ratio correction in presets that support it. + * + * This sets a flag presets can use to aspect-correct rendered shapes, which otherwise would + * be distorted if the viewport isn't exactly square. + * + * @param instance The projectM instance handle. + * @param enabled True to enable aspect correction, false to disable it. + */ +PROJECTM_EXPORT void projectm_set_aspect_correction(projectm_handle instance, bool enabled); + +/** + * @brief Returns whether aspect ratio correction is enabled or not. + * @param instance The projectM instance handle. + * @return True if aspect ratio correction is enabled, false otherwise. + */ +PROJECTM_EXPORT bool projectm_get_aspect_correction(projectm_handle instance); + +/** + * @brief Sets the "easter egg" value. + * + *

This doesn't enable any fancy feature, it only influences the randomized display time of presets. It's + * passed as the "sigma" value of the gaussian random number generator used to determine the maximum display time, + * effectively multiplying the generated number of seconds by this amount.

+ * + *

See function sampledPresetDuration() of the TimeKeeper class on how it is used.

+ * + * @param instance The projectM instance handle. + * @param value The new "easter egg" value. + */ +PROJECTM_EXPORT void projectm_set_easter_egg(projectm_handle instance, float value); + +/** + * @brief Returns the current "easter egg" value. + * @param instance The projectM instance handle. + * @return The current "easter egg" value. + */ +PROJECTM_EXPORT float projectm_get_easter_egg(projectm_handle instance); /** * @brief Starts a touch event or moves an existing waveform. @@ -573,6 +739,13 @@ PROJECTM_EXPORT unsigned int projectm_get_preset_index(projectm_handle instance, */ PROJECTM_EXPORT void projectm_select_preset_by_name(projectm_handle instance, const char* preset_name, bool hard_cut); +/** + * @brief Returns the current preset search text. + * @param instance The projectM instance handle. + * @return The current search text used to search for presets in the playlist. + */ +PROJECTM_EXPORT const char* projectm_get_search_text(projectm_handle instance); + /** * @brief Sets the current preset search text. * @param instance The projectM instance handle. @@ -604,7 +777,7 @@ PROJECTM_EXPORT void projectm_reset_search_text(projectm_handle instance); * @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_selected_preset_index(projectm_handle instance, unsigned int* index); +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. @@ -658,7 +831,8 @@ PROJECTM_EXPORT bool projectm_preset_position_valid(projectm_handle instance); * @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_url(projectm_handle instance, unsigned int 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! @@ -674,7 +848,7 @@ PROJECTM_EXPORT const char* projectm_get_preset_name(projectm_handle instance, u * @param index the playlist item index to change. * @param name The new display name. */ -PROJECTM_EXPORT void projectm_change_preset_name(projectm_handle instance, unsigned int index, const char* 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. @@ -693,8 +867,8 @@ PROJECTM_EXPORT int projectm_get_preset_rating(projectm_handle instance, unsigne * @param rating The new rating value. * @param rating_type The type of the rating, either hard or soft cut. */ -PROJECTM_EXPORT void projectm_change_preset_rating(projectm_handle instance, unsigned int index, int rating, - projectm_preset_rating_type rating_type); +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. @@ -703,6 +877,13 @@ PROJECTM_EXPORT void projectm_change_preset_rating(projectm_handle instance, uns */ 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. @@ -710,13 +891,6 @@ PROJECTM_EXPORT unsigned int projectm_get_playlist_size(projectm_handle instance */ PROJECTM_EXPORT void projectm_set_shuffle_enabled(projectm_handle instance, bool shuffle_enabled); -/** - * @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_is_shuffle_enabled(projectm_handle instance); - /** * @brief Gets the index of the provided preset name in the current search result list. * @param instance The projectM instance handle. @@ -733,7 +907,7 @@ PROJECTM_EXPORT unsigned int projectm_get_search_index(projectm_handle instance, * @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(projectm_handle instance, bool hard_cut); +PROJECTM_EXPORT void projectm_select_previous_preset(projectm_handle instance, bool hard_cut); /** * @brief Switches to the next preset in the current playlist. @@ -743,7 +917,7 @@ PROJECTM_EXPORT void projectm_select_previous(projectm_handle instance, bool har * @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(projectm_handle instance, bool hard_cut); +PROJECTM_EXPORT void projectm_select_next_preset(projectm_handle instance, bool hard_cut); /** * @brief Switches to a random preset in the current playlist. @@ -753,21 +927,26 @@ PROJECTM_EXPORT void projectm_select_next(projectm_handle instance, bool hard_cu * @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(projectm_handle instance, bool hard_cut); +PROJECTM_EXPORT void projectm_select_random_preset(projectm_handle instance, bool hard_cut); /** - * @brief Returns the current viewport width in pixels. + * @brief Returns the current viewport size in pixels. * @param instance The projectM instance handle. - * @return The viewport width in pixels. + * @param width Valid pointer to a size_t variable that will receive the window width value. + * @param height Valid pointer to a size_t variable that will receive the window height value. */ -PROJECTM_EXPORT int projectm_get_window_width(projectm_handle instance); +PROJECTM_EXPORT void projectm_get_window_size(projectm_handle instance, size_t* width, size_t* height); /** - * @brief Returns the current viewport height in pixels. + * @brief Sets the current viewport size in pixels. + * + * Calling this function will reset the OpenGL renderer. + * * @param instance The projectM instance handle. - * @return The viewport height in pixels. + * @param width New viewport width in pixels. + * @param height New viewport height in pixels. */ -PROJECTM_EXPORT int projectm_get_window_height(projectm_handle instance); +PROJECTM_EXPORT void projectm_set_window_size(projectm_handle instance, size_t width, size_t height); /** * @brief Returns whether the current preset was loaded successfully or not. diff --git a/src/libprojectM/projectM.hpp b/src/libprojectM/projectM.hpp index 89f2b5fe1..dbb828ae0 100644 --- a/src/libprojectM/projectM.hpp +++ b/src/libprojectM/projectM.hpp @@ -121,55 +121,40 @@ public: static const int FLAG_NONE = 0; static const int FLAG_DISABLE_PLAYLIST_LOAD = 1 << 0; - struct Settings { - int meshX; - int meshY; - int fps; - int textureSize; - int windowWidth; - int windowHeight; + class Settings { + public: + size_t meshX{ 32 }; + size_t meshY{ 24 }; + size_t fps{ 35 }; + size_t textureSize{ 512 }; + size_t windowWidth{ 512 }; + size_t windowHeight{ 512 }; std::string presetURL; std::string titleFontURL; std::string menuFontURL; std::string datadir; - double smoothPresetDuration; - double presetDuration; - bool hardcutEnabled; - int hardcutDuration; - float hardcutSensitivity; - float beatSensitivity; - bool aspectCorrection; - float easterEgg; - bool shuffleEnabled; - bool softCutRatingsEnabled; - - Settings() : - meshX(32), - meshY(24), - fps(35), - textureSize(512), - windowWidth(512), - windowHeight(512), - smoothPresetDuration(10.0), - presetDuration(15.0), - hardcutEnabled(false), - hardcutDuration(60), - hardcutSensitivity(2.0), - beatSensitivity(1.0), - aspectCorrection(true), - easterEgg(0.0), - shuffleEnabled(true), - softCutRatingsEnabled(false) {} - }; + double presetDuration{ 15.0 }; + double softCutDuration{ 10.0 }; + double hardCutDuration{ 60.0 }; + bool hardCutEnabled{ false }; + float hardCutSensitivity{ 2.0 }; + float beatSensitivity{ 1.0 }; + bool aspectCorrection{ true }; + float easterEgg{ 0.0 }; + bool shuffleEnabled{ true }; + bool softCutRatingsEnabled{ false }; + }; projectM(std::string config_file, int flags = FLAG_NONE); projectM(Settings settings, int flags = FLAG_NONE); virtual ~projectM(); - void projectM_resetGL( int width, int height ); + void projectM_resetGL(size_t width, size_t height); void projectM_resetTextures(); - void projectM_setTitle( std::string title ); + + std::string getTitle() const; + void setTitle(const std::string& title); void renderFrame(); Pipeline * renderFrameOnlyPass1(Pipeline *pPipeline); void renderFrameOnlyPass2(Pipeline *pPipeline,int xoffset,int yoffset,int eye); @@ -178,12 +163,26 @@ public: void key_handler( projectMEvent event, projectMKeycode keycode, projectMModifier modifier ); - void changeTextureSize(int size); - void changeHardcutDuration(int seconds); - void changeHardcutDuration(double seconds); - void changePresetDuration(int seconds); - void changePresetDuration(double seconds); - void getMeshSize(int *w, int *h); + void setTextureSize(size_t size); + size_t getTextureSize() const; + double getSoftCutDuration() const; + void setSoftCutDuration(int seconds); + void setSoftCutDuration(double seconds); + double getHardCutDuration() const; + void setHardCutDuration(int seconds); + void setHardCutDuration(double seconds); + bool getHardCutEnabled() const; + void setHardCutEnabled(bool enabled); + float getHardCutSensitivity() const; + void setHardCutSensitivity(float sensitivity); + void setPresetDuration(int seconds); + void setPresetDuration(double seconds); + bool getAspectCorrection() const; + void setAspectCorrection(bool enabled); + float getEasterEgg() const; + void setEasterEgg(float value); + void getMeshSize(size_t& w, size_t& h) const; + void setMeshSize(size_t w, size_t h); void touch(float x, float y, int pressure, int touchtype); void touchDrag(float x, float y, int pressure); void touchDestroy(float x, float y); @@ -239,6 +238,8 @@ public: /// Plays a preset immediately when given preset name void selectPresetByName(std::string name, bool hardCut = true); + // search based on keystroke + std::string getSearchText() const; // search based on keystroke void setSearchText(const std::string & searchKey); // delete part of search term (backspace) @@ -395,7 +396,7 @@ private: std::unique_ptr switchToCurrentPreset(); bool startPresetTransition(bool hard_cut); - + void recreateRenderer(); }; #endif diff --git a/src/projectM-qt/qplaylistmodel.cpp b/src/projectM-qt/qplaylistmodel.cpp index d011086ea..a6aedaff8 100644 --- a/src/projectM-qt/qplaylistmodel.cpp +++ b/src/projectM-qt/qplaylistmodel.cpp @@ -109,13 +109,13 @@ bool QPlaylistModel::setData ( const QModelIndex & index, const QVariant & value { if ( role == QPlaylistModel::RatingRole ) { - projectm_change_preset_rating(m_projectM, index.row(), value.toInt(), PROJECTM_HARD_CUT_RATING_TYPE); + projectm_set_preset_rating(m_projectM, index.row(), value.toInt(), PROJECTM_HARD_CUT_RATING_TYPE); return true; } else if (role == QPlaylistModel::BreedabilityRole) { - projectm_change_preset_rating(m_projectM, index.row(), value.toInt(), PROJECTM_SOFT_CUT_RATING_TYPE); + projectm_set_preset_rating(m_projectM, index.row(), value.toInt(), PROJECTM_SOFT_CUT_RATING_TYPE); return true; } else if (role == QPlaylistModel::NameRole) { - projectm_change_preset_name(m_projectM, index.row(), value.toString().toLocal8Bit().data()); + projectm_set_preset_name(m_projectM, index.row(), value.toString().toLocal8Bit().data()); return true; } else @@ -294,7 +294,7 @@ QVariant QPlaylistModel::data ( const QModelIndex & index, int role = Qt::Displa return QVariant ( projectm_get_preset_rating(m_projectM, rowidx, PROJECTM_SOFT_CUT_RATING_TYPE) ); case Qt::BackgroundRole: - if (!projectm_selected_preset_index(m_projectM, &pos)) + if (!projectm_get_selected_preset_index(m_projectM, &pos)) return QVariant(); if (projectm_is_preset_locked(m_projectM) && rowidx >= 0 && static_cast(rowidx) == pos ) return QColor(Qt::red); @@ -303,7 +303,7 @@ QVariant QPlaylistModel::data ( const QModelIndex & index, int role = Qt::Displa return QVariant(); case QPlaylistModel::URLInfoRole: { - auto presetUrl = projectm_get_preset_url(m_projectM, rowidx); + auto presetUrl = projectm_get_preset_filename(m_projectM, rowidx); QString qPresetUrl(presetUrl); projectm_free_string(presetUrl); return qPresetUrl; diff --git a/src/projectM-qt/qprojectm_mainwindow.cpp b/src/projectM-qt/qprojectm_mainwindow.cpp index 3fb818fb2..7fe3af1b4 100644 --- a/src/projectM-qt/qprojectm_mainwindow.cpp +++ b/src/projectM-qt/qprojectm_mainwindow.cpp @@ -164,9 +164,9 @@ void QProjectM_MainWindow::readConfig(const QString& configFile ) { setMenuVisible(settings.value("MenuOnStartup", false).toBool()); - - int wvw = projectm_get_window_width(qprojectM()->instance()); - int wvh = projectm_get_window_height(qprojectM()->instance()); + size_t windowWidth; + size_t windowHeight; + projectm_get_window_size(qprojectM()->instance(), &windowWidth, &windowHeight); auto projectMSettings = projectm_get_settings(qprojectM()->instance()); @@ -174,7 +174,7 @@ void QProjectM_MainWindow::readConfig(const QString& configFile ) { projectm_free_settings(projectMSettings); - this->resize(wvw, wvh); + this->resize(static_cast(windowWidth), static_cast(windowHeight)); } QProjectM_MainWindow::~QProjectM_MainWindow() @@ -935,7 +935,7 @@ void QProjectM_MainWindow::copyPlaylist() historyHash.insert ( QString(), items ); uint index; - if (projectm_selected_preset_index(qprojectM()->instance(), &index)) + if (projectm_get_selected_preset_index(qprojectM()->instance(), &index)) *activePresetIndex = index; else activePresetIndex->nullify(); @@ -1223,7 +1223,7 @@ void QProjectM_MainWindow::updateFilteredPlaylist ( const QString & text ) const QString filter = text.toLower(); unsigned int presetIndexBackup ; - bool presetSelected = projectm_selected_preset_index(qprojectM()->instance(), &presetIndexBackup); + bool presetSelected = projectm_get_selected_preset_index(qprojectM()->instance(), &presetIndexBackup); Nullable activePresetId; if (!presetSelected && activePresetIndex->hasValue()) { diff --git a/src/projectM-qt/qprojectmconfigdialog.cpp b/src/projectM-qt/qprojectmconfigdialog.cpp index c756a2a30..e9fa97d52 100644 --- a/src/projectM-qt/qprojectmconfigdialog.cpp +++ b/src/projectM-qt/qprojectmconfigdialog.cpp @@ -141,7 +141,7 @@ void QProjectMConfigDialog::saveConfig() { settings->preset_url = projectm_alloc_string(_ui.startupPlaylistDirectoryLineEdit->text().length() + 1); strncpy(settings->preset_url, _ui.startupPlaylistDirectoryLineEdit->text().toLocal8Bit().data(), _ui.startupPlaylistDirectoryLineEdit->text().length()); settings->texture_size = _ui.textureSizeComboBox->itemData(_ui.textureSizeComboBox->currentIndex()).toInt(); - settings->smooth_preset_duration = _ui.smoothPresetDurationSpinBox->value(); + settings->soft_cut_duration = _ui.smoothPresetDurationSpinBox->value(); settings->preset_duration = _ui.presetDurationSpinBox->value(); settings->fps = _ui.maxFPSSpinBox->value(); settings->aspect_correction = _ui.useAspectCorrectionCheckBox->checkState() == Qt::Checked; @@ -195,7 +195,7 @@ void QProjectMConfigDialog::loadConfig() { _ui.textureSizeComboBox->insertItem(0, QString("%1").arg(settings->texture_size), settings->texture_size); _ui.textureSizeComboBox->setCurrentIndex(0); - _ui.smoothPresetDurationSpinBox->setValue(settings->smooth_preset_duration); + _ui.smoothPresetDurationSpinBox->setValue(settings->soft_cut_duration); _ui.presetDurationSpinBox->setValue(settings->preset_duration); _ui.easterEggParameterSpinBox->setValue(settings->easter_egg); _ui.softCutRatingsEnabledCheckBox->setCheckState(settings->soft_cut_ratings_enabled ? Qt::Checked : Qt::Unchecked); diff --git a/src/projectM-qt/qprojectmwidget.hpp b/src/projectM-qt/qprojectmwidget.hpp index 802fa0c76..8ad5a748b 100644 --- a/src/projectM-qt/qprojectmwidget.hpp +++ b/src/projectM-qt/qprojectmwidget.hpp @@ -65,7 +65,7 @@ class QProjectMWidget : public QOpenGLWidget { // Setup viewport, projection etc setup_opengl ( w,h ); - projectm_reset_gl(m_projectM->instance(), w, h); + projectm_set_window_size(m_projectM->instance(), static_cast(w), static_cast(h)); } inline const QString& configFile() diff --git a/src/projectM-sdl/pmSDL.cpp b/src/projectM-sdl/pmSDL.cpp index 03d8445d0..7295c5d18 100644 --- a/src/projectM-sdl/pmSDL.cpp +++ b/src/projectM-sdl/pmSDL.cpp @@ -37,8 +37,7 @@ projectMSDL::projectMSDL(SDL_GLContext glCtx, projectm_settings* settings, int f , _projectM(projectm_create_settings(settings, flags)) , _settings(settings) { - width = projectm_get_window_width(_projectM); - height = projectm_get_window_height(_projectM); + projectm_get_window_size(_projectM, &width, &height); projectm_set_preset_switched_event_callback(_projectM, &projectMSDL::presetSwitchedEvent, static_cast(this)); } @@ -47,8 +46,7 @@ projectMSDL::projectMSDL(SDL_GLContext glCtx, const std::string& config_file, in , _projectM(projectm_create(config_file.c_str(), flags)) , _settings(projectm_get_settings(_projectM)) { - width = projectm_get_window_width(_projectM); - height = projectm_get_window_height(_projectM); + projectm_get_window_size(_projectM, &width, &height); projectm_set_preset_switched_event_callback(_projectM, &projectMSDL::presetSwitchedEvent, static_cast(this)); } @@ -175,12 +173,12 @@ void projectMSDL::scrollHandler(SDL_Event* sdl_evt) // handle mouse scroll wheel - up++ if (sdl_evt->wheel.y > 0) { - projectm_select_previous(_projectM, true); + projectm_select_previous_preset(_projectM, true); } // handle mouse scroll wheel - down-- if (sdl_evt->wheel.y < 0) { - projectm_select_next(_projectM, true); + projectm_select_next_preset(_projectM, true); } } @@ -357,7 +355,7 @@ void projectMSDL::resize(unsigned int width_, unsigned int height_) { width = width_; height = height_; - projectm_reset_gl(_projectM, width, height); + projectm_set_window_size(_projectM, width, height); } void projectMSDL::pollEvent() @@ -498,7 +496,7 @@ void projectMSDL::renderFrame() void projectMSDL::init(SDL_Window* window, const bool _renderToTexture) { win = window; - projectm_reset_gl(_projectM, width, height); + projectm_set_window_size(_projectM, width, height); #ifdef WASAPI_LOOPBACK wasapi = true; @@ -509,7 +507,7 @@ void projectMSDL::init(SDL_Window* window, const bool _renderToTexture) std::string projectMSDL::getActivePresetName() { unsigned int index = 0; - if (projectm_selected_preset_index(_projectM, &index)) + if (projectm_get_selected_preset_index(_projectM, &index)) { auto presetName = projectm_get_preset_name(_projectM, index); std::string presetNameString(presetName); diff --git a/src/projectM-sdl/pmSDL.hpp b/src/projectM-sdl/pmSDL.hpp index 0e05d5b90..c68cf29e8 100644 --- a/src/projectM-sdl/pmSDL.hpp +++ b/src/projectM-sdl/pmSDL.hpp @@ -152,8 +152,8 @@ private: SDL_Window *win{ nullptr }; bool isFullScreen{ false }; SDL_AudioDeviceID audioInputDevice{ 0 }; - unsigned int width{ 0 }; - unsigned int height{ 0 }; + size_t width{ 0 }; + size_t height{ 0 }; GLuint programID{ 0 }; GLuint m_vbo{ 0 }; GLuint m_vao{ 0 }; diff --git a/src/projectM-sdl/setup.cpp b/src/projectM-sdl/setup.cpp index f2ad4e971..779c9e75f 100644 --- a/src/projectM-sdl/setup.cpp +++ b/src/projectM-sdl/setup.cpp @@ -225,11 +225,11 @@ projectMSDL *setupSDLApp() { settings->mesh_x = 128; settings->mesh_y = settings->mesh_x * heightWidthRatio; settings->fps = maxRefreshRate; - settings->smooth_preset_duration = 3; // seconds + settings->soft_cut_duration = 3; // seconds settings->preset_duration = 22; // seconds - settings->hardcut_enabled = true; - settings->hardcut_duration = 60; - settings->hardcut_sensitivity = 1.0; + settings->hard_cut_enabled = true; + settings->hard_cut_duration = 60; + settings->hard_cut_sensitivity = 1.0; settings->beat_sensitivity = 1.0; settings->aspect_correction = 1; settings->shuffle_enabled = 1;