libdebugger: Add initial version of network interface.
[haiku.git] / src / kits / midi / MidiSettings.cpp
blobbc62f90d901fbe2b5ea64b9c87b0376916e20cbd
1 /*
2 * Copyright 2015 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
6 #include <MidiSettings.h>
8 #include <File.h>
9 #include <FindDirectory.h>
10 #include <Path.h>
12 #include <driver_settings.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
18 #define SETTINGS_FILE "Media/midi_settings"
20 namespace BPrivate {
22 status_t
23 read_midi_settings(struct midi_settings* settings)
25 if (settings == NULL)
26 return B_ERROR;
28 BPath path;
29 status_t status = find_directory(B_USER_SETTINGS_DIRECTORY, &path);
30 if (status != B_OK)
31 return status;
33 path.Append(SETTINGS_FILE);
34 void* handle = load_driver_settings(path.Path());
35 if (handle == NULL)
36 return B_ERROR;
38 const char* soundfont = get_driver_parameter(handle, "soundfont", NULL,
39 NULL);
40 if (soundfont == NULL)
41 return B_ERROR;
42 strlcpy(settings->soundfont_file, soundfont,
43 sizeof(settings->soundfont_file));
45 unload_driver_settings(handle);
46 return B_OK;
50 status_t
51 write_midi_settings(struct midi_settings settings)
53 BPath path;
54 status_t status = find_directory(B_USER_SETTINGS_DIRECTORY, &path);
55 if (status != B_OK)
56 return status;
58 path.Append(SETTINGS_FILE);
60 BFile file;
61 if (file.SetTo(path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE)
62 != B_OK)
63 return B_ERROR;
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)
72 return B_ERROR;
74 return B_OK;