MediaPreferences: midi: added a BStringView with the currently active soundfont

This commit is contained in:
Stefano Ceccherini 2016-09-24 20:35:01 +02:00
parent 806ccfda6c
commit 873a8ad914
2 changed files with 31 additions and 12 deletions

View File

@ -22,6 +22,7 @@
#include <PathFinder.h> #include <PathFinder.h>
#include <ScrollView.h> #include <ScrollView.h>
#include <StringList.h> #include <StringList.h>
#include <StringView.h>
#include <stdio.h> #include <stdio.h>
@ -55,6 +56,8 @@ MidiSettingsView::MidiSettingsView()
BLayoutBuilder::Group<>(this) BLayoutBuilder::Group<>(this)
.SetInsets(0, 0, 0, 0) .SetInsets(0, 0, 0, 0)
.Add(defaultsBox) .Add(defaultsBox)
.Add(fActiveSoundFont = new BStringView("ActiveSoundFont",
"Active Sound Font:"))
.AddGlue(); .AddGlue();
} }
@ -77,9 +80,13 @@ void
MidiSettingsView::MessageReceived(BMessage* message) MidiSettingsView::MessageReceived(BMessage* message)
{ {
switch (message->what) { switch (message->what) {
case kSelectSoundFont: case kSelectSoundFont: {
BString text = "Active Sound Font: ";
text << _SelectedSoundFont();
fActiveSoundFont->SetText(text);
_SaveSettings(); _SaveSettings();
break; break;
}
default: default:
SettingsView::MessageReceived(message); SettingsView::MessageReceived(message);
@ -142,16 +149,25 @@ MidiSettingsView::_LoadSettings()
void void
MidiSettingsView::_SaveSettings() MidiSettingsView::_SaveSettings()
{ {
int32 selection = fListView->CurrentSelection(); BString soundFont = _SelectedSoundFont();
if (selection < 0) if (soundFont.Length() > 0) {
return; struct BPrivate::midi_settings settings;
strlcpy(settings.soundfont_file, soundFont, sizeof(settings.soundfont_file));
BStringItem* item = (BStringItem*)fListView->ItemAt(selection); BPrivate::write_midi_settings(settings);
if (item == NULL) }
return;
struct BPrivate::midi_settings settings;
strlcpy(settings.soundfont_file, item->Text(), sizeof(settings.soundfont_file));
BPrivate::write_midi_settings(settings);
} }
BString
MidiSettingsView::_SelectedSoundFont() const
{
BString string;
int32 selection = fListView->CurrentSelection();
if (selection >= 0) {
BStringItem* item = (BStringItem*)fListView->ItemAt(selection);
if (item != NULL)
string = item->Text();
}
return string;
}

View File

@ -11,6 +11,7 @@
class BButton; class BButton;
class BListView; class BListView;
class BStringView;
class MidiSettingsView : public SettingsView { class MidiSettingsView : public SettingsView {
public: public:
MidiSettingsView(); MidiSettingsView();
@ -21,8 +22,10 @@ private:
void _RetrieveSoftSynthList(); void _RetrieveSoftSynthList();
void _LoadSettings(); void _LoadSettings();
void _SaveSettings(); void _SaveSettings();
BString _SelectedSoundFont() const;
BListView* fListView; BListView* fListView;
BStringView* fActiveSoundFont;
}; };
#endif /* MIDIVIEW_H_ */ #endif /* MIDIVIEW_H_ */