* Changed ContinuousMessageFilter to register for parameter value changes,
and change its slider value when such a message arrives. * Currently, this will only work if such a view already received a message; added a TODO about how it should be done, but since those would require some more changes, I don't want to do that as long as Sean Healy is working on that file. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30083 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,28 +1,29 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2003-2007, Axel Dörfler, [email protected]. All rights reserved.
|
* Copyright 2003-2009, Axel Dörfler, [email protected].
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "DefaultMediaTheme.h"
|
#include "DefaultMediaTheme.h"
|
||||||
#include "debug.h"
|
|
||||||
|
|
||||||
#include <ParameterWeb.h>
|
|
||||||
|
|
||||||
#include <Slider.h>
|
|
||||||
#include <ScrollBar.h>
|
|
||||||
#include <StringView.h>
|
|
||||||
#include <Button.h>
|
|
||||||
#include <TextControl.h>
|
|
||||||
#include <OptionPopUp.h>
|
|
||||||
#include <ChannelSlider.h>
|
|
||||||
#include <Box.h>
|
#include <Box.h>
|
||||||
|
#include <Button.h>
|
||||||
|
#include <ChannelSlider.h>
|
||||||
#include <CheckBox.h>
|
#include <CheckBox.h>
|
||||||
#include <TabView.h>
|
#include <MediaRoster.h>
|
||||||
#include <MenuField.h>
|
#include <MenuField.h>
|
||||||
#include <MessageFilter.h>
|
#include <MessageFilter.h>
|
||||||
|
#include <OptionPopUp.h>
|
||||||
|
#include <ParameterWeb.h>
|
||||||
|
#include <ScrollBar.h>
|
||||||
|
#include <Slider.h>
|
||||||
|
#include <StringView.h>
|
||||||
|
#include <TabView.h>
|
||||||
|
#include <TextControl.h>
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
|
|
||||||
using namespace BPrivate;
|
using namespace BPrivate;
|
||||||
|
|
||||||
@@ -121,7 +122,11 @@ class ContinuousMessageFilter : public MessageFilter {
|
|||||||
virtual filter_result Filter(BMessage *message, BHandler **target);
|
virtual filter_result Filter(BMessage *message, BHandler **target);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void _UpdateControl();
|
||||||
|
|
||||||
|
BControl *fControl;
|
||||||
BContinuousParameter &fParameter;
|
BContinuousParameter &fParameter;
|
||||||
|
bool fRegistered;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DiscreteMessageFilter : public MessageFilter {
|
class DiscreteMessageFilter : public MessageFilter {
|
||||||
@@ -588,33 +593,22 @@ MessageFilter::FilterFor(BView *view, BParameter ¶meter)
|
|||||||
ContinuousMessageFilter::ContinuousMessageFilter(BControl *control,
|
ContinuousMessageFilter::ContinuousMessageFilter(BControl *control,
|
||||||
BContinuousParameter ¶meter)
|
BContinuousParameter ¶meter)
|
||||||
: MessageFilter(),
|
: MessageFilter(),
|
||||||
fParameter(parameter)
|
fControl(control),
|
||||||
|
fParameter(parameter),
|
||||||
|
fRegistered(false)
|
||||||
{
|
{
|
||||||
// initialize view for us
|
// initialize view for us
|
||||||
control->SetMessage(new BMessage(kMsgParameterChanged));
|
control->SetMessage(new BMessage(kMsgParameterChanged));
|
||||||
|
|
||||||
// set initial value
|
if (BSlider *slider = dynamic_cast<BSlider *>(fControl))
|
||||||
// ToDo: response support!
|
|
||||||
|
|
||||||
float value[fParameter.CountChannels()];
|
|
||||||
size_t size = sizeof(value);
|
|
||||||
if (parameter.GetValue((void *)&value, &size, NULL) < B_OK) {
|
|
||||||
ERROR("ContinuousMessageFilter: Could not get value for continuous "
|
|
||||||
"parameter %p (name '%s', node %d)\n", ¶meter,
|
|
||||||
parameter.Name(), (int)(parameter.Web()->Node().node));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (BSlider *slider = dynamic_cast<BSlider *>(control)) {
|
|
||||||
slider->SetValue((int32) (1000 * value[0]));
|
|
||||||
slider->SetModificationMessage(new BMessage(kMsgParameterChanged));
|
slider->SetModificationMessage(new BMessage(kMsgParameterChanged));
|
||||||
} else if (BChannelSlider *slider = dynamic_cast<BChannelSlider *>(control)) {
|
else if (BChannelSlider *slider = dynamic_cast<BChannelSlider *>(fControl))
|
||||||
for (int32 i = 0; i < fParameter.CountChannels(); i++)
|
|
||||||
slider->SetValueFor(i, (int32) (1000 * value[i]));
|
|
||||||
|
|
||||||
slider->SetModificationMessage(new BMessage(kMsgParameterChanged));
|
slider->SetModificationMessage(new BMessage(kMsgParameterChanged));
|
||||||
} else
|
else
|
||||||
ERROR("ContinuousMessageFilter: unknown continuous parameter view\n");
|
ERROR("ContinuousMessageFilter: unknown continuous parameter view\n");
|
||||||
|
|
||||||
|
// set initial value
|
||||||
|
_UpdateControl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -626,32 +620,87 @@ ContinuousMessageFilter::~ContinuousMessageFilter()
|
|||||||
filter_result
|
filter_result
|
||||||
ContinuousMessageFilter::Filter(BMessage *message, BHandler **target)
|
ContinuousMessageFilter::Filter(BMessage *message, BHandler **target)
|
||||||
{
|
{
|
||||||
BControl *control;
|
if (*target != fControl)
|
||||||
|
|
||||||
if (message->what != kMsgParameterChanged
|
|
||||||
|| (control = dynamic_cast<BControl *>(*target)) == NULL)
|
|
||||||
return B_DISPATCH_MESSAGE;
|
return B_DISPATCH_MESSAGE;
|
||||||
|
|
||||||
// update view
|
// TODO: remove this work-around! We can solve this by subclassing the
|
||||||
// ToDo: support for response!
|
// slider classes, and start watching in their AttachedToWindow() method
|
||||||
|
if (!fRegistered) {
|
||||||
|
if (BMediaRoster* roster = BMediaRoster::CurrentRoster()) {
|
||||||
|
roster->StartWatching(fControl, fParameter.Web()->Node(),
|
||||||
|
B_MEDIA_NEW_PARAMETER_VALUE);
|
||||||
|
}
|
||||||
|
fRegistered = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (message->what == kMsgParameterChanged) {
|
||||||
|
// update parameter from control
|
||||||
|
// TODO: support for response!
|
||||||
|
|
||||||
|
float value[fParameter.CountChannels()];
|
||||||
|
|
||||||
|
if (BSlider *slider = dynamic_cast<BSlider *>(fControl)) {
|
||||||
|
value[0] = (float)(slider->Value() / 1000.0);
|
||||||
|
} else if (BChannelSlider *slider
|
||||||
|
= dynamic_cast<BChannelSlider *>(fControl)) {
|
||||||
|
for (int32 i = 0; i < fParameter.CountChannels(); i++)
|
||||||
|
value[i] = (float)(slider->ValueFor(i) / 1000.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TRACE("ContinuousMessageFilter::Filter: update view %s, %ld "
|
||||||
|
"channels\n", control->Name(), fParameter.CountChannels());
|
||||||
|
|
||||||
|
if (fParameter.SetValue((void *)value, sizeof(value),
|
||||||
|
system_time()) < B_OK) {
|
||||||
|
ERROR("ContinuousMessageFilter::Filter: Could not set parameter "
|
||||||
|
"value for %p\n", &fParameter);
|
||||||
|
return B_DISPATCH_MESSAGE;
|
||||||
|
}
|
||||||
|
return B_SKIP_MESSAGE;
|
||||||
|
}
|
||||||
|
if (message->what == B_MEDIA_NEW_PARAMETER_VALUE) {
|
||||||
|
// update view from parameter -- if the message concerns us
|
||||||
|
const media_node* node;
|
||||||
|
int32 parameterID;
|
||||||
|
ssize_t size;
|
||||||
|
if (message->FindInt32("parameter", ¶meterID) != B_OK
|
||||||
|
|| fParameter.ID() != parameterID
|
||||||
|
|| message->FindData("node", B_RAW_TYPE, (const void**)&node,
|
||||||
|
&size) != B_OK
|
||||||
|
|| fParameter.Web()->Node() != *node)
|
||||||
|
return B_DISPATCH_MESSAGE;
|
||||||
|
|
||||||
|
_UpdateControl();
|
||||||
|
return B_SKIP_MESSAGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return B_DISPATCH_MESSAGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ContinuousMessageFilter::_UpdateControl()
|
||||||
|
{
|
||||||
|
// TODO: response support!
|
||||||
|
|
||||||
float value[fParameter.CountChannels()];
|
float value[fParameter.CountChannels()];
|
||||||
|
size_t size = sizeof(value);
|
||||||
if (BSlider *slider = dynamic_cast<BSlider *>(control)) {
|
if (fParameter.GetValue((void *)&value, &size, NULL) < B_OK) {
|
||||||
value[0] = (float)(slider->Value() / 1000.0);
|
ERROR("ContinuousMessageFilter: Could not get value for continuous "
|
||||||
} else if (BChannelSlider *slider = dynamic_cast<BChannelSlider *>(control)) {
|
"parameter %p (name '%s', node %d)\n", &fParameter,
|
||||||
for (int32 i = 0; i < fParameter.CountChannels(); i++)
|
fParameter.Name(), (int)fParameter.Web()->Node().node);
|
||||||
value[i] = (float)(slider->ValueFor(i) / 1000.0);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
TRACE("ContinuousMessageFilter::Filter: update view %s, %ld channels\n", control->Name(), fParameter.CountChannels());
|
if (BSlider *slider = dynamic_cast<BSlider *>(fControl)) {
|
||||||
|
slider->SetValue((int32) (1000 * value[0]));
|
||||||
if (fParameter.SetValue((void *)value, sizeof(value), system_time()) < B_OK) {
|
slider->SetModificationMessage(new BMessage(kMsgParameterChanged));
|
||||||
ERROR("ContinuousMessageFilter::Filter: Could not set parameter value for %p\n", &fParameter);
|
} else if (BChannelSlider *slider
|
||||||
return B_DISPATCH_MESSAGE;
|
= dynamic_cast<BChannelSlider *>(fControl)) {
|
||||||
|
for (int32 i = 0; i < fParameter.CountChannels(); i++) {
|
||||||
|
slider->SetValueFor(i, (int32) (1000 * value[i]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_SKIP_MESSAGE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user