patch by Fredrik Modéen with changes by myself
* toggle the "marked" state of the settings menu items correctly * implement muting/unmuting the volume * implement volume up/down triggered by keyboard events * forward the skip next/previous events to the controller (various kinds of keyboard navigation or mouse wheel) * establish the notification link for volume and muted changes git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22594 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
c9518b6240
commit
540fe7aef9
@ -76,6 +76,7 @@ void Controller::Listener::AudioStatsChanged() {}
|
||||
void Controller::Listener::PlaybackStateChanged(uint32) {}
|
||||
void Controller::Listener::PositionChanged(float) {}
|
||||
void Controller::Listener::VolumeChanged(float) {}
|
||||
void Controller::Listener::MutedChanged(bool) {}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
@ -86,6 +87,7 @@ Controller::Controller()
|
||||
, fPaused(false)
|
||||
, fStopped(true)
|
||||
, fVolume(1.0)
|
||||
, fMuted(false)
|
||||
|
||||
, fRef()
|
||||
, fMediaFile(0)
|
||||
@ -494,12 +496,57 @@ void
|
||||
Controller::SetVolume(float value)
|
||||
{
|
||||
printf("Controller::SetVolume %.4f\n", value);
|
||||
if (Lock()) {
|
||||
if (!Lock())
|
||||
return;
|
||||
|
||||
value = max_c(0.0, min_c(2.0, value));
|
||||
|
||||
if (fVolume != value) {
|
||||
if (fMuted)
|
||||
ToggleMute();
|
||||
|
||||
fVolume = value;
|
||||
if (fSoundOutput)
|
||||
fSoundOutput->SetVolume(fVolume);
|
||||
Unlock();
|
||||
|
||||
_NotifyVolumeChanged(fVolume);
|
||||
}
|
||||
|
||||
Unlock();
|
||||
}
|
||||
|
||||
void
|
||||
Controller::VolumeUp()
|
||||
{
|
||||
// TODO: linear <-> exponential
|
||||
SetVolume(Volume() + 0.05);
|
||||
}
|
||||
|
||||
void
|
||||
Controller::VolumeDown()
|
||||
{
|
||||
// TODO: linear <-> exponential
|
||||
SetVolume(Volume() - 0.05);
|
||||
}
|
||||
|
||||
void
|
||||
Controller::ToggleMute()
|
||||
{
|
||||
if (!Lock())
|
||||
return;
|
||||
|
||||
fMuted = !fMuted;
|
||||
|
||||
if (fSoundOutput) {
|
||||
if (fMuted)
|
||||
fSoundOutput->SetVolume(0.0);
|
||||
else
|
||||
fSoundOutput->SetVolume(fVolume);
|
||||
}
|
||||
|
||||
_NotifyMutedChanged(fMuted);
|
||||
|
||||
Unlock();
|
||||
}
|
||||
|
||||
|
||||
@ -1330,3 +1377,14 @@ Controller::_NotifyVolumeChanged(float volume)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Controller::_NotifyMutedChanged(bool muted)
|
||||
{
|
||||
BList listeners(fListeners);
|
||||
int32 count = listeners.CountItems();
|
||||
for (int32 i = 0; i < count; i++) {
|
||||
Listener* listener = (Listener*)listeners.ItemAtFast(i);
|
||||
listener->MutedChanged(muted);
|
||||
}
|
||||
}
|
||||
|
@ -57,6 +57,7 @@ public:
|
||||
virtual void PlaybackStateChanged(uint32 state);
|
||||
virtual void PositionChanged(float position);
|
||||
virtual void VolumeChanged(float volume);
|
||||
virtual void MutedChanged(bool muted);
|
||||
};
|
||||
|
||||
Controller();
|
||||
@ -89,6 +90,9 @@ public:
|
||||
|
||||
void SetVolume(float value);
|
||||
float Volume() const;
|
||||
void VolumeUp();
|
||||
void VolumeDown();
|
||||
void ToggleMute();
|
||||
void SetPosition(float value);
|
||||
|
||||
bool HasFile();
|
||||
@ -146,6 +150,7 @@ private:
|
||||
void _NotifyPlaybackStateChanged();
|
||||
void _NotifyPositionChanged(float position);
|
||||
void _NotifyVolumeChanged(float volume);
|
||||
void _NotifyMutedChanged(bool muted);
|
||||
|
||||
friend class InfoWin;
|
||||
|
||||
@ -169,6 +174,7 @@ private:
|
||||
volatile bool fPaused;
|
||||
volatile bool fStopped;
|
||||
float fVolume;
|
||||
bool fMuted;
|
||||
|
||||
entry_ref fRef;
|
||||
BMediaFile * fMediaFile;
|
||||
|
@ -137,3 +137,16 @@ ControllerObserver::VolumeChanged(float volume)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ControllerObserver::MutedChanged(bool muted)
|
||||
{
|
||||
if (!(fObserveFlags & OBSERVE_VOLUME_CHANGES))
|
||||
return;
|
||||
|
||||
BMessage message(MSG_CONTROLLER_MUTED_CHANGED);
|
||||
message.AddBool("muted", muted);
|
||||
|
||||
DeliverMessage(message);
|
||||
}
|
||||
|
||||
|
||||
|
@ -23,7 +23,8 @@ enum {
|
||||
|
||||
MSG_CONTROLLER_PLAYBACK_STATE_CHANGED = 'cnps',
|
||||
MSG_CONTROLLER_POSITION_CHANGED = 'cnpc',
|
||||
MSG_CONTROLLER_VOLUME_CHANGED = 'cnvc'
|
||||
MSG_CONTROLLER_VOLUME_CHANGED = 'cnvc',
|
||||
MSG_CONTROLLER_MUTED_CHANGED = 'cnmc'
|
||||
};
|
||||
|
||||
enum {
|
||||
@ -57,6 +58,7 @@ class ControllerObserver : public Controller::Listener,
|
||||
virtual void PlaybackStateChanged(uint32 state);
|
||||
virtual void PositionChanged(float position);
|
||||
virtual void VolumeChanged(float volume);
|
||||
virtual void MutedChanged(bool muted);
|
||||
|
||||
private:
|
||||
uint32 fObserveFlags;
|
||||
|
@ -145,7 +145,7 @@ ControllerView::VolumeChanged(float value)
|
||||
void
|
||||
ControllerView::ToggleMute()
|
||||
{
|
||||
printf("ControllerView::ToggleMute()\n");
|
||||
fController->ToggleMute();
|
||||
}
|
||||
|
||||
|
||||
|
@ -36,11 +36,6 @@ public:
|
||||
Playlist* playlist);
|
||||
~ControllerView();
|
||||
|
||||
private:
|
||||
void AttachedToWindow();
|
||||
void MessageReceived(BMessage *msg);
|
||||
void Draw(BRect updateRect);
|
||||
|
||||
// TransportControlGroup interface
|
||||
virtual uint32 EnabledButtons();
|
||||
virtual void TogglePlaying();
|
||||
@ -53,6 +48,11 @@ private:
|
||||
virtual void ToggleMute();
|
||||
virtual void PositionChanged(float value);
|
||||
|
||||
private:
|
||||
void AttachedToWindow();
|
||||
void MessageReceived(BMessage* message);
|
||||
void Draw(BRect updateRect);
|
||||
|
||||
// ControllerView
|
||||
void CheckSkippable();
|
||||
|
||||
|
@ -72,8 +72,8 @@ enum {
|
||||
M_PREFERENCES,
|
||||
M_VOLUME_UP,
|
||||
M_VOLUME_DOWN,
|
||||
M_CHANNEL_NEXT,
|
||||
M_CHANNEL_PREV,
|
||||
M_SKIP_NEXT,
|
||||
M_SKIP_PREV,
|
||||
M_ASPECT_100000_1,
|
||||
M_ASPECT_106666_1,
|
||||
M_ASPECT_109091_1,
|
||||
@ -105,7 +105,8 @@ MainWin::MainWin()
|
||||
, fController(new Controller)
|
||||
, fControllerObserver(new ControllerObserver(this,
|
||||
OBSERVE_FILE_CHANGES | OBSERVE_TRACK_CHANGES
|
||||
| OBSERVE_PLAYBACK_STATE_CHANGES | OBSERVE_POSITION_CHANGES))
|
||||
| OBSERVE_PLAYBACK_STATE_CHANGES | OBSERVE_POSITION_CHANGES
|
||||
| OBSERVE_VOLUME_CHANGES))
|
||||
, fIsFullscreen(false)
|
||||
, fKeepAspectRatio(true)
|
||||
, fAlwaysOnTop(false)
|
||||
@ -168,8 +169,7 @@ MainWin::MainWin()
|
||||
|
||||
// setup the playlist window now, we need to have it
|
||||
// running for the undo/redo playlist editing
|
||||
fPlaylistWindow = new PlaylistWindow(BRect(150, 150, 400, 500),
|
||||
fPlaylist, fController);
|
||||
fPlaylistWindow = new PlaylistWindow(BRect(150, 150, 400, 500), fPlaylist, fController);
|
||||
fPlaylistWindow->Hide();
|
||||
fPlaylistWindow->Show();
|
||||
// this makes sure the window thread is running without
|
||||
@ -315,6 +315,7 @@ MainWin::DispatchMessage(BMessage *msg, BHandler *handler)
|
||||
void
|
||||
MainWin::MessageReceived(BMessage *msg)
|
||||
{
|
||||
// msg->PrintToStream();
|
||||
switch (msg->what) {
|
||||
case B_REFS_RECEIVED:
|
||||
printf("MainWin::MessageReceived: B_REFS_RECEIVED\n");
|
||||
@ -397,6 +398,18 @@ MainWin::MessageReceived(BMessage *msg)
|
||||
fControls->SetPosition(position);
|
||||
break;
|
||||
}
|
||||
case MSG_CONTROLLER_VOLUME_CHANGED: {
|
||||
float volume;
|
||||
if (msg->FindFloat("volume", &volume) == B_OK)
|
||||
fControls->SetVolume(volume);
|
||||
break;
|
||||
}
|
||||
case MSG_CONTROLLER_MUTED_CHANGED: {
|
||||
bool muted;
|
||||
if (msg->FindBool("muted", &muted) == B_OK)
|
||||
fControls->SetMuted(muted);
|
||||
break;
|
||||
}
|
||||
|
||||
// menu item messages
|
||||
case M_FILE_NEWPLAYER:
|
||||
@ -437,32 +450,26 @@ MainWin::MessageReceived(BMessage *msg)
|
||||
|
||||
case M_TOGGLE_FULLSCREEN:
|
||||
_ToggleFullscreen();
|
||||
// fSettingsMenu->ItemAt(1)->SetMarked(fIsFullscreen);
|
||||
break;
|
||||
|
||||
case M_TOGGLE_NO_MENU:
|
||||
_ToggleNoMenu();
|
||||
// fSettingsMenu->ItemAt(3)->SetMarked(fNoMenu);
|
||||
break;
|
||||
|
||||
case M_TOGGLE_NO_CONTROLS:
|
||||
_ToggleNoControls();
|
||||
// fSettingsMenu->ItemAt(3)->SetMarked(fNoControls);
|
||||
break;
|
||||
|
||||
case M_TOGGLE_NO_BORDER:
|
||||
_ToggleNoBorder();
|
||||
// fSettingsMenu->ItemAt(4)->SetMarked(fNoBorder);
|
||||
break;
|
||||
|
||||
case M_TOGGLE_ALWAYS_ON_TOP:
|
||||
_ToggleAlwaysOnTop();
|
||||
// fSettingsMenu->ItemAt(5)->SetMarked(fAlwaysOnTop);
|
||||
break;
|
||||
|
||||
case M_TOGGLE_KEEP_ASPECT_RATIO:
|
||||
_ToggleKeepAspectRatio();
|
||||
// fSettingsMenu->ItemAt(6)->SetMarked(fKeepAspectRatio);
|
||||
break;
|
||||
|
||||
case M_TOGGLE_NO_BORDER_NO_MENU_NO_CONTROLS:
|
||||
@ -527,47 +534,28 @@ MainWin::MessageReceived(BMessage *msg)
|
||||
float dx = msg->FindFloat("be:wheel_delta_x");
|
||||
float dy = msg->FindFloat("be:wheel_delta_y");
|
||||
bool inv = modifiers() & B_COMMAND_KEY;
|
||||
if (dx > 0.1) PostMessage(inv ? M_VOLUME_DOWN : M_CHANNEL_PREV);
|
||||
if (dx < -0.1) PostMessage(inv ? M_VOLUME_UP : M_CHANNEL_NEXT);
|
||||
if (dy > 0.1) PostMessage(inv ? M_CHANNEL_PREV : M_VOLUME_DOWN);
|
||||
if (dy < -0.1) PostMessage(inv ? M_CHANNEL_NEXT : M_VOLUME_UP);
|
||||
if (dx > 0.1) PostMessage(inv ? M_VOLUME_DOWN : M_SKIP_PREV);
|
||||
if (dx < -0.1) PostMessage(inv ? M_VOLUME_UP : M_SKIP_NEXT);
|
||||
if (dy > 0.1) PostMessage(inv ? M_SKIP_PREV : M_VOLUME_DOWN);
|
||||
if (dy < -0.1) PostMessage(inv ? M_SKIP_NEXT : M_VOLUME_UP);
|
||||
break;
|
||||
}
|
||||
*/
|
||||
case M_SKIP_NEXT:
|
||||
fControls->SkipForward();
|
||||
break;
|
||||
|
||||
case M_CHANNEL_NEXT:
|
||||
{
|
||||
printf("M_CHANNEL_NEXT\n");
|
||||
int chan = fController->CurrentChannel();
|
||||
if (chan != -1) {
|
||||
chan++;
|
||||
if (chan < fController->ChannelCount())
|
||||
SelectChannel(chan);
|
||||
}
|
||||
case M_SKIP_PREV:
|
||||
fControls->SkipBackward();
|
||||
break;
|
||||
}
|
||||
|
||||
case M_CHANNEL_PREV:
|
||||
{
|
||||
printf("M_CHANNEL_PREV\n");
|
||||
int chan = fController->CurrentChannel();
|
||||
if (chan != -1) {
|
||||
chan--;
|
||||
if (chan >= 0)
|
||||
SelectChannel(chan);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case M_VOLUME_UP:
|
||||
printf("M_VOLUME_UP\n");
|
||||
fController->VolumeUp();
|
||||
break;
|
||||
|
||||
case M_VOLUME_DOWN:
|
||||
printf("M_VOLUME_DOWN\n");
|
||||
fController->VolumeDown();
|
||||
break;
|
||||
*/
|
||||
|
||||
case M_ASPECT_100000_1:
|
||||
VideoFormatChange(fSourceWidth, fSourceHeight, 1.0, 1.0);
|
||||
@ -1145,7 +1133,7 @@ MainWin::_KeyDown(BMessage *msg)
|
||||
|
||||
case B_UP_ARROW:
|
||||
if (modifiers & B_COMMAND_KEY) {
|
||||
PostMessage(M_CHANNEL_NEXT);
|
||||
PostMessage(M_SKIP_NEXT);
|
||||
} else {
|
||||
PostMessage(M_VOLUME_UP);
|
||||
}
|
||||
@ -1153,7 +1141,7 @@ MainWin::_KeyDown(BMessage *msg)
|
||||
|
||||
case B_DOWN_ARROW:
|
||||
if (modifiers & B_COMMAND_KEY) {
|
||||
PostMessage(M_CHANNEL_PREV);
|
||||
PostMessage(M_SKIP_PREV);
|
||||
} else {
|
||||
PostMessage(M_VOLUME_DOWN);
|
||||
}
|
||||
@ -1163,7 +1151,7 @@ MainWin::_KeyDown(BMessage *msg)
|
||||
if (modifiers & B_COMMAND_KEY) {
|
||||
PostMessage(M_VOLUME_UP);
|
||||
} else {
|
||||
PostMessage(M_CHANNEL_NEXT);
|
||||
PostMessage(M_SKIP_NEXT);
|
||||
}
|
||||
return B_OK;
|
||||
|
||||
@ -1171,16 +1159,16 @@ MainWin::_KeyDown(BMessage *msg)
|
||||
if (modifiers & B_COMMAND_KEY) {
|
||||
PostMessage(M_VOLUME_DOWN);
|
||||
} else {
|
||||
PostMessage(M_CHANNEL_PREV);
|
||||
PostMessage(M_SKIP_PREV);
|
||||
}
|
||||
return B_OK;
|
||||
|
||||
case B_PAGE_UP:
|
||||
PostMessage(M_CHANNEL_NEXT);
|
||||
PostMessage(M_SKIP_NEXT);
|
||||
return B_OK;
|
||||
|
||||
case B_PAGE_DOWN:
|
||||
PostMessage(M_CHANNEL_PREV);
|
||||
PostMessage(M_SKIP_PREV);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
@ -1213,12 +1201,12 @@ MainWin::_KeyDown(BMessage *msg)
|
||||
|
||||
case 0x39: // numeric keypad page up
|
||||
case 0x4a: // numeric keypad right arrow
|
||||
PostMessage(M_CHANNEL_NEXT);
|
||||
PostMessage(M_SKIP_NEXT);
|
||||
return B_OK;
|
||||
|
||||
case 0x5a: // numeric keypad page down
|
||||
case 0x48: // numeric keypad left arrow
|
||||
PostMessage(M_CHANNEL_PREV);
|
||||
PostMessage(M_SKIP_PREV);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
@ -1281,6 +1269,8 @@ MainWin::_ToggleFullscreen()
|
||||
Show();
|
||||
}
|
||||
|
||||
_MarkSettingsItem(M_TOGGLE_FULLSCREEN, fIsFullscreen);
|
||||
|
||||
printf("_ToggleFullscreen leave\n");
|
||||
}
|
||||
|
||||
@ -1304,6 +1294,8 @@ MainWin::_ToggleNoControls()
|
||||
ResizeBy(0, fControlsHeight);
|
||||
}
|
||||
|
||||
_MarkSettingsItem(M_TOGGLE_NO_CONTROLS, fNoControls);
|
||||
|
||||
printf("_ToggleNoControls leave\n");
|
||||
}
|
||||
|
||||
@ -1329,6 +1321,8 @@ MainWin::_ToggleNoMenu()
|
||||
ResizeBy(0, fMenuBarHeight);
|
||||
}
|
||||
|
||||
_MarkSettingsItem(M_TOGGLE_NO_MENU, fNoMenu);
|
||||
|
||||
printf("_ToggleNoMenu leave\n");
|
||||
}
|
||||
|
||||
@ -1336,30 +1330,30 @@ MainWin::_ToggleNoMenu()
|
||||
void
|
||||
MainWin::_ToggleNoBorder()
|
||||
{
|
||||
printf("_ToggleNoBorder enter\n");
|
||||
fNoBorder = !fNoBorder;
|
||||
SetLook(fNoBorder ? B_BORDERED_WINDOW_LOOK : B_TITLED_WINDOW_LOOK);
|
||||
printf("_ToggleNoBorder leave\n");
|
||||
|
||||
_MarkSettingsItem(M_TOGGLE_NO_BORDER, fNoBorder);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MainWin::_ToggleAlwaysOnTop()
|
||||
{
|
||||
printf("_ToggleAlwaysOnTop enter\n");
|
||||
fAlwaysOnTop = !fAlwaysOnTop;
|
||||
SetFeel(fAlwaysOnTop ? B_FLOATING_ALL_WINDOW_FEEL : B_NORMAL_WINDOW_FEEL);
|
||||
printf("_ToggleAlwaysOnTop leave\n");
|
||||
|
||||
_MarkSettingsItem(M_TOGGLE_ALWAYS_ON_TOP, fAlwaysOnTop);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MainWin::_ToggleKeepAspectRatio()
|
||||
{
|
||||
printf("_ToggleKeepAspectRatio enter\n");
|
||||
fKeepAspectRatio = !fKeepAspectRatio;
|
||||
FrameResized(Bounds().Width(), Bounds().Height());
|
||||
printf("_ToggleKeepAspectRatio leave\n");
|
||||
|
||||
_MarkSettingsItem(M_TOGGLE_KEEP_ASPECT_RATIO, fKeepAspectRatio);
|
||||
}
|
||||
|
||||
|
||||
@ -1442,3 +1436,11 @@ MainWin::_MarkPlaylistItem(int32 index)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MainWin::_MarkSettingsItem(uint32 command, bool mark)
|
||||
{
|
||||
if (BMenuItem* item = fSettingsMenu->FindItem(command))
|
||||
item->SetMarked(mark);
|
||||
}
|
||||
|
||||
|
||||
|
@ -91,6 +91,7 @@ private:
|
||||
int32 index);
|
||||
void _RemovePlaylistItem(int32 index);
|
||||
void _MarkPlaylistItem(int32 index);
|
||||
void _MarkSettingsItem(uint32 command, bool mark);
|
||||
|
||||
BMenuBar* fMenuBar;
|
||||
BView* fBackground;
|
||||
|
@ -429,13 +429,12 @@ TransportControlGroup::SetMuted(bool mute)
|
||||
void
|
||||
TransportControlGroup::SetVolume(float value)
|
||||
{
|
||||
if (B_OK != LockLooperWithTimeout(50000))
|
||||
return;
|
||||
float db = _GainToDb(value);
|
||||
float exponential = _LinearToExponential(db);
|
||||
float gain = _DbToGain(exponential);
|
||||
int32 pos = (int32)(floorf(gain * kVolumeFactor + 0.5));
|
||||
|
||||
fVolumeSlider->SetValue(_DbToGain(_ExponentialToLinear(
|
||||
_GainToDb(value))) * kVolumeFactor);
|
||||
|
||||
UnlockLooper();
|
||||
fVolumeSlider->SetValueNoInvoke(pos);
|
||||
}
|
||||
|
||||
|
||||
|
@ -90,6 +90,16 @@ VolumeSlider::SetValue(int32 value)
|
||||
Invoke();
|
||||
}
|
||||
|
||||
// SetValueNoInvoke
|
||||
void
|
||||
VolumeSlider::SetValueNoInvoke(int32 value)
|
||||
{
|
||||
if (value == Value())
|
||||
return;
|
||||
|
||||
BControl::SetValue(value);
|
||||
}
|
||||
|
||||
// SetEnabled
|
||||
void
|
||||
VolumeSlider::SetEnabled(bool enable)
|
||||
|
@ -25,6 +25,7 @@ class VolumeSlider : public BControl {
|
||||
// BControl
|
||||
virtual void AttachedToWindow();
|
||||
virtual void SetValue(int32 value);
|
||||
void SetValueNoInvoke(int32 value);
|
||||
virtual void SetEnabled(bool enable);
|
||||
virtual void Draw(BRect updateRect);
|
||||
virtual void MouseDown(BPoint where);
|
||||
|
Loading…
Reference in New Issue
Block a user