xref: /haiku/src/kits/interface/ChannelControl.cpp (revision 0b421b8025a1da938c3689ae67c58d5a58c8542f)
108c97b50SAxel Dörfler /*
21f424632SJohn Scipione  * Copyright 2005-2014 Haiku Inc. All rights reserved.
308c97b50SAxel Dörfler  * Distributed under the terms of the MIT License.
408c97b50SAxel Dörfler  */
508c97b50SAxel Dörfler 
608c97b50SAxel Dörfler 
708c97b50SAxel Dörfler #include <ChannelControl.h>
8976f53a9SStefano Ceccherini #include <PropertyInfo.h>
9976f53a9SStefano Ceccherini 
10*0b421b80SStefano Ceccherini #include <map>
11*0b421b80SStefano Ceccherini #include <string>
12*0b421b80SStefano Ceccherini 
13*0b421b80SStefano Ceccherini struct limit_label {
14*0b421b80SStefano Ceccherini 	std::string min_label;
15*0b421b80SStefano Ceccherini 	std::string max_label;
16*0b421b80SStefano Ceccherini };
17*0b421b80SStefano Ceccherini 
18*0b421b80SStefano Ceccherini typedef std::map<int32, limit_label> label_map;
19976f53a9SStefano Ceccherini 
207730601aSStefano Ceccherini static property_info
21976f53a9SStefano Ceccherini sPropertyInfo[] = {
227730601aSStefano Ceccherini 	{ "ChannelCount",
237730601aSStefano Ceccherini 		{ B_GET_PROPERTY, B_SET_PROPERTY, 0 },
24f4fc3d62SJérôme Duval 		{ B_DIRECT_SPECIFIER, 0 }, NULL, 0, { B_INT32_TYPE }
25f4fc3d62SJérôme Duval 	},
267730601aSStefano Ceccherini 
277730601aSStefano Ceccherini 	{ "CurrentChannel",
287730601aSStefano Ceccherini 		{ B_GET_PROPERTY, B_SET_PROPERTY, 0 },
29f4fc3d62SJérôme Duval 		{ B_DIRECT_SPECIFIER, 0 }, NULL, 0, { B_INT32_TYPE }
30f4fc3d62SJérôme Duval 	},
317730601aSStefano Ceccherini 
327730601aSStefano Ceccherini 	{ "MaxLimitLabel",
337730601aSStefano Ceccherini 		{ B_GET_PROPERTY, B_SET_PROPERTY, 0 },
34f4fc3d62SJérôme Duval 		{ B_DIRECT_SPECIFIER, 0 }, NULL, 0, { B_STRING_TYPE }
35f4fc3d62SJérôme Duval 	},
367730601aSStefano Ceccherini 
377730601aSStefano Ceccherini 	{ "MinLimitLabel",
387730601aSStefano Ceccherini 		{ B_GET_PROPERTY, B_SET_PROPERTY, 0 },
39f4fc3d62SJérôme Duval 		{ B_DIRECT_SPECIFIER, 0 }, NULL, 0, { B_STRING_TYPE }
40f4fc3d62SJérôme Duval 	},
417730601aSStefano Ceccherini 
42976f53a9SStefano Ceccherini 	{ 0 }
43976f53a9SStefano Ceccherini };
4408c97b50SAxel Dörfler 
4508c97b50SAxel Dörfler 
BChannelControl(BRect frame,const char * name,const char * label,BMessage * model,int32 channel_count,uint32 resizingMode,uint32 flags)461f424632SJohn Scipione BChannelControl::BChannelControl(BRect frame, const char* name,
471f424632SJohn Scipione 	const char* label, BMessage* model, int32 channel_count,
481f424632SJohn Scipione 	uint32 resizingMode, uint32 flags)
491f424632SJohn Scipione 	:
501f424632SJohn Scipione 	BControl(frame, name, label, model, resizingMode, flags),
51422c0791SStefano Ceccherini 	fChannelCount(channel_count),
52422c0791SStefano Ceccherini 	fCurrentChannel(0),
53422c0791SStefano Ceccherini 	fChannelMin(NULL),
54422c0791SStefano Ceccherini 	fChannelMax(NULL),
55422c0791SStefano Ceccherini 	fChannelValues(NULL),
56422c0791SStefano Ceccherini 	fMultiLabels(NULL),
571c3a6ab0SStefano Ceccherini 	fModificationMsg(NULL)
5808c97b50SAxel Dörfler {
59422c0791SStefano Ceccherini 	fChannelMin = new int32[channel_count];
60422c0791SStefano Ceccherini 	memset(fChannelMin, 0, sizeof(int32) * channel_count);
611c3a6ab0SStefano Ceccherini 
62422c0791SStefano Ceccherini 	fChannelMax = new int32[channel_count];
6320c7c2f9SStefano Ceccherini 	for (int32 i = 0; i < channel_count; i++)
6420c7c2f9SStefano Ceccherini 		fChannelMax[i] = 100;
651c3a6ab0SStefano Ceccherini 
66422c0791SStefano Ceccherini 	fChannelValues = new int32[channel_count];
67422c0791SStefano Ceccherini 	memset(fChannelValues, 0, sizeof(int32) * channel_count);
68*0b421b80SStefano Ceccherini 
69*0b421b80SStefano Ceccherini 	fMultiLabels = (void*)new label_map;
7008c97b50SAxel Dörfler }
7108c97b50SAxel Dörfler 
7208c97b50SAxel Dörfler 
BChannelControl(const char * name,const char * label,BMessage * model,int32 channelCount,uint32 flags)73a0b1d631SStephan Aßmus BChannelControl::BChannelControl(const char* name, const char* label,
741f424632SJohn Scipione 	BMessage* model, int32 channelCount, uint32 flags)
751f424632SJohn Scipione 	:
761f424632SJohn Scipione 	BControl(name, label, model, flags),
771f424632SJohn Scipione 	fChannelCount(channelCount),
78a0b1d631SStephan Aßmus 	fCurrentChannel(0),
79a0b1d631SStephan Aßmus 	fChannelMin(NULL),
80a0b1d631SStephan Aßmus 	fChannelMax(NULL),
81a0b1d631SStephan Aßmus 	fChannelValues(NULL),
82a0b1d631SStephan Aßmus 	fMultiLabels(NULL),
83a0b1d631SStephan Aßmus 	fModificationMsg(NULL)
84a0b1d631SStephan Aßmus {
851f424632SJohn Scipione 	fChannelMin = new int32[channelCount];
861f424632SJohn Scipione 	memset(fChannelMin, 0, sizeof(int32) * channelCount);
87a0b1d631SStephan Aßmus 
881f424632SJohn Scipione 	fChannelMax = new int32[channelCount];
891f424632SJohn Scipione 	for (int32 i = 0; i < channelCount; i++)
90a0b1d631SStephan Aßmus 		fChannelMax[i] = 100;
91a0b1d631SStephan Aßmus 
921f424632SJohn Scipione 	fChannelValues = new int32[channelCount];
931f424632SJohn Scipione 	memset(fChannelValues, 0, sizeof(int32) * channelCount);
94*0b421b80SStefano Ceccherini 
95*0b421b80SStefano Ceccherini 	fMultiLabels = (void*)new label_map;
96a0b1d631SStephan Aßmus }
97a0b1d631SStephan Aßmus 
98a0b1d631SStephan Aßmus 
BChannelControl(BMessage * archive)9908c97b50SAxel Dörfler BChannelControl::BChannelControl(BMessage* archive)
1001f424632SJohn Scipione 	:
1011f424632SJohn Scipione 	BControl(archive),
102016e74b2SStefano Ceccherini 	fChannelCount(0),
103016e74b2SStefano Ceccherini 	fCurrentChannel(0),
104016e74b2SStefano Ceccherini 	fChannelMin(NULL),
105016e74b2SStefano Ceccherini 	fChannelMax(NULL),
106016e74b2SStefano Ceccherini 	fChannelValues(NULL),
107016e74b2SStefano Ceccherini 	fMultiLabels(NULL),
108016e74b2SStefano Ceccherini 	fModificationMsg(NULL)
10908c97b50SAxel Dörfler {
110016e74b2SStefano Ceccherini 	archive->FindInt32("be:_m_channel_count", &fChannelCount);
111016e74b2SStefano Ceccherini 	archive->FindInt32("be:_m_value_channel", &fCurrentChannel);
112016e74b2SStefano Ceccherini 
113016e74b2SStefano Ceccherini 	if (fChannelCount > 0) {
114016e74b2SStefano Ceccherini 		fChannelMin = new int32[fChannelCount];
115016e74b2SStefano Ceccherini 		memset(fChannelMin, 0, sizeof(int32) * fChannelCount);
116016e74b2SStefano Ceccherini 
117016e74b2SStefano Ceccherini 		fChannelMax = new int32[fChannelCount];
118a85419eeSStefano Ceccherini 		for (int32 i = 0; i < fChannelCount; i++)
119a85419eeSStefano Ceccherini 			fChannelMax[i] = 100;
120016e74b2SStefano Ceccherini 
121016e74b2SStefano Ceccherini 		fChannelValues = new int32[fChannelCount];
122016e74b2SStefano Ceccherini 		memset(fChannelValues, 0, sizeof(int32) * fChannelCount);
123016e74b2SStefano Ceccherini 
124016e74b2SStefano Ceccherini 		for (int32 c = 0; c < fChannelCount; c++) {
125016e74b2SStefano Ceccherini 			archive->FindInt32("be:_m_channel_min", c, &fChannelMin[c]);
126016e74b2SStefano Ceccherini 			archive->FindInt32("be:_m_channel_max", c, &fChannelMax[c]);
127016e74b2SStefano Ceccherini 			archive->FindInt32("be:_m_channel_val", c, &fChannelValues[c]);
128016e74b2SStefano Ceccherini 		}
129016e74b2SStefano Ceccherini 	}
130016e74b2SStefano Ceccherini 
131016e74b2SStefano Ceccherini 	const char* label = NULL;
132a85419eeSStefano Ceccherini 	if (archive->FindString("be:_m_min_label", &label) == B_OK)
133016e74b2SStefano Ceccherini 		fMinLabel = label;
1341f424632SJohn Scipione 
135016e74b2SStefano Ceccherini 	if (archive->FindString("be:_m_max_label", &label) == B_OK)
136016e74b2SStefano Ceccherini 		fMaxLabel = label;
137016e74b2SStefano Ceccherini 
138016e74b2SStefano Ceccherini 	BMessage* modificationMessage = new BMessage;
139016e74b2SStefano Ceccherini 	if (archive->FindMessage("_mod_msg", modificationMessage) == B_OK)
140016e74b2SStefano Ceccherini 		fModificationMsg = modificationMessage;
141016e74b2SStefano Ceccherini 	else
142016e74b2SStefano Ceccherini 		delete modificationMessage;
143*0b421b80SStefano Ceccherini 
144*0b421b80SStefano Ceccherini 	fMultiLabels = (void*)new label_map;
14508c97b50SAxel Dörfler }
14608c97b50SAxel Dörfler 
14708c97b50SAxel Dörfler 
~BChannelControl()14808c97b50SAxel Dörfler BChannelControl::~BChannelControl()
14908c97b50SAxel Dörfler {
150422c0791SStefano Ceccherini 	delete[] fChannelMin;
151422c0791SStefano Ceccherini 	delete[] fChannelMax;
152422c0791SStefano Ceccherini 	delete[] fChannelValues;
153016e74b2SStefano Ceccherini 	delete fModificationMsg;
154*0b421b80SStefano Ceccherini 	delete reinterpret_cast<label_map*>(fMultiLabels);
15508c97b50SAxel Dörfler }
15608c97b50SAxel Dörfler 
15708c97b50SAxel Dörfler 
15808c97b50SAxel Dörfler status_t
Archive(BMessage * data,bool deep) const1591f424632SJohn Scipione BChannelControl::Archive(BMessage* data, bool deep) const
16008c97b50SAxel Dörfler {
1611f424632SJohn Scipione 	status_t status = BControl::Archive(data, deep);
162016e74b2SStefano Ceccherini 	if (status == B_OK)
1631f424632SJohn Scipione 		status = data->AddInt32("be:_m_channel_count", fChannelCount);
1641f424632SJohn Scipione 
1652c323083SStefano Ceccherini 	if (status == B_OK)
1661f424632SJohn Scipione 		status = data->AddInt32("be:_m_value_channel", fCurrentChannel);
1671f424632SJohn Scipione 
1682c323083SStefano Ceccherini 	if (status == B_OK)
1691f424632SJohn Scipione 		status = data->AddString("be:_m_min_label", fMinLabel.String());
1701f424632SJohn Scipione 
1712c323083SStefano Ceccherini 	if (status == B_OK)
1721f424632SJohn Scipione 		status = data->AddString("be:_m_max_label", fMaxLabel.String());
1732c323083SStefano Ceccherini 
1742c323083SStefano Ceccherini 	if (status == B_OK && fChannelValues != NULL
1752c323083SStefano Ceccherini 		&& fChannelMax != NULL && fChannelMin != NULL) {
1762c323083SStefano Ceccherini 		for (int32 i = 0; i < fChannelCount; i++) {
1771f424632SJohn Scipione 			status = data->AddInt32("be:_m_channel_min", fChannelMin[i]);
1782c323083SStefano Ceccherini 			if (status < B_OK)
1792c323083SStefano Ceccherini 				break;
1801f424632SJohn Scipione 
1811f424632SJohn Scipione 			status = data->AddInt32("be:_m_channel_max", fChannelMax[i]);
1822c323083SStefano Ceccherini 			if (status < B_OK)
1832c323083SStefano Ceccherini 				break;
1841f424632SJohn Scipione 
1851f424632SJohn Scipione 			status = data->AddInt32("be:_m_channel_val", fChannelValues[i]);
1862c323083SStefano Ceccherini 			if (status < B_OK)
1872c323083SStefano Ceccherini 				break;
1882c323083SStefano Ceccherini 		}
1892c323083SStefano Ceccherini 	}
1902c323083SStefano Ceccherini 
1912c323083SStefano Ceccherini 	return status;
19208c97b50SAxel Dörfler }
19308c97b50SAxel Dörfler 
19408c97b50SAxel Dörfler 
19508c97b50SAxel Dörfler void
FrameResized(float newWidth,float newHeight)1961f424632SJohn Scipione BChannelControl::FrameResized(float newWidth, float newHeight)
19708c97b50SAxel Dörfler {
1981f424632SJohn Scipione 	BView::FrameResized(newWidth, newHeight);
19908c97b50SAxel Dörfler }
20008c97b50SAxel Dörfler 
20108c97b50SAxel Dörfler 
20208c97b50SAxel Dörfler void
SetFont(const BFont * font,uint32 mask)20308c97b50SAxel Dörfler BChannelControl::SetFont(const BFont* font, uint32 mask)
20408c97b50SAxel Dörfler {
2051c3a6ab0SStefano Ceccherini 	BView::SetFont(font, mask);
20608c97b50SAxel Dörfler }
20708c97b50SAxel Dörfler 
20808c97b50SAxel Dörfler 
20908c97b50SAxel Dörfler void
AttachedToWindow()21008c97b50SAxel Dörfler BChannelControl::AttachedToWindow()
21108c97b50SAxel Dörfler {
2121c3a6ab0SStefano Ceccherini 	BControl::AttachedToWindow();
21308c97b50SAxel Dörfler }
21408c97b50SAxel Dörfler 
21508c97b50SAxel Dörfler 
21608c97b50SAxel Dörfler void
DetachedFromWindow()21708c97b50SAxel Dörfler BChannelControl::DetachedFromWindow()
21808c97b50SAxel Dörfler {
2191c3a6ab0SStefano Ceccherini 	BControl::DetachedFromWindow();
22008c97b50SAxel Dörfler }
22108c97b50SAxel Dörfler 
22208c97b50SAxel Dörfler 
22308c97b50SAxel Dörfler void
ResizeToPreferred()22408c97b50SAxel Dörfler BChannelControl::ResizeToPreferred()
22508c97b50SAxel Dörfler {
22624ab95eeSJérôme Duval 	BControl::ResizeToPreferred();
22708c97b50SAxel Dörfler }
22808c97b50SAxel Dörfler 
22908c97b50SAxel Dörfler 
23008c97b50SAxel Dörfler void
MessageReceived(BMessage * message)23108c97b50SAxel Dörfler BChannelControl::MessageReceived(BMessage* message)
23208c97b50SAxel Dörfler {
2331c3a6ab0SStefano Ceccherini 	BControl::MessageReceived(message);
23408c97b50SAxel Dörfler }
23508c97b50SAxel Dörfler 
23608c97b50SAxel Dörfler 
23708c97b50SAxel Dörfler BHandler*
ResolveSpecifier(BMessage * message,int32 index,BMessage * specifier,int32 what,const char * property)2381f424632SJohn Scipione BChannelControl::ResolveSpecifier(BMessage* message, int32 index,
2391f424632SJohn Scipione 	BMessage* specifier, int32 what, const char* property)
24008c97b50SAxel Dörfler {
2412c323083SStefano Ceccherini 	BHandler* target = this;
2422c323083SStefano Ceccherini 	BPropertyInfo propertyInfo(sPropertyInfo);
2431f424632SJohn Scipione 	if (propertyInfo.FindMatch(message, index, specifier, what, property)
2441f424632SJohn Scipione 			< B_OK) {
2451f424632SJohn Scipione 		target = BControl::ResolveSpecifier(message, index, specifier,
2461f424632SJohn Scipione 			what, property);
2471f424632SJohn Scipione 	}
2482c323083SStefano Ceccherini 
2492c323083SStefano Ceccherini 	return target;
25008c97b50SAxel Dörfler }
25108c97b50SAxel Dörfler 
25208c97b50SAxel Dörfler 
25308c97b50SAxel Dörfler status_t
GetSupportedSuites(BMessage * data)25408c97b50SAxel Dörfler BChannelControl::GetSupportedSuites(BMessage* data)
25508c97b50SAxel Dörfler {
256976f53a9SStefano Ceccherini 	if (data == NULL)
257976f53a9SStefano Ceccherini 		return B_BAD_VALUE;
258976f53a9SStefano Ceccherini 
259f4fc3d62SJérôme Duval 	status_t err = data->AddString("suites", "suite/vnd.Be-channel-control");
260976f53a9SStefano Ceccherini 
261976f53a9SStefano Ceccherini 	BPropertyInfo propertyInfo(sPropertyInfo);
262f4fc3d62SJérôme Duval 	if (err == B_OK)
263f4fc3d62SJérôme Duval 		err = data->AddFlat("messages", &propertyInfo);
264976f53a9SStefano Ceccherini 
265f4fc3d62SJérôme Duval 	if (err == B_OK)
266976f53a9SStefano Ceccherini 		return BControl::GetSupportedSuites(data);
2671f424632SJohn Scipione 
268f4fc3d62SJérôme Duval 	return err;
26908c97b50SAxel Dörfler }
27008c97b50SAxel Dörfler 
27108c97b50SAxel Dörfler 
27208c97b50SAxel Dörfler void
SetModificationMessage(BMessage * message)27308c97b50SAxel Dörfler BChannelControl::SetModificationMessage(BMessage* message)
27408c97b50SAxel Dörfler {
2751c3a6ab0SStefano Ceccherini 	delete fModificationMsg;
2761c3a6ab0SStefano Ceccherini 	fModificationMsg = message;
27708c97b50SAxel Dörfler }
27808c97b50SAxel Dörfler 
27908c97b50SAxel Dörfler 
28008c97b50SAxel Dörfler BMessage*
ModificationMessage() const28108c97b50SAxel Dörfler BChannelControl::ModificationMessage() const
28208c97b50SAxel Dörfler {
2831c3a6ab0SStefano Ceccherini 	return fModificationMsg;
28408c97b50SAxel Dörfler }
28508c97b50SAxel Dörfler 
28608c97b50SAxel Dörfler 
28708c97b50SAxel Dörfler status_t
Invoke(BMessage * message)2881f424632SJohn Scipione BChannelControl::Invoke(BMessage* message)
28908c97b50SAxel Dörfler {
290fd873802SStefano Ceccherini 	bool notify = false;
291fd873802SStefano Ceccherini 	BMessage invokeMessage(InvokeKind(&notify));
292fd873802SStefano Ceccherini 
2931f424632SJohn Scipione 	if (message != NULL)
2941f424632SJohn Scipione 		invokeMessage = *message;
295fd873802SStefano Ceccherini 	else if (Message() != NULL)
296fd873802SStefano Ceccherini 		invokeMessage = *Message();
297fd873802SStefano Ceccherini 
298fd873802SStefano Ceccherini 	invokeMessage.AddInt32("be:current_channel", fCurrentChannel);
299fd873802SStefano Ceccherini 
300fd873802SStefano Ceccherini 	return BControl::Invoke(&invokeMessage);
30108c97b50SAxel Dörfler }
30208c97b50SAxel Dörfler 
30308c97b50SAxel Dörfler 
30408c97b50SAxel Dörfler status_t
InvokeChannel(BMessage * message,int32 fromChannel,int32 channelCount,const bool * _mask)3051f424632SJohn Scipione BChannelControl::InvokeChannel(BMessage* message, int32 fromChannel,
3061f424632SJohn Scipione 	int32 channelCount, const bool* _mask)
30708c97b50SAxel Dörfler {
3082c323083SStefano Ceccherini 	bool notify = false;
3092c323083SStefano Ceccherini 	BMessage invokeMessage(InvokeKind(&notify));
3102c323083SStefano Ceccherini 
3111f424632SJohn Scipione 	if (message != NULL)
3121f424632SJohn Scipione 		invokeMessage = *message;
3132c323083SStefano Ceccherini 	else if (Message() != NULL)
3142c323083SStefano Ceccherini 		invokeMessage = *Message();
3152c323083SStefano Ceccherini 
3162c323083SStefano Ceccherini 	invokeMessage.AddInt32("be:current_channel", fCurrentChannel);
317789b86ecSJérôme Duval 	if (channelCount < 0)
3182c323083SStefano Ceccherini 		channelCount = fChannelCount - fromChannel;
3192c323083SStefano Ceccherini 
320789b86ecSJérôme Duval 	for (int32 i = 0; i < channelCount; i++) {
3211f424632SJohn Scipione 		invokeMessage.AddInt32("be:channel_value",
3221f424632SJohn Scipione 			fChannelValues[fromChannel + i]);
3231f424632SJohn Scipione 		invokeMessage.AddBool("be:channel_changed", _mask ? _mask[i] : true);
3242c323083SStefano Ceccherini 	}
3252c323083SStefano Ceccherini 
3262c323083SStefano Ceccherini 	return BControl::Invoke(&invokeMessage);
32708c97b50SAxel Dörfler }
32808c97b50SAxel Dörfler 
32908c97b50SAxel Dörfler 
33008c97b50SAxel Dörfler status_t
InvokeNotifyChannel(BMessage * message,uint32 kind,int32 fromChannel,int32 channelCount,const bool * _mask)3311f424632SJohn Scipione BChannelControl::InvokeNotifyChannel(BMessage* message, uint32 kind,
3321f424632SJohn Scipione 	int32 fromChannel, int32 channelCount, const bool* _mask)
33308c97b50SAxel Dörfler {
3341c3a6ab0SStefano Ceccherini 	BeginInvokeNotify(kind);
3351f424632SJohn Scipione 	status_t status = InvokeChannel(message, fromChannel, channelCount, _mask);
3361c3a6ab0SStefano Ceccherini 	EndInvokeNotify();
3371c3a6ab0SStefano Ceccherini 
3381c3a6ab0SStefano Ceccherini 	return status;
33908c97b50SAxel Dörfler }
34008c97b50SAxel Dörfler 
34108c97b50SAxel Dörfler 
34208c97b50SAxel Dörfler void
SetValue(int32 value)34308c97b50SAxel Dörfler BChannelControl::SetValue(int32 value)
34408c97b50SAxel Dörfler {
3451c3a6ab0SStefano Ceccherini 	// Get real
346422c0791SStefano Ceccherini 	if (value > fChannelMax[fCurrentChannel])
347422c0791SStefano Ceccherini 		value = fChannelMax[fCurrentChannel];
3481c3a6ab0SStefano Ceccherini 
349a8e3f157SStefano Ceccherini 	if (value < fChannelMin[fCurrentChannel])
350422c0791SStefano Ceccherini 		value = fChannelMin[fCurrentChannel];
3511c3a6ab0SStefano Ceccherini 
352422c0791SStefano Ceccherini 	if (value != fChannelValues[fCurrentChannel]) {
353422c0791SStefano Ceccherini 		StuffValues(fCurrentChannel, 1, &value);
3541c3a6ab0SStefano Ceccherini 		BControl::SetValue(value);
3551c3a6ab0SStefano Ceccherini 	}
35608c97b50SAxel Dörfler }
35708c97b50SAxel Dörfler 
35808c97b50SAxel Dörfler 
35908c97b50SAxel Dörfler status_t
SetCurrentChannel(int32 channel)36008c97b50SAxel Dörfler BChannelControl::SetCurrentChannel(int32 channel)
36108c97b50SAxel Dörfler {
362422c0791SStefano Ceccherini 	if (channel < 0 || channel >= fChannelCount)
3631c3a6ab0SStefano Ceccherini 		return B_BAD_INDEX;
3641c3a6ab0SStefano Ceccherini 
365422c0791SStefano Ceccherini 	if (channel != fCurrentChannel) {
366422c0791SStefano Ceccherini 		fCurrentChannel = channel;
367422c0791SStefano Ceccherini 		BControl::SetValue(fChannelValues[fCurrentChannel]);
3681c3a6ab0SStefano Ceccherini 	}
3691c3a6ab0SStefano Ceccherini 
3701c3a6ab0SStefano Ceccherini 	return B_OK;
37108c97b50SAxel Dörfler }
37208c97b50SAxel Dörfler 
37308c97b50SAxel Dörfler 
37408c97b50SAxel Dörfler int32
CurrentChannel() const37508c97b50SAxel Dörfler BChannelControl::CurrentChannel() const
37608c97b50SAxel Dörfler {
377422c0791SStefano Ceccherini 	return fCurrentChannel;
37808c97b50SAxel Dörfler }
37908c97b50SAxel Dörfler 
38008c97b50SAxel Dörfler 
38108c97b50SAxel Dörfler int32
CountChannels() const38208c97b50SAxel Dörfler BChannelControl::CountChannels() const
38308c97b50SAxel Dörfler {
384422c0791SStefano Ceccherini 	return fChannelCount;
38508c97b50SAxel Dörfler }
38608c97b50SAxel Dörfler 
38708c97b50SAxel Dörfler 
38808c97b50SAxel Dörfler status_t
SetChannelCount(int32 channel_count)38908c97b50SAxel Dörfler BChannelControl::SetChannelCount(int32 channel_count)
39008c97b50SAxel Dörfler {
3911c3a6ab0SStefano Ceccherini 	if (channel_count < 0 || channel_count >= MaxChannelCount())
3921c3a6ab0SStefano Ceccherini 		return B_BAD_VALUE;
3931c3a6ab0SStefano Ceccherini 
3941c3a6ab0SStefano Ceccherini 	// TODO: Currently we only grow the buffer. Test what BeOS does
395422c0791SStefano Ceccherini 	if (channel_count > fChannelCount) {
3961c3a6ab0SStefano Ceccherini 		int32* newMin = new int32[channel_count];
3971c3a6ab0SStefano Ceccherini 		int32* newMax = new int32[channel_count];
3981c3a6ab0SStefano Ceccherini 		int32* newVal = new int32[channel_count];
3991c3a6ab0SStefano Ceccherini 
400422c0791SStefano Ceccherini 		memcpy(newMin, fChannelMin, fChannelCount);
401422c0791SStefano Ceccherini 		memcpy(newMax, fChannelMax, fChannelCount);
402422c0791SStefano Ceccherini 		memcpy(newVal, fChannelValues, fChannelCount);
4031c3a6ab0SStefano Ceccherini 
404422c0791SStefano Ceccherini 		delete[] fChannelMin;
405422c0791SStefano Ceccherini 		delete[] fChannelMax;
406422c0791SStefano Ceccherini 		delete[] fChannelValues;
4071c3a6ab0SStefano Ceccherini 
408422c0791SStefano Ceccherini 		fChannelMin = newMin;
409422c0791SStefano Ceccherini 		fChannelMax = newMax;
410422c0791SStefano Ceccherini 		fChannelValues = newVal;
4111c3a6ab0SStefano Ceccherini 	}
4121c3a6ab0SStefano Ceccherini 
413422c0791SStefano Ceccherini 	fChannelCount = channel_count;
4141c3a6ab0SStefano Ceccherini 
4151c3a6ab0SStefano Ceccherini 	return B_OK;
41608c97b50SAxel Dörfler }
41708c97b50SAxel Dörfler 
41808c97b50SAxel Dörfler 
41908c97b50SAxel Dörfler int32
ValueFor(int32 channel) const42008c97b50SAxel Dörfler BChannelControl::ValueFor(int32 channel) const
42108c97b50SAxel Dörfler {
4221c3a6ab0SStefano Ceccherini 	int32 value = 0;
4231c3a6ab0SStefano Ceccherini 	if (GetValue(&value, channel, 1) <= 0)
42408c97b50SAxel Dörfler 		return -1;
4251c3a6ab0SStefano Ceccherini 
4261c3a6ab0SStefano Ceccherini 	return value;
42708c97b50SAxel Dörfler }
42808c97b50SAxel Dörfler 
42908c97b50SAxel Dörfler 
43008c97b50SAxel Dörfler int32
GetValue(int32 * outValues,int32 fromChannel,int32 channelCount) const43108c97b50SAxel Dörfler BChannelControl::GetValue(int32* outValues, int32 fromChannel,
43208c97b50SAxel Dörfler 	int32 channelCount) const
43308c97b50SAxel Dörfler {
4341c3a6ab0SStefano Ceccherini 	int32 i = 0;
4351c3a6ab0SStefano Ceccherini 	for (i = 0; i < channelCount; i++)
436422c0791SStefano Ceccherini 		outValues[i] = fChannelValues[fromChannel + i];
4371c3a6ab0SStefano Ceccherini 
4381c3a6ab0SStefano Ceccherini 	return i;
43908c97b50SAxel Dörfler }
44008c97b50SAxel Dörfler 
44108c97b50SAxel Dörfler 
44208c97b50SAxel Dörfler status_t
SetValueFor(int32 channel,int32 value)44308c97b50SAxel Dörfler BChannelControl::SetValueFor(int32 channel, int32 value)
44408c97b50SAxel Dörfler {
4451c3a6ab0SStefano Ceccherini 	return SetValue(channel, 1, &value);
44608c97b50SAxel Dörfler }
44708c97b50SAxel Dörfler 
44808c97b50SAxel Dörfler 
44908c97b50SAxel Dörfler status_t
SetValue(int32 fromChannel,int32 channelCount,const int32 * values)45008c97b50SAxel Dörfler BChannelControl::SetValue(int32 fromChannel, int32 channelCount,
4511f424632SJohn Scipione 	const int32* values)
45208c97b50SAxel Dörfler {
4531f424632SJohn Scipione 	return StuffValues(fromChannel, channelCount, values);
45408c97b50SAxel Dörfler }
45508c97b50SAxel Dörfler 
45608c97b50SAxel Dörfler 
45708c97b50SAxel Dörfler status_t
SetAllValue(int32 values)45808c97b50SAxel Dörfler BChannelControl::SetAllValue(int32 values)
45908c97b50SAxel Dörfler {
46020c7c2f9SStefano Ceccherini 	int32* newValues = new int32[fChannelCount];
4615040785eSStefano Ceccherini 	for (int32 i = 0; i < fChannelCount; i++) {
4625040785eSStefano Ceccherini 		int32 limitedValue = max_c(values, MinLimitList()[i]);
4635040785eSStefano Ceccherini 		limitedValue = min_c(limitedValue, MaxLimitList()[i]);
4645040785eSStefano Ceccherini 
4655040785eSStefano Ceccherini 		newValues[i] = limitedValue;
4665040785eSStefano Ceccherini 	}
46720c7c2f9SStefano Ceccherini 
468a85419eeSStefano Ceccherini 	delete[] fChannelValues;
46920c7c2f9SStefano Ceccherini 	fChannelValues = newValues;
470789b86ecSJérôme Duval 	BControl::SetValue(fChannelValues[fCurrentChannel]);
47120c7c2f9SStefano Ceccherini 
47220c7c2f9SStefano Ceccherini 	return B_OK;
47308c97b50SAxel Dörfler }
47408c97b50SAxel Dörfler 
47508c97b50SAxel Dörfler 
47608c97b50SAxel Dörfler status_t
SetLimitsFor(int32 channel,int32 minimum,int32 maximum)47708c97b50SAxel Dörfler BChannelControl::SetLimitsFor(int32 channel, int32 minimum, int32 maximum)
47808c97b50SAxel Dörfler {
479fd873802SStefano Ceccherini 	return SetLimitsFor(channel, 1, &minimum, &maximum);
48008c97b50SAxel Dörfler }
48108c97b50SAxel Dörfler 
48208c97b50SAxel Dörfler 
48308c97b50SAxel Dörfler status_t
GetLimitsFor(int32 channel,int32 * minimum,int32 * maximum) const4841f424632SJohn Scipione BChannelControl::GetLimitsFor(int32 channel, int32* minimum,
4851f424632SJohn Scipione 	int32* maximum) const
48608c97b50SAxel Dörfler {
487fd873802SStefano Ceccherini 	return GetLimitsFor(channel, 1, minimum, maximum);
48808c97b50SAxel Dörfler }
48908c97b50SAxel Dörfler 
49008c97b50SAxel Dörfler 
49108c97b50SAxel Dörfler status_t
SetLimitsFor(int32 fromChannel,int32 channelCount,const int32 * minimum,const int32 * maximum)49208c97b50SAxel Dörfler BChannelControl::SetLimitsFor(int32 fromChannel, int32 channelCount,
49308c97b50SAxel Dörfler 	const int32* minimum, const int32* maximum)
49408c97b50SAxel Dörfler {
49518108ef7SJérôme Duval 	if (fromChannel + channelCount > CountChannels())
49618108ef7SJérôme Duval 		channelCount = CountChannels() - fromChannel;
4971f424632SJohn Scipione 
49818108ef7SJérôme Duval 	for (int i = 0; i < channelCount; i++) {
49918108ef7SJérôme Duval 		if (minimum[i] > maximum[i])
50018108ef7SJérôme Duval 			return B_BAD_VALUE;
5011f424632SJohn Scipione 
50218108ef7SJérôme Duval 		fChannelMin[fromChannel + i] = minimum[i];
50318108ef7SJérôme Duval 		fChannelMax[fromChannel + i] = maximum[i];
50418108ef7SJérôme Duval 		if (fChannelValues[fromChannel + i] < minimum[i])
50518108ef7SJérôme Duval 			fChannelValues[fromChannel + i] = minimum[i];
50618108ef7SJérôme Duval 		else if (fChannelValues[fromChannel + i] > maximum[i])
50718108ef7SJérôme Duval 			fChannelValues[fromChannel + i] = maximum[i];
50818108ef7SJérôme Duval 	}
5091f424632SJohn Scipione 
51018108ef7SJérôme Duval 	return B_OK;
51108c97b50SAxel Dörfler }
51208c97b50SAxel Dörfler 
51308c97b50SAxel Dörfler 
51408c97b50SAxel Dörfler status_t
GetLimitsFor(int32 fromChannel,int32 channelCount,int32 * minimum,int32 * maximum) const51508c97b50SAxel Dörfler BChannelControl::GetLimitsFor(int32 fromChannel, int32 channelCount,
51608c97b50SAxel Dörfler 	int32* minimum, int32* maximum) const
51708c97b50SAxel Dörfler {
51818108ef7SJérôme Duval 	if (minimum == NULL || maximum == NULL)
51918108ef7SJérôme Duval 		return B_BAD_VALUE;
52018108ef7SJérôme Duval 
52118108ef7SJérôme Duval 	if (fChannelMin == NULL || fChannelMax == NULL)
52208c97b50SAxel Dörfler 		return B_ERROR;
52318108ef7SJérôme Duval 	if (fromChannel + channelCount > CountChannels())
52418108ef7SJérôme Duval 		channelCount = CountChannels() - fromChannel;
5251f424632SJohn Scipione 
52618108ef7SJérôme Duval 	for (int i = 0; i < channelCount; i++) {
52718108ef7SJérôme Duval 		minimum[i] = fChannelMin[fromChannel + i];
52818108ef7SJérôme Duval 		maximum[i] = fChannelMax[fromChannel + i];
52918108ef7SJérôme Duval 	}
53018108ef7SJérôme Duval 
53118108ef7SJérôme Duval 	return B_OK;
53208c97b50SAxel Dörfler }
53308c97b50SAxel Dörfler 
53408c97b50SAxel Dörfler 
53508c97b50SAxel Dörfler status_t
SetLimits(int32 minimum,int32 maximum)53608c97b50SAxel Dörfler BChannelControl::SetLimits(int32 minimum, int32 maximum)
53708c97b50SAxel Dörfler {
5387730601aSStefano Ceccherini 	if (minimum > maximum)
5397730601aSStefano Ceccherini 		return B_BAD_VALUE;
5407730601aSStefano Ceccherini 
5417730601aSStefano Ceccherini 	int32 numChannels = CountChannels();
5427730601aSStefano Ceccherini 
5437730601aSStefano Ceccherini 	for (int32 c = 0; c < numChannels; c++) {
54457735c40SMarcus Overhagen 		fChannelMin[c] = minimum;
54557735c40SMarcus Overhagen 		fChannelMax[c] = maximum;
54657735c40SMarcus Overhagen 		if (fChannelValues[c] < minimum)
54757735c40SMarcus Overhagen 			fChannelValues[c] = minimum;
54857735c40SMarcus Overhagen 		else if (fChannelValues[c] > maximum)
54957735c40SMarcus Overhagen 			fChannelValues[c] = maximum;
5507730601aSStefano Ceccherini 	}
5517730601aSStefano Ceccherini 
55257735c40SMarcus Overhagen 	return B_OK;
55308c97b50SAxel Dörfler }
55408c97b50SAxel Dörfler 
55508c97b50SAxel Dörfler 
55608c97b50SAxel Dörfler status_t
GetLimits(int32 * outMinimum,int32 * outMaximum) const55708c97b50SAxel Dörfler BChannelControl::GetLimits(int32* outMinimum, int32* outMaximum) const
55808c97b50SAxel Dörfler {
5597730601aSStefano Ceccherini 	if (outMinimum == NULL || outMaximum == NULL)
5607730601aSStefano Ceccherini 		return B_BAD_VALUE;
5617730601aSStefano Ceccherini 
5627730601aSStefano Ceccherini 	if (fChannelMin == NULL || fChannelMax == NULL)
56308c97b50SAxel Dörfler 		return B_ERROR;
5647730601aSStefano Ceccherini 
5657730601aSStefano Ceccherini 	int32 numChannels = CountChannels();
5667730601aSStefano Ceccherini 	for (int32 c = 0; c < numChannels; c++) {
5677730601aSStefano Ceccherini 		outMinimum[c] = fChannelMin[c];
5687730601aSStefano Ceccherini 		outMaximum[c] = fChannelMax[c];
5697730601aSStefano Ceccherini 	}
5707730601aSStefano Ceccherini 
5717730601aSStefano Ceccherini 	return B_OK;
57208c97b50SAxel Dörfler }
57308c97b50SAxel Dörfler 
57408c97b50SAxel Dörfler 
57508c97b50SAxel Dörfler status_t
SetLimitLabels(const char * minLabel,const char * maxLabel)576fd873802SStefano Ceccherini BChannelControl::SetLimitLabels(const char* minLabel, const char* maxLabel)
57708c97b50SAxel Dörfler {
578fd873802SStefano Ceccherini 	if (minLabel != fMinLabel)
579fd873802SStefano Ceccherini 		fMinLabel = minLabel;
580fd873802SStefano Ceccherini 
581fd873802SStefano Ceccherini 	if (maxLabel != fMaxLabel)
582fd873802SStefano Ceccherini 		fMaxLabel = maxLabel;
583fd873802SStefano Ceccherini 
584fd873802SStefano Ceccherini 	Invalidate();
585fd873802SStefano Ceccherini 
586fd873802SStefano Ceccherini 	return B_OK;
58708c97b50SAxel Dörfler }
58808c97b50SAxel Dörfler 
58908c97b50SAxel Dörfler 
59008c97b50SAxel Dörfler const char*
MinLimitLabel() const59108c97b50SAxel Dörfler BChannelControl::MinLimitLabel() const
59208c97b50SAxel Dörfler {
593fd873802SStefano Ceccherini 	return fMinLabel.String();
59408c97b50SAxel Dörfler }
59508c97b50SAxel Dörfler 
59608c97b50SAxel Dörfler 
59708c97b50SAxel Dörfler const char*
MaxLimitLabel() const59808c97b50SAxel Dörfler BChannelControl::MaxLimitLabel() const
59908c97b50SAxel Dörfler {
600fd873802SStefano Ceccherini 	return fMaxLabel.String();
60108c97b50SAxel Dörfler }
60208c97b50SAxel Dörfler 
60308c97b50SAxel Dörfler 
60408c97b50SAxel Dörfler status_t
SetLimitLabelsFor(int32 channel,const char * minLabel,const char * maxLabel)6051f424632SJohn Scipione BChannelControl::SetLimitLabelsFor(int32 channel, const char* minLabel,
6061f424632SJohn Scipione 	const char* maxLabel)
60708c97b50SAxel Dörfler {
608*0b421b80SStefano Ceccherini 	(*(label_map*)fMultiLabels)[channel].max_label = maxLabel;
609*0b421b80SStefano Ceccherini 	(*(label_map*)fMultiLabels)[channel].min_label = minLabel;
610*0b421b80SStefano Ceccherini 	return B_OK;
61108c97b50SAxel Dörfler }
61208c97b50SAxel Dörfler 
61308c97b50SAxel Dörfler 
61408c97b50SAxel Dörfler status_t
SetLimitLabelsFor(int32 fromChannel,int32 channelCount,const char * minLabel,const char * maxLabel)6151f424632SJohn Scipione BChannelControl::SetLimitLabelsFor(int32 fromChannel, int32 channelCount,
6161f424632SJohn Scipione 	const char* minLabel, const char* maxLabel)
61708c97b50SAxel Dörfler {
618*0b421b80SStefano Ceccherini 	for (int32 i = fromChannel; i < fromChannel + channelCount; i++) {
619*0b421b80SStefano Ceccherini 		SetLimitLabelsFor(i, minLabel, maxLabel);
620*0b421b80SStefano Ceccherini 	}
621*0b421b80SStefano Ceccherini 	return B_OK;
62208c97b50SAxel Dörfler }
62308c97b50SAxel Dörfler 
62408c97b50SAxel Dörfler 
62508c97b50SAxel Dörfler const char*
MinLimitLabelFor(int32 channel) const62608c97b50SAxel Dörfler BChannelControl::MinLimitLabelFor(int32 channel) const
62708c97b50SAxel Dörfler {
628*0b421b80SStefano Ceccherini 	if (fMultiLabels != NULL) {
629*0b421b80SStefano Ceccherini 		label_map::const_iterator iter = ((label_map*)fMultiLabels)->find(channel);
630*0b421b80SStefano Ceccherini 		if (iter != ((label_map*)fMultiLabels)->end())
631*0b421b80SStefano Ceccherini 			return (*iter).second.min_label.c_str();
632*0b421b80SStefano Ceccherini 	}
63308c97b50SAxel Dörfler 	return NULL;
63408c97b50SAxel Dörfler }
63508c97b50SAxel Dörfler 
63608c97b50SAxel Dörfler 
63708c97b50SAxel Dörfler const char*
MaxLimitLabelFor(int32 channel) const63808c97b50SAxel Dörfler BChannelControl::MaxLimitLabelFor(int32 channel) const
63908c97b50SAxel Dörfler {
640*0b421b80SStefano Ceccherini 	if (fMultiLabels != NULL) {
641*0b421b80SStefano Ceccherini 		label_map::const_iterator iter = ((label_map*)fMultiLabels)->find(channel);
642*0b421b80SStefano Ceccherini 		if (iter != ((label_map*)fMultiLabels)->end())
643*0b421b80SStefano Ceccherini 			return (*iter).second.max_label.c_str();
644*0b421b80SStefano Ceccherini 	}
64508c97b50SAxel Dörfler 	return NULL;
64608c97b50SAxel Dörfler }
64708c97b50SAxel Dörfler 
64808c97b50SAxel Dörfler 
64908c97b50SAxel Dörfler status_t
StuffValues(int32 fromChannel,int32 channelCount,const int32 * values)65008c97b50SAxel Dörfler BChannelControl::StuffValues(int32 fromChannel, int32 channelCount,
6511f424632SJohn Scipione 	const int32* values)
65208c97b50SAxel Dörfler {
6531f424632SJohn Scipione 	if (values == NULL)
654fd873802SStefano Ceccherini 		return B_BAD_VALUE;
655fd873802SStefano Ceccherini 
65620c7c2f9SStefano Ceccherini 	if (fromChannel < 0 || fromChannel > fChannelCount
6571f424632SJohn Scipione 		|| fromChannel + channelCount > fChannelCount) {
658fd873802SStefano Ceccherini 		return B_BAD_INDEX;
659fd873802SStefano Ceccherini 	}
660fd873802SStefano Ceccherini 
6611f424632SJohn Scipione 	for (int32 i = 0; i < channelCount; i++) {
6621f424632SJohn Scipione 		if (values[i] <= fChannelMax[fromChannel + i]
6631f424632SJohn Scipione 			&& values[i] >= fChannelMin[fromChannel + i]) {
6641f424632SJohn Scipione 			fChannelValues[fromChannel + i] = values[i];
6651f424632SJohn Scipione 		}
6661f424632SJohn Scipione 	}
6671f424632SJohn Scipione 
6681f424632SJohn Scipione 	// if the current channel was updated, update also the control value
6691f424632SJohn Scipione 	if (fCurrentChannel >= fromChannel
6701f424632SJohn Scipione 		&& fCurrentChannel <= fromChannel + channelCount) {
671fd873802SStefano Ceccherini 		BControl::SetValue(fChannelValues[fCurrentChannel]);
6721f424632SJohn Scipione 	}
673fd873802SStefano Ceccherini 
674fd873802SStefano Ceccherini 	return B_OK;
67508c97b50SAxel Dörfler }
67608c97b50SAxel Dörfler 
67708c97b50SAxel Dörfler 
_Reserverd_ChannelControl_0(void *,...)67808c97b50SAxel Dörfler void BChannelControl::_Reserverd_ChannelControl_0(void*, ...) {}
_Reserverd_ChannelControl_1(void *,...)67908c97b50SAxel Dörfler void BChannelControl::_Reserverd_ChannelControl_1(void*, ...) {}
_Reserverd_ChannelControl_2(void *,...)68008c97b50SAxel Dörfler void BChannelControl::_Reserverd_ChannelControl_2(void*, ...) {}
_Reserverd_ChannelControl_3(void *,...)68108c97b50SAxel Dörfler void BChannelControl::_Reserverd_ChannelControl_3(void*, ...) {}
_Reserverd_ChannelControl_4(void *,...)68208c97b50SAxel Dörfler void BChannelControl::_Reserverd_ChannelControl_4(void*, ...) {}
_Reserverd_ChannelControl_5(void *,...)68308c97b50SAxel Dörfler void BChannelControl::_Reserverd_ChannelControl_5(void*, ...) {}
_Reserverd_ChannelControl_6(void *,...)68408c97b50SAxel Dörfler void BChannelControl::_Reserverd_ChannelControl_6(void*, ...) {}
_Reserverd_ChannelControl_7(void *,...)68508c97b50SAxel Dörfler void BChannelControl::_Reserverd_ChannelControl_7(void*, ...) {}
_Reserverd_ChannelControl_8(void *,...)68608c97b50SAxel Dörfler void BChannelControl::_Reserverd_ChannelControl_8(void*, ...) {}
_Reserverd_ChannelControl_9(void *,...)68708c97b50SAxel Dörfler void BChannelControl::_Reserverd_ChannelControl_9(void*, ...) {}
_Reserverd_ChannelControl_10(void *,...)68808c97b50SAxel Dörfler void BChannelControl::_Reserverd_ChannelControl_10(void*, ...) {}
_Reserverd_ChannelControl_11(void *,...)68908c97b50SAxel Dörfler void BChannelControl::_Reserverd_ChannelControl_11(void*, ...) {}
690