2 * Copyright 2015 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 #include <MidiSettings.h>
9 #include <FindDirectory.h>
12 #include <driver_settings.h>
18 #define SETTINGS_FILE "Media/midi_settings"
23 read_midi_settings(struct midi_settings
* settings
)
29 status_t status
= find_directory(B_USER_SETTINGS_DIRECTORY
, &path
);
33 path
.Append(SETTINGS_FILE
);
34 void* handle
= load_driver_settings(path
.Path());
38 const char* soundfont
= get_driver_parameter(handle
, "soundfont", NULL
,
40 if (soundfont
== NULL
)
42 strlcpy(settings
->soundfont_file
, soundfont
,
43 sizeof(settings
->soundfont_file
));
45 unload_driver_settings(handle
);
51 write_midi_settings(struct midi_settings settings
)
54 status_t status
= find_directory(B_USER_SETTINGS_DIRECTORY
, &path
);
58 path
.Append(SETTINGS_FILE
);
61 if (file
.SetTo(path
.Path(), B_WRITE_ONLY
| B_CREATE_FILE
| B_ERASE_FILE
)
65 char buffer
[B_FILE_NAME_LENGTH
+ 128];
66 snprintf(buffer
, sizeof(buffer
), "# Midi\n\tsoundfont \"%s\"\n",
67 settings
.soundfont_file
);
69 size_t bufferSize
= strlen(buffer
);
70 if (file
.InitCheck() != B_OK
71 || file
.Write(buffer
, bufferSize
) != (ssize_t
)bufferSize
)