Introduction

From STX Wiki
Jump to navigationJump to search

This chapter contains a general introduction to the structure of the STx programming and execution environment.

Application Environment

The application environment contains all the data structures and functionallities which are available to the whole application.

Loaded Source Files

All scripts, macros, classes and spu's must be loaded from the source file before they can be executed or instantiated. All loaded sources are available to the whole application.

See also: shell commands LOAD, UNLOAD and LIST

Open Soundfiles

All soundfiles which are opened to STx a stored in a global list and can be accessed by all shells. Before the content (signal or metadata) of a soundfile ca be accessed, it must be opened using the command LOAD SOUNDFILE.

See also: shell commands LOAD, UNLOAD and LIST; wave items

Active Shells

All running shells are registered in the application envrionment.

See also: shell commands SHELL, and LIST

Global Variables

The application environment contains a global variable space, which can be accessed from the whole application. All name prefix character @ is used to address the global variable space. The global variables are used for configuration purposes and should not be changed. The following table shows some of the most important global variables.

name description
@WORK The full pathname of the working directory
@ROOT the full pathname of the STx installation directory
@TEMPDIR The full pathname of the directory for temporary files
@DATASETFILE The full pathname of the active project file
@MASTER The id of the master shell
@OSVER The operating system version
@PROFILE The full pathname of the workspace file

Shell

A shell is the command interpreter and the envrionment executing the loaded code objects. It is created with the SHELL command and ends when the last macro running in the shell is finished (EXIT). All shell are registered in the application environment. A shell can exchange messages with other shells. If a shell is started via the command SHELL mainmacro {arguments}, the macro mainmacro takes control of the shell. If this macro is finished, the shell is also ended

Message Loop

A shell can receive and send messages. The messages are used to communicate with other shells, with the shell items owned by a shell and with the main window of the application. To access the message queue and process messages the command MSG or the library macros GETMESSAGE, DISPATCHMSG, MSGQUEUE, POSTMESSAGE and SETMSGHANDLER can be used.

Shell Items

A shell maintains a list of the owned [Programmer_Guide/Shell_Items|shell items]]. A shell item is owned by a shell if it was created in a macro or instance of a class executed by the shell. Shell items are managed by the commands NEW and DELETE.

  • Normally a shell item is visible only inside a shell, but it is possible to share selected items between shells by using . This technique is used for the workspace and the project
  • All shell items must be deleted before the shell is finished. If the shell executes a user script, using the BScript application, an application cleanup function is used to delete shell items which was created but not deleted by the script.

Shell items are connecting STx with the operation system and its peripherals.

  • The GUI is implemented by the display-, the graph- and the dialog items.
  • The file item can be used to create and access files of several formats, but also to test the existence of a file and to scan directories.
  • tables implements simple database features but can also be used as numerical objects in expressions.
  • The wave item addresses signals stored in soundfiles and/or virtual sequences of synthetic signals. The interface to the sound devices of system for playback and recording is also implemented via the wave items.
  • Via the SPU items a programmable signal processing circuit subsystem is implemented. SPUs can be connected to graphs, value items and to other SPUs.
  • The value item can be used as input for SPUs, as timer and as numerical object in expressions.
  • DCOM and DDECONV items implements interfaces to other applications.
  • ...

Shell Variables

The shell contains a variable space, which can be accessed from all macros and classes executed by the shell. All variables starting with a letter are stored in the shell variable space.

name description see also
SHELL The id of the shell and of the parent shell (thisshell parentshell). This variable is used by some library macros to communicate with other shells. POSTMESSAGE
BDATASET The name of the project instance. This variable must be used to access the content of the current project file. BDATASET
BSTXINI The name of the workspace instance. This variable must be used to access the content of the current workspace file. BSTXINI
APPNAME The name of the application. Only valid if the shell implements a STx application and was started via the application management system. APPMAIN
APPTITLE The title of the application. Only valid if the shell implements a STx application and was started via the application management system. APPMAIN
APPMODE The run mode of the application. Only valid if the shell implements a STx application and was started via the application management system.
>0: the application is running, message processing is activated

<=0: the application is finished, message processing is deactivated
APPMAIN
PARENT The name of the display used as parent window of the application. CREATEMENU
RC The completion code of the last shell command
EMSG The text message corresponding to RC
CSF The full path of the currently selected soundfile. If this variable is empty, no soundfile is selected. LOAD SOUNDFILE
CSFH The header parameters of the currently selected soundfile
(samplingrate channels numberOfSamples samplingCode fileFormat accessMode)
LOAD SOUNDFILE

Macros

A macro is a collection of command lines which can be executed. Macros are used to implement an application, a script or a library function. The macro source code is defined in a source file which must be loaded before the macro can be executed.


