変数

grandMA3 ユーザマニュアル » マクロ » 変数 Version 2.2

Variables can be used in macros or command line entries.

Variables have a user-defined name that the variable content replaces when executing the command.

変数には、以下の3種類のデータ型を格納できます。

  • Integer: 符号付き整数
  • Double: 小数部6桁の符号付き固定小数点数
  • Text: 文字列

Signed numbers can be negative numbers, for instance, -7.

Variables are typeless. This means an existing variable can be changed to contain a different type.

変数名には、任意の文字を使えます。大文字と小文字は区別されます。

ヒント
必須ではありませんが、変数名には空白を入れない方がよいでしょう。代わりに、キャメルケース(例: myName)やパスカルケース(例: MyName)を用いることをお勧めします。

変数には2種類のスコープがあります。

変数は、ユーザに対してスコープを設定することも、グローバル変数にすることも可能です。

User variables can only be seen and used by the user profile that creates them, while global variables can be seen and used by all users in the session.


SetGlobalVariable と SetUserVariable

グローバル変数でもユーザ変数でも作成方法は同様ですが、それぞれに使用するキーワードは、SetGlobalVariableSetUserVariable になります。

This is the syntax:

SetGlobalVariable ["変数名"] ["Content text with or without spaces"]

SetGlobalVariable ["変数名"] [Integer or Double]

SetUserVariable ["変数名"] ["Content text with or without spaces"]

SetUserVariable ["変数名"] [Integer または Double]

重要
変数名に空白が含まれている場合、引用符が必要です。空白が含まれていない場合は省略できます。
変数内容の文字列についても同様です。確実に Text 型として保存するには、変数内容を引用符で囲んでください。

User name[Fixture]>SetUserVariable MyFavoriteNumber 9
User name[Fixture]>SetUserVariable MyFavoriteText "9"

These two commands create two variables that might seem to have the same content, but the first is a number, and the second is a text. So, it is not because of the names but the quotation marks in the second example.

シングル・クォーテーションとダブル・クォーテーション

引用符で囲まれたテキストを含む文字列を変数に格納したい場合があります。このとき、ソフトウェアが入力をどのように解釈し、実行時に呼び出された変数がどのように解釈されるかが問題になります。

変数システムでは、シングル・クォーテーションとダブル・クォーテーションのペアに対応しています。

異なる引用符が使われている場合、文字列は引用符で囲まれたテキストを含むことができます。

特定の名前のグループ("Spots Grid")をさまざまな状況で操作したいとします。以下のようにして、"Group" と名前を含む内容を、変数に格納できます。

User name[Fixture]>SetUserVariable MySpecialGroup "Group 'Spots Grid' "

変数のテキスト文字列全体がダブル・クォーテーションで、グループ名がシングル・クォーテーションで囲まれていることに注目してください。これら2種類の引用符を逆にしても、同じ結果になります。

これで、変数によってグループをアドレス指定できます。

User name[Fixture]>$MySpecialGroup At 80

The $ is placed before the command so we can recall the variable.

This is the software's reply:

OK: Group "Spots Grid" At 80

GetGlobalVariable と GetUserVariable

変数の内容と型は、GetGlobalVariableGetUserVariable キーワードを用いて一覧表示できます。

これらのキーワードでは、表示したい変数を指定します。構文は以下の通りです。

GetGlobalVariable ["変数名"]

GetUserVariable ["変数名"]

これらのコマンドは、変数名、型、および内容に関する情報を Command Line History ウィンドウ に表示します。

GetGlobalVariable ではグローバル変数のみが、GetUserVariable ではユーザ変数のみが表示されます。

この構文では、変数名が既知であることを前提としています。

The asterisk (*) wildcard can show all variables or a filtered list of variables for which a part of the name is known.

"MySpecialGroup" という変数の現在の内容は、以下のコマンドで表示できます。

User name[Fixture]>GetUserVariable MySpecialGroup

Command Line History ウィンドウには、以下のように表示されます。

"MySpecialGroup": Type = Text, Value = "Group 'Spots Grid' "
OK: GetUserVariable "MySpecialGroup"

以下の例は、名前に "Our" という語が含まれるすべてのグローバル変数を一覧表示します。

User name[Fixture]>GetUserVariable *ur*

"O" はアスタリスクにマッチするため、"Our" で始まる変数も表示されます。先頭にあるワイルドカードのアスタリスクは、指定文字の前に何らかの文字が必要であることを示しています。この例では、"Hour" で始まる変数や、名前のどこかに "ur" が含まれる変数も表示されます。"Our" で始まる変数を指定するには、以下のように入力します。

User name[Fixture]>GetUserVariable Our*

この例は、すべてのユーザ変数を表示します。

User name[Fixture]>GetUserVariable *

Use Variables

