83 changes: 55 additions & 28 deletions src/develop/develop.c
Original file line number Diff line number Diff line change
Expand Up @@ -808,12 +808,14 @@ int dt_dev_write_history_item(const int imgid, dt_dev_history_item_t *h, int32_t
// *(float *)h->params, *(((float *)h->params)+1));
sqlite3_finalize(stmt);
// clang-format off
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"UPDATE main.history"
" SET operation = ?1, op_params = ?2, module = ?3, enabled = ?4, "
" blendop_params = ?7, blendop_version = ?8, multi_priority = ?9, multi_name = ?10"
" WHERE imgid = ?5 AND num = ?6",
-1, &stmt, NULL);
DT_DEBUG_SQLITE3_PREPARE_V2
(dt_database_get(darktable.db),
"UPDATE main.history"
" SET operation = ?1, op_params = ?2, module = ?3, enabled = ?4, "
" blendop_params = ?7, blendop_version = ?8, multi_priority = ?9,"
" multi_name = ?10, multi_name_hand_edited = ?11"
" WHERE imgid = ?5 AND num = ?6",
-1, &stmt, NULL);
// clang-format on
DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 1, h->module->op, -1, SQLITE_TRANSIENT);
DT_DEBUG_SQLITE3_BIND_BLOB(stmt, 2, h->params, h->module->params_size, SQLITE_TRANSIENT);
Expand All @@ -825,6 +827,7 @@ int dt_dev_write_history_item(const int imgid, dt_dev_history_item_t *h, int32_t
DT_DEBUG_SQLITE3_BIND_INT(stmt, 8, dt_develop_blend_version());
DT_DEBUG_SQLITE3_BIND_INT(stmt, 9, h->multi_priority);
DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 10, h->multi_name, -1, SQLITE_TRANSIENT);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 11, h->multi_name_hand_edited);