During its execution the macro can access:

  • all loaded files (macros, classes, spu's and soundfiles)
  • the global variables (@variablename)
  • all items of the shell executing the macro
  • the shell variables
  • the local variables of the macro (#variablename)

The local variable space of a macro is created when the execution of a macro starts and deleted at the end of the macro execution. The following table shows the special local variables.

name description see also
#ARGV, #ARGC The macro argument string without parsing and the number of arguments passed to the macro.
These variables are generated on macro start and used for read: argument passing style.
macro header, READVAR
#QARGV, #QARGC The macro argument string with parsing information and the number of arguments passed to the macro.
These variables are generated on macro start and used for arg: and argopt: argument passing style.
macro header, ARG, SHIFT,
#MAC The name of the macro.
#READ The result returned by the last READ command.
#MSG The result returned by the last MSG command.
#NEW The result returned by the last NEW command.


Normally shell items created in a macro remain existing when the macro is finished, but in some cases temporary shell items are created, which are automatically deletet at the end of the macro.

Classes, Instances

A class is a special type of macro which enables the programmer to use object-oriented programming techniques. There a two possibilities to execute classes.

  • A class can be used like a macro if its name is used as command.
classname argumens
  • The class can be passed to the NEW command to create an instance of the class.
NEW INSTANCE classname

A member function of an instance can be called by using the following syntax:

instanceItemName memberFunctionName {memberFunctionArguments}

A member function is a part of a class source code starting at the member function label and ending with an EXIT command.

During its execution the member function can access:

  • all loaded files (macros, classes, spu's and soundfiles)
  • the global variables (@variablename)
  • all items of the shell executing the macro
  • the shell variables
  • the local variables of the member function (#variablename)
  • the member variables of the instance (&variablename)

The local variable space of a member function exists only during the runtime of the member function. In addition to the special local variables as described for macros, the following variables are stored in the local variable space when a member function is called

name description
#THIS The name of the instance item. This variable is used by some library macros to communicate with other shells.
#THISMF The name of the member function.

The member variable space of an instance has the same lifetime as the instance itself. This means it exists from the creation to the deletion of the instance item. No special member variables are defined.

The member variables can be accessed from outside the instance as follows:

  • Assign a value to a member variable:
instance.variablename := value
instance.&variablename := value
  • Retrieve a value of a member variable:
instance[!VARIABLE,variablename]
instance[!VARIABLE,&variablename]
  • Parse a member variable:
READVAR instance.variablename targetvar1 ...
READVAR instance.&variablename targetvar1 ...

Note: The member variable prefix character & is assumed, if not specified, and is therefor optional.

If a member variable of an instance is bound to a control of a dialog (e.g. EDIT, COMBOBOX, ...) to syntax instance.variablename (with or without &) should be used, to ensure the dialog item can always access the variable.

Signal Processing Units (SPU)

Script Commands

A script is a collection of commands to be executed. There are different types of commands.

Build-In Commands

shellcommand argumentstring
shellcommand
a build-in command of the shell command interpreter
argstring
the arguments and options supplied to the command

The argstring of a shell command consists of arguments and options. An argument is seperated from each other by blanks or by quotes. If an argument contains whitespace characters (blank, tab, ...) it must be enclosed in quotes.

Examples:

arg1 arg2'arg3' arg4 'arg 5'
This argument string consists of five arguments with the values arg1, arg2, arg3, arg4 and arg 5.
'arg1 arg2 arg3'arg4'arg 5'
This argument string consists of three arguments with the values arg1 arg2 arg3, arg4 and and arg 5.

If a shell command supports options, they must be specified using the syntax /optionname (for switches) or /optionname=optionvalue. The option must start with the character / (slash) and not be inside a quoted part of argstring. Only the first character of optionname is significant. Normally the options are not case sensitive, but there are some exceptions from this rule (e.g.: the options /U and /u of the NEW command).

Example:

arg1 /a/b '/c=arg3' /d='arg4' /e=evalue
This argument string consists of the arguments arg1, /c=arg3, arg4 and the options a, b and e=evalue.

Note: If a parsing character (like / or ') or a special tag character (like $ or [) should be used as part of an argument, it can be escaped with the backquote (`).

Example:

`/oname `$vname iname`[aname`]: This argument string consists of the arguments /oname, $vname and iname[aname]. Without escaping the arguments would be: value of variable vname, attribute aname of shell item iname and the option o.


macroname argumentstring

classname argumentstring

GOSUB subroutinelabel argumentstring

instanceitemname argumentstring




Control Commands

Normally the commands are executed in the order of appearance in the source file, but a special group of commands, the control commands, can be used to change this natural order of execution.

GOTO

GOSUB

WHILE condition

FOR initcommand TO condition STEP stepcommand

IF condition command

IF-THEN-ELSE-END



Many macros use the call-format: name command arguments (e.g. MSGBOX MSG text). If you want to pass quoted arguments to such a macro, use the format MSGBOX 'MSG text' instead of MSGBOX MSG 'text'. This is necessary because the argument string MSG 'text' is passed (after command-line processing) as MSGtext to the macro.If a new shell is called to run a macro, the id (8 hex digits) is assigned to the variable #SHELL of the caller. In the new shell, the variable SHELL is set to 'this_shellid caller_shellid'. The two variables can be used to identify the shells in communication messages.It is not necessary to use the command MACRO explicitly, because the interpreter tries to execute all 'non-shell' commands as a macro. This means the command line MACRO macroname is equivalent to command line macroname.

Navigation menu

Personal tools