generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings-tab.ts
259 lines (232 loc) · 10.8 KB
/
settings-tab.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
import { App, PluginSettingTab, Setting, TFolder, Vault, DropdownComponent } from 'obsidian';
import AudioRecorderPlugin from './main';
export interface AudioRecorderSettings {
recordingFormat: string;
saveFolder: string;
filePrefix: string;
startStopHotkey: string;
pauseHotkey: string;
resumeHotkey: string;
audioDeviceId: string;
sampleRate: number;
bitrate: number;
enableMultiTrack: boolean;
maxTracks: number;
outputMode: 'single' | 'multiple';
useSourceNamesForTracks: boolean;
trackAudioSources: { [key: number]: string };
debug: boolean;
}
export const DEFAULT_SETTINGS: AudioRecorderSettings = {
recordingFormat: 'webm',
saveFolder: '',
filePrefix: 'recording',
startStopHotkey: '',
pauseHotkey: '',
resumeHotkey: '',
audioDeviceId: '',
sampleRate: 44100,
bitrate: 128000,
enableMultiTrack: false,
maxTracks: 2,
outputMode: 'single',
useSourceNamesForTracks: true,
trackAudioSources: {},
debug: false
}
export class AudioRecorderSettingTab extends PluginSettingTab {
plugin: AudioRecorderPlugin;
constructor(app: App, plugin: AudioRecorderPlugin) {
super(app, plugin);
this.plugin = plugin;
}
async getAudioInputDevices() {
const devices = await navigator.mediaDevices.enumerateDevices();
return devices.filter(device => device.kind === 'audioinput');
}
async getSupportedFormats() {
const formats = ['ogg', 'webm', 'mp3', 'm4a', 'mp4', 'wav'];
const supportedFormats = formats.filter(format => MediaRecorder.isTypeSupported(`audio/${format}`));
return supportedFormats;
}
getFolderOptions(): string[] {
const folders: string[] = [];
Vault.recurseChildren(this.app.vault.getRoot(), (file) => {
if (file instanceof TFolder) {
folders.push(file.path);
}
});
return folders;
}
async display(): Promise<void> {
const { containerEl } = this;
containerEl.empty();
new Setting(containerEl)
.setName('Audio recorder plus')
.setDesc('Configure the settings for the Audio Recorder Plus plugin.')
.setHeading();
const supportedFormats = await this.getSupportedFormats();
new Setting(containerEl)
.setName('Recording format')
.setDesc('Select the audio recording format.')
.addDropdown(dropdown => {
supportedFormats.forEach(format => {
dropdown.addOption(format, format);
});
dropdown.setValue(this.plugin.settings.recordingFormat);
dropdown.onChange(async (value) => {
this.plugin.settings.recordingFormat = value;
await this.plugin.saveSettings();
});
});
new Setting(containerEl)
.setName('Sample rate')
.setDesc('Select the audio sample rate.')
.addDropdown(dropdown => {
const sampleRates = [8000, 16000, 22050, 44100, 48000];
sampleRates.forEach(rate => {
dropdown.addOption(rate.toString(), rate.toString());
});
dropdown.setValue(this.plugin.settings.sampleRate.toString());
dropdown.onChange(async (value) => {
this.plugin.settings.sampleRate = parseInt(value);
await this.plugin.saveSettings();
});
});
new Setting(containerEl)
.setName('Save folder')
.setDesc('Specify the folder to save recordings. Auto-complete enabled.')
.addText(text => {
const folderOptions = this.getFolderOptions();
text.inputEl.setAttribute('list', 'folder-options');
const datalist = document.createElement('datalist');
datalist.id = 'folder-options';
folderOptions.forEach(folder => {
const option = document.createElement('option');
option.value = folder;
datalist.appendChild(option);
});
text.inputEl.appendChild(datalist);
text.setValue(this.plugin.settings.saveFolder);
text.onChange(async (value) => {
this.plugin.settings.saveFolder = value;
await this.plugin.saveSettings();
});
});
new Setting(containerEl)
.setName('File naming')
.setDesc('Use the File prefix setting to customize the naming of your audio files. ' +
'The final file name will include this prefix followed by a timestamp. ' +
'For example, if your prefix is "meeting", the file name will look like ' +
'"meeting-2023-07-21T15-30-00.ogg"')
.setHeading();
new Setting(containerEl)
.setName('File prefix')
.setDesc('Set a prefix for the audio file names.')
.addText(text => text
.setPlaceholder('Enter file prefix')
.setValue(this.plugin.settings.filePrefix)
.onChange(async (value) => {
this.plugin.settings.filePrefix = value;
await this.plugin.saveSettings();
}));
new Setting(containerEl)
.setName('Debug mode')
.setDesc('Enable debug logging')
.addToggle(toggle => toggle
.setValue(this.plugin.settings.debug)
.onChange(async (value) => {
this.plugin.settings.debug = value;
await this.plugin.saveSettings();
}));
new Setting(containerEl)
.setName('Multi-track recording')
.setDesc('Configure settings for multi-track recording.')
.setHeading();
new Setting(containerEl)
.setName('Enable multi-track recording')
.setDesc('Toggle to activate or deactivate multi-track recording.')
.addToggle(toggle => toggle
.setValue(this.plugin.settings.enableMultiTrack)
.onChange(async (value) => {
this.plugin.settings.enableMultiTrack = value;
await this.plugin.saveSettings();
this.display(); // Refresh the settings page
}));
if (this.plugin.settings.enableMultiTrack) {
new Setting(containerEl)
.setName('Maximum tracks')
.setDesc('Set the number of simultaneous tracks (1-8).')
.addSlider(slider => slider
.setLimits(1, 8, 1)
.setValue(this.plugin.settings.maxTracks)
.setDynamicTooltip()
.onChange(async (value) => {
this.plugin.settings.maxTracks = value;
await this.plugin.saveSettings();
this.display(); // Refresh the settings page
}));
new Setting(containerEl)
.setName('Output mode')
.setDesc('Choose between single combined file or separate files for each track.')
.addDropdown(dropdown => dropdown
.addOption('single', 'Single File')
.addOption('multiple', 'Multiple Files')
.setValue(this.plugin.settings.outputMode)
.onChange(async (value: 'single' | 'multiple') => {
this.plugin.settings.outputMode = value;
await this.plugin.saveSettings();
}));
// new Setting(containerEl)
// .setName('Use source names for tracks')
// .setDesc('Use audio source names for individual track filenames.')
// .addToggle(toggle => toggle
// .setValue(this.plugin.settings.useSourceNamesForTracks)
// .onChange(async (value) => {
// this.plugin.settings.useSourceNamesForTracks = value;
// await this.plugin.saveSettings();
// }));
for (let i = 1; i <= this.plugin.settings.maxTracks; i++) {
new Setting(containerEl)
.setName(`Audio Source for Track ${i}`)
.setDesc(`Select the audio input device for track ${i}`)
.addDropdown(async (dropdown) => {
await this.populateAudioDevices(dropdown);
dropdown.setValue(this.plugin.settings.trackAudioSources[i] || "");
dropdown.onChange(async (value) => {
this.plugin.settings.trackAudioSources[i] = value;
await this.plugin.saveSettings();
});
});
}
}
new Setting(containerEl)
.setName('Documentation')
.setDesc(
'File Prefix: Customize the prefix for your audio files. The final filename includes this prefix and a timestamp.\n\n' +
'Recording Format: Choose between OGG, WEBM, MP3, or M4A for your audio recordings.\n\n' +
'Save Folder: Specify where recordings will be saved. Autocomplete suggestions are available.\n\n' +
'Audio Input Device: Select the microphone for recording.\n\n' +
'Sample Rate: Set the sample rate for your audio recordings.\n\n' +
'Hotkeys:\n' +
'- Start/Stop: Set a hotkey to quickly start and stop recordings.\n' +
'- Pause: Set a hotkey to pause recordings.\n' +
'- Resume: Set a hotkey to resume recordings.\n\n' +
'Bitrate: Adjust to control quality and file size of your recordings.\n\n' +
'Visual Indicators: The status bar displays when recording is active.\n\n' +
'Multi-track Recording:\n' +
'- Enable to record multiple audio sources simultaneously.\n' +
'- Maximum Tracks: Set the number of simultaneous tracks (1-8).\n' +
'- Output Mode: Choose between a single combined file or separate files for each track.\n' +
'- Use Source Names: Option to use audio source names for individual track filenames.\n' +
'- Audio Source Selection: Choose specific audio input devices for each track.'
)
.setHeading();
}
async populateAudioDevices(dropdown: DropdownComponent) {
const devices = await this.getAudioInputDevices();
devices.forEach(device => {
dropdown.addOption(device.deviceId, device.label || `Audio Device ${device.deviceId}`);
});
}
}