You are here: Using External Control Systems with HAL > Integrating Stardraw Control Systems > Exploring the Stardraw Example Application > Selectors

Selectors

The example application provides two selector controls, one for the lounge program source and one for the lounge tone. In the Stardraw form, both of these use the same built-in MultiPositionKnob control from the Stardraw Toolbox Controls palette.

Lounge Source Selector

The selector controls are the most complex controls in the Stardraw application and in the HAL1 example driver. This is because the application not only responds to changes to the current selection value, but it also dynamically sets the number of selection items and the name of each item in response to messages that the Halogen/HAL Control Server sends.

Dynamic Selection Items

The lounge Source Selector Control in the Halogen example configuration contains three selections: Classical, Jazz, and Reggae. In the Stardraw form, however, the MultiPositionKnob control (named SourceSelectionControl) has the default set of selections and names:

When you run the application, however, it looks like this:

"So," you ask, "what’s going on here?" Well, the answer is that when the Stardraw application starts up, it asks the HAL1 driver for all of the current values of the controls defined for in the HAL configuration. This includes a request for the number of selection items in the Source Selector Control. When the Halogen/HAL Control Server returns the value (via a ‘set selection link’ message), the HAL1 driver notifies the Stardraw application so that it can set the number of items in SourceSelectionControl to match. In addition, whenever the HAL1 driver receives a ‘set selection link’ message, it then makes a request to the Halogen/Hal Control Server for each of the selection names. Halogen/HAL responds by sending a ‘set selection name’ message for each name, causing the Stardraw application to update its names in the SourceSelectionControl.

To see how the Stardraw application’s SourceSelectionControl knob is configured to do this, double-click on the Source MultiPositionKnob control in the Stardraw form. In the Actions dialog that appears, use the event drop down arrow to navigate to the Devices -> HAL1 (1) -> Control Port -> OnSourceSelectionMaximumChanged event. The Actions dialog shows the event and associated actions:

When the HAL1 Stardraw driver receives a ‘set selection message’ for the source selection control, it raises the OnSourceSelectionMaximumChanged event. The Stardraw action, shown above, sets the Maximum property of the SourceSelectionControl to the current value of the HAL1 driver’s SourceSelectionMaximum. The SourceSelectionControl’s Maximum property determines the number of selection items for the MultiPositionKnob control.

Dynamic Selection Names

The HAL1 driver includes a set of names for the Stardraw Source selector knob. Whenever the Halogen/HAL Control Server updates a selection name via a ‘set selection name’ message for the Source Selector Control, the driver records the new name and raises an OnSourceSelectionNamesChanged event. The Stardraw application has mapped an action to this event, which updates the set of names in the SourceSelectionControl. For the Stardraw MultiPositionKnob, the selection names are contained in the control’s Cases property, a String array. When the OnSourceSelectionNamesChanged event occurs, the action sets the Cases property of SourceSelectionControl to the current value of the HAL1 driver’s SourceSelectionNames driver. This one action takes care of setting all of the names at once.

To see this, use the drop down arrow in the Actions property for the Stardraw application’s SourceSelectionControl to navigate to the Devices -> HAL1 (1) -> Control Port -> OnSourceSelectionNamesChanged event. The dialog shows the event and associated action as follows:

Current Selection

The value of the SourceSelectionControl is the currently selected item, which is a number starting at 0 for the first item and ranging to the maximum item, in this case 2 because there are a total of three selection items.

When the Stardraw end user changes the selector knob, the application generates a ValueChanged event for the SourceSelectorControl. The action for this event sets the HAL1 driver’s SourceSelection property to the current Value of the Stardraw form’s SourceSelectorControl. This in turn causes the driver to send a ‘set selection’ message for the Source Selector Control to the Halogen/HAL Control Server. To see this, open the SourceSelectorControl by double clicking on the Source knob on the form. This brings up the Actions dialog for the SourceSelectorControl, which shows the ValueChanged event and the associated action:

The Stardraw example application also responds to Source Selector Control updates that the Halogen/HAL Control Server sends whenever the control changes in the HAL System. To do this, the application maps the HAL1 driver’s OnSourceSelectionChanged event to an action that updates the form’s SourceSelectorControl Value property. To see this, use the event drop down arrow in the Stardraw SourceSelectorControl’s Actions dialog to navigate to Devices -> HAL1 (1) -> Control Port -> OnSourceSelectionChanged event. The dialog changes to show the event and associated action:

Lounge Tone Selector

The configuration of the Lounge tone selector MultiPositionKnob is very similar to the Source knob configuration. In this instance however, name of the form control is ToneSelectorControl, and the application maps the following events to actions:

Description Event Action
Set the number of selector items in the MultiPostionKnob Tone control (ToneSelectorControl) Devices -> HAL1 (1) -> Control Port -> OnToneSelectionNamesChanged Set the ToneSelectorControl Maximum property to the HAL1 driver ToneSelectorMaximum property
Set the names of the ToneSelectorControl items Devices -> HAL1 (1) -> Control Port -> OnToneSelectionNamesChanged Set the ToneSelectorControl Cases property to the HAL1 drivers ToneSelectionNames property
When the Stardraw end user changes the Tone knob setting. Controls -> ToneSelectorControl -> ValueChanged Set the HAL1 driver’s ToneSelection property to the form’s ToneSelectionControl Value property
When the Tone Selector Control changes in Halogen/HAL Devices -> HAL1 (1) -> Control Port -> OnToneSelectionChanged Set the ToneSelectorControl Value property to the HAL1 driver’s ToneSelection property

As before, you can see these events and associated actions by double clicking on the form’s Tone MultiPostionKnob control and navigating to the event.