Variables are used where the content of the variable is needed.

The following variable was used in a previous example:

User name[Fixture]>$MySpecialGroup At 80

The variable's text string ("Group 'Spots Grid' ") replaces the $MySpecialGroup. This works because the variable contains a text string with commands.

重要
Using quotation marks when using variables is essential and makes a difference.

If the variable is used with quotation marks:

User name[Fixture]>$"MySpecialGroup" At 80

This will fail because the content of the variable is explicitly called as a string, and the resulting feedback is:

Illegal object: Fixture "Group 'Spots Grid'" At 80

The software tries to use the variable content as a text string and does not interpret it as a command.

This might be useful in other cases. When the variable name contains a text string that should be used as text, it must be in quotation marks. See the example below.

This example uses a variable that contains the name of a group:

User name[Fixture]>SetUserVariable MyGroupName "Spots Grid"

Now, this variable can be used where the text would be used otherwise:

User name[Fixture]>Group $"MyGroupName" At 80

It will fail If the quotation marks are omitted:

User name[Fixture]>Group $MyGroupName At 80
Illegal object: Group  "Spots"  Grid At  80

The text string is interpreted as a command.

Let's assume you are running a musical show with multiple songs that will run off timecode.
The following macro example will create a variable that will be used to set the desk ready for each song.

Opened windows requirement:

  • Macro Pool
  • Pages Pool
  • Timecode Pool
  • Sequence Pool
  • Playbacks
  • Timecode Viewer
  • Sequence Sheet

It could look like this:

For this example, you will need to:

  • Store two sequences, one labeled FirstSong and a second labeled SecondSong. Both sequences should have cue one as the first cue. For more information, see Cues and Sequences.
  • Store two timecode shows, one labeled FirstSong, where the track's target is the sequence labeled FirstSong, and a second timecode show labeled SecondSong, where the track's target is the sequence labeled SecondSong. For more information, see Timecode Viewer.
  • Assign the sequence labeled FirstSong to page 3 executor 201 and the sequence labeled SecondSong to page 4 executor 201.
  • Store a macro labeled FirstSong.
  • Store a macro labeled SongSetup.

Here's the workflow:

  1. Edit the macro labeled FirstSong.
  2. Insert two macro lines.
  • Macro Line1: First, we need to create a new variable. Edit the command on macro line 1 and type:

This is the feedback in the command history window when the command is executed: 

OK:SetGlobalVariable   "curentsong" "FirstSong"

  • Macro Line 2: Here, we are going to call the macro that we have labeled SongSetup. Edit the command on macro line 2 and type:

This is what the macro looks like:


Next, we build a macro that will be used throughout the show to set the desk ready for each song.

  1. Edit the macro labeled SongSetup.
  2. Insert eight macro lines.
  • Macro Line 1: Using the new variable "currentsong", we will instruct the software on what page to select. Edit the command on macro line 1 and type:

This is the feedback in the command history window when the command is executed: 

OKPage "FirstSong"

You can see here that the variable "current song" is replaced with the variable content "FirstSong".

  • Macro Line 2: Now we must instruct the software which executor to select. Edit the command on macro line 2 and type: 

This is the feedback in the command history window when the command is executed: 

OK: Select Page  "FirstSong"  Executor  201

 

  • Macro Line 3: Stop any running timecode is a good idea. To do so, edit the command on macro line 3 and type:

This is the feedback in the command history window when the command is executed:

OK::Off Timecode  Thru

  • Macro Line 4: Here, we will rewind all timecodes to time 00h00m00.0. Edit the command on macro line 4 and type:

This is the feedback in the command history window when the command is executed: 

OK: <<< Timecode 1 Thru

Macro Line 5: To select the timecode show, edit the command on macro line 5 and type:  


This is the feedback in the command history window when the command is executed: 

OK: Select Timecode  "FirstSong"

Macro Line 6: Now we instruct the software what timecode show to execute. Edit the command on macro line 6 and type:  


This is the feedback in the command history window when the command is executed: 

OK: Go+ Timecode  "FirstSong"

  • Macro Line 7: Here, we instruct the software to turn off all running executors from page 2 through page 100 except the one running the sequence labeled FirstSong. It's usually a good idea to keep page 1 for any sequences that need to be manipulated manually outside of the running timecode sequences; this is why the command also excludes sequences running on page 1. Edit the command on macro line 7 and type:  


This is the feedback in the command line window:

OK: Off Page  2 Thru  100  "FirstSong"

  • Macro Line 8: Finally, even if the timecode should trigger cue 1, it is safe to add the following command. Edit the command on macro line 8 and type:

This is the feedback in the command line window:

OK: Go+ Cue  1

This is what the macro looks like:

