Browse Source

implement default velocity selector

Allow using last edited velocity on newly created notes.

Implements https://todo.sr.ht/~alextee/zrythm-feature/459.
audio_region_bpm_change_fix
parent
commit
18026d961c
Signed by: alex
GPG Key ID: 022EAE42313D70F3
  1. 3
      data/css-themes/zrythm/theme.scss
  2. 10
      inc/audio/velocity.h
  3. 13
      inc/gui/widgets/editor_toolbar.h
  4. 4
      inc/gui/widgets/playhead_scroll_buttons.h
  5. 57
      inc/gui/widgets/velocity_settings.h
  6. 4
      inc/utils/gtk.h
  7. 10
      resources/ui/editor_toolbar.ui
  8. 3
      resources/ui/playhead_scroll_buttons.ui
  9. 17
      scripts/gen-schema.scm.in
  10. 49
      src/audio/velocity.c
  11. 6
      src/gui/widgets/editor_toolbar.c
  12. 1
      src/gui/widgets/meson.build
  13. 29
      src/gui/widgets/midi_arranger.c
  14. 15
      src/gui/widgets/midi_modifier_arranger.c
  15. 36
      src/gui/widgets/playhead_scroll_buttons.c
  16. 6
      src/gui/widgets/rotated_label.c
  17. 127
      src/gui/widgets/velocity_settings.c

3
data/css-themes/zrythm/theme.scss

