Skip to content

Commit 69fe936

Browse files
committed
work on saving settings
1 parent 28666f1 commit 69fe936

File tree

5 files changed

+278
-0
lines changed

5 files changed

+278
-0
lines changed
+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
{
2+
"ActiveBank": "LINE",
3+
"SelectedChannel": 1,
4+
"channels": [
5+
{
6+
"Channel Number": 1,
7+
"volume": "00",
8+
"Trim": 20,
9+
"Pre Insert": "",
10+
"Post Insert": "",
11+
"Assignment": [1,2,"LR"],
12+
"Pan": 0,
13+
"Phase": false,
14+
"Group": 0,
15+
"Filter": false,
16+
"Delay": 0,
17+
"Playback": "Run",
18+
"Write": true, // channellist
19+
"Isolate": false,
20+
"AUX": [
21+
{
22+
"1": {
23+
"Send Level": 0,
24+
"Pre Fader": true
25+
},
26+
"2": {
27+
"Send Level": 0,
28+
"Pre Fader": true
29+
},
30+
"3": {
31+
"Send Level": 0,
32+
"Pre Fader": true
33+
},
34+
"4": {
35+
"Send Level": 0,
36+
"Pre Fader": true
37+
},
38+
"5": {
39+
"Send Level": 0,
40+
"Pre Fader": true
41+
},
42+
"6": {
43+
"Send Level": 0,
44+
"Pre Fader": true
45+
},
46+
"7": {
47+
"Send Level": 0,
48+
"Pre Fader": true
49+
},
50+
"8": {
51+
"Send Level": 0,
52+
"Pre Fader": true
53+
}
54+
}
55+
],
56+
"Stereo AUX": [
57+
{
58+
"9-10": {
59+
"Send Level": 0,
60+
"PrePost": "pre",
61+
"Pan": -67
62+
},
63+
"11-12": {
64+
"Send Level": 0,
65+
"PrePost": "pre",
66+
"Pan": -67
67+
}
68+
}
69+
],
70+
71+
"EQ": {
72+
"low": -3,
73+
"mid": 2,
74+
"high": 4
75+
},
76+
"Compressor": {
77+
"Active": false,
78+
"Threshold": "10D5",
79+
"Ratio": "45D1",
80+
"Attack": "4C3",
81+
"Release": "32",
82+
"Output": "00",
83+
"Soft": false
84+
},
85+
"Gate": {
86+
"Active": false,
87+
"Range": "109C",
88+
"Attack": "FFFF",
89+
"Release": "24D",
90+
"Threshold": "708",
91+
"Expand": false,
92+
"Ratio": "FFFF",
93+
"Midi": false
94+
}
95+
},
96+
97+
],
98+
"Effects": {},
99+
"Returns": {},
100+
"Groups": {
101+
"Volume": ["C1", "C1", "C1", "C1", "C1", "C1", "C1", "C1"]
102+
},
103+
"MIDI": {},
104+
"BUS": {
105+
"1": {
106+
"volume": "C1"
107+
}
108+
},
109+
110+
"master": {
111+
"volume": 90,
112+
"AUX send": {
113+
"1": {}
114+
}
115+
"eq": {
116+
"low": 2,
117+
"mid": 0,
118+
"high": -2
119+
}
120+
},
121+
"masterSection": {
122+
"Locator": {},
123+
"channel1": "output1",
124+
"channel2": "output2",
125+
// More routing configurations...
126+
},
127+
"Editor": {}
128+
}

Builds/LinuxMakefile/Makefile

+6
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ OBJECTS_APP := \
9595
$(JUCE_OBJDIR)/MixerManagerClass_34f257d5.o \
9696
$(JUCE_OBJDIR)/SettingsClass_e17fe7f6.o \
9797
$(JUCE_OBJDIR)/SettingsComponent_119b047b.o \
98+
$(JUCE_OBJDIR)/SettingsFileManagerClass_6f55e533.o \
9899
$(JUCE_OBJDIR)/SettingsWindow_d17777fc.o \
99100
$(JUCE_OBJDIR)/include_juce_core_f26d17db.o \
100101
$(JUCE_OBJDIR)/include_juce_data_structures_7471b1e3.o \
@@ -230,6 +231,11 @@ $(JUCE_OBJDIR)/SettingsComponent_119b047b.o: ../../Source/SettingsComponent.cpp
230231
@echo "Compiling SettingsComponent.cpp"
231232
$(V_AT)$(CXX) $(JUCE_CXXFLAGS) $(JUCE_CPPFLAGS_APP) $(JUCE_CFLAGS_APP) -o "$@" -c "$<"
232233

234+
$(JUCE_OBJDIR)/SettingsFileManagerClass_6f55e533.o: ../../Source/SettingsFileManagerClass.cpp
235+
-$(V_AT)mkdir -p $(@D)
236+
@echo "Compiling SettingsFileManagerClass.cpp"
237+
$(V_AT)$(CXX) $(JUCE_CXXFLAGS) $(JUCE_CPPFLAGS_APP) $(JUCE_CFLAGS_APP) -o "$@" -c "$<"
238+
233239
$(JUCE_OBJDIR)/SettingsWindow_d17777fc.o: ../../Source/SettingsWindow.cpp
234240
-$(V_AT)mkdir -p $(@D)
235241
@echo "Compiling SettingsWindow.cpp"

Source/SettingsFileManagerClass.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
==============================================================================
3+
4+
SettingsFileManagerClass.cpp
5+
Created: 29 Aug 2024 10:46:18pm
6+
Author: anders
7+
8+
==============================================================================
9+
*/
10+
11+
#include "SettingsFileManagerClass.h"

