Commit 676fc97e authored by Robert Sprowson's avatar Robert Sprowson
Browse files

Move beep on error option into Sound Setup

Part of simplification of the window setup plugin.
Also, to avoid having to maintain two similar plugins, the differences from the former VIDC oriented Sound Setup are integrated
* If SoundControl module is running behave as before
* If no SoundControl but there is a VIDC, adapt to add
  + 16b/8b hardware option
  + oversampling option
  + don't permit muting of the (one and only) mixing channel
  + the mixing channel governs the *VOLUME and corresponding CMOS bits
* Updated common functions from other plugins
* Use definitions from HighFSI, OsBytes, CMOS in place of local ones

Tested on a Risc PC (ie. VIDC style) and Beagleboard xM (ie. mixer style).

Version 2.07. Tagged as 'SndSetup-2_07'
parent f5cd9d78
IF "<Choices$Write>" = "" OR "<Boot$Path>" = "" THEN Error No Boot application appears to have been run
RMEnsure UtilityModule 3.80 Error This version of SndSetup requires RISC OS 3.80 or later
IfThere <Obey$Dir>.VIDC.!SndSetup.!Run Then Set SndSetup$VIDC True Else Set SndSetup$VIDC False
RMEnsure SoundControl 1.00 If "<SndSetup$VIDC>"="True" Then Run <Obey$Dir>.VIDC.!SndSetup.!Run %*0
RMEnsure SoundControl 1.00 If "<SndSetup$VIDC>"="True" Then Obey
RMEnsure UtilityModule 5.03 Error This version of SndSetup requires RISC OS 5.03 or later
IF "<Boot$Dir>" = "" THEN Error No !Boot application has been run.
IF "<Choices$Write>" = "" THEN Error No !Boot application has been run.
Set SndSetup$Dir <Obey$Dir>
IconSprites <SndSetup$Dir>.!Sprites
RMEnsure Toolbox 1.36 RMLoad System:Modules.Toolbox.Toolbox
RMEnsure Toolbox 1.36 Error You need Toolbox 1.36 or later to run SndSetup
RMEnsure Window 1.44 RMLoad System:Modules.Toolbox.Window
RMEnsure Window 1.44 Error You need Window 1.44 or later to run SndSetup
RMEnsure Menu 0.29 RMLoad System:Modules.Toolbox.Menu
RMEnsure Menu 0.29 Error You need Menu 0.29 or later to run SndSetup
RMEnsure SoundControl 1.00 Error You need SoundControl 1.00 or later to run SndSetup
RMEnsure Toolbox 1.36 RMLoad System:Modules.Toolbox.Toolbox
RMEnsure Toolbox 1.36 Error You need Toolbox 1.36 or later to run SndSetup
RMEnsure Window 1.44 RMLoad System:Modules.Toolbox.Window
RMEnsure Window 1.44 Error You need Window 1.44 or later to run SndSetup
RMEnsure Menu 0.29 RMLoad System:Modules.Toolbox.Menu
RMEnsure Menu 0.29 Error You need Menu 0.29 or later to run SndSetup
WimpSlot 40k 40k
Run <SndSetup$Dir>.!RunImage %*0
# Messages file for Sound configuration
_TaskName:Sound setup
_TaskName:Sound Setup
_Purpose:Configuring the sound system
_Author:© Acorn Computers Ltd, 1998
_Version:VERSION
......@@ -11,8 +11,9 @@ _ConfigSprite:co_sound
reportt:Message from Configure
# Error messages
NotEnoughMemory:There is not enough memory to do that operation.
ChoicesFileNotOpen:Couldn't open choices file.
NotEnoughMemory:There is not enough memory to do that operation
ChoicesFileNotOpen:Couldn't open choices file
NoSoundCtl:You need SoundControl 1.00 or later to run Sound Setup
# Tokens for mixer channels.
# Suffixes: [O]utput/[I]nput, absolute category number, [m]ono/[s]tereo, index (starting from 0), total indexes for this category.
......
No preview for this file type
---------------------------------------------------------------------------
Project: Ursula
Module: FilrSetup
Module: SndSetup
Created: 20-May-98
By: Richard Leggett
First version: 0.03
......
/* (2.06)
/* (2.07)
*
* This file is automatically maintained by srccommit, do not edit manually.
* Last processed by srccommit version: 1.1.
*
*/
#define Module_MajorVersion_CMHG 2.06
#define Module_MajorVersion_CMHG 2.07
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 17 Jul 2013
#define Module_Date_CMHG 20 Jul 2013
#define Module_MajorVersion "2.06"
#define Module_Version 206
#define Module_MajorVersion "2.07"
#define Module_Version 207
#define Module_MinorVersion ""
#define Module_Date "17 Jul 2013"
#define Module_Date "20 Jul 2013"
#define Module_ApplicationDate "17-Jul-13"
#define Module_ApplicationDate "20-Jul-13"
#define Module_ComponentName "SndSetup"
#define Module_ComponentPath "castle/RiscOS/Sources/SystemRes/Configure2/PlugIns/SndSetup"
#define Module_FullVersion "2.06"
#define Module_HelpVersion "2.06 (17 Jul 2013)"
#define Module_LibraryVersionInfo "2:6"
#define Module_FullVersion "2.07"
#define Module_HelpVersion "2.07 (20 Jul 2013)"
#define Module_LibraryVersionInfo "2:7"
......@@ -13,7 +13,7 @@
* limitations under the License.
*/
/*---------------------------------------------------------------------------*/
/* File: c.common */
/* File: common.c */
/* Purpose: Commonly used Wimp routines */
/* Author: Richard Leggett */
/* History: 28-Oct-97: RML: Begun (some routines nicked from PhotoQV) */
......@@ -23,6 +23,7 @@
#include <stdlib.h>
#include <string.h>
#include "Global/OsBytes.h"
#include "kernel.h"
#include "wimp.h"
#include "wimplib.h"
......@@ -32,8 +33,6 @@
#include "common.h"
#include "defines.h"
#define Flag_GadgetFaded 1u<<31
char TaskName[30] = "?";
/* Global messages file descriptor and string pointer */
......@@ -51,7 +50,17 @@ static char *message_buffer;
* type - 0 means non-fatal, otherwise program will exit after reporting *
*---------------------------------------------------------------------------*/
extern inline void error_trap(_kernel_oserror *err, int err_type);
void error_trap(_kernel_oserror *err, int err_type)
{
/* Report the appropriate error, has one occured */
if (err != NULL)
{
wimp_report_error(err, 0, TaskName, 0, 0, 0);
/* Now, if it was a fatal error (type != 0), exit at once */
if (err_type != 0) exit(0);
}
}
/*---------------------------------------------------------------------------*
......@@ -121,16 +130,13 @@ const char* messages_lookup_withparam(const char *token_string, const char* para
/*---------------------------------------------------------------------------*
* common_read_screensize *
* *
* Return the size of rhe screen in OS units *
* Return the size of the screen in OS units *
*---------------------------------------------------------------------------*/
_kernel_oserror* common_read_screensize(int *x, int *y)
_kernel_oserror *common_read_screensize(int *x, int *y)
{
_kernel_oserror* e;
int xeig;
int yeig;
int xpix;
int ypix;
_kernel_oserror *e;
int xeig, yeig, xpix, ypix;
e=_swix(OS_ReadModeVariable, _INR(0,1)|_OUT(2), -1, 4, &xeig); if (e) return e;
e=_swix(OS_ReadModeVariable, _INR(0,1)|_OUT(2), -1, 5, &yeig); if (e) return e;
......@@ -150,9 +156,10 @@ _kernel_oserror* common_read_screensize(int *x, int *y)
* Given a string, return a kernel_oserror compatible error. *
*---------------------------------------------------------------------------*/
_kernel_oserror* common_error(char *s)
_kernel_oserror *common_error(char *s)
{
static _kernel_oserror e;
e.errnum = 0;
strcpy(e.errmess, s);
......@@ -174,7 +181,7 @@ void grey_gadget(int objectid, int gadgetid)
unsigned int flags;
error_trap(gadget_get_flags(0, objectid, gadgetid, &flags), 0);
flags=flags | Flag_GadgetFaded;
flags = flags | Gadget_Faded;
error_trap(gadget_set_flags(0, objectid, gadgetid, flags), 0);
}
......@@ -193,7 +200,7 @@ void ungrey_gadget(int objectid, int gadgetid)
unsigned int flags;
error_trap(gadget_get_flags(0, objectid, gadgetid, &flags), 0);
if (flags & Flag_GadgetFaded) flags=flags^Flag_GadgetFaded;
flags &= ~Gadget_Faded;
error_trap(gadget_set_flags(0, objectid, gadgetid, flags), 0);
}
......@@ -216,11 +223,11 @@ int strncmpa(char *str1, char *str2, int size)
int n;
int equal = size;
for (n=0; n<size; n++)
for (n = 0; n < size; n++)
{
if (str1[n]==str2[n]) equal--;
else if (str1[n]==str2[n]-32) equal--;
else if (str1[n]-32==str2[n]) equal--;
if (str1[n] == str2[n]) equal--;
else if (str1[n] == str2[n] - 32) equal--;
else if (str1[n]-32 == str2[n]) equal--;
}
return equal;
......@@ -240,7 +247,8 @@ int strncmpa(char *str1, char *str2, int size)
int read_cmos_value(int location)
{
int result;
_swix(OS_Byte, _INR(0,1)|_OUT(2), 161, location, &result);
_swix(OS_Byte, _INR(0,1) | _OUT(2), OsByte_ReadCMOS, location, &result);
return result;
}
......@@ -256,5 +264,5 @@ int read_cmos_value(int location)
void write_cmos_value(int location, int value)
{
_swix(OS_Byte, _INR(0,2), 162, location, value);
_swix(OS_Byte, _INR(0,2), OsByte_WriteCMOS, location, value);
}
......@@ -13,7 +13,7 @@
* limitations under the License.
*/
/*---------------------------------------------------------------------------*/
/* File: c.main */
/* File: main.c */
/* Purpose: Main WIMP shell for Sound configuration */
/* Author: Richard Leggett */
/* History: 29-Jan-98: RML: Begun. */
......@@ -37,7 +37,7 @@
static MessagesFD messages_desc;
static IdBlock idb;
static char messages_string[255];
static int config_window_id;
static ObjectId config_window_id;
/*---------------------------------------------------------------------------*
......@@ -55,7 +55,7 @@ static void program_exit(void)
/*---------------------------------------------------------------------------*
* try_system_beep *
* *
* Restore original choices. *
* Go 'toot'. *
*---------------------------------------------------------------------------*/
static void try_system_beep(void)
......@@ -117,8 +117,8 @@ static int action_selected(int event_code, ToolboxEvent *event_block, IdBlock *i
switch (icon)
{
case SetButton:
sound_save_choices(config_window_id);
sound_read_write_cmos_settings(WriteCMOSSettings, config_window_id);
sound_save_choices(config_window_id);
if ((block->hdr.flags & 1) == 0) program_exit(); /* Return or left button pressed */
sound_reset_to_configured(config_window_id);
break;
......@@ -187,11 +187,12 @@ static int message_reopen(WimpMessage *event, void *handler)
static void open_configure_window(int at_x, int at_y)
{
BBox bbox;
int adjustment = 0;
int screenx;
int screeny;
WindowShowObjectBlock buffer;
const ComponentId stretch_gadgets[] = { BeepGroup, VoicesStringset };
const ComponentId move_gadgets[] = { DefaultButton, VoicesLabel, QuietRadio, LoudRadio };
const ComponentId stretch_gadgets[] = { BeepGroup, VoicesStringSet };
const ComponentId move_gadgets[] = { DefaultButton, VoicesLabel, QuietRadio, LoudRadio, BeepingErrorsOption };
/* Create window */
error_trap(toolbox_create_object(0, "Window", &config_window_id), 1);
......@@ -221,7 +222,22 @@ static void open_configure_window(int at_x, int at_y)
if (gadget_template_size[2] > max_template_size) max_template_size = gadget_template_size[2];
if (gadget_template_size[3] > max_template_size) max_template_size = gadget_template_size[3];
char gadget[max_template_size];
if (!vidcmix)
{
/* Adjust for the 2 gadget height equivalent of OversamplingOption & SixteenBitOption */
for (int i = 0; i < 4; i++)
{
((Gadget *)gadget_template[i])->hdr.box.ymax -= 2 * SLIDER_HEIGHT;
((Gadget *)gadget_template[i])->hdr.box.ymin -= 2 * SLIDER_HEIGHT;
}
adjustment = 2;
/* And get rid of them */
error_trap(window_remove_gadget(0, config_window_id, OversamplingOption), 0);
error_trap(window_remove_gadget(0, config_window_id, SixteenBitOption), 0);
}
/* 1) Name field */
memcpy(gadget, gadget_template[0], gadget_template_size[0]);
((Gadget *)gadget)->hdr.box.ymax += nchannels * SLIDER_HEIGHT;
((Gadget *)gadget)->hdr.box.ymin += nchannels * SLIDER_HEIGHT;
......@@ -258,6 +274,7 @@ static void open_configure_window(int at_x, int at_y)
error_trap(window_add_gadget(0, config_window_id, (Gadget *)gadget, NULL), 0);
}
/* 2) Mono/stereo tote */
memcpy(gadget, gadget_template[1], gadget_template_size[1]);
((Gadget *)gadget)->hdr.box.ymax += nchannels * SLIDER_HEIGHT;
((Gadget *)gadget)->hdr.box.ymin += nchannels * SLIDER_HEIGHT;
......@@ -273,6 +290,7 @@ static void open_configure_window(int at_x, int at_y)
error_trap(window_add_gadget(0, config_window_id, (Gadget *)gadget, NULL), 0);
}
/* 3) Slider */
memcpy(gadget, gadget_template[2], gadget_template_size[2]);
((Gadget *)gadget)->hdr.box.ymax += nchannels * SLIDER_HEIGHT;
((Gadget *)gadget)->hdr.box.ymin += nchannels * SLIDER_HEIGHT;
......@@ -292,6 +310,7 @@ static void open_configure_window(int at_x, int at_y)
error_trap(slider_set_bounds(7, config_window_id, 2+i*4, channel[i].mingain, channel[i].maxgain, channel[i].step), 0);
}
/* 4) Mute option */
memcpy(gadget, gadget_template[3], gadget_template_size[3]);
((Gadget *)gadget)->hdr.box.ymax += nchannels * SLIDER_HEIGHT;
((Gadget *)gadget)->hdr.box.ymin += nchannels * SLIDER_HEIGHT;
......@@ -305,6 +324,7 @@ static void open_configure_window(int at_x, int at_y)
strcat(token, channel[i].token_suffix);
((Gadget *)gadget)->hdr.help_message = (char *)messages_lookup_withparam(token, channel[i].name);
((Gadget *)gadget)->hdr.flags &= ~Gadget_Faded;
if (vidcmix) ((Gadget *)gadget)->hdr.flags |= Gadget_Faded; /* Unmutable */
if (channel[i].fixed) ((Gadget *)gadget)->hdr.flags |= Gadget_Faded;
error_trap(window_add_gadget(0, config_window_id, (Gadget *)gadget, NULL), 0);
}
......@@ -313,7 +333,7 @@ static void open_configure_window(int at_x, int at_y)
stretch_width = widest_label + /* fudge factor */ 16 - stretch_width;
error_trap(window_get_extent(0, config_window_id, &bbox), 0);
bbox.xmin -= stretch_width;
bbox.ymax += (nchannels - 1) * SLIDER_HEIGHT;
bbox.ymax += (nchannels - 1 - adjustment) * SLIDER_HEIGHT;
error_trap(window_set_extent(0, config_window_id, &bbox), 0);
for (ComponentId g = 0; g < 4 * nchannels; g+= 4)
......@@ -421,6 +441,7 @@ int main(int argc, char *argv[])
/* Do main initialisation */
if (!main_initialise()) return 0;
sound_detect_mix_mode();
sound_read_channel_info();
open_configure_window(openat_x, openat_y);
sound_make_voices_menu(config_window_id);
......
......@@ -13,7 +13,7 @@
* limitations under the License.
*/
/*---------------------------------------------------------------------------*/
/* File: c.sound */
/* File: sound.c */
/* Purpose: Sound specific code */
/* Author: Richard Leggett */
/* History: 29-Jan-98: RML: Begun. */
......@@ -24,6 +24,11 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "Global/OsBytes.h"
#include "Global/FileTypes.h"
#include "Global/CMOS.h"
#include "Interface/HighFSI.h"
#include "Interface/MixerDevice.h"
#include "swis.h"
#include "toolbox.h"
#include "gadgets.h"
......@@ -43,9 +48,10 @@
struct channel channel[MAX_CHANNELS];
unsigned int nchannels;
BOOL vidcmix;
static int menu_to_voice_map[16];
static int cmos_voice, cmos_volume;
static int cmos_sound, cmos_loud;
typedef struct
{
......@@ -56,6 +62,79 @@ typedef struct
int step;
} mixer_features;
/*---------------------------------------------------------------------------*
* sound_detect_mix_mode *
* *
* Find if this is an old style VIDC system or a full mixing desk. *
*---------------------------------------------------------------------------*/
void sound_detect_mix_mode(void)
{
if (_swix(OS_CLI, _IN(0), "RMEnsure SoundControl 1.00") == NULL)
{
vidcmix = FALSE;
}
else
{
int dummy;
if ((_swix(OS_Memory, _INR(0,1) | _OUT(1), 9, 3<<8, &dummy) == NULL) &&
(dummy != 0))
{
vidcmix = TRUE;
}
else
{
/* No sound mixer module and no VIDC, that's fatal */
error_trap(common_error(messages_lookup("NoSoundCtl")), 1);
}
}
}
/*---------------------------------------------------------------------------*
* sound_db_to_volume *
* *
* Translate a dB*16 setting into a volume. *
*---------------------------------------------------------------------------*/
static int sound_db_to_volume(int db)
{
int volume;
/* Round down to nearest step multiple of 3dB*16 */
db = (db - 47) / 48;
/* Every 3dB is a volume step of 16 */
volume = 127 + (16 * db);
if (volume <= 0) volume = 1;
if (volume > 127) volume = 127;
return volume;
}
/*---------------------------------------------------------------------------*
* sound_volume_to_db *
* *
* Translate a volume setting into dB*16s. *
*---------------------------------------------------------------------------*/
static int sound_volume_to_db(int volume)
{
int db;
/* Round down to nearest step of 16 */
volume = (volume - 15) / 16;
/* Every 16 is a step of -3dB*16 */
db = 0 - (48 * (7 - volume));
return db;
}
/*---------------------------------------------------------------------------*
* sound_read_channel_info *
* *
......@@ -66,6 +145,33 @@ void sound_read_channel_info(void)
{
size_t space_needed;
size_t block_size;
if (vidcmix)
{
static const struct channel vidcchannel = { VIDC_CHANNEL };
const char *name;
char nametoken[10] = "name";
int volume;
/* Just fill in the one static channel */
nchannels = 1;
channel[0] = vidcchannel;
strcat(nametoken, channel[0].token_suffix);
name = messages_lookup_withparam(nametoken, "");
if ((channel[0].name = malloc(strlen(name) + 1)) != NULL)
{
strcpy(channel[0].name, name);
}
/* Original state retrieved from *VOLUME setting */
error_trap(_swix(Sound_Volume, _IN(0) | _OUT(0), 0, &volume), 0);
channel[0].original_gain = sound_volume_to_db(volume);
channel[0].original_mute = FALSE;
return;
}
/* Query the mixable channels and levels */
error_trap(_swix(SoundCtrl_ExamineMixer, _INR(0,2)|_OUTR(2,3),
0,
NULL,
......@@ -188,7 +294,7 @@ void sound_make_voices_menu(int window_id)
char* name_local;
int i, m;
memset(strings, 0, 1024);
memset(strings, 0, sizeof(strings));
/* menu_to_voice_map maps from menu item number to internal voice number */
for (m=15; m>=0; m--) menu_to_voice_map[m] = -1;
......@@ -207,7 +313,7 @@ void sound_make_voices_menu(int window_id)
}
}
error_trap(stringset_set_available(0, window_id, VoicesStringset, strings), 0);
error_trap(stringset_set_available(0, window_id, VoicesStringSet, strings), 0);
}
......@@ -223,46 +329,76 @@ void sound_make_voices_menu(int window_id)
void sound_read_write_cmos_settings(int condition_code, int window_id)
{
static int cmos_voice, cmos_volume;
int voice = -1;
int n = -1;
int cmos_errors = read_cmos_value(WimpFlagsCMOS);
int cmos_soundsys = read_cmos_value(PrintSoundCMOS);
/* Are we reading or writing CMOS? */
if (condition_code == ReadCMOSSettings)
{
cmos_voice = read_cmos_value(CMOS_Voice);
cmos_volume = read_cmos_value(CMOS_BellVolume);
cmos_sound = read_cmos_value(SoundCMOS);
cmos_loud = read_cmos_value(DBTBCMOS);
voice = 1 + (cmos_voice & 0x0f);
voice = 1 + (cmos_sound & 0x0f);
/* Try to find the name in the stringset to match the CMOS-set channel */
error_trap(stringset_set_selected(0, window_id, VoicesStringset, ""), 0);
error_trap(stringset_set_selected(0, window_id, VoicesStringSet, ""), 0);
for (n=0; n<15; n++)
{
if (menu_to_voice_map[n] == voice)
{
error_trap(stringset_set_selected(1, window_id, VoicesStringset, (char*)n), 0);
error_trap(stringset_set_selected(1, window_id, VoicesStringSet, (char*)n), 0);
}
}
/* Is beep quiet or loud? */
error_trap(radiobutton_set_state(0, window_id, cmos_volume & 2 ? LoudRadio : QuietRadio, 1), 0);
error_trap(radiobutton_set_state(0, window_id, cmos_loud & 2 ? LoudRadio : QuietRadio, 1), 0);
/* Error boxes go beep? */
error_trap(optionbutton_set_state(0, window_id, BeepingErrorsOption, cmos_errors & 16 ? 0 : 1), 0);
if (vidcmix)
{
/* Extra hardware options */
error_trap(optionbutton_set_state(0, window_id, OversamplingOption, cmos_soundsys & 0x80 ? 1 : 0), 0);
error_trap(optionbutton_set_state(0, window_id, SixteenBitOption, cmos_soundsys & 0x60 ? 1 : 0), 0);
}
}
else if (condition_code == WriteCMOSSettings)
{
error_trap(stringset_get_selected(1, window_id, VoicesStringset, &n), 0);
char command[32];
error_trap(stringset_get_selected(1, window_id, VoicesStringSet, &n), 0);
if (n != -1) voice = menu_to_voice_map[n] - 1;
if (voice >= 0)
{
cmos_voice &= ~0x0f;
cmos_voice |= voice;
write_cmos_value(CMOS_Voice, cmos_voice);
cmos_sound &= ~0x0f;
cmos_sound |= voice;
write_cmos_value(SoundCMOS, cmos_sound);
}
error_trap(radiobutton_get_state(0, window_id, LoudRadio, &n, NULL), 0);
cmos_volume &= ~2;
cmos_volume |= 2 * n;
write_cmos_value(CMOS_BellVolume, cmos_volume);
cmos_loud &= ~2;
cmos_loud |= 2 * n;
write_cmos_value(DBTBCMOS, cmos_loud);
error_trap(optionbutton_get_state(0, window_id, BeepingErrorsOption, &n), 0);
cmos_errors &= ~16;
cmos_errors |= 16 * (1 - n);
sprintf(command, "CONFIGURE WIMPFLAGS %d", cmos_errors);
_swix(OS_CLI, _IN(0), command); /* This gives an instant effect, unlike poking CMOS */
if (vidcmix)
{
error_trap(optionbutton_get_state(0, window_id, OversamplingOption, &n), 0);
cmos_soundsys &= ~0x80;
cmos_soundsys |= 0x80 * n;
error_trap(optionbutton_get_state(0, window_id, SixteenBitOption, &n), 0);
cmos_soundsys &= ~0x60;
cmos_soundsys |= 0x20 * n; /* DAC clk slave, use ext clk, per Risc PC & A7000(+) */
write_cmos_value(PrintSoundCMOS, cmos_soundsys);
}
}
}
......@@ -285,6 +421,18 @@ void sound_read_choices(int window_id)
unsigned char mute;
int gain;
if (vidcmix)
{
int volume;
/* Comes from CMOS rather than Choices: */
volume = 1 + (18 * ((cmos_sound >> 4) & 7));
channel[0].configured_gain = sound_volume_to_db(volume + 15);
channel[0].configured_mute = FALSE;
return;
}
/* Start with hard defaults */
for (int i = 0; i < nchannels; i++)
{
......@@ -292,12 +440,12 @@ void sound_read_choices(int window_id)
channel[i].configured_mute = channel[i].muted_by_default;
}
fp = fopen(ChoicesRead, "r");
if (fp)
if (fp != NULL)
{
while (more)
{
/* Get next string */
more = fgets(buffer, 256, fp);
more = fgets(buffer, sizeof(buffer), fp);
if (more)
{
/* Check for a suitable looking line */
......@@ -319,12 +467,6 @@ void sound_read_choices(int window_id)
fclose(fp);
}
/* Set up UI */
for (int i = 0; i < nchannels; i++)
{
error_trap(slider_set_value(0, window_id, 2 + i * 4, channel[i].configured_gain), 0);
error_trap(optionbutton_set_state(0, window_id, 3 + i * 4, channel[i].configured_mute), 0);
}
}
......@@ -341,12 +483,30 @@ void sound_save_choices(int window_id)
FILE *fp;
FILE *fp2;
char buffer[256];
int mute;
if (vidcmix)
{
int volume;
/* Turn dB*16 back into 3dB per 16 volume */
error_trap(slider_get_value(0, window_id, 2 + 0 * 4, &channel[0].original_gain), 0);
volume = sound_db_to_volume(channel[0].original_gain);
/* Cram into 3 sound CMOS bits */
volume = (volume - 1) / 18;
cmos_sound &= ~0x70;
cmos_sound |= (volume << 4);
write_cmos_value(SoundCMOS, cmos_sound);
return;
}
fp = fopen(ChoicesWrite, "w");
if (fp)
if (fp != NULL)
{
fp2 = fopen(BlankChoices, "r");
if (fp2)
if (fp2 != NULL)
{
bool more;
do
......@@ -360,7 +520,6 @@ void sound_save_choices(int window_id)
for (int i = 0; i < nchannels; i++)
{
error_trap(slider_get_value(0, window_id, 2 + i * 4, &channel[i].original_gain), 0);
int mute;
error_trap(optionbutton_get_state(0, window_id, 3 + i * 4, &mute), 0);
channel[i].original_mute = mute;
fprintf(fp, "MixVolume 0 %d %u %c %d\n", channel[i].category, channel[i].index, mute + '0', channel[i].original_gain);
......@@ -368,9 +527,9 @@ void sound_save_choices(int window_id)
fclose(fp);
}
_swix(OS_File, _INR(0,2),
18,
OSFile_SetType,
ChoicesWrite,
0xFEB);
FileType_Obey);
}
......@@ -384,10 +543,11 @@ void sound_save_choices(int window_id)
int sound_reflect_gadget_state(int event_code, ToolboxEvent *event_block, IdBlock *id_block, void *handle)
{
(void)event_code;
(void)event_block;
int window_id = id_block->self_id;
(void)handle;
(void)event_code;
(void)event_block;
for (int i = 0; i < nchannels; i++)
{
int gain;
......@@ -416,16 +576,23 @@ int sound_reflect_gadget_state(int event_code, ToolboxEvent *event_block, IdBloc
}
if (!channel[i].fixed)
{
error_trap(_swix(SoundCtrl_SetMix, _INR(0,4),
0,
channel[i].category,
channel[i].index,
mute,
gain), 0);
if (vidcmix)
{
error_trap(_swix(Sound_Volume, _IN(0), sound_db_to_volume(gain)), 0);
}
else
{
error_trap(_swix(SoundCtrl_SetMix, _INR(0,4),
0,
channel[i].category,
channel[i].index,
mute,
gain), 0);
}
}
}
int voiceindex;
error_trap(stringset_get_selected(1, window_id, VoicesStringset, &voiceindex), 0);
error_trap(stringset_get_selected(1, window_id, VoicesStringSet, &voiceindex), 0);
int voiceslot;
if (voiceindex != -1 && (voiceslot = menu_to_voice_map[voiceindex]) != -1)
{
......@@ -435,21 +602,21 @@ int sound_reflect_gadget_state(int event_code, ToolboxEvent *event_block, IdBloc
error_trap(radiobutton_get_state(0, window_id, QuietRadio, &quiet, NULL), 0);
int old_volume;
_swix(OS_Byte, _INR(0,2)|_OUT(1),
OSBYTE_ReadWriteBellVolume,
OsByte_RW_BELLVolume,
0,
255,
&old_volume);
if (quiet && old_volume != 0xD0)
{
_swix(OS_Byte, _INR(0,2),
OSBYTE_ReadWriteBellVolume,
OsByte_RW_BELLVolume,
0xD0,
0);
}
else if (!quiet && old_volume != 0x90)
{
_swix(OS_Byte, _INR(0,2),
OSBYTE_ReadWriteBellVolume,
OsByte_RW_BELLVolume,
0x90,
0);
}
......@@ -467,8 +634,15 @@ int sound_reflect_gadget_state(int event_code, ToolboxEvent *event_block, IdBloc
void sound_reset_to_configured(int window_id)
{
sound_read_choices(window_id);
sound_read_write_cmos_settings(ReadCMOSSettings, window_id);
sound_read_choices(window_id);
/* Set up UI */
for (int i = 0; i < nchannels; i++)
{
error_trap(slider_set_value(0, window_id, 2 + i * 4, channel[i].configured_gain), 0);
error_trap(optionbutton_set_state(0, window_id, 3 + i * 4, channel[i].configured_mute), 0);
}
sound_reflect_gadget_state(0, NULL, &(IdBlock){ .self_id = window_id }, NULL);
}
......@@ -488,7 +662,7 @@ void sound_reset_to_defaults(int window_id)
error_trap(slider_set_value(0, window_id, 2 + i * 4, 0), 0);
error_trap(optionbutton_set_state(0, window_id, 3 + i * 4, channel[i].muted_by_default), 0);
}
error_trap(stringset_set_selected(1, window_id, VoicesStringset, 0), 0);
error_trap(stringset_set_selected(1, window_id, VoicesStringSet, 0), 0);
error_trap(radiobutton_set_state(0, window_id, QuietRadio, 1), 0);
sound_reflect_gadget_state(0, NULL, &(IdBlock){ .self_id = window_id }, NULL);
}
......@@ -503,21 +677,28 @@ void sound_reset_to_defaults(int window_id)
void sound_restore_original_settings(void)
{
for (int i = 0; i < nchannels; i++)
if (vidcmix)
{
_swix(Sound_Volume, _IN(0), sound_db_to_volume(channel[0].original_gain));
}
else
{
_swix(SoundCtrl_SetMix, _INR(0,4),
0,
channel[i].category,
channel[i].index,
channel[i].original_mute,
channel[i].original_gain);
for (int i = 0; i < nchannels; i++)
{
_swix(SoundCtrl_SetMix, _INR(0,4),
0,
channel[i].category,
channel[i].index,
channel[i].original_mute,
channel[i].original_gain);
}
}
_swix(Sound_AttachVoice, _INR(0,1),
1,
1 + (cmos_voice & 0x0f));
1 + (cmos_sound & 0x0f));
_swix(OS_Byte, _INR(0,2),
OSBYTE_ReadWriteBellVolume,
cmos_volume & 2 ? 0x90 : 0xD0,
OsByte_RW_BELLVolume,
cmos_loud & 2 ? 0x90 : 0xD0,
0);
}
......
......@@ -13,25 +13,13 @@
* limitations under the License.
*/
/*---------------------------------------------------------------------------*/
/* File: h.common */
/* File: common.h */
/*---------------------------------------------------------------------------*/
#include "wimplib.h"
#include "defines.h"
#define NewLine 0x0A
#define Wimp_MOpenConfigWindow 0x50d83
typedef struct
{
char type;
int value;
} evexp;
inline void error_trap(_kernel_oserror *err, int err_type);
void error_trap(_kernel_oserror *err, int err_type);
void messages_register(MessagesFD *messagefd_point, char *messagebuff_point);
char *messages_lookup(char *token_string);
const char* messages_lookup_withparam(const char *token_string, const char* parameter);
......@@ -44,26 +32,3 @@ int read_cmos_value(int location);
void write_cmos_value(int location, int value);
extern char TaskName[];
/*---------------------------------------------------------------------------*
* error_trap *
* *
* Wrap around a function to report an error if one occurred eg.: *
* error_trap(event_initialise(&idb), 0); *
* *
* In: err - a kernel_oserror block *
* type - 0 means non-fatal, otherwise program will exit after reporting *
*---------------------------------------------------------------------------*/
inline void error_trap(_kernel_oserror *err, int err_type)
{
/* Report the appropriate error, has one occured */
if (err != NULL)
{
wimp_report_error(err, 0, TaskName, 0, 0, 0);
/* Now, if it was a fatal error (type != 0), exit at once */
if (err_type != 0) exit(0);
}
}
......@@ -13,35 +13,30 @@
* limitations under the License.
*/
/*---------------------------------------------------------------------------*/
/* File: h.defines */
/* File: defines.h */
/*---------------------------------------------------------------------------*/
/* Toolbox gadgets */
#define TemplateLabel ((ComponentId) 0x000)
#define TemplateButton ((ComponentId) 0x001)
#define TemplateSlider ((ComponentId) 0x002)
#define TemplateOption ((ComponentId) 0x003)
#define SetButton ((ComponentId) 0x100)
#define CancelButton ((ComponentId) 0x101)
#define DefaultButton ((ComponentId) 0x102)
#define BeepGroup ((ComponentId) 0x200)
#define VoicesLabel ((ComponentId) 0x201)
#define VoicesStringset ((ComponentId) 0x202)
#define QuietRadio ((ComponentId) 0x203)
#define LoudRadio ((ComponentId) 0x204)
#define TryButton ((ComponentId) 0x205)
#define TemplateLabel ((ComponentId) 0x000)
#define TemplateButton ((ComponentId) 0x001)
#define TemplateSlider ((ComponentId) 0x002)
#define TemplateOption ((ComponentId) 0x003)
#define SetButton ((ComponentId) 0x100)
#define CancelButton ((ComponentId) 0x101)
#define DefaultButton ((ComponentId) 0x102)
#define BeepGroup ((ComponentId) 0x200)
#define VoicesLabel ((ComponentId) 0x201)
#define VoicesStringSet ((ComponentId) 0x202)
#define QuietRadio ((ComponentId) 0x203)
#define LoudRadio ((ComponentId) 0x204)
#define TryButton ((ComponentId) 0x205)
#define BeepingErrorsOption ((ComponentId) 0x206)
#define OversamplingOption ((ComponentId) 0x207)
#define SixteenBitOption ((ComponentId) 0x208)
/* Heigt offset between volume sliders (OS units) */
/* Height offset between volume sliders (OS units) */
#define SLIDER_HEIGHT (56)
/* CMOS */
#define CMOS_BellVolume 0x10
#define CMOS_PrintSound 0x84
#define CMOS_SoundDefault 0x94
#define CMOS_Volume 0x94
#define CMOS_Voice 0x94
#define CMOS_Speaker 0x94
/* Other stuff */
#define ChoicesWrite "<Choices$Write>.Boot.PreDesk.SndSetup"
#define ChoicesRead "Choices:Boot.PreDesk.SndSetup"
......
......@@ -13,7 +13,7 @@
* limitations under the License.
*/
/*---------------------------------------------------------------------------*/
/* File: h.sound */
/* File: sound.h */
/*---------------------------------------------------------------------------*/
#include <stdbool.h>
......@@ -21,8 +21,6 @@
#define ReadCMOSSettings 1
#define WriteCMOSSettings 2
#define OSBYTE_ReadWriteBellVolume 212
#define MAX_CHANNELS 64 /* currently dictated by component IDs */
extern struct channel
......@@ -41,11 +39,18 @@ extern struct channel
int mingain;
int maxgain;
int step;
}
channel[MAX_CHANNELS];
} channel[MAX_CHANNELS];
#define VIDC_CHANNEL "O2s01", NULL, mixer_CATEGORY_HEADPHONES, 0, \
0, FALSE, \
0, FALSE, \
FALSE, FALSE, FALSE, \
-21*16, 0*16, 3*16
extern unsigned int nchannels;
extern BOOL vidcmix;
void sound_detect_mix_mode(void);
void sound_read_channel_info(void);
void sound_make_voices_menu(int window_id);
void sound_read_write_cmos_settings(int condition_code, int window_id);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment