Commit ebc33b99 authored by Richard Leggett's avatar Richard Leggett
Browse files

Initial import of SndSetup plugin for Configure.

c/** gitlab-language=c linguist-language=c linguist-detectable=true
h/** gitlab-language=c linguist-language=c linguist-detectable=true
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
# Copyright 1998 Acorn Computers Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Makefile for Sound plug-in
#
# ***********************************
# *** C h a n g e L i s t ***
# ***********************************
# Date Name Description
# ---- ---- -----------
# 03-Apr-98 RML Created
#
# Program specific options:
#
COMPONENT = SndSetup
APP = !${COMPONENT}
RDIR = Resources
LDIR = ${RDIR}.${LOCALE}
#
# Generic options:
#
MKDIR = cdir
CC = cc
LD = link
CP = copy
RM = remove
SQUISH = squish
WIPE = -wipe
AFLAGS = ${THROWBACK} -depend !Depend -nocache -stamp -quit -module
CFLAGS = ${THROWBACK} -depend !Depend -ffa ${INCLUDES}
CPFLAGS = ~cfr~v
SQFLAGS = -nolist
WFLAGS = ~c~v
#
# Libraries
#
CLIB = CLib:o.stubs
EVENTLIB = tbox:o.eventlib
TOOLBOXLIB = tbox:o.toolboxlib
WIMPLIB = tbox:o.wimplib
#
# Include files
#
INCLUDES = -Itbox:,C:
FILES =\
${RDIR}.!Boot \
${RDIR}.!Run \
${RDIR}.!Sprites22 \
${RDIR}.CoSprite22 \
${RDIR}.!RunImage \
${LDIR}.Messages \
${LDIR}.Res
OBJS =\
o.main \
o.common \
o.sound
#
# Rule patterns
#
.SUFFIXES: .o
.c.o:; @echo
@echo Compiling $<
@${CC} ${CFLAGS} ${DFLAGS} -c -o $@ $<
#
# Main rules:
#
all: ${FILES}
@echo ${COMPONENT}: Application made.
install: ${FILES}
@echo
@echo ${COMPONENT}: Creating application ${APP}
${MKDIR} ${INSTDIR}.${APP}
${CP} ${RDIR}.!Boot ${INSTDIR}.${APP}.!Boot ${CPFLAGS}
${CP} ${RDIR}.!Run ${INSTDIR}.${APP}.!Run ${CPFLAGS}
${CP} ${RDIR}.!Sprites22 ${INSTDIR}.${APP}.!Sprites22 ${CPFLAGS}
${CP} ${RDIR}.CoSprite22 ${INSTDIR}.${APP}.CoSprite22 ${CPFLAGS}
${CP} ${RDIR}.!RunImage ${INSTDIR}.${APP}.!RunImage ${CPFLAGS}
${CP} ${LDIR}.Messages ${INSTDIR}.${APP}.Messages ${CPFLAGS}
${CP} ${LDIR}.Res ${INSTDIR}.${APP}.Res ${CPFLAGS}
Access ${INSTDIR}.${APP}.* wr/r
@echo
@echo ${COMPONENT}: Application installed {Disc}
clean:
${WIPE} o.* ${WFLAGS}
${WIPE} ${APP}.* ${WFLAGS}
${RM} ${RDIR}.!RunImage
${RM} ${APP}
@echo ${COMPONENT}: cleaned
#
# Static dependencies:
#
Resources.!RunImage: ${OBJS} ${EVENTLIB} ${TOOLBOXLIB} ${WIMPLIB} ${CLIB}
${LD} -o $@ ${CLIB} ${EVENTLIB} ${TOOLBOXLIB} ${WIMPLIB} ${OBJS}
#---------------------------------------------------------------------------
# Dynamic dependencies:
| Copyright 1998 Acorn Computers Ltd
|
| Licensed under the Apache License, Version 2.0 (the "License");
| you may not use this file except in compliance with the License.
| You may obtain a copy of the License at
|
| http://www.apache.org/licenses/LICENSE-2.0
|
| Unless required by applicable law or agreed to in writing, software
| distributed under the License is distributed on an "AS IS" BASIS,
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
| See the License for the specific language governing permissions and
| limitations under the License.
|
Dir <Obey$Dir>
amu_machine all THROWBACK=-throwback
| Copyright 1998 Acorn Computers Ltd
|
| Licensed under the Apache License, Version 2.0 (the "License");
| you may not use this file except in compliance with the License.
| You may obtain a copy of the License at
|
| http://www.apache.org/licenses/LICENSE-2.0
|
| Unless required by applicable law or agreed to in writing, software
| distributed under the License is distributed on an "AS IS" BASIS,
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
| See the License for the specific language governing permissions and
| limitations under the License.
|
Dir <Obey$Dir>
amu_machine clean
| Copyright 1998 Acorn Computers Ltd
|
| Licensed under the Apache License, Version 2.0 (the "License");
| you may not use this file except in compliance with the License.
| You may obtain a copy of the License at
|
| http://www.apache.org/licenses/LICENSE-2.0
|
| Unless required by applicable law or agreed to in writing, software
| distributed under the License is distributed on an "AS IS" BASIS,
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
| See the License for the specific language governing permissions and
| limitations under the License.
|
Dir <Obey$Dir>
amu_machine install INSTDIR=<obey$dir> THROWBACK=-throwback
| !Boot file for Sound configuration plug-in
Set SoundConfig$Dir <Obey$Dir>
Iconsprites <SoundConfig$Dir>.!Sprites
| !Run file for Sound configuration plug-in
RMEnsure UtilityModule 3.10 Error This version of Sound Configure requires RISC OS 3.1 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 SoundConfig$Dir <Obey$Dir>
Iconsprites <SoundConfig$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 Sound Configure
RMEnsure Window 1.41 RMLoad System:modules.toolbox.window
RMEnsure Window 1.41 Error You need Window 1.41 or later to run Sound Configure.
RMEnsure Menu 0.28 RMLoad System:modules.toolbox.menu
RMEnsure Menu 0.28 Error You need Menu 0.28 or later to run Sound Configure.
RMEnsure SoundCtrl 0.00 Error You need SoundCtrl 0.00 or later to run Sound Configure.
WimpSlot -min 256k -max 256k
Run <SoundConfig$Dir>.!RunImage %*0
File added
File added
# Messages file for Sound configuration
_TaskName:Sound Setup
_Purpose:Configuring the sound system
_Author:© Acorn Computers Ltd, 1998
_Version:0.03 (03-Apr-98)
_ConfigText:Sound
_ConfigHelp:Click SELECT to open the Sound configuration window.
_ConfigSprite:co_sound
# Standard miscellaneous messages
reportt:Message from Configure
# Error messages
NotEnoughMemory:There is not enough memory to do that operation.
ChoicesFileNotOpen:Couldn't open choices file.
File added
/* Copyright 1998 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*---------------------------------------------------------------------------*/
/* File: c.common */
/* Purpose: Commonly used Wimp routines */
/* Author: Richard Leggett */
/* History: 28-Oct-97: RML: Begun (some routines nicked from PhotoQV) */
/* */
/* Copyright 1997 Acorn Computers Ltd., Cambridge, UK. */
/*---------------------------------------------------------------------------*/
#include <stdlib.h>
#include <string.h>
#include "kernel.h"
#include "wimp.h"
#include "wimplib.h"
#include "toolbox.h"
#include "gadgets.h"
#include "swis.h"
#include "defines.h"
#define Flag_GadgetFaded 1u<<31
/* Global messages file descriptor and string pointer */
MessagesFD *message_block;
char *message_buffer;
/*---------------------------------------------------------------------------*
* 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 *
*---------------------------------------------------------------------------*/
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);
}
}
/*---------------------------------------------------------------------------*
* messages_register *
* *
* Registers the message file descriptor with the library so that it knows *
* where to find the message block for lookups. *
* *
* In: *
*---------------------------------------------------------------------------*/
void messages_register(MessagesFD *messagefd_point, char *messagebuff_point)
{
message_block = messagefd_point;
message_buffer = messagebuff_point;
}
/*---------------------------------------------------------------------------*
* messages_lookup *
* *
* Searches the 'messages' file for the text represented by the token string *
* and returns a pointer to a buffer storing this text *
* *
* In: *
*---------------------------------------------------------------------------*/
char* messages_lookup(char *token_string)
{
_kernel_swi_regs regs;
regs.r[0] = (int)message_block;
regs.r[1] = (int)token_string;
regs.r[2] = (int)message_buffer;
regs.r[3] = 255;
_kernel_swi(MessageTrans_Lookup, &regs, &regs);
return message_buffer;
}
/*---------------------------------------------------------------------------*
* common_read_screensize *
* *
* Return the size of rhe screen in OS units *
*---------------------------------------------------------------------------*/
_kernel_oserror* common_read_screensize(int *x, int *y)
{
_kernel_oserror* e;
int xeig;
int yeig;
int xpix;
int 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;
e=_swix(OS_ReadModeVariable, _INR(0,1)|_OUT(2), -1, 11, &xpix); if (e) return e;
e=_swix(OS_ReadModeVariable, _INR(0,1)|_OUT(2), -1, 12, &ypix); if (e) return e;
*x = xpix << xeig;
*y = ypix << yeig;
return NULL;
}
/*---------------------------------------------------------------------------*
* common_error *
* *
* Given a string, return a kernel_oserror compatible error. *
*---------------------------------------------------------------------------*/
_kernel_oserror* common_error(char *s)
{
static _kernel_oserror e;
e.errnum = 0;
strcpy(e.errmess, s);
return &e;
}
/*---------------------------------------------------------------------------*
* grey_gadget *
* *
* Grey a a gadget. *
* *
* In: objectid = ID of the object containing the gadget. *
* gadgetid = ID of the gadget. *
*---------------------------------------------------------------------------*/
void grey_gadget(int objectid, int gadgetid)
{
unsigned int flags;
error_trap(gadget_get_flags(0, objectid, gadgetid, &flags), 0);
flags=flags | Flag_GadgetFaded;
error_trap(gadget_set_flags(0, objectid, gadgetid, flags), 0);
}
/*---------------------------------------------------------------------------*
* ungrey_gadget *
* *
* Ungrey a a gadget. *
* *
* In: objectid = ID of the object containing the gadget. *
* gadgetid = ID of the gadget. *
*---------------------------------------------------------------------------*/
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;
error_trap(gadget_set_flags(0, objectid, gadgetid, flags), 0);
}
/*---------------------------------------------------------------------------*
* strncmpa *
* *
* Compare n letters of a string, case insensitive. *
* *
* In: str1 -> first string *
* str2 -> second string *
* size = number of characters to compare. *
* *
* Returns: 0 if strings equal, otherwise number of characters they differ *
* by. *
*---------------------------------------------------------------------------*/
int strncmpa(char *str1, char *str2, int size)
{
int n;
int equal = size;
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--;
}
return equal;
}
/*---------------------------------------------------------------------------*
* read_cmos_value *
* *
* Read a byte of CMOS ram *
* *
* In: location = CMOS location to read *
* *
* Returns: contents of location. *
*---------------------------------------------------------------------------*/
int read_cmos_value(int location)
{
int result;
_swix(OS_Byte, _INR(0,1)|_OUT(2), 161, location, &result);
return result;
}
/*---------------------------------------------------------------------------*
* write_cmos_value *
* *
* Write a byte of CMOS ram *
* *
* In: location = CMOS location to write *
* value = value to write *
*---------------------------------------------------------------------------*/
void write_cmos_value(int location, int value)
{
_swix(OS_Byte, _INR(0,2), 162, location, value);
}
/* Copyright 1998 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*---------------------------------------------------------------------------*/
/* File: c.main */
/* Purpose: Main WIMP shell for Sound configuration */
/* Author: Richard Leggett */
/* History: 29-Jan-98: RML: Begun. */
/* 20-Mar-98: RML: Minor modifications. */
/* */
/* Copyright 1998 Acorn Computers Ltd., Cambridge, UK. */
/*---------------------------------------------------------------------------*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "swis.h"
#include "toolbox.h"
#include "event.h"
#include "common.h"
#include "window.h"
#include "wimplib.h"
#include "defines.h"
#include "sound.h"
static MessagesFD messages_desc;
static IdBlock idb;
static char messages_string[255];
static int config_window_id;
/*---------------------------------------------------------------------------*
* program_exit *
* *
* Finished with this plug-in, so exit. *
*---------------------------------------------------------------------------*/
static void program_exit(void)
{
exit(0);
}
/*---------------------------------------------------------------------------*
* set_default_choices *
* *
* Fill in the default choices in the dialogue box. *
*---------------------------------------------------------------------------*/
static void set_default_choices(void)
{
int n;
/* Default volume level is 0 for each channel */
for (n=0; n<NumberOfChannels; n++)
{
error_trap(numberrange_set_value(0, config_window_id, n, 0), 0);
sound_set_volume(n, 0);
}
sound_set_cmos_defaults();
error_trap(stringset_set_selected(1, config_window_id, VoicesStringset, (char*)0), 0);
error_trap(radiobutton_set_state(0, config_window_id, LoudRadio, 1), 0);
}
/*---------------------------------------------------------------------------*
* restore_choices *
* *
* Restore original choices. *
*---------------------------------------------------------------------------*/
static void restore_choices(void)
{
sound_read_choices(config_window_id);
sound_read_write_cmos_settings(WriteCMOSSettings, config_window_id);
}
/*-----------------------------------------------------------------------------------------------*/
/* Event handlers */
/*-----------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*
* toolbox_error *
* *
* Handler for errors from toolbox. *
*---------------------------------------------------------------------------*/
static int toolbox_error(int event_code, ToolboxEvent *event, IdBlock *id_block, void *handle)
{
ToolboxErrorEvent *error_event = (ToolboxErrorEvent *)event;
_kernel_oserror err;
strcpy(err.errmess, error_event->errmess);
err.errnum = error_event->errnum;
wimp_report_error(&err, 0, "Configure", 0, 0, 0);
return 1;
}
/*---------------------------------------------------------------------------*
* default_key_handler *
* *
* Handler for key presses. *
*---------------------------------------------------------------------------*/
static int default_key_handler(int event_code, WimpPollBlock *event, IdBlock *id_block, void *handle)
{
int key_code = event->key_pressed.key_code;
wimp_process_key(key_code);
return 1;
}
/*---------------------------------------------------------------------------*
* radio_changed *
* *
* The quiet/loud radio button has changed state. *
*---------------------------------------------------------------------------*/
static int radio_changed(int event_code, ToolboxEvent *event_block, IdBlock *id_block, void *handle)
{
int state;
int selected;
int byte;
byte = read_cmos_value(CMOS_BellVolume);
error_trap(radiobutton_get_state(0, config_window_id, QuietRadio, &state, &selected), 0);
switch(selected)
{
case QuietRadio:
if (byte & 2) byte = byte^2;
break;
case LoudRadio:
if (!(byte & 2)) byte = byte^2;
break;
}
/* Beep */
write_cmos_value(CMOS_BellVolume, byte);
_kernel_osbyte(OSBYTE_ReadWriteBellVolume, selected == LoudRadio ? 0x80 : 0xd0, 0);
printf("\07");
return 1;
}
/*---------------------------------------------------------------------------*
* voice_changed *
*---------------------------------------------------------------------------*/
static int voice_changed(int event_code, ToolboxEvent *event_block, IdBlock *id_block, void *handle)
{
int index;
error_trap(stringset_get_selected(1, config_window_id, VoicesStringset, &index), 0);
sound_change_voice(index);
return 1;
}
/*---------------------------------------------------------------------------*
* slider_value_changed *
* *
* The user has dragged a slider and changed it's value. *
*---------------------------------------------------------------------------*/
static int slider_value_changed(int event_code, ToolboxEvent *event_block, IdBlock *id_block, void *handle)
{
NumberRangeValueChangedEvent *event = (NumberRangeValueChangedEvent*)event_block;
int value = event->new_value;
int icon = id_block->self_component;
sound_set_volume(icon, value);
return 1;
}
/*---------------------------------------------------------------------------*
* action_selected *
* *
* Handler for when action buttons are clicked on. *
*---------------------------------------------------------------------------*/
static int action_selected(int event_code, ToolboxEvent *event_block, IdBlock *id_block, void *handle)
{
ActionButtonSelectedEvent *block = (ActionButtonSelectedEvent*) event_block;
int icon = id_block->self_component;
switch (icon)
{
case SetButton:
sound_save_choices(config_window_id);
if ((block->hdr.flags & 7)==0) program_exit(); /* Return pressed */
if (block->hdr.flags & 4) program_exit(); /* Left button */
break;
case CancelButton:
restore_choices();
if ((block->hdr.flags & 7)==0) program_exit(); /* Escape pressed */
if (block->hdr.flags & 4) program_exit(); /* Left button */
break;
case DefaultButton:
set_default_choices();
break;
}
return 1;
}
/*---------------------------------------------------------------------------*
* message_quit *
* *
* Called when wimp quit message received. *
*---------------------------------------------------------------------------*/
static int message_quit(WimpMessage *event, void *handler)
{
program_exit();
return 1;
}
/*---------------------------------------------------------------------------*
* message_reopen *
* *
* Called when we receive a message from Configure telling us to reopen our *
* window. *
*---------------------------------------------------------------------------*/
static int message_reopen(WimpMessage *event, void *handler)
{
error_trap(toolbox_show_object(0, config_window_id, 0, 0, 0, 0), 0);
return 1;
}
/*---------------------------------------------------------------------------*
* close_window *
* *
* Called when user has clicked on close icon of window. *
*---------------------------------------------------------------------------*/
static int close_window(int event_code, WimpPollBlock *event, IdBlock *id_block, void *handle)
{
program_exit();
return 1;
}
/*----------------------------------------------------------------------------------------------*/
/* Program startup & polling loop */
/*----------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*
* open_configure_window *
* *
* Called to open the configure window on screen and register handlers. *
*---------------------------------------------------------------------------*/
static void open_configure_window(int at_x, int at_y)
{
BBox bbox;
int screenx;
int screeny;
int buffer[2];
/* Create window */
error_trap(toolbox_create_object(0, "Window", &config_window_id), 1);
/* Register handlers for the configure window */
error_trap(event_register_toolbox_handler(config_window_id, ActionButton_Selected, action_selected, NULL), 0);
error_trap(event_register_toolbox_handler(config_window_id, NumberRange_ValueChanged, slider_value_changed, NULL), 0);
error_trap(event_register_toolbox_handler(config_window_id, RadioButton_StateChanged, radio_changed, NULL), 0);
error_trap(event_register_toolbox_handler(config_window_id, StringSet_ValueChanged, voice_changed, NULL), 0);
error_trap(event_register_wimp_handler(config_window_id, Wimp_ECloseWindow, close_window, NULL), 0);
error_trap(event_register_wimp_handler(-1, Wimp_EKeyPressed, default_key_handler, NULL), 0);
/* Work out positioning (unless it was supplied in the command line) */
if ((at_x==-1) && (at_y==-1))
{
error_trap(common_read_screensize(&screenx, &screeny), 0);
error_trap(window_get_extent(0, config_window_id, &bbox), 0);
at_y = screeny - ((screeny+bbox.ymin)/2);
at_x = (screenx - bbox.xmax)/2;
}
/* Show the window */
buffer[0] = at_x;
buffer[1] = at_y;
error_trap(toolbox_show_object(0, config_window_id, 2, buffer, 0, 0), 0);
}
/*---------------------------------------------------------------------------*
* main_initialise *
* *
* Initialise toolbox etc. *
* *
* In: Nothing. *
* *
* Returns: 1 if everything went okay, 0 otherwise *
*---------------------------------------------------------------------------*/
static int main_initialise(void)
{
static int mess_wanted[] = {Wimp_MQuit,
Wimp_MOpenConfigWindow,
0};
static int tbox_wanted[] = {Toolbox_Error,
ActionButton_Selected,
NumberRange_ValueChanged,
RadioButton_StateChanged,
StringSet_ValueChanged,
0};
int task_handle;
error_trap(toolbox_initialise(0, 310, mess_wanted, tbox_wanted,
"<SoundConfig$Dir>", &messages_desc, &idb,
0, &task_handle, 0) ,1);
error_trap(event_initialise(&idb), 0);
error_trap(event_set_mask(Wimp_Poll_NullMask), 0);
messages_register(&messages_desc, messages_string);
error_trap(event_register_message_handler(Wimp_MQuit, message_quit, NULL), 0);
error_trap(event_register_message_handler(Wimp_MOpenConfigWindow, message_reopen, NULL), 0);
error_trap(event_register_toolbox_handler(-1,Toolbox_Error,toolbox_error,NULL) ,0);
return 1;
}
/*---------------------------------------------------------------------------*
* main *
* *
* Main polling loop *
*---------------------------------------------------------------------------*/
int main(int argc, char *argv[])
{
WimpPollBlock wpb;
int event_code;
int openat_x = -1;
int openat_y = -1;
/* Have we been passed any co-ordinates to open at? */
if (strcmp(argv[1], "-openat")==0)
{
openat_x = atoi(argv[2]);
openat_y = atoi(argv[3]);
}
/* Do main initialisation */
if (!main_initialise()) return 0;
open_configure_window(openat_x, openat_y);
sound_make_voices_menu(config_window_id);
sound_read_channel_info(config_window_id);
sound_read_choices(config_window_id);
sound_read_write_cmos_settings(ReadCMOSSettings, config_window_id);
/* Poll loop */
while (TRUE)
{
error_trap(event_poll(&event_code, &wpb, NULL), 0);
}
return 0;
}
/* Copyright 1998 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*---------------------------------------------------------------------------*/
/* File: c.sound */
/* Purpose: Sound specific code */
/* Author: Richard Leggett */
/* History: 29-Jan-98: RML: Begun. */
/* */
/* Copyright 1998 Acorn Computers Ltd., Cambridge, UK. */
/*---------------------------------------------------------------------------*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "swis.h"
#include "toolbox.h"
#include "gadgets.h"
#include "common.h"
#include "defines.h"
#include "sound.h"
#define SoundCtrl_SetVolume 0x50002
#define SoundCtrl_ChannelInfo 0x50004
#define Flag_LeftMuted 1u<<0
#define Flag_RightMuted 2u<<1
/* SndSetup numbers channels from 0 to NumberOfChannels. The toolbox ID of the slider
gadget equals this channel number. However, SoundCtrl adopts different numbering, so
the array channel_no maps between SndSetup and SoundCtrl's numbering. The array
channel_name contains the name of each channel as specified in the Sound configuration
file in <Choices$Write>.Sound. */
static char *channel_name[NumberOfChannels] = { "Master", "System", "CD", "Line",
"Mic", "Capture", "Playback", "Wavetable" };
static int channel_no[NumberOfChannels] = { 0, 11, 2, 1,
5, 12, 8, 10 };
static int min_volume[NumberOfChannels];
static int menu_to_voice_map[16];
static int cmos_voice, cmos_volume;
/*---------------------------------------------------------------------------*
* sound_read_channel_info *
* *
* Read the min volume, max volume and step for each channel and set the *
* sliders accordingly. *
* *
* In: window_id = ID of the Sound configure window. *
*---------------------------------------------------------------------------*/
void sound_read_channel_info(int window_id)
{
int n;
int min_i, max_i, step_i;
float min_f, max_f, step_f;
/* Read in min, max & volume settings for the channels */
for (n=0; n<NumberOfChannels; n++)
{
/* Read the min, max and step of the volume for this channel */
error_trap(_swix(SoundCtrl_ChannelInfo, _INR(0,1)|_OUTR(4,6),
0, channel_no[n], &min_i, &max_i, &step_i), 1);
/* Convert the values we read back (32bit, 16bit for fraction) into floats */
min_f = 10 * ((float)min_i) / (1<<16);
max_f = 10 * ((float)max_i) / (1<<16);
step_f = 10 * ((float)step_i) / (1<<16);
min_volume[n] = (int)min_f;
error_trap(numberrange_set_bounds(15, window_id, n, (int)min_f, (int)max_f, (int)step_f, 1), 0);
}
/* Set up the sliders - min max step */
//error_trap(numberrange_set_bounds(15, window_id, 0, -465, 0, 15, 1), 0); /* Master */
//error_trap(numberrange_set_bounds(15, window_id, 1, -945, 0, 15, 1), 0); /* IS 1 = VIDC */
//error_trap(numberrange_set_bounds(15, window_id, 2, -345, 120, 15, 1), 0); /* CD */
//error_trap(numberrange_set_bounds(15, window_id, 3, -345, 120, 15, 1), 0); /* Line */
//error_trap(numberrange_set_bounds(15, window_id, 4, -450, 0, 30, 1), 0); /* Mic */
//error_trap(numberrange_set_bounds(15, window_id, 5, 0, 225, 15, 1), 0); /* Playback */
//error_trap(numberrange_set_bounds(15, window_id, 6, -945, 0, 15, 1), 0); /* Capture */
//error_trap(numberrange_set_bounds(15, window_id, 7, -945, 0, 15, 1), 0); /* IS 0 = Wavetable */
}
/*---------------------------------------------------------------------------*
* sound_set_volume *
* *
* Set the volume for a given channel. *
* *
* In: channel = channel whose volume we wish to change. This number is our *
* internal number (between 0 and 7), rather than the channel *
* number held by SoundCtrl. The channel_no array maps between *
* the two. *
* volume = volume, in db, times 10. *
*---------------------------------------------------------------------------*/
void sound_set_volume(int channel, int volume)
{
float db;
int flags;
/* If volume is minimum value, then mute instead */
if (volume == min_volume[channel]) flags = Flag_LeftMuted + Flag_RightMuted;
else flags = 0;
/* Convert a volume integer (db*10 eg. -125 means -12.5db) into 32bit with 16bit fraction */
db = (1<<16) * ((float)volume) / 10;
/* Set the volume */
error_trap(_swix(SoundCtrl_SetVolume, _INR(0,4), flags, channel_no[channel], 0, (int)db, (int)db), 0);
}
/*---------------------------------------------------------------------------*
* sound_read_write_cmos_settings *
* *
* Read or write the CMOS settings for volume and voice, then update the *
* appropriate window gadgets. *
* *
* In: condition_code = ReadCMOSSettings or WriteCMOSSettings *
* window_id = toolbox ID of the configuration window *
*---------------------------------------------------------------------------*/
void sound_read_write_cmos_settings(int condition_code, int window_id)
{
int voice, n;
/* Are we reading or writing CMOS? */
if (condition_code == ReadCMOSSettings)
{
cmos_voice = read_cmos_value(CMOS_Voice);
cmos_volume = read_cmos_value(CMOS_BellVolume);
}
else if (condition_code == WriteCMOSSettings)
{
write_cmos_value(CMOS_Voice, cmos_voice);
write_cmos_value(CMOS_BellVolume, cmos_volume);
}
voice = 1 + (cmos_voice & 0x0f);
/* Try and find the name in the stringset to match the CMOS-set channel */
error_trap(stringset_set_selected(0, window_id, VoicesStringset, "*** None ***"), 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);
_swix(Sound_AttachVoice, _INR(0,1), 1, voice);
}
}
/* Is beep quiet or loud? */
error_trap(radiobutton_set_state(0, window_id, cmos_volume & 2 ? LoudRadio : QuietRadio, 1), 0);
_kernel_osbyte(OSBYTE_ReadWriteBellVolume, cmos_volume & 2 ? 0x80 : 0xd0, 0);
}
/*---------------------------------------------------------------------------*
* sound_set_unused *
* *
* Set 16bit sound and volume settings stored in CMOS. These are no longer *
* configurable. *
*---------------------------------------------------------------------------*/
void sound_set_cmos_defaults(void)
{
int byte;
/* Set 16bit sound (bits 5-6 of CMOS_PrintSound byte) */
byte = read_cmos_value(CMOS_PrintSound);
byte = (byte & 0x9f) | (1<<5);
write_cmos_value(CMOS_PrintSound, byte);
/* Sound default CMOS byte, composed of:
bits 0-3: channel 0 default voice (0)
bits 4-6: loudness, 0 - 7 (7)
bit 7: loudspeaker enable (1) */
byte = 0 + (7<<4) + (1<<7);
write_cmos_value(CMOS_SoundDefault, byte);
/* Set bell volume to loud (bit 1) of Miscellaneous flags byte */
byte = read_cmos_value(CMOS_BellVolume);
byte = (byte & 0xFD) | 1;
write_cmos_value(CMOS_BellVolume, byte);
/* Set voice and loud bell volume */
_swix(Sound_AttachVoice, _INR(0,1), 1, 1);
_kernel_osbyte(OSBYTE_ReadWriteBellVolume, 0x80, 0);
}
/*---------------------------------------------------------------------------*
* sound_read_choices *
* *
* Read the sound choices from the Choices file. *
* *
* In: window_id = toolbox ID of sound configuration window. *
*---------------------------------------------------------------------------*/
void sound_read_choices(int window_id)
{
FILE *fp;
char *item;
char *value;
char buffer[256];
int n, colon, more=1;
fp = fopen(ChoicesFile, "r");
if (fp)
{
while (more)
{
/* Get next string */
more = (int)fgets(buffer, 256, fp);
if (more)
{
/* Check for a colon in this line */
colon = strstr(buffer, ":") - buffer;
if (colon>0)
{
/* Break the string into item eg. ("Master") and value (eg. "-45") */
buffer[colon] = 0;
item = buffer;
value = item + colon + 1;
value[strlen(value)-1] = 0;
/* Is this item one of the names of channels? */
for (n=0; n<NumberOfChannels; n++)
{
if (strcmp(channel_name[n], item)==0)
{
/* The item corresponds to channel n in our array */
int v = (int) (atof(value)*10);
/* Update slider and set volume */
error_trap(numberrange_set_value(0, window_id, n, v), 0);
sound_set_volume(n, v);
}
}
}
}
}
fclose(fp);
}
}
/*---------------------------------------------------------------------------*
* sound_save_choices *
* *
* Write the volume levels choices file. *
* *
* In: window_id = Toolbox ID of the sound configure window. *
*---------------------------------------------------------------------------*/
void sound_save_choices(int window_id)
{
FILE *fp;
int type, n, v;
char dbstring[16];
char string[32];
/* Ensure choices directory exists */
_swix(OS_File, _INR(0,1)|_OUT(0), 17, ChoicesDir, &type);
if (type==0) error_trap(_swix(OS_CLI, _IN(0), "CDir "ChoicesDir), 0);
/* Write the file */
fp = fopen(ChoicesFile, "w");
if (fp)
{
/* Write the comment lines */
fputs(SoundConfigurationString, fp);
fputc(NewLine, fp);
fputc(NewLine, fp);
fputs(VolumeLevelsString, fp);
fputc(NewLine, fp);
/* Loop through all the channels and make a string for their volumes */
for (n=0; n<NumberOfChannels; n++)
{
error_trap(numberrange_get_value(0, window_id, n, &v), 0);
sprintf(dbstring, "%f", (float)((float)v / 10));
*(strstr(dbstring, ".")+2) = 0;
sprintf(string, "%s:%s", channel_name[n], dbstring);
fputs(string, fp);
fputc(NewLine, fp);
}
fclose(fp);
}
}
/*---------------------------------------------------------------------------*
* sound_make_voices_menu *
* *
* Make a menu of voice modules available. *
* *
* In: window_id - Toolbox ID of the configuration window *
*---------------------------------------------------------------------------*/
void sound_make_voices_menu(int window_id)
{
char strings[1024];
char* name;
char* first = 0;
char* name_local;
int i, m;
memset(strings, 0, 1024);
/* 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;
/* Only read first 16 voices, as 16 is maximum value which can be stored in 4 CMOS bits */
m=0;
for (i=1; i<=16; i++)
{
_swix(Sound_InstallVoice, _INR(0,1)|_OUTR(2,3), 2, i, &name, &name_local);
if (name!=0)
{
if (strlen(strings) > 0) strcat(strings, ",");
if (strlen(strings) == 0) first = name_local;
strcat(strings, name_local);
menu_to_voice_map[m++] = i;
}
}
error_trap(stringset_set_available(0, window_id, VoicesStringset, strings), 0);
error_trap(stringset_set_selected(0, window_id, VoicesStringset, first), 0);
}
/*---------------------------------------------------------------------------*
* sound_change_voice *
* *
* Change the system beep (channel 1) voice *
* *
* In: n = selection number from voices menu *
*---------------------------------------------------------------------------*/
void sound_change_voice(int n)
{
int byte;
int voice = menu_to_voice_map[n];
if ((voice>=1) && (voice<=16))
{
byte = read_cmos_value(CMOS_Voice);
write_cmos_value(CMOS_Voice, (byte & 0xf0) | (voice-1));
_swix(Sound_AttachVoice, _INR(0,1), 1, voice);
}
/* Beep */
printf("\07");
}
/* Copyright 1998 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*---------------------------------------------------------------------------*/
/* File: h.common */
/*---------------------------------------------------------------------------*/
#define NewLine 0x0A
#define Wimp_MOpenConfigWindow 0x50d83
typedef struct
{
char type;
int value;
} evexp;
void error_trap(_kernel_oserror *err, int err_type);
void messages_register(MessagesFD *messagefd_point, char *messagebuff_point);
char *messages_lookup(char *token_string);
_kernel_oserror *common_read_screensize(int* x, int* y);
_kernel_oserror* common_error(char *s);
void grey_gadget(int objectid, int gadgetid);
void ungrey_gadget(int objectid, int gadgetid);
int strncmpa(char* str1, char* str2, int size);
int read_cmos_value(int location);
void write_cmos_value(int location, int value);
/* Copyright 1998 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*---------------------------------------------------------------------------*/
/* File: h.defines */
/*---------------------------------------------------------------------------*/
/* Toolbox gadgets */
#define VoicesStringset 0x1a
#define QuietRadio 0x1e
#define LoudRadio 0x1f
#define DefaultButton 0x20
#define CancelButton 0x21
#define SetButton 0x22
/* 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
/* Strings to output to file */
#define SoundConfigurationString "# Sound configuration"
#define VolumeLevelsString "# Volume levels"
/* Other stuff */
#define TaskName "Sound configuration"
#define ChoicesDir "<Choices$Write>.Sound"
#define ChoicesFile "<Choices$Write>.Sound.Sound"
#define ScrapFile "<Wimp$ScrapDir>.Sound"
/* Copyright 1998 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*---------------------------------------------------------------------------*/
/* File: h.sound */
/*---------------------------------------------------------------------------*/
#define NumberOfChannels 8
#define ReadCMOSSettings 1
#define WriteCMOSSettings 2
#define OSBYTE_ReadWriteBellVolume 212
void sound_read_channel_info(int window_id);
void sound_read_write_cmos_settings(int condition_code, int window_id);
void sound_read_choices(int window_id);
void sound_set_volume(int channel_no, int volume);
void sound_save_choices(int window_id);
void sound_make_voices_menu(int window_id);
void sound_change_voice(int n);
void sound_set_cmos_defaults(void);
*
!.gitignore
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