sqlite3_step(stmt);
sqlite3_finalize(stmt);
Expand Down Expand Up @@ -929,6 +932,7 @@ static void _dev_add_history_item_ext(dt_develop_t *dev, dt_iop_module_t *module
hist->params = malloc(module->params_size);
hist->iop_order = module->iop_order;
hist->multi_priority = module->multi_priority;
hist->multi_name_hand_edited = module->multi_name_hand_edited;
g_strlcpy(hist->multi_name, module->multi_name, sizeof(hist->multi_name));
/* allocate and set hist blend_params */
hist->blend_params = malloc(sizeof(dt_develop_blend_params_t));
Expand Down Expand Up @@ -959,6 +963,7 @@ static void _dev_add_history_item_ext(dt_develop_t *dev, dt_iop_module_t *module

hist->iop_order = module->iop_order;
hist->multi_priority = module->multi_priority;
hist->multi_name_hand_edited = module->multi_name_hand_edited;
memcpy(hist->multi_name, module->multi_name, sizeof(module->multi_name));
hist->enabled = module->enabled;

Expand Down Expand Up @@ -1220,6 +1225,7 @@ void dt_dev_pop_history_items_ext(dt_develop_t *dev, int32_t cnt)
hist->module->enabled = hist->enabled;
g_strlcpy(hist->module->multi_name, hist->multi_name, sizeof(hist->module->multi_name));
if(hist->forms) forms = hist->forms;
hist->module->multi_name_hand_edited = hist->multi_name_hand_edited;

history = g_list_next(history);
}
Expand Down Expand Up @@ -1398,7 +1404,7 @@ void _dev_insert_module(dt_develop_t *dev, dt_iop_module_t *module, const int im

DT_DEBUG_SQLITE3_PREPARE_V2(
dt_database_get(darktable.db),
"INSERT INTO memory.history VALUES (?1, 0, ?2, ?3, ?4, 1, NULL, 0, 0, '')",
"INSERT INTO memory.history VALUES (?1, 0, ?2, ?3, ?4, 1, NULL, 0, 0, '', 0)",
-1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, imgid);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 2, module->version());
Expand All @@ -1425,8 +1431,8 @@ static gboolean _dev_auto_apply_presets(dt_develop_t *dev)
const gboolean is_raw = dt_image_is_raw(image);
const gboolean is_modern_chroma = dt_is_scene_referred();

// flag was already set? only apply presets once in the lifetime of a history stack.
// (the flag will be cleared when removing it).
// flag was already set? only apply presets once in the lifetime of
// a history stack. (the flag will be cleared when removing it).
if(!run || image->id <= 0)
{
// Next section is to recover old edits where all modules with
Expand Down Expand Up @@ -1464,14 +1470,15 @@ static gboolean _dev_auto_apply_presets(dt_develop_t *dev)
// raw file we need to add one now with the default legacy
// parameters. And we want to do this only for old edits.
//
// For new edits the temperature will be added back depending on the chromatic
// adaptation the standard way.
// For new edits the temperature will be added back
// depending on the chromatic adaptation the standard way.

if(!strcmp(module->op, "temperature")
&& (image->change_timestamp == -1))
{
// it is important to recover temperature in this case (modern chroma and
// not module present as we need to have the pre 3.0 default parameters used.
// it is important to recover temperature in this case
// (modern chroma and not module present as we need to
// have the pre 3.0 default parameters used.

dt_conf_set_string("plugins/darkroom/workflow", "display-referred (legacy)");
dt_iop_reload_defaults(module);
Expand Down Expand Up @@ -1526,16 +1533,20 @@ static gboolean _dev_auto_apply_presets(dt_develop_t *dev)
}
}

// select all presets from one of the following table and add them into memory.history. Note that
// this is appended to possibly already present default modules.
// select all presets from one of the following table and add them
// into memory.history. Note that this is appended to possibly
// already present default modules.
const char *preset_table[2] = { "data.presets", "main.legacy_presets" };
const int legacy = (image->flags & DT_IMAGE_NO_LEGACY_PRESETS) ? 0 : 1;
char query[1024];
// clang-format off

snprintf(query, sizeof(query),
"INSERT INTO memory.history"
"INSERT OR REPLACE INTO memory.history"
" SELECT ?1, 0, op_version, operation, op_params,"
" enabled, blendop_params, blendop_version, multi_priority, multi_name"
" enabled, blendop_params, blendop_version,"
" ROW_NUMBER() OVER (PARTITION BY operation ORDER BY operation) - 1,"
" COALESCE(NULLIF(multi_name,''), NULLIF(name,'')), 0"
" FROM %s"
" WHERE ( (autoapply=1"
" AND ((?2 LIKE model AND ?3 LIKE maker) OR (?4 LIKE model AND ?5 LIKE maker))"
Expand Down Expand Up @@ -1619,27 +1630,35 @@ static gboolean _dev_auto_apply_presets(dt_develop_t *dev)
// 0: dontcare, 1: ldr, 2: raw plus monochrome & color
DT_DEBUG_SQLITE3_BIND_INT(stmt, 11, iformat);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 12, excluded);

GList *iop_list = NULL;

if(sqlite3_step(stmt) == SQLITE_ROW)
{
const char *params = (char *)sqlite3_column_blob(stmt, 0);
const int32_t params_len = sqlite3_column_bytes(stmt, 0);
GList *iop_list = dt_ioppr_deserialize_iop_order_list(params, params_len);
dt_ioppr_write_iop_order_list(iop_list, imgid);
g_list_free_full(iop_list, free);
dt_ioppr_set_default_iop_order(dev, imgid);
iop_list = dt_ioppr_deserialize_iop_order_list(params, params_len);
}
else
{
// we have no auto-apply order, so apply iop order, depending of the workflow
GList *iop_list;
if(is_scene_referred || is_workflow_none)
iop_list = dt_ioppr_get_iop_order_list_version(DT_IOP_ORDER_V30);
else
iop_list = dt_ioppr_get_iop_order_list_version(DT_IOP_ORDER_LEGACY);
dt_ioppr_write_iop_order_list(iop_list, imgid);
g_list_free_full(iop_list, free);
dt_ioppr_set_default_iop_order(dev, imgid);
}

// add multi-instance entries that could have been added if more
// than one auto-applied preset was found for a single iop.

GList *mi_list = dt_ioppr_get_multiple_instances_iop_order_list(imgid, TRUE);
GList *final_list = dt_ioppr_merge_multi_instance_iop_order_list(iop_list, mi_list);

dt_ioppr_write_iop_order_list(final_list, imgid);
g_list_free_full(mi_list, free);
g_list_free_full(final_list, free);
dt_ioppr_set_default_iop_order(dev, imgid);

sqlite3_finalize(stmt);
}