@ -651,6 +651,7 @@ folder-channel button.toggle:hover { @@ -651,6 +651,7 @@ folder-channel button.toggle:hover {
}
viewswitcher stack,
event-viewer stack {
event-viewer stack,
dropdown stack {
background-color: transparent;
}

10
inc/audio/velocity.h

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2021 Alexandros Theodotou <alex at zrythm dot org>
* Copyright (C) 2019-2022 Alexandros Theodotou <alex at zrythm dot org>
*
* This file is part of Zrythm
*
@ -144,6 +144,14 @@ MidiNote * @@ -144,6 +144,14 @@ MidiNote *
velocity_get_midi_note (
const Velocity * const self);
const char *
velocity_setting_enum_to_str (
guint index);
guint
velocity_setting_str_to_enum (
const char * str);
/**
* @}
*/

13
inc/gui/widgets/editor_toolbar.h

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2021 Alexandros Theodotou <alex at zrythm dot org>
* Copyright (C) 2019-2022 Alexandros Theodotou <alex at zrythm dot org>
*
* This file is part of Zrythm
*
@ -29,10 +29,8 @@ @@ -29,10 +29,8 @@
#define EDITOR_TOOLBAR_WIDGET_TYPE \
(editor_toolbar_widget_get_type ())
G_DECLARE_FINAL_TYPE (
EditorToolbarWidget,
editor_toolbar_widget,
Z, EDITOR_TOOLBAR_WIDGET,
GtkBox)
EditorToolbarWidget, editor_toolbar_widget,
Z, EDITOR_TOOLBAR_WIDGET, GtkBox)
#define MW_EDITOR_TOOLBAR \
MW_CLIP_EDITOR->editor_toolbar
@ -45,6 +43,8 @@ typedef struct _ButtonWithMenuWidget @@ -45,6 +43,8 @@ typedef struct _ButtonWithMenuWidget
ButtonWithMenuWidget;
typedef struct _PlayheadScrollButtonsWidget
PlayheadScrollButtonsWidget;
typedef struct _VelocitySettingsWidget
VelocitySettingsWidget;
/**
* The PianoRoll toolbar in the top.
@ -67,6 +67,9 @@ typedef struct _EditorToolbarWidget @@ -67,6 +67,9 @@ typedef struct _EditorToolbarWidget
GtkSeparator * sep_after_chord_highlight;
GtkBox * chord_highlight_box;
VelocitySettingsWidget * velocity_settings;
GtkSeparator * sep_after_velocity_settings;
PlayheadScrollButtonsWidget * playhead_scroll;
GMenuModel * midi_functions_menu;

4
inc/gui/widgets/playhead_scroll_buttons.h

@ -38,14 +38,14 @@ G_DECLARE_FINAL_TYPE ( @@ -38,14 +38,14 @@ G_DECLARE_FINAL_TYPE (
PlayheadScrollButtonsWidget,
playhead_scroll_buttons_widget,
Z, PLAYHEAD_SCROLL_BUTTONS_WIDGET,
GtkBox)
GtkWidget)
#define MW_PLAYHEAD_SCROLL_BUTTONS \
MW_HOME_TOOLBAR->snap_box
typedef struct _PlayheadScrollButtonsWidget
{
GtkBox parent_instance;
GtkWidget parent_instance;
GtkToggleButton * scroll_edges;
GtkToggleButton * follow;
} PlayheadScrollButtonsWidget;

57
inc/gui/widgets/velocity_settings.h

@ -0,0 +1,57 @@ @@ -0,0 +1,57 @@
/*
* Copyright (C) 2022 Alexandros Theodotou <alex at zrythm dot org>
*
* This file is part of Zrythm
*
* Zrythm is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Zrythm is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Zrythm. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \file
*
* Velocity settings buttons.
*/
#ifndef __GUI_WIDGETS_VELOCITY_SETTINGS_H__
#define __GUI_WIDGETS_VELOCITY_SETTINGS_H__
#include <gtk/gtk.h>
/**
* @addtogroup widgets
*
* @{
*/
#define VELOCITY_SETTINGS_WIDGET_TYPE \
(velocity_settings_widget_get_type ())
G_DECLARE_FINAL_TYPE (
VelocitySettingsWidget, velocity_settings_widget,
Z, VELOCITY_SETTINGS_WIDGET, GtkWidget)
/**
* Velocity settings for toolbars.
*/
typedef struct _VelocitySettingsWidget
{
GtkWidget parent_instance;
GtkDropDown * default_velocity_dropdown;
} VelocitySettingsWidget;
/**
* @}
*/
#endif

4
inc/utils/gtk.h

@ -201,10 +201,6 @@ z_gtk_list_store_splice ( @@ -201,10 +201,6 @@ z_gtk_list_store_splice (
GListStore * store,
GPtrArray * ptr_array);
/**
* @note Bumps reference, must be decremented after
* calling.
*/
void
z_gtk_widget_remove_all_children (
GtkWidget * widget);

10
resources/ui/editor_toolbar.ui

@ -85,9 +85,17 @@ @@ -85,9 +85,17 @@
<property name="orientation">vertical</property>
</object>
</child>
<child>
<object class="VelocitySettingsWidget" id="velocity_settings">
</object>
</child>
<child>
<object class="GtkSeparator" id="sep_after_velocity_settings">
<property name="orientation">vertical</property>
</object>
</child>
<child>
<object class="PlayheadScrollButtonsWidget" id="playhead_scroll">
<property name="visible">True</property>
</object>
</child>
<child>

3
resources/ui/playhead_scroll_buttons.ui

@ -1,8 +1,7 @@ @@ -1,8 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk" version="4.0"/>
<template class="PlayheadScrollButtonsWidget" parent="GtkBox">
<property name="spacing">1</property>
<template class="PlayheadScrollButtonsWidget" parent="GtkWidget">
<child>
<object class="GtkToggleButton" id="scroll_edges">
<property name="focusable">1</property>

17
scripts/gen-schema.scm.in

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
;;;
;;; Copyright (C) 2020-2021 Alexandros Theodotou <alex at zrythm dot org>
;;; Copyright (C) 2020-2022 Alexandros Theodotou <alex at zrythm dot org>
;;; Copyright (C) 2020 Ryan Gonzalez <rymg19 at gmail dot com>
;;;
;;; This file is part of Zrythm.
@ -220,7 +220,7 @@ Args: @@ -220,7 +220,7 @@ Args:
"<?xml version=\"1.0\" encoding=\"utf-8\"?>
<!--
Copyright (C) 2018-2020 Alexandros Theodotou <alex at zrythm dot org>
Copyright (C) 2018-2022 Alexandros Theodotou <alex at zrythm dot org>
This file is part of Zrythm
@ -349,6 +349,9 @@ Args: @@ -349,6 +349,9 @@ Args:
"preroll-count"
'("none" "one-bar" "two-bars"
"four-bars"))
(print-enum
"default-velocity"
'("last-note" "40" "90" "120"))
(newline)
;; -- print normal schemas --
@ -492,6 +495,16 @@ Args: @@ -492,6 +495,16 @@ Args:
"note-notation" "notes"
"Note notation"
"The note notation used in the piano roll - MIDI pitch index or notes (C, C#, etc.)")
(make-schema-key-with-enum
"piano-roll-default-velocity"
"default-velocity" "last-note"
"Default velocity"
"The default velocity to use when creating new MIDI notes.")
(make-schema-key
"piano-roll-last-set-velocity"
"i" "90"
"Last set velocity"
"Last set velocity on a MIDI note.")
(make-schema-key
"musical-mode" "b" "false"
"Musical mode"

49
src/audio/velocity.c

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 Alexandros Theodotou <alex at zrythm dot org>
* Copyright (C) 2019-2022 Alexandros Theodotou <alex at zrythm dot org>
*
* This file is part of Zrythm
*
@ -24,6 +24,7 @@ @@ -24,6 +24,7 @@
#include "audio/velocity.h"
#include "gui/widgets/velocity.h"
#include "utils/objects.h"
#include "utils/string.h"
#include "utils/types.h"
#include <gtk/gtk.h>
@ -139,3 +140,49 @@ velocity_get_midi_note ( @@ -139,3 +140,49 @@ velocity_get_midi_note (
return region->midi_notes[self->note_pos];
#endif
}
const char *
velocity_setting_enum_to_str (
guint index)
{
switch (index)
{
case 0:
return "last-note";
case 1:
return "40";
case 2:
return "90";
case 3:
return "120";
default:
break;
}
g_return_val_if_reached (NULL);
}
guint
velocity_setting_str_to_enum (
const char * str)
{
guint val;
if (string_is_equal (str, "40"))
{
val = 1;
}
else if (string_is_equal (str, "90"))
{
val = 2;
}
else if (string_is_equal (str, "120"))
{
val = 3;
}
else
{
val = 0;
}
return val;
}

6
src/gui/widgets/editor_toolbar.c

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2021 Alexandros Theodotou <alex at zrythm dot org>
* Copyright (C) 2019-2022 Alexandros Theodotou <alex at zrythm dot org>
*
* This file is part of Zrythm
*
@ -31,6 +31,7 @@ @@ -31,6 +31,7 @@
#include "gui/widgets/quantize_box.h"
#include "gui/widgets/snap_box.h"
#include "gui/widgets/snap_grid.h"
#include "gui/widgets/velocity_settings.h"
#include "plugins/plugin_manager.h"
#include "project.h"
#include "settings/settings.h"
@ -413,6 +414,7 @@ editor_toolbar_widget_init ( @@ -413,6 +414,7 @@ editor_toolbar_widget_init (
g_type_ensure (
PLAYHEAD_SCROLL_BUTTONS_WIDGET_TYPE);
g_type_ensure (SNAP_BOX_WIDGET_TYPE);
g_type_ensure (VELOCITY_SETTINGS_WIDGET_TYPE);
gtk_widget_init_template (GTK_WIDGET (self));
@ -486,6 +488,8 @@ editor_toolbar_widget_class_init ( @@ -486,6 +488,8 @@ editor_toolbar_widget_class_init (
BIND_CHILD (audio_functions_btn);
BIND_CHILD (midi_functions_btn);
BIND_CHILD (automation_functions_btn);
BIND_CHILD (velocity_settings);
BIND_CHILD (sep_after_velocity_settings);
BIND_CHILD (playhead_scroll);
#undef BIND_CHILD

1
src/gui/widgets/meson.build

@ -166,6 +166,7 @@ widget_srcs = files([ @@ -166,6 +166,7 @@ widget_srcs = files([
'transport_controls.c',
'two_col_expander_box.c',
'velocity.c',
'velocity_settings.c',
'view_toolbar.c',
'visibility.c',
'volume.c',

29
src/gui/widgets/midi_arranger.c

@ -100,12 +100,37 @@ midi_arranger_widget_create_note ( @@ -100,12 +100,37 @@ midi_arranger_widget_create_note (
UI_OVERLAY_ACTION_CREATING_RESIZING_R;
}
int default_velocity_type =
g_settings_get_enum (
S_UI, "piano-roll-default-velocity");
midi_byte_t velocity = VELOCITY_DEFAULT;
switch (default_velocity_type)
{
case 0:
velocity =
(midi_byte_t)
g_settings_get_int (
S_UI, "piano-roll-last-set-velocity");
break;
case 1:
velocity = 40;
break;
case 2:
velocity = 90;
break;
case 3:
velocity = 120;
break;
default:
break;
}
/* create midi note */
MidiNote * midi_note =
midi_note_new (
&region->id, &local_pos, &local_pos,
(midi_byte_t) note,
VELOCITY_DEFAULT);
(midi_byte_t) note, velocity);
ArrangerObject * midi_note_obj =
(ArrangerObject *) midi_note;

15
src/gui/widgets/midi_modifier_arranger.c

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2021 Alexandros Theodotou <alex at zrythm dot org>
* Copyright (C) 2019-2022 Alexandros Theodotou <alex at zrythm dot org>
*
* This file is part of Zrythm
*
@ -36,6 +36,7 @@ @@ -36,6 +36,7 @@
#include "gui/widgets/timeline_ruler.h"
#include "gui/widgets/velocity.h"
#include "project.h"
#include "settings/settings.h"
#include "utils/arrays.h"
#include "utils/objects.h"
#include "utils/flags.h"
@ -325,6 +326,18 @@ midi_modifier_arranger_widget_resize_velocities ( @@ -325,6 +326,18 @@ midi_modifier_arranger_widget_resize_velocities (
}
#endif
}
if (self->start_object)
{
g_return_if_fail (
self->start_object->type ==
ARRANGER_OBJECT_TYPE_VELOCITY);
Velocity * vel =
(Velocity *) self->start_object;
g_settings_set_int (
S_UI, "piano-roll-last-set-velocity",
vel->vel);
}
}
/**

36
src/gui/widgets/playhead_scroll_buttons.c

@ -17,11 +17,6 @@ @@ -17,11 +17,6 @@
* along with Zrythm. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \file
*
*/
#include "gui/widgets/main_window.h"
#include "gui/widgets/playhead_scroll_buttons.h"
#include "project.h"
@ -30,7 +25,24 @@ @@ -30,7 +25,24 @@
G_DEFINE_TYPE (
PlayheadScrollButtonsWidget,
playhead_scroll_buttons_widget,
GTK_TYPE_BOX)
GTK_TYPE_WIDGET)
static void
on_dispose (
GObject * object)
{
PlayheadScrollButtonsWidget * self =
Z_PLAYHEAD_SCROLL_BUTTONS_WIDGET (object);
gtk_widget_unparent (
GTK_WIDGET (self->scroll_edges));
gtk_widget_unparent (
GTK_WIDGET (self->follow));
G_OBJECT_CLASS (
playhead_scroll_buttons_widget_parent_class)->
dispose (object);
}
static void
playhead_scroll_buttons_widget_class_init (
@ -51,6 +63,9 @@ playhead_scroll_buttons_widget_class_init ( @@ -51,6 +63,9 @@ playhead_scroll_buttons_widget_class_init (
BIND_CHILD (follow);
#undef BIND_CHILD
GObjectClass * oklass = G_OBJECT_CLASS (_klass);
oklass->dispose = on_dispose;
}
static void
@ -58,4 +73,13 @@ playhead_scroll_buttons_widget_init ( @@ -58,4 +73,13 @@ playhead_scroll_buttons_widget_init (
PlayheadScrollButtonsWidget * self)
{
gtk_widget_init_template (GTK_WIDGET (self));
GtkBoxLayout * box_layout =
GTK_BOX_LAYOUT (
gtk_box_layout_new (
GTK_ORIENTATION_HORIZONTAL));
gtk_box_layout_set_spacing (box_layout, 1);
gtk_widget_set_layout_manager (
GTK_WIDGET (self),
GTK_LAYOUT_MANAGER (box_layout));
}

6
src/gui/widgets/rotated_label.c

@ -146,10 +146,8 @@ static void @@ -146,10 +146,8 @@ static void
on_dispose (
GObject * object)
{
RotatedLabelWidget * self =
Z_ROTATED_LABEL_WIDGET (object);
gtk_widget_unparent (GTK_WIDGET (self->lbl));
z_gtk_widget_remove_all_children (
GTK_WIDGET (object));
G_OBJECT_CLASS (
rotated_label_widget_parent_class)->

127
src/gui/widgets/velocity_settings.c

@ -0,0 +1,127 @@ @@ -0,0 +1,127 @@
/*
* Copyright (C) 2022 Alexandros Theodotou <alex at zrythm dot org>
*
* This file is part of Zrythm
*
* Zrythm is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Zrythm is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Zrythm. If not, see <https://www.gnu.org/licenses/>.
*/
#include "gui/widgets/main_window.h"
#include "gui/widgets/velocity_settings.h"
#include "project.h"
#include "settings/settings.h"
#include "utils/gtk.h"
#include "utils/resources.h"
#include <glib/gi18n.h>
G_DEFINE_TYPE (
VelocitySettingsWidget, velocity_settings_widget,
GTK_TYPE_WIDGET)
static gboolean
get_mapping (
GValue * value,
GVariant * variant,
VelocitySettingsWidget * self)
{
const char * str =
g_variant_get_string (variant, NULL);
guint val =
velocity_setting_str_to_enum (str);
g_value_set_uint (value, val);
return true;
}
static GVariant *
set_mapping (
const GValue * value,
const GVariantType * expected_type,
VelocitySettingsWidget * self)
{
guint val = g_value_get_uint (value);
const char * str =
velocity_setting_enum_to_str (val);
return g_variant_new_string (str);
}
static void
on_dispose (
GObject * object)
{
z_gtk_widget_remove_all_children (
GTK_WIDGET (object));
G_OBJECT_CLASS (
velocity_settings_widget_parent_class)->
dispose (object);
}
static void
velocity_settings_widget_class_init (
VelocitySettingsWidgetClass * _klass)
{
GtkWidgetClass * klass =
GTK_WIDGET_CLASS (_klass);
gtk_widget_class_set_css_name (
klass, "velocity-settings");
GObjectClass * oklass = G_OBJECT_CLASS (_klass);
oklass->dispose = on_dispose;
}
static void
velocity_settings_widget_init (
VelocitySettingsWidget * self)
{
GtkBoxLayout * box_layout =
GTK_BOX_LAYOUT (
gtk_box_layout_new (GTK_ORIENTATION_HORIZONTAL));
gtk_box_layout_set_spacing (box_layout, 1);
gtk_widget_set_layout_manager (
GTK_WIDGET (self),
GTK_LAYOUT_MANAGER (box_layout));
GtkWidget * lbl =
gtk_label_new (_("Default Velocity"));
gtk_widget_set_parent (lbl, GTK_WIDGET (self));
const char * list[] = {
_("Last Note"), "40", "90", "120", NULL };
self->default_velocity_dropdown =
GTK_DROP_DOWN (
gtk_drop_down_new_from_strings (list));
gtk_widget_set_parent (
GTK_WIDGET (self->default_velocity_dropdown),
GTK_WIDGET (self));
#if 0
g_signal_connect (
G_OBJECT (self->default_velocity_dropdown),
"activate",
G_CALLBACK (on_default_velocity_activate), self);
#endif
g_settings_bind_with_mapping (
S_UI, "piano-roll-default-velocity",
G_OBJECT (self->default_velocity_dropdown),
"selected", G_SETTINGS_BIND_DEFAULT,
(GSettingsBindGetMapping) get_mapping,
(GSettingsBindSetMapping) set_mapping,
self, NULL);
}
Loading…
Cancel
Save