Source/SettingsFileManagerClass.h

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*
2+
==============================================================================
3+
4+
SettingsFileManagerClass.h
5+
Created: 29 Aug 2024 10:46:18pm
6+
Author: anders
7+
8+
We need to be able to save settings. This class is meant to handle this.
9+
The idea is to keep the file open consistently, to avoid having to open/close
10+
at every write - this will optimize, since we are aiming to write changes
11+
to settings as they happen.
12+
TODO: Maybe the class should occationally write to a backup file?
13+
14+
==============================================================================
15+
*/
16+
17+
THIS IS AIMING AT HANDLING ALL SETTINGS, WRITING ALL EVERY TIME.
18+
INEFFECIENT.
19+
LETS MAKE IT SO WE CAN EFFECIENTLY CHANGE A SINGLE SETTING.
20+
BUT HOW OFTEN DO WE WRITE?
21+
DO WE REALLY WANT TO WRITE ON EVERYTHING, OR INSTEAD ON MAIN CHANGES?
22+
NO - THERE IS A SAVE OPTION - SO WE ONLY SAVE TO FILE WHEN THAT IT USED.
23+
SO WE MUST KEEP A "STANDARD SETTINGS" FILE....
24+
25+
from manual:
26+
New Session (Ctrl+N)
27+
• Press Ctrl+N or click the File menu, drag down to
28+
New Session, and release.
29+
• Select this to—wait, let me guess—start a new
30+
session.
31+
• The OS will ask you to save changes to the
32+
current session, if necessary.
33+
• Next, you get the chance to name the new session,
34+
select which folder it ends up in, create a new
35+
folder to put it in, or cancel.
36+
• The session can be saved to the internal hard
37+
drive or to a 3.5" floppy disk.
38+
• A session consists of all snapshots, automation
39+
data, and—if you choose—custom EQ, effects,
40+
and dynamics patches.
41+
• A new session uses the Template as its initial
42+
status"
43+
44+
45+
autosave feature.....
46+
47+
a new session is using a template, but we can also save as template to update the ... tadaaa... template.
48+
49+
the following are stored in the Template:
50+
• Channel Name
51+
• Noise Filter setting (in Channel List)
52+
• Channel Layout (rearrangement)
53+
• MDS Network settings
54+
• Stereo/Surround setting
55+
• Current Tempo (default to 120 bpm)
56+
• Time View (SMPTE/BBT/Milliseconds)
57+
• Mix Editor – Grid Setting (resolution—called
58+
Snap Grid in the pull-down), Enable Snapping,
59+
Snap to Cues, Snap to Grid
60+
61+
#pragma once
62+
63+
#include <cstdio>
64+
#include <mutex>
65+
66+
class SettingsFileManager
67+
{
68+
private:
69+
FILE *file;
70+
std::mutex fileMutex;
71+
const char *filename;
72+
73+
public:
74+
SettingsFileManager(const char *filename) : filename(filename), file(nullptr)
75+
{
76+
openFile();
77+
}
78+
79+
~SettingsFileManager()
80+
{
81+
closeFile();
82+
}
83+
84+
void openFile()
85+
{
86+
std::lock_guard<std::mutex> lock(fileMutex);
87+
if (!file)
88+
{
89+
file = fopen(filename, "r+b"); // Open for reading and writing in binary mode
90+
if (!file)
91+
{ // File does not exist, create it
92+
file = fopen(filename, "w+b");
93+
}
94+
}
95+
}
96+
97+
void closeFile()
98+
{
99+
std::lock_guard<std::mutex> lock(fileMutex);
100+
if (file)
101+
{
102+
fclose(file);
103+
file = nullptr;
104+
}
105+
}
106+
107+
bool writeSettings(const void *settings, size_t size)
108+
{
109+
std::lock_guard<std::mutex> lock(fileMutex);
110+
if (file && fseek(file, 0, SEEK_SET) == 0)
111+
{
112+
size_t written = fwrite(settings, size, 1, file);
113+
fflush(file); // Flush the file buffer to ensure data is written to disk
114+
return written == 1;
115+
}
116+
return false;
117+
}
118+
119+
bool readSettings(void *settings, size_t size)
120+
{
121+
std::lock_guard<std::mutex> lock(fileMutex);
122+
if (file && fseek(file, 0, SEEK_SET) == 0)
123+
{
124+
size_t read = fread(settings, size, 1, file);
125+
return read == 1;
126+
}
127+
return false;
128+
}
129+
};

d8b_pi.jucer

+4
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@
9292
file="Source/SettingsComponent.cpp"/>
9393
<FILE id="ukFybi" name="SettingsComponent.h" compile="0" resource="0"
9494
file="Source/SettingsComponent.h"/>
95+
<FILE id="A8xJx9" name="SettingsFileManagerClass.cpp" compile="1" resource="0"
96+
file="Source/SettingsFileManagerClass.cpp"/>
97+
<FILE id="xoxQm2" name="SettingsFileManagerClass.h" compile="0" resource="0"
98+
file="Source/SettingsFileManagerClass.h"/>
9599
<FILE id="kHmpSU" name="SettingsWindow.cpp" compile="1" resource="0"
96100
file="Source/SettingsWindow.cpp"/>
97101
<FILE id="UzBH4k" name="SettingsWindow.h" compile="0" resource="0"

0 commit comments

Comments
 (0)