Expand Down Expand Up @@ -1774,7 +1793,7 @@ static void _dev_merge_history(dt_develop_t *dev, const int imgid)
"INSERT INTO main.history"
" SELECT imgid, num, module, operation, op_params, enabled, "
" blendop_params, blendop_version, multi_priority,"
" multi_name"
" multi_name, multi_name_hand_edited"
" FROM memory.history",
-1, &stmt, NULL);
// clang-format on
Expand Down Expand Up @@ -1891,7 +1910,8 @@ void dt_dev_read_history_ext(dt_develop_t *dev,
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"SELECT imgid, num, module, operation,"
" op_params, enabled, blendop_params,"
" blendop_version, multi_priority, multi_name"
" blendop_version, multi_priority, multi_name,"
" multi_name_hand_edited"
" FROM main.history"
" WHERE imgid = ?1"
" ORDER BY num",
Expand All @@ -1904,7 +1924,8 @@ void dt_dev_read_history_ext(dt_develop_t *dev,
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"SELECT id, num, module, operation,"
" op_params, enabled, blendop_params,"
" blendop_version, multi_priority, multi_name"
" blendop_version, multi_priority, multi_name,"
" multi_name_hand_edited"
" FROM memory.history_snapshot"
" WHERE id = ?1"
" ORDER BY num",
Expand All @@ -1929,6 +1950,7 @@ void dt_dev_read_history_ext(dt_develop_t *dev,
const int blendop_version = sqlite3_column_int(stmt, 7);
const int multi_priority = sqlite3_column_int(stmt, 8);
const char *multi_name = (const char *)sqlite3_column_text(stmt, 9);
const int multi_name_hand_edited = sqlite3_column_int(stmt, 10);

const int param_length = sqlite3_column_bytes(stmt, 4);
const int bl_length = sqlite3_column_bytes(stmt, 6);
Expand Down Expand Up @@ -1963,6 +1985,7 @@ void dt_dev_read_history_ext(dt_develop_t *dev,
g_strlcpy(module->multi_name, multi_name, sizeof(module->multi_name));
else
memset(module->multi_name, 0, sizeof(module->multi_name));
module->multi_name_hand_edited = multi_name_hand_edited;
break;
}
else if(multi_priority > 0)
Expand All @@ -1982,6 +2005,7 @@ void dt_dev_read_history_ext(dt_develop_t *dev,
new_module->iop_order = iop_order;

g_strlcpy(new_module->multi_name, multi_name, sizeof(new_module->multi_name));
new_module->multi_name_hand_edited = multi_name_hand_edited;

dev->iop = g_list_append(dev->iop, new_module);

Expand Down Expand Up @@ -2026,6 +2050,7 @@ void dt_dev_read_history_ext(dt_develop_t *dev,
hist->num = num;
hist->iop_order = iop_order;
hist->multi_priority = multi_priority;
hist->multi_name_hand_edited = multi_name_hand_edited;
g_strlcpy(hist->op_name, hist->module->op, sizeof(hist->op_name));
g_strlcpy(hist->multi_name, multi_name, sizeof(hist->multi_name));
hist->params = malloc(hist->module->params_size);
Expand Down Expand Up @@ -2545,6 +2570,8 @@ dt_iop_module_t *dt_dev_module_duplicate(dt_develop_t *dev, dt_iop_module_t *bas

// the multi instance name
g_strlcpy(module->multi_name, mname, sizeof(module->multi_name));
module->multi_name_hand_edited = 0;

// we insert this module into dev->iop
base->dev->iop = g_list_insert_sorted(base->dev->iop, module, dt_sort_iop_by_order);

Expand Down
1 change: 1 addition & 0 deletions src/develop/develop.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ typedef struct dt_dev_history_item_t
int iop_order;
int multi_priority;
char multi_name[128];
gboolean multi_name_hand_edited;
GList *forms; // snapshot of dt_develop_t->forms
int num; // num of history on database
int32_t focus_hash; // used to determine whether or not to start a new item or to merge down
Expand Down
131 changes: 100 additions & 31 deletions src/develop/imageop.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "common/iop_group.h"
#include "common/module.h"
#include "common/opencl.h"
#include "common/presets.h"
#include "common/usermanual_url.h"
#include "control/control.h"
#include "develop/blend.h"
Expand Down Expand Up @@ -355,6 +356,7 @@ int dt_iop_load_module_by_so(dt_iop_module_t *module, dt_iop_module_so_t *so, dt
module->histogram_stats.bins_count = 0;
module->histogram_stats.pixels = 0;
module->multi_priority = 0;
module->multi_name_hand_edited = 0;
module->iop_order = 0;
module->cache_next_important = FALSE;
for(int k = 0; k < 3; k++)
Expand Down Expand Up @@ -812,31 +814,44 @@ static gboolean _rename_module_key_press(GtkWidget *entry, GdkEventKey *event, d
{
int ended = 0;

if(event->type == GDK_FOCUS_CHANGE || event->keyval == GDK_KEY_Return || event->keyval == GDK_KEY_KP_Enter)
if(event->type == GDK_FOCUS_CHANGE
|| event->keyval == GDK_KEY_Return
|| event->keyval == GDK_KEY_KP_Enter)
{
if(gtk_entry_get_text_length(GTK_ENTRY(entry)) > 0)
{
// name is not empty, set new multi_name

const gchar *name = gtk_entry_get_text(GTK_ENTRY(entry));

// restore saved 1st character of instance name (without it the same name wouls still produce unnecessary copy + add history item)
// restore saved 1st character of instance name (without it the
// same name wouls still produce unnecessary copy + add history
// item)
module->multi_name[0] = module->multi_name[sizeof(module->multi_name) - 1];
module->multi_name[sizeof(module->multi_name) - 1] = 0;

if(g_strcmp0(module->multi_name, name) != 0)
{
g_strlcpy(module->multi_name, name, sizeof(module->multi_name));
// this has been hand edited, the name should not be changed when
// applying a preset or a style.
module->multi_name_hand_edited = TRUE;
dt_dev_add_history_item(module->dev, module, TRUE);
}
}
else
{
// clear out multi-name (set 1st char to 0)
module->multi_name[0] = 0;
module->multi_name_hand_edited = FALSE;
dt_dev_add_history_item(module->dev, module, TRUE);
}

// make sure we write history & xmp to ensure that the new module name
// gets recorded into the XMP and won't be lost in case of crash.
dt_dev_write_history(darktable.develop);
dt_image_synch_xmp(darktable.develop->image_storage.id);

ended = 1;
}
else if(event->keyval == GDK_KEY_Escape)
Expand Down Expand Up @@ -1196,7 +1211,9 @@ static void _init_presets(dt_iop_module_so_t *module_so)
sqlite3_stmt *stmt;
DT_DEBUG_SQLITE3_PREPARE_V2(
dt_database_get(darktable.db),
"SELECT name, op_version, op_params, blendop_version, blendop_params FROM data.presets WHERE operation = ?1",
"SELECT name, op_version, op_params, blendop_version, blendop_params"
" FROM data.presets"
" WHERE operation = ?1",
-1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 1, module_so->op, -1, SQLITE_TRANSIENT);

Expand All @@ -1217,9 +1234,12 @@ static void _init_presets(dt_iop_module_so_t *module_so)
// the module version from that.

sqlite3_stmt *stmt2;
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"SELECT module FROM main.history WHERE operation = ?1 AND op_params = ?2", -1,
&stmt2, NULL);
DT_DEBUG_SQLITE3_PREPARE_V2
(dt_database_get(darktable.db),
"SELECT module"
" FROM main.history"
" WHERE operation = ?1 AND op_params = ?2", -1,
&stmt2, NULL);
DT_DEBUG_SQLITE3_BIND_TEXT(stmt2, 1, module_so->op, -1, SQLITE_TRANSIENT);
DT_DEBUG_SQLITE3_BIND_BLOB(stmt2, 2, old_params, old_params_size, SQLITE_TRANSIENT);

Expand All @@ -1244,8 +1264,11 @@ static void _init_presets(dt_iop_module_so_t *module_so)
fprintf(stderr, "[imageop_init_presets] Found version %d for '%s' preset '%s'\n", old_params_version,
module_so->op, name);

DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"UPDATE data.presets SET op_version=?1 WHERE operation=?2 AND name=?3", -1,
DT_DEBUG_SQLITE3_PREPARE_V2
(dt_database_get(darktable.db),
"UPDATE data.presets"
" SET op_version=?1"
" WHERE operation=?2 AND name=?3", -1,
&stmt2, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt2, 1, old_params_version);
DT_DEBUG_SQLITE3_BIND_TEXT(stmt2, 2, module_so->op, -1, SQLITE_TRANSIENT);
Expand All @@ -1255,7 +1278,8 @@ static void _init_presets(dt_iop_module_so_t *module_so)
sqlite3_finalize(stmt2);
}

if(module_version > old_params_version && module_so->legacy_params != NULL)
if(module_version > old_params_version
&& module_so->legacy_params != NULL)
{
// we need a dt_iop_module_t for legacy_params()
dt_iop_module_t *module;
Expand All @@ -1265,17 +1289,6 @@ static void _init_presets(dt_iop_module_so_t *module_so)
free(module);
continue;
}
/*
module->init(module);
if(module->params_size == 0)
{
dt_iop_cleanup_module(module);
free(module);
continue;
}
// we call reload_defaults() in case the module defines it
if(module->reload_defaults) module->reload_defaults(module); // why not call dt_iop_reload_defaults? (if needed at all)
*/

const int32_t new_params_size = module->params_size;
void *new_params = calloc(1, new_params_size);
Expand All @@ -1296,9 +1309,10 @@ static void _init_presets(dt_iop_module_so_t *module_so)
// and write the new params back to the database
sqlite3_stmt *stmt2;
// clang-format off
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "UPDATE data.presets "
"SET op_version=?1, op_params=?2 "
"WHERE operation=?3 AND name=?4",
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"UPDATE data.presets"
" SET op_version=?1, op_params=?2"
" WHERE operation=?3 AND name=?4",
-1, &stmt2, NULL);
// clang-format on
DT_DEBUG_SQLITE3_BIND_INT(stmt2, 1, module->version());
Expand Down Expand Up @@ -1360,9 +1374,10 @@ static void _init_presets(dt_iop_module_so_t *module_so)
// and write the new blend params back to the database
sqlite3_stmt *stmt2;
// clang-format off
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "UPDATE data.presets "
"SET blendop_version=?1, blendop_params=?2 "
"WHERE operation=?3 AND name=?4",
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"UPDATE data.presets"
" SET blendop_version=?1, blendop_params=?2"
" WHERE operation=?3 AND name=?4",
-1, &stmt2, NULL);
// clang-format on
DT_DEBUG_SQLITE3_BIND_INT(stmt2, 1, dt_develop_blend_version());
Expand All @@ -1387,7 +1402,10 @@ static void _init_presets_actions(dt_iop_module_so_t *module)
/** load shortcuts for presets **/
sqlite3_stmt *stmt;
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"SELECT name FROM data.presets WHERE operation=?1 ORDER BY writeprotect DESC, rowid",
"SELECT name"
" FROM data.presets"
" WHERE operation=?1"
" ORDER BY writeprotect DESC, rowid",
-1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 1, module->op, -1, SQLITE_TRANSIENT);
while(sqlite3_step(stmt) == SQLITE_ROW)
Expand Down Expand Up @@ -1415,7 +1433,8 @@ static void _init_module_so(void *m)
// create a gui and have the widgets register their accelerators
dt_iop_module_t *module_instance = (dt_iop_module_t *)calloc(1, sizeof(dt_iop_module_t));

if(module->gui_init && !dt_iop_load_module_by_so(module_instance, module, NULL))
if(module->gui_init
&& !dt_iop_load_module_by_so(module_instance, module, NULL))
{
darktable.control->accel_initialising = TRUE;
dt_iop_gui_init(module_instance);
Expand Down Expand Up @@ -1505,6 +1524,10 @@ GList *dt_iop_load_modules(dt_develop_t *dev)

void dt_iop_cleanup_module(dt_iop_module_t *module)
{
if(module->label_recompute_handle)
g_source_remove(module->label_recompute_handle);
module->label_recompute_handle = 0;

module->cleanup(module);

free(module->blend_params);
Expand Down Expand Up @@ -1698,10 +1721,41 @@ gboolean _iop_validate_params(dt_introspection_field_t *field, gpointer params,
return all_ok;
}

static gboolean _iop_update_label(gpointer data)
{
dt_iop_module_t *module = (dt_iop_module_t *)data;

char *preset_name =
dt_presets_get_name(module->op,
module->params, module->params_size,
module->blend_params, sizeof(dt_develop_blend_params_t));

// if we have a preset-name, use it. otherwise set the label to the multi-priority
// except for 0 where the multi-name is cleared.

if(preset_name)
snprintf(module->multi_name, sizeof(module->multi_name), "%s", preset_name);
else if(module->multi_priority != 0)
snprintf(module->multi_name, sizeof(module->multi_name), "%d", module->multi_priority);
else
g_strlcpy(module->multi_name, "", sizeof(module->multi_name));

g_free(preset_name);

dt_iop_gui_update_header(module);

module->label_recompute_handle = 0;
return G_SOURCE_REMOVE;
}

void dt_iop_commit_params(dt_iop_module_t *module, dt_iop_params_t *params,
TurboGit marked this conversation as resolved.
Show resolved Hide resolved
dt_develop_blend_params_t *blendop_params, dt_dev_pixelpipe_t *pipe,
dt_dev_pixelpipe_iop_t *piece)
{
const gboolean module_is_enabled = module->enabled;
const gboolean module_params_changed
= memcmp(module->params, params, module->params_size) == 0;

// 1. commit params

memcpy(piece->blendop_data, blendop_params, sizeof(dt_develop_blend_params_t));
Expand All @@ -1723,6 +1777,19 @@ void dt_iop_commit_params(dt_iop_module_t *module, dt_iop_params_t *params,

module->commit_params(module, params, pipe, piece);

// adjust the label to match presets if possible or otherwise the default
// multi_name for this module.

if(!dt_iop_is_hidden(module)
&& module_is_enabled
&& module_params_changed
&& !module->multi_name_hand_edited)
{
if(module->label_recompute_handle)
g_source_remove(module->label_recompute_handle);
module->label_recompute_handle = g_timeout_add(500, _iop_update_label, module);
TurboGit marked this conversation as resolved.
Show resolved Hide resolved
}

// 2. compute the hash only if piece is enabled

piece->hash = 0;
Expand Down Expand Up @@ -1813,9 +1880,11 @@ static void _gui_reset_callback(GtkButton *button, GdkEventButton *event, dt_iop
const gboolean disabled = !module->default_enabled && module->hide_enable_button;
if(disabled) return;

//Ctrl is used to apply any auto-presets to the current module
//If Ctrl was not pressed, or no auto-presets were applied, reset the module parameters
if(!(event && dt_modifier_is(event->state, GDK_CONTROL_MASK)) || !dt_gui_presets_autoapply_for_module(module))
// Ctrl is used to apply any auto-presets to the current module
// If Ctrl was not pressed, or no auto-presets were applied, reset the module parameters
if(!(event
&& dt_modifier_is(event->state, GDK_CONTROL_MASK))
|| !dt_gui_presets_autoapply_for_module(module))
{
// if a drawn mask is set, remove it from the list
if(module->blend_params->mask_id > 0)
Expand Down
5 changes: 3 additions & 2 deletions src/develop/imageop.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ typedef enum dt_iop_flags_t
IOP_FLAGS_GUIDES_SPECIAL_DRAW = 1 << 14, // handle the grid drawing directly
IOP_FLAGS_GUIDES_WIDGET = 1 << 15, // require the guides widget
IOP_FLAGS_CACHE_IMPORTANT_NOW = 1 << 16, // hints for higher priority in iop cache
IOP_FLAGS_CACHE_IMPORTANT_NEXT = 1 << 17
IOP_FLAGS_CACHE_IMPORTANT_NEXT = 1 << 17
} dt_iop_flags_t;

/** status of a module*/
Expand Down Expand Up @@ -288,6 +288,7 @@ typedef struct dt_iop_module_t
/** multi-instances things */
int multi_priority; // user may change this
char multi_name[128]; // user may change this name
gboolean multi_name_hand_edited;
gboolean multi_show_close;
gboolean multi_show_up;
gboolean multi_show_down;
Expand All @@ -296,6 +297,7 @@ typedef struct dt_iop_module_t

/** delayed-event handling */
guint timeout_handle;
guint label_recompute_handle;

void (*process_plain)(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece,
const void *const i, void *const o, const struct dt_iop_roi_t *const roi_in,
Expand Down Expand Up @@ -517,4 +519,3 @@ void dt_iop_gui_changed(dt_action_t *action, GtkWidget *widget, gpointer data);
// vim: shiftwidth=2 expandtab tabstop=2 cindent
// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
// clang-format on

11 changes: 8 additions & 3 deletions src/gui/presets.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ static void _edit_preset_response(GtkDialog *dialog, gint response_id, dt_gui_pr

// we verify eventual name collisions
const gchar *name = gtk_entry_get_text(g->name);
if(((g->old_id >= 0) && (strcmp(g->original_name, name) != 0)) || (g->old_id < 0))
if(((g->old_id >= 0)
&& (strcmp(g->original_name, name) != 0))
|| (g->old_id < 0))
{
if(name == NULL || *name == '\0' || strcmp(_("new preset"), name) == 0)
{
Expand All @@ -221,8 +223,8 @@ static void _edit_preset_response(GtkDialog *dialog, gint response_id, dt_gui_pr
return;
}

// editing existing preset with different name or store new preset -> check for a preset with the same
// name:
// editing existing preset with different name or store new
// preset -> check for a preset with the same name:
// clang-format off
DT_DEBUG_SQLITE3_PREPARE_V2(
dt_database_get(darktable.db),
Expand Down Expand Up @@ -858,6 +860,9 @@ void dt_gui_presets_apply_preset(const gchar* name, dt_iop_module_t *module)
{
memcpy(module->params, op_params, op_length);
module->enabled = enabled;
// if module name has not been hand edited, use preset name as module label
if(!module->multi_name_hand_edited)
g_strlcpy(module->multi_name, name, sizeof(module->multi_name));
}
if(blendop_params && (blendop_version == dt_develop_blend_version())
&& (bl_length == sizeof(dt_develop_blend_params_t)))
Expand Down
3 changes: 2 additions & 1 deletion src/libs/snapshots.c
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,8 @@ static void _lib_snapshots_add_button_clicked_callback(GtkWidget *widget, gpoint
(dt_database_get(darktable.db),
"INSERT INTO memory.history_snapshot"
" SELECT ?1, num, module, operation, op_params,"
" enabled, blendop_params, blendop_version, multi_priority, multi_name"
" enabled, blendop_params, blendop_version, multi_priority,"
" multi_name, multi_name_hand_edited"
" FROM main.history"
" WHERE imgid = ?2 AND num < ?3",
-1, &stmt, NULL);
Expand Down
27 changes: 20 additions & 7 deletions src/views/darkroom.c
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,14 @@ static void _dev_change_image(dt_develop_t *dev, const int32_t imgid)
// stop crazy users from sleeping on key-repeat spacebar:
if(dev->image_loading) return;

// deactivate module label timer if set
if(darktable.develop->gui_module
&& darktable.develop->gui_module->label_recompute_handle)
{
g_source_remove(darktable.develop->gui_module->label_recompute_handle);
darktable.develop->gui_module->label_recompute_handle = 0;
}

// Pipe reset needed when changing image
// FIXME: synch with dev_init() and dev_cleanup() instead of redoing it
dev->proxy.chroma_adaptation = NULL;
Expand All @@ -812,15 +820,18 @@ static void _dev_change_image(dt_develop_t *dev, const int32_t imgid)
{
sqlite3_stmt *stmt;
// clang-format off
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"SELECT m.imgid FROM memory.collected_images as m, main.selected_images as s "
"WHERE m.imgid=s.imgid",
-1, &stmt, NULL);
DT_DEBUG_SQLITE3_PREPARE_V2
(dt_database_get(darktable.db),
"SELECT m.imgid"
" FROM memory.collected_images as m, main.selected_images as s"
" WHERE m.imgid=s.imgid",
-1, &stmt, NULL);
// clang-format on
gboolean follow = FALSE;
if(sqlite3_step(stmt) == SQLITE_ROW)
{
if(sqlite3_column_int(stmt, 0) == dev->image_storage.id && sqlite3_step(stmt) != SQLITE_ROW)
if(sqlite3_column_int(stmt, 0) == dev->image_storage.id
&& sqlite3_step(stmt) != SQLITE_ROW)
{
follow = TRUE;
}
Expand All @@ -837,9 +848,11 @@ static void _dev_change_image(dt_develop_t *dev, const int32_t imgid)
dt_iop_color_picker_reset(darktable.lib->proxy.colorpicker.picker_proxy->module, FALSE);

// update aspect ratio
if(dev->preview_pipe->backbuf && dev->preview_status == DT_DEV_PIXELPIPE_VALID)
if(dev->preview_pipe->backbuf
&& dev->preview_status == DT_DEV_PIXELPIPE_VALID)
{
const double aspect_ratio = (double)dev->preview_pipe->backbuf_width / (double)dev->preview_pipe->backbuf_height;
const double aspect_ratio =
(double)dev->preview_pipe->backbuf_width / (double)dev->preview_pipe->backbuf_height;
dt_image_set_aspect_ratio_to(dev->preview_pipe->image.id, aspect_ratio, TRUE);
}
else
Expand Down