Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/avtk/clipselector.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@


#include "clipselector.hxx"
#include "hotkeydialog.hxx"

#include <unistd.h>

#pragma GCC diagnostic ignored "-Wmissing-field-initializers"

#include "../gui.hxx"
#include "../hotkeymanager.hxx"

extern Gui* gui;

Expand Down Expand Up @@ -276,6 +278,7 @@ int ClipSelector::handle(int event)
{0},
//{ "Record" },
{ "Use as tempo" },
{ "Assign Hotkey" },
{ "Rename", 0, 0, 0, FL_MENU_DIVIDER},
{ "Clear" },
{ 0 }
Expand All @@ -285,6 +288,19 @@ int ClipSelector::handle(int event)
return 0;
} else if ( strcmp(m->label(), "Load") == 0 ) {
gui->selectLoadSample( ID, clipNum );
} else if ( strcmp(m->label(), "Assign Hotkey") == 0 ) {
int currentKey = getCurrentKeyForClip(ID, clipNum);
HotkeyDialog* dialog = new HotkeyDialog(300, 140, currentKey);
dialog->show();
while (dialog->shown()) {
Fl::wait();
}

int newKey = dialog->getHotkey();
if (newKey) {
updateKeyToGrid(currentKey, newKey, ID, clipNum);
}

} else if ( strcmp(m->label(), "Save") == 0 ) {
//gui->saveBufferPath = "/tmp/test.wav";
char* tmp = gui->selectSavePath();
Expand Down
61 changes: 61 additions & 0 deletions src/avtk/hotkeydialog.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include "hotkeydialog.hxx"
#include <FL/Fl.H>
#include <FL/fl_draw.H>
#include <iostream>

HotkeyDialog::HotkeyDialog(int w, int h, int currentKey)
: Fl_Window(w, h, "Assign New Hotkey"), hotkey(0) {
this->set_modal(); // Prevent application closing without this window closing first
current_key_label = new Fl_Box(10, 10, w - 20, 20, "Current key:");
current_key_label->box(FL_NO_BOX);
current_key_label->align(FL_ALIGN_INSIDE | FL_ALIGN_CENTER);

// Concert currentKey to string if available
if (currentKey) {
current_key_str = static_cast<char>(currentKey);
} else {
current_key_label->hide();
current_key_str = "No key set";
}

current_key_display = new Fl_Box(10, 30, w - 20, 30, current_key_str.c_str());
current_key_display->box(FL_NO_BOX);
current_key_display->align(FL_ALIGN_INSIDE | FL_ALIGN_CENTER);
current_key_display->labelfont(FL_HELVETICA_BOLD);
current_key_display->labelsize(14);

instructions_box = new Fl_Box(10, 60, w - 20, 30, "Press new hotkey: \n(Esc to cancel)");
instructions_box->box(FL_NO_BOX);
instructions_box->align(FL_ALIGN_INSIDE | FL_ALIGN_CENTER);

cancel_button = new Fl_Button(w / 2 - 40, h - 40, 80, 30, "Cancel");
cancel_button->callback(Cancel_CB, this);
end();
}

int HotkeyDialog::getHotkey() const {
return hotkey;
}

int HotkeyDialog::handle(int event) {
switch (event) {
case FL_KEYDOWN:
if (Fl::event_key() == FL_Escape || Fl::event_key() == FL_Shift_L || Fl::event_key() == FL_Shift_R) {
hide();
return 1;
}
hotkey = Fl::event_key();
//std::cout << "Hotkey captured: " << hotkey << std::endl;
hide();
return 1;

default:
break;
}
return Fl_Window::handle(event);
}

void HotkeyDialog::Cancel_CB(Fl_Widget*, void* v) {
HotkeyDialog* dialog = (HotkeyDialog*)v;
dialog->hide();
}
30 changes: 30 additions & 0 deletions src/avtk/hotkeydialog.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef HOTKEYDIALOG_H
#define HOTKEYDIALOG_H

#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Box.H>
#include <string>

class HotkeyDialog : public Fl_Window {
public:
HotkeyDialog(int w, int h, int currentKey);
int getHotkey() const;

protected:
int handle(int event) override;

private:
static void Cancel_CB(Fl_Widget*, void* v);

Fl_Box* current_key_label;
Fl_Box* current_key_display;
Fl_Box* instructions_box;
Fl_Button* cancel_button;
int hotkey;

std::string message_text;
std::string current_key_str;
};

#endif // HOTKEYDIALOG_H
2 changes: 1 addition & 1 deletion src/avtk/meson.build
Original file line number Diff line number Diff line change
@@ -1 +1 @@
luppp_src += files( 'bindings.cxx', 'volume.cxx', 'clipselector.cxx')
luppp_src += files( 'bindings.cxx', 'volume.cxx', 'clipselector.cxx', 'hotkeydialog.cxx')
19 changes: 18 additions & 1 deletion src/diskreader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "audiobuffer.hxx"
#include "eventhandler.hxx"
#include "gmastertrack.hxx"

#include "hotkeymanager.hxx"
#include "controller/genericmidi.hxx"

#include <sndfile.hh>
Expand Down Expand Up @@ -93,6 +93,23 @@ int DiskReader::loadPreferences()
LUPPP_NOTE("No default controllers active.");
}

cJSON* hotkeyAssignment = cJSON_GetObjectItem(preferencesJson, "hotkeyAssignment");
if (hotkeyAssignment) {
keyToGrid.clear();
cJSON* key = hotkeyAssignment->child;
while (key) {
int keycode = atoi(key->string);
cJSON* gridArray = key;
if (cJSON_GetArraySize(gridArray) == 2) {
int x = cJSON_GetArrayItem(gridArray, 0)->valueint;
int y = cJSON_GetArrayItem(gridArray, 1)->valueint;
keyToGrid[keycode] = {x, y};
}
key = key->next;
}
} else {
LUPPP_WARN("No hotkeyAssignment found in preferences");
}

cJSON* projDir=cJSON_GetObjectItem(preferencesJson,"saveDirectory");
string dir=getenv("HOME");
Expand Down
23 changes: 22 additions & 1 deletion src/diskwriter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <FL/fl_ask.H>

#include "gui.hxx"
#include "hotkeymanager.hxx"
#include "gmastertrack.hxx"

#include "controller/genericmidi.hxx"
Expand Down Expand Up @@ -474,9 +475,29 @@ void DiskWriter::writeDefaultConfigToUserHome()

// per track send and return option
cJSON_AddNumberToObject( prfs, "enablePerTrackSendReturns", 0 );

cJSON* hotkeyAssignment = cJSON_CreateObject();

// Iterate through the keyToGrid map and add each key-value pair to hotkeyAssignment
for (const auto& pair : keyToGrid) {
int key = pair.first;
int id = pair.second.first;
int clipNumber = pair.second.second;

// Create an array for the id and clipNumber
cJSON* array = cJSON_CreateArray();
cJSON_AddItemToArray(array, cJSON_CreateNumber(id));
cJSON_AddItemToArray(array, cJSON_CreateNumber(clipNumber));

// Convert key to string and add to hotkeyAssignment
cJSON_AddItemToObject(hotkeyAssignment, std::to_string(key).c_str(), array);
}
cJSON_AddItemToObject(prfs, "hotkeyAssignment", hotkeyAssignment);

// test output on console
// cout << endl << cJSON_Print( prfs ) << endl << endl;




// write JSON to .config/openAV/luppp/luppp.prfs
stringstream f;
Expand Down
Loading