This is where it gets interesting. To create a macro for the next song:

  1. Copy the macro you have created labeled FirstSong to an empty macro pool object.
  2. Edit that new macro and label it SecondSong.
  3. Edit the command on Macro Line 1 by replacing the variable content "FirstSong" with "SecondSong".

This is what the macro SecondSong looks like:

The only thing that changed is the variable content on Macro Line 1: SetGlobalVariable "currentsong" "SecondSong". So, each time the variable is recalled, it will refer to that new content. This method can be repeated for all songs in the show.



DeleteGlobalVariable と DeleteUserVariable

変数は、DeleteGlobalVariable および DeleteUserVariable キーワードによって削除できます。

構文は以下のようになります。

DeleteGlobalVariable ["変数名"]

DeleteUserVariable ["変数名"]

重要
変数の削除は取り消せません。変数の削除については、他に付け加えることはありません。削除された変数は、もう存在しません。

変数の連結

変数は、新しい変数に格納することで連結できます。

ここで求めているのは、連結された変数を含む複合文字列の作成です。出力は常に文字列です。数値変数の算術的加算については、後述を参照してください。

構文は以下のようになります。

SetGlobalVariable [MyConcatResult] $[変数名]$[変数名]

SetUserVariable [MyConcatResult] $[変数名]$[変数名]

連結する変数間や、連結の一部となる他の文字列との間に、空白を入れてはいけません。

文字列を変数に連結するには、引用符で囲み、それらの末尾と先頭の引用符との間に空白を入れずに追加します。引用符の内側には空白があってもかまいません。後述の例を参照してください。

以下の例では、3つの変数を用います。

変数名 内容
MyInteger Integer 9
MyKeyword Text Group
MyGroupName Text Perfect Macro

目標は、これらの変数を、グループを保存するためのコマンド文字列に連結することです。

1つのコマンドでも可能ですが、ここでは別の機能を見るために分割しています。

最初に、キーワードと整数を連結して新しい変数にします。

User name[Fixture]>SetUserVariable MyCommandString $"MyKeyword"" "$MyInteger

This command uses many quotation marks. Setting the variable names in quotation marks ensures the variable content is interpreted as text. This also means that the integer variable is converted to a text string.

Furthermore, there is a " " between the two variables to add a space between them.

Show results using this command:

User name[Fixture]>GetUserVariable MyCommandString

Next, add the macro name to the string:

User name[Fixture]>SetUserVariable MyCommandString $"MyCommandString"" '"$"MyGroupName""'"

Again, it can be hard to see what is happening. The two names of the variable are in quotation marks. Between the two are a space and a single quotation mark in double quotation marks. After the last variable name, there is another single quotation mark inside the double quotation marks.

Here you can spot them better: SetUserVariable MyCommandString $"MyCommandString"" ' "$"MyGroupName"" ' "

The command looks like this without the double quotations:  SetUserVariable MyCommandString $MyCommandString '$MyGroupName'

The existing content of MyCommandString is added to MyCommandString, plus the content of MyGroupName in single quotations.

The result is that MyCommandString is Group 9 'Perfect Macro' as a text string.

Now, some fixtures can be selected, and this command can be executed:

User name[Fixture]>Store $MyCommandString

Then, a group with the name is stored at group 9. Quotation marks must not be used in the command above.

Variable Addition

Concatenating variables with integer and/or double types performs a mathematical addition instead of an actual concatenation. Here, quotation marks are not used.

結果は変数に格納する必要があります。

この例では、以下の3つの変数を用います。

変数名 内容
MyInteger Integer 9
MySignedInteger Integer -2
MyDouble Double 6.500000

The first two variables can be added to each other with this command:

User name[Fixture]>SetUserVariable MyResult $MyInteger$MySignedInteger

The result can be seen by looking at the command line feedback. It shows that the variable is stored with a value of 7.

The double can be added with an integer. The result will be a double to avoid data loss.

User name[Fixture]>SetUserVariableMyResult $MyInteger$MyDouble

MyResult には、15.500000 という値が格納されます。

型変換

上の例では、型変換が行われています。

An integer or double can be converted to text by putting the variable name in quotation marks. The command will convert then when it is executed.

Setting variables without quotation marks can convert text to an integer.

Integer は、0.000000 という値の Double に加算することで Double に変換できます。

Double を Integer に変換することはできません。

この例では、以下の変数を用います。

変数名 内容
MyInteger Integer 9
MyEmptyDouble Double 0.000000
MyText Text Hello

この例では、Integer を Text に変換しています。

User name[Fixture]>SetUserVariable MyInteger $"MyInteger"

これを Integer に戻すには、以下のコマンドを用います。

User name[Fixture]>SetUserVariable MyInteger $MyInteger

Integer を Double に変換するには、以下のコマンドを用います。

User name[Fixture]>SetUserVariable MyResult $MyInteger$MyEmptyDouble