nonemm-recorder is a separate program (src/Nonemm.Recorder.App) over a library (src/Nonemm.Recorder). Each row in its list is one channel of one device, and each row becomes one channel in an Ogg Opus file: 60 ms frames, complexity 9, 32 kbps per channel by default. - A device that is not connected keeps its row, in red, and writes silence. It is recorded from the moment it returns, also during a recording. - Output devices are recorded as loopback: WASAPI on Windows, the "Monitor of" sources on PulseAudio and PipeWire. - A headphone button plays one channel, in mono, on the default device. - The rows, bitrate and folder are saved when the window closes. SoundFlow 1.4.2 numbers its backend enum one higher than the miniaudio it ships, so asking for PulseAudio gave ALSA and Wasapi gave DirectSound. SoundFlowBackend lowers the value by one and checks which backend started. Output devices and live capture are not tested on real hardware. The tests use a fake sound system and decode the written file. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
51 lines
1.5 KiB
C#
51 lines
1.5 KiB
C#
using System.Text.Json;
|
|
|
|
namespace Nonemm.Recorder;
|
|
|
|
/// Reads and writes the one configuration file.
|
|
public sealed class RecorderConfigStore
|
|
{
|
|
private static readonly JsonSerializerOptions Options = new() { WriteIndented = true };
|
|
|
|
private readonly string path;
|
|
|
|
public RecorderConfigStore(string path)
|
|
{
|
|
this.path = path;
|
|
}
|
|
|
|
public static string DefaultPath()
|
|
{
|
|
string folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
|
|
return Path.Combine(folder, "nonemm-recorder", "config.json");
|
|
}
|
|
|
|
/// A missing file gives the default configuration. A file that cannot be
|
|
/// read throws, so a damaged file is not replaced without the operator
|
|
/// knowing.
|
|
public RecorderConfig Load()
|
|
{
|
|
if (!File.Exists(path))
|
|
{
|
|
return new RecorderConfig();
|
|
}
|
|
try
|
|
{
|
|
using FileStream stream = File.OpenRead(path);
|
|
return JsonSerializer.Deserialize<RecorderConfig>(stream, Options) ?? new RecorderConfig();
|
|
}
|
|
catch (JsonException cause)
|
|
{
|
|
throw new InvalidDataException($"{path} is not a recorder configuration", cause);
|
|
}
|
|
}
|
|
|
|
public void Save(RecorderConfig config)
|
|
{
|
|
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
|
|
string temporary = path + ".tmp";
|
|
File.WriteAllText(temporary, JsonSerializer.Serialize(config, Options));
|
|
File.Move(temporary, path, overwrite: true);
|
|
}
|
|
}
|