1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--Converted with LaTeX2HTML 2008 (1.71)
original version by: Nikos Drakos, CBLU, University of Leeds
* revised and updated by: Marcus Hennecke, Ross Moore, Herb Swan
* with significant contributions from:
Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
<HTML>
<HEAD>
<TITLE>Variables, Conditionals and Jumps</TITLE>
<META NAME="description" CONTENT="Variables, Conditionals and Jumps">
<META NAME="keywords" CONTENT="mma">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<META NAME="Generator" CONTENT="LaTeX2HTML v2008">
<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">
<LINK REL="STYLESHEET" HREF="mma.css">
<LINK REL="next" HREF="node22.html">
<LINK REL="previous" HREF="node20.html">
<LINK REL="up" HREF="mma.html">
<LINK REL="next" HREF="node22.html">
</HEAD>
<BODY bgcolor="#ffffff">
<DIV CLASS="navigation"><!--Navigation Panel-->
<A NAME="tex2html788"
HREF="node22.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A>
<A NAME="tex2html786"
HREF="mma.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A>
<A NAME="tex2html780"
HREF="node20.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A>
<BR>
<B> Next:</B> <A NAME="tex2html789"
HREF="node22.html">Subroutines</A>
<B> Up:</B> <A NAME="tex2html787"
HREF="mma.html">Reference Manual</A>
<B> Previous:</B> <A NAME="tex2html781"
HREF="node20.html">Repeats</A>
<BR>
<BR></DIV>
<!--End of Navigation Panel-->
<!--Table of Child-Links-->
<A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></A>
<UL CLASS="ChildLinks">
<LI><A NAME="tex2html790"
HREF="node21.html#SECTION002110000000000000000">Variables</A>
<UL>
<LI><A NAME="tex2html791"
HREF="node21.html#SECTION002111000000000000000">Set</A>
<LI><A NAME="tex2html792"
HREF="node21.html#SECTION002112000000000000000">NewSet</A>
<LI><A NAME="tex2html793"
HREF="node21.html#SECTION002113000000000000000">Mset</A>
<LI><A NAME="tex2html794"
HREF="node21.html#SECTION002114000000000000000">RndSet</A>
<LI><A NAME="tex2html795"
HREF="node21.html#SECTION002115000000000000000">UnSet VariableName</A>
<LI><A NAME="tex2html796"
HREF="node21.html#SECTION002116000000000000000">ShowVars</A>
<LI><A NAME="tex2html797"
HREF="node21.html#SECTION002117000000000000000">Inc and Dec</A>
<LI><A NAME="tex2html798"
HREF="node21.html#SECTION002118000000000000000">VExpand On or Off</A>
<LI><A NAME="tex2html799"
HREF="node21.html#SECTION002119000000000000000">StackValue</A>
</UL>
<BR>
<LI><A NAME="tex2html800"
HREF="node21.html#SECTION002120000000000000000">Predefined Variables</A>
<LI><A NAME="tex2html801"
HREF="node21.html#SECTION002130000000000000000">Indexing and Slicing</A>
<LI><A NAME="tex2html802"
HREF="node21.html#SECTION002140000000000000000">Mathematical Expressions</A>
<LI><A NAME="tex2html803"
HREF="node21.html#SECTION002150000000000000000">Conditionals</A>
<LI><A NAME="tex2html804"
HREF="node21.html#SECTION002160000000000000000">Goto</A>
</UL>
<!--End of Table of Child-Links-->
<HR>
<H1><A NAME="SECTION002100000000000000000"></A>
<A NAME="sec-variables"></A>
<BR>
Variables, Conditionals and Jumps
</H1>
<P>
To make the processing of your music easier,
<FONT Face="Serif" Color="Navy"><I>MMA</I></FONT> supports a very
primitive set for variable manipulations along with some conditional
testing and the oft-frowned-upon <SMALL>GOTO</SMALL> command.
<P>
<H1><A NAME="SECTION002110000000000000000">
Variables</A>
</H1>
<P>
<FONT Face="Serif" Color="Navy"><I>MMA</I></FONT> lets you set a variable, much like in other programming
languages and to do some basic manipulations on them. Variables are
most likely to be used for two reasons:
<P>
<UL>
<LI>For use in setting up conditional segments of your file,
<P>
</LI>
<LI>As a shortcut to entering complex chord sequences.
<P>
</LI>
</UL>
<P>
To begin, the following list shows the available commands to set and
manipulate variables:
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>Set VariableName <SPAN CLASS="textit">String</SPAN>
<BR>
Mset VariableName ...MsetEnd
<BR>
UnSet VariableName
<BR>
ShowVars
<BR>
Inc Variablename [value]
<BR>
Dec Variablename [value]
<BR>
Vexpand ON/Off </B>
</td></tr>
</Table>
<P>
All variable names are case-insensitive. Any characters can be used in
a variable name. The only exceptions are that a variable name cannot
start with a ``$'' or a ``_'' (an underscore--this is reserved for
internal variables, see below) <SPAN CLASS="textit">and</SPAN> names cannot contain a
``['' or ``]'' character (brace characters are reserved for
indexing, <A HREF="#slicing">details here</A>).
<P>
Variables are set and manipulated by using their names. Variables are
expanded when their name is prefaced by a space followed by single
``$'' sign. For example:
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>Set Silly Am / Bm /
<BR>
1 $Silly </B>
</td></tr>
</Table>
<P>
The first line creates the variable ``Silly''; the second creates a
bar of music with the chords ``Am / Bm /''.
<P>
<SPAN CLASS="textit">Note that the ``$'' must be the first item on a line or follow a
space character. The variable name must be terminated by a space or
the end of a line.</SPAN> For example, the following will NOT work:
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>Set Silly 4a;b;c;d;
<BR>
1 Am {$Silly } // needs space before the $ </B>
</td></tr>
</Table>
<P>
Nor will:
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>1 Am { $Silly} // needs space at the end of the name </B>
</td></tr>
</Table>
<P>
However:
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>1 Am { $Silly } </B>
</td></tr>
</Table>
<P>
will work fine.
<P>
Following are details on all the available variable commands:
<P>
<H2><A NAME="SECTION002111000000000000000">
Set</A>
</H2>
<P>
Set or create a variable. You can skip the <SPAN CLASS="textit">String</SPAN> if you do
want to assign an empty string to the variable. A valid example is:
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>Set PassCount 1 </B>
</td></tr>
</Table>
<P>
You can concatenate variables or constants by using a single ``+''.
For example:
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>Groove Rhumba
<BR>
Repeat
<BR> ...
<BR>
Set a $_Groove + Sus
<BR>
Groove $a
<BR> ...
<BR>
Groove Rhumba1
<BR>
Repeatend </B>
</td></tr>
</Table>
<P>
This can be useful in calling G<SMALL>ROOVE</SMALL> variations.
<P>
<H2><A NAME="SECTION002112000000000000000">
NewSet</A>
</H2>
<P>
The N<SMALL>EW</SMALL>S<SMALL>ET</SMALL> command works the same as S<SMALL>ET</SMALL> with the
exception that that it is completely ignored if the variable already
exists. So,
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>NewSet ChordVoice JazzGuitar </B>
</td></tr>
</Table>
<P>
and
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>If NDef ChordVoice
<BR>
Set ChordVoice JazzGuitar
<BR>
Endif </B>
</td></tr>
</Table>
<P>
have identical results.
<P>
<H2><A NAME="SECTION002113000000000000000"></A> <A NAME="sec-mset"></A>
<BR>
Mset
</H2>
<P>
This command is quite similar to S<SMALL>ET</SMALL>, but M<SMALL>SET</SMALL> expects
multiple lines. An example:
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>MSet LongVar
<BR>
1 Cm
<BR>
2 Gm
<BR>
3 G7
<BR>
MsetEnd </B>
</td></tr>
</Table>
<P>
It is quite possible to set a variable to hold an entire section of
music (perhaps a chorus) and insert this via macro expansion at
various places in your file.
<P>
Each M<SMALL>SET</SMALL> must be terminated by a E<SMALL>ND</SMALL>M<SMALL>SET</SMALL> or
M<SMALL>SET</SMALL>E<SMALL>ND</SMALL> command (on its own separate line).
<P>
Be careful if you use an MS<SMALL>ET</SMALL> variable in a P<SMALL>RINT</SMALL>
statement ... you'll probably get an error. The P<SMALL>RINT</SMALL>
command will print the <SPAN CLASS="textit">first</SPAN> line of the variable and the
remainder will be reinserted into the input stream for interpretation.
<P>
Variables are <SPAN CLASS="textit">not</SPAN> expanded when creating an M<SMALL>SET</SMALL>
macro (lines are read verbatim from the input path)--this makes
M<SMALL>SET</SMALL> subtly different from S<SMALL>ET</SMALL>. Variables <SPAN CLASS="textit">are</SPAN>
expanded when the macro is executed.
<P>
Special code in
<FONT Face="Serif" Color="Navy"><I>MMA</I></FONT> will maintain the block settings from
B<SMALL>EGIN</SMALL>/E<SMALL>ND</SMALL>. So, you can do something like:
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>Mset Spam
<BR> Line one
<BR> Line 2
<BR> 333
<BR>
EndMset
<BR>
Begin Print
<BR> $Spam
<BR>
End </B>
</td></tr>
</Table>
<P>
<H2><A NAME="SECTION002114000000000000000"></A>
<A NAME="rndset"></A>
<BR>
RndSet
</H2>
<P>
There are times when you may want a random value to use in selecting a
G<SMALL>ROOVE</SMALL> or for other more creative purposes. The R<SMALL>ND</SMALL>S<SMALL>ET</SMALL>
command sets a variable from a value in a list. The list can be
anything; just remember that each white space forms the start of a new
item. So,
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>RndSet Var 1 2 3 4 5 </B>
</td></tr>
</Table>
<P>
will set $V<SMALL>AR</SMALL> to one of the values 1, 2, 3, 4 or 5.
<P>
You could use this to randomly select a G<SMALL>ROOVE</SMALL>:
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>Groove $var Groove1 Groove2 Groove3 </B>
</td></tr>
</Table>
<P>
Alternately,
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>RndSet Grv Groove1 Groove2 Groove3 </B>
</td></tr>
</Table>
<P>
will set $G<SMALL>RV</SMALL> to one of ``Groove1'', ``Groove2'' or
``Groove3''.
<P>
Then you can do the same as in the earlier example with:
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>Groove $Grv </B>
</td></tr>
</Table>
<P>
You can also have fun using random values for timing, transposition,
etc.
<P>
<H2><A NAME="SECTION002115000000000000000">
UnSet VariableName</A>
</H2>
<P>
Removes the variable. This can be useful if you have conditional tests
which simply rely on a certain variable being ``defined''.
<P>
<H2><A NAME="SECTION002116000000000000000">
ShowVars</A>
</H2>
<P>
Mainly used for debugging, this command displays the names of the
defined variables and their contents. The display will preface each
variable name with a ``$''. Note that internal
<FONT Face="Serif" Color="Navy"><I>MMA</I></FONT> variables are
not displayed with this command.
<P>
You can call S<SMALL>HOW</SMALL>V<SMALL>ARS</SMALL> with an argument list. In this case the
values of the variables names in the list will be printed. Variables
which do not exist will <SPAN CLASS="textit">not</SPAN> cause an error, e.g.:
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>ShowVars xXx Count foo
<BR> $XXX - not defined
<BR> $COUNT: 11
<BR> $FOO: This is Foo </B>
</td></tr>
</Table>
<P>
<H2><A NAME="SECTION002117000000000000000">
Inc and Dec</A>
</H2>
<P>
These commands increment or decrement a variable. If no argument is
given, a value of 1 is used; otherwise, the value specified is used.
The value can be an integer or a floating point number.
<P>
A short example:
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>Set PassCount 1
<BR>
Set Foobar 4
<BR>
Showvars
<BR>
Inc FooBar 4
<BR>
Inc PassCount
<BR>
ShowVars </B>
</td></tr>
</Table>
<P>
This command is quite useful for creating conditional tests for proper
handling of codas or groove changes in repeats.
<P>
<H2><A NAME="SECTION002118000000000000000">
VExpand On or Off</A>
</H2>
<P>
Normally variable expansion is enabled. These two options will turn
expansion on or off. Why would you want to do this? Well, here's a
simple example:
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>Set LeftC Am Em
<BR>
Set RightC G /
<BR>
VExpand Off
<BR>
Set Full $LeftC $RightC
<BR>
VExpand On </B>
</td></tr>
</Table>
<P>
In this case the actual contents of the variable ``Full'' is ``$LeftC
$RightC''. If the O<SMALL>FF/</SMALL>O<SMALL>N</SMALL> option lines had not been used, the
contents would be ``Am Em G /''. You can easily verify this with the
S<SMALL>HOW</SMALL>V<SMALL>ARS</SMALL> option.
<P>
When
<FONT Face="Serif" Color="Navy"><I>MMA</I></FONT> processes a file it expands variables in a recursive
manner. This means that, in the above example, the line:
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>1 $Full </B>
</td></tr>
</Table>
<P>
will be changed to:
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>1 Am Em G / </B>
</td></tr>
</Table>
<P>
However, if later in the file, you change the definition of one of the
variables ... for example:
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>Set LeftC Am / </B>
</td></tr>
</Table>
<P>
the same line will now be ``1 Am / G /''.
<P>
Most of
<FONT Face="Serif" Color="Navy"><I>MMA</I></FONT> 's internal commands <SPAN CLASS="textit">can</SPAN> be redefined with
variables. However, you really shouldn't use this feature. It's been
left for two reasons: it might be useful, and, it's hard to disable.
<P>
Not all commands can be redefined. The following examples will work,
however <SPAN CLASS="textit">in most cases we
recommend that you do not redefine
<FONT Face="Serif" Color="Navy"><I>MMA</I></FONT> commands</SPAN>.
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>Set Rate Tempo 120
<BR> $Rate
<BR>
Set R Repeat
<BR> $R </B>
</td></tr>
</Table>
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>Set B Begin
<BR>
Set E End
<BR> $B Arpeggio Define
<BR> ...
<BR> $E </B>
</td></tr>
</Table>
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>Set A Define Arpeggio
<BR>
Begin
<BR> $a ...
<BR>
End </B>
</td></tr>
</Table>
<P>
Even though you can use a variable to substitute for the R<SMALL>EPEAT</SMALL>
or I<SMALL>F</SMALL> directives, using one for R<SMALL>EPEAT</SMALL>E<SMALL>ND</SMALL>,
E<SMALL>ND</SMALL>R<SMALL>EPEAT</SMALL>, R<SMALL>EPEAT</SMALL>E<SMALL>NDING</SMALL>, L<SMALL>ABEL</SMALL>, I<SMALL>F</SMALL>E<SMALL>ND</SMALL> or
E<SMALL>ND</SMALL>I<SMALL>F</SMALL> will fail.
<P>
Variable expansion should usually not be a concern. In most normal
files,
<FONT Face="Serif" Color="Navy"><I>MMA</I></FONT> will expand variables as they are encountered. However,
when reading the data in a R<SMALL>EPEAT</SMALL>, I<SMALL>F</SMALL> or M<SMALL>SET</SMALL>
section the expansion function is skipped--but, when the lines are
processed, after being stored in an internal queue, variables are
expanded.
<P>
V<SMALL>EXPAND</SMALL> only has an effect when creating a macro using
S<SMALL>ET</SMALL>. It has <SPAN CLASS="textit">no</SPAN> effect when using M<SMALL>SET</SMALL>.
<P>
<H2><A NAME="SECTION002119000000000000000"></A>
<A NAME="stackvalue"></A>
<BR>
StackValue
</H2>
<P>
Sometimes you just want to save a value for a few lines of code. The
S<SMALL>TACK</SMALL>V<SMALL>ALUE</SMALL> command will save its arguments. You can later
retrieve them via the $_StackValue macro. For example (taken from
the <TT><SPAN CLASS="textbf">stdpats.mma</SPAN></TT> file):
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>StackValue $_SwingMode
<BR>
SwingMode On
<BR>
Begin Drum Define
<BR> Swing8 1 0 90 * 8
<BR>
End
<BR> ...
<BR>
SwingMode $_StackValue </B>
</td></tr>
</Table>
<P>
Note that the $_StackValue macro removes the last value from the
stack. If you invoke the macro when there is nothing saved an error
will occur.
<P>
<H1><A NAME="SECTION002120000000000000000"></A>
<A NAME="sec-sysvariables"></A>
<BR>
Predefined Variables
</H1>
<P>
For your convenience
<FONT Face="Serif" Color="Navy"><I>MMA</I></FONT> tracks a number of internal settings and
you can access these values with special macros.<A NAME="tex2html81"
HREF="#foot11484"><SUP><SPAN CLASS="arabic">21</SPAN>.<SPAN CLASS="arabic">1</SPAN></SUP></A> All of these ``system'' variables are
prefaced with a single underscore. For example, the current tempo is
displayed with the variable $_TEMPO.
<P>
There are two categories of system variables. The first are the simple
values for global settings:
<P>
<DL>
<DT><STRONG> $_AutoLibPath</STRONG></DT>
<DD>Current A<SMALL>UTO</SMALL>L<SMALL>IB</SMALL>P<SMALL>ATH</SMALL> setting.
<P>
</DD>
<DT><STRONG> $_BarNum</STRONG></DT>
<DD>Current bar number of song.
<P>
</DD>
<DT><STRONG> $_ChordAdjust</STRONG></DT>
<DD>The chord adjustment table values
<A HREF="node14.html#sec-chordadjust">(see here)</A>. Note,
you cannot use this value to reset the table.
<P>
</DD>
<DT><STRONG> $_CTabs</STRONG></DT>
<DD>List of the time-set chord tabs.
<P>
</DD>
<DT><STRONG> $_Debug</STRONG></DT>
<DD>Current debug settings.
<P>
</DD>
<DT><STRONG> $_Groove</STRONG></DT>
<DD>Name of the currently selected groove. May be
empty if no groove has been selected.
<P>
</DD>
<DT><STRONG> $_Groovelist</STRONG></DT>
<DD>List of all currently defined G<SMALL>ROOVE</SMALL> names.
<P>
</DD>
<DT><STRONG> $_KeySig</STRONG></DT>
<DD>Key signature as defined in song file. If no key
signature is set the somewhat cryptic 0# will be returned.
<P>
</DD>
<DT><STRONG> $_IncPath</STRONG></DT>
<DD>Current I<SMALL>NC</SMALL>P<SMALL>ATH</SMALL> setting.
<P>
</DD>
<DT><STRONG> $_LastDebug</STRONG></DT>
<DD>Debug settings prior to last D<SMALL>EBUG</SMALL>
command. This setting can be used to restore settings, e.g.:
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>Debug Warnings=off
<BR> ...stuff generating annoying warnings
<BR>
Debug $_LastDebug </B>
</td></tr>
</Table>
<P>
</DD>
<DT><STRONG> $_LastGroove</STRONG></DT>
<DD>Name of the groove selected <SPAN CLASS="textit">before</SPAN> the
currently selected groove.
<P>
</DD>
<DT><STRONG> $_LastVolume</STRONG></DT>
<DD>Previously set global volume setting.
<P>
</DD>
<DT><STRONG> $_LibPath</STRONG></DT>
<DD>Current L<SMALL>IB</SMALL>P<SMALL>ATH</SMALL> setting.
<P>
</DD>
<DT><STRONG> $_LineNum</STRONG></DT>
<DD>Line number in current file.
<P>
</DD>
<DT><STRONG> $_Lyric</STRONG></DT>
<DD>Current L<SMALL>YRIC</SMALL> settings.
<P>
</DD>
<DT><STRONG> $_MMAPath</STRONG></DT>
<DD>The root directory used by
<FONT Face="Serif" Color="Navy"><I>MMA</I></FONT> . The modules,
library, etc. are in this directory. This is set at startup and
cannot be modified by the user.
<P>
</DD>
<DT><STRONG> $_MIDISplit</STRONG></DT>
<DD>List of S<SMALL>PLIT</SMALL>C<SMALL>HANNELS</SMALL>.
<P>
</DD>
<DT><STRONG> $_MIDIPlayer</STRONG></DT>
<DD>Current M<SMALL>IDI</SMALL>P<SMALL>LAYER</SMALL> setting, including options.
<P>
</DD>
<DT><STRONG> $_NoteLen(n)</STRONG></DT>
<DD>Returns value of the duration in MIDI ticks of
``n''. Note: No spaces are permitted. Examples:
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>$_NoteLen(8.) </B>
</td></tr>
</Table>
returns 144T, the duration of a dotted eight note,
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>$_NoteLen(5:4+16) </B>
</td></tr>
</Table>
returns 86T, the duration of a 5:4 tuplet plus a 16th.
<P>
</DD>
<DT><STRONG> $_OutPath</STRONG></DT>
<DD>Current O<SMALL>UT</SMALL>P<SMALL>ATH</SMALL> setting.
<P>
</DD>
<DT><STRONG> $_Plugins</STRONG></DT>
<DD>A list of registered simple plugins.
<P>
</DD>
<DT><STRONG> $_Seq</STRONG></DT>
<DD>Current S<SMALL>EQ</SMALL> point (0 to
S<SMALL>EQ</SMALL>S<SMALL>IZE</SMALL>). Useful in debugging.
<P>
</DD>
<DT><STRONG> $_SeqRnd</STRONG></DT>
<DD>Global S<SMALL>EQ</SMALL>R<SMALL>ND</SMALL> setting (on, off or track
list).
<P>
</DD>
<DT><STRONG> $_SeqRndWeight</STRONG></DT>
<DD>Global S<SMALL>EQ</SMALL>R<SMALL>ND</SMALL>W<SMALL>EIGHT</SMALL> settings.
<P>
</DD>
<DT><STRONG> $_SeqSize</STRONG></DT>
<DD>Current S<SMALL>EQ</SMALL>S<SMALL>IZE</SMALL> setting.
<P>
</DD>
<DT><STRONG> $_SwingMode</STRONG></DT>
<DD>Current S<SMALL>WING</SMALL>M<SMALL>ODE</SMALL> setting (On or Off)
and the Skew value.
<P>
</DD>
<DT><STRONG> $_StackValue</STRONG></DT>
<DD>The last value stored on the S<SMALL>TACK</SMALL>V<SMALL>ALUE</SMALL>
stack.
<P>
</DD>
<DT><STRONG> $_Tempo</STRONG></DT>
<DD>Current T<SMALL>EMPO</SMALL>. Note that if you have used
the optional <SPAN CLASS="textit">bar count</SPAN> in setting the tempo this will be the
target tempo.
<P>
</DD>
<DT><STRONG> $_TickPos</STRONG></DT>
<DD>Helpful in debugging, this variable is set to the
current tick position in the generated MIDI file.
<P>
</DD>
<DT><STRONG> $_Time</STRONG></DT>
<DD>The current T<SMALL>IME</SMALL> (beats per bar) setting.
<P>
</DD>
<DT><STRONG> $_TimeSig</STRONG></DT>
<DD>The last value set for TimeSig.
<P>
</DD>
<DT><STRONG> $_ToneTr</STRONG></DT>
<DD>List of all T<SMALL>ONE</SMALL>TR settings.
<P>
</DD>
<DT><STRONG> $_Tracklist</STRONG></DT>
<DD>List of all currently defined T<SMALL>RACK</SMALL> names.
<P>
</DD>
<DT><STRONG> $_Transpose</STRONG></DT>
<DD>Current T<SMALL>RANSPOSE</SMALL> setting.
<P>
</DD>
<DT><STRONG> $_VExpand</STRONG></DT>
<DD>VExpand value (On/Off). Not very useful since you
can't enable VEXPAND back with a macro.
<P>
</DD>
<DT><STRONG> $_VoiceTr</STRONG></DT>
<DD>List of all V<SMALL>OICE</SMALL>TR settings.
<P>
</DD>
<DT><STRONG> $_Volume</STRONG></DT>
<DD>Current global volume setting.
<P>
</DD>
<DT><STRONG> $_VolumeRatio</STRONG></DT>
<DD>Global volume ratio (track vrs. master) from
A<SMALL>DJUST</SMALL>V<SMALL>OLUME</SMALL> Ratio setting.
<P>
</DD>
</DL>
<P>
The second type of system variable is for settings in a certain track.
Each of these variables is in the form $_TRACKNAME_VALUE. For
example, the current voice setting for the ``Bass-Sus'' track can be
accessed with the variable $_Bass-Sus_Voice.
<P>
If the associated command permits a value for each sequence in your
pattern, the macro will more than one value. For example (assuming a
S<SMALL>EQ</SMALL>S<SMALL>IZE</SMALL> of 4):
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>Bass Octave 3 4 2 4
<BR>
Print $_Bass_Octave
<BR> ...
<BR>
3 4 2 4 </B>
</td></tr>
</Table>
<P>
The following are the available ``TrackName'' macros:
<P>
<DL>
<DT><STRONG> $_TRACKNAME_Accent</STRONG></DT>
<DD>
</DD>
<DT><STRONG> $_TRACKNAME_Articulate</STRONG></DT>
<DD>
</DD>
<DT><STRONG> $_TRACKNAME_Channel</STRONG></DT>
<DD>Assigned MIDI channel 1-16, 0 if not
assigned.
</DD>
<DT><STRONG> $_TRACKNAME_Compress</STRONG></DT>
<DD>
</DD>
<DT><STRONG> $_TRACKNAME_Delay</STRONG></DT>
<DD>
</DD>
<DT><STRONG> $_TRACKNAME_Direction</STRONG></DT>
<DD>
</DD>
<DT><STRONG> $_TRACKNAME_DupRoot</STRONG></DT>
<DD>(only permitted in Chord Tracks)
</DD>
<DT><STRONG> $_TRACKNAME_Harmony</STRONG></DT>
<DD>
</DD>
<DT><STRONG> $_TRACKNAME_HarmonyOnly</STRONG></DT>
<DD>
</DD>
<DT><STRONG> $_TRACKNAME_HarmonyVolume</STRONG></DT>
<DD>
</DD>
<DT><STRONG> $_TRACKNAME_Invert</STRONG></DT>
<DD>
</DD>
<DT><STRONG> $_TRACKNAME_Limit</STRONG></DT>
<DD>
</DD>
<DT><STRONG> $_TRACKNAME_Mallet</STRONG></DT>
<DD>Rate and delay values (only valid in
Solo and Melody tracks)
</DD>
<DT><STRONG> $_TRACKNAME_MidiNote</STRONG></DT>
<DD>Current setting
</DD>
<DT><STRONG> $_TRACKNAME_MOctave</STRONG></DT>
<DD>
</DD>
<DT><STRONG> $_TRACKNAME_MIDIVolume</STRONG></DT>
<DD>
</DD>
<DT><STRONG> $_TRACKNAME_NoteSpan</STRONG></DT>
<DD>
</DD>
<DT><STRONG> $_TRACKNAME_Octave</STRONG></DT>
<DD>
</DD>
<DT><STRONG> $_TRACKNAME_Ornament</STRONG></DT>
<DD>(all options)
</DD>
<DT><STRONG> $_TRACKNAME_Plugins</STRONG></DT>
<DD>(track registered plugins, the same for all tracks)
</DD>
<DT><STRONG> $_TRACKNAME_Range</STRONG></DT>
<DD>
</DD>
<DT><STRONG> $_TRACKNAME_RDuration</STRONG></DT>
<DD>
</DD>
<DT><STRONG> $_TRACKNAME_Rpitch</STRONG></DT>
<DD>
</DD>
<DT><STRONG> $_TRACKNAME_Rskip</STRONG></DT>
<DD>
</DD>
<DT><STRONG> $_TRACKNAME_Rtime</STRONG></DT>
<DD>
</DD>
<DT><STRONG> $_TRACKNAME_Rvolume</STRONG></DT>
<DD>
</DD>
<DT><STRONG> $_TRACKNAME_SeqRnd</STRONG></DT>
<DD>
</DD>
<DT><STRONG> $_TRACKNAME_SeqRndWeight</STRONG></DT>
<DD>
</DD>
<DT><STRONG> $_TRACKNAME_Sequence</STRONG></DT>
<DD>
</DD>
<DT><STRONG> $_TRACKNAME_Span</STRONG></DT>
<DD>
</DD>
<DT><STRONG> $_TRACKNAME_Sticky</STRONG></DT>
<DD>
</DD>
<DT><STRONG> $_TRACKNAME_Strum</STRONG></DT>
<DD>
</DD>
<DT><STRONG> $_TRACKNAME_StrumAdd</STRONG></DT>
<DD>
</DD>
<DT><STRONG> $_TRACKNAME_Tone</STRONG></DT>
<DD>(only permitted in Drum tracks)
</DD>
<DT><STRONG> $_TRACKNAME_Trigger</STRONG></DT>
<DD>
</DD>
<DT><STRONG> $_TRACKNAME_Unify</STRONG></DT>
<DD>
</DD>
<DT><STRONG> $_TRACKNAME_Voice</STRONG></DT>
<DD>
</DD>
<DT><STRONG> $_TRACKNAME_Voicing</STRONG></DT>
<DD>(only permitted in Chord tracks)
</DD>
<DT><STRONG> $_TRACKNAME_Volume</STRONG></DT>
<DD><P>
</DD>
</DL>
<P>
The ``TrackName'' macros are useful in copying values between
non-similar tracks and C<SMALL>H</SMALL>S<SMALL>HARE</SMALL> tracks. For example:
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>Begin Bass
<BR> Voice AcousticBass
<BR> Octave 3
<BR> ...
<BR>
End
<BR>
Begin Walk
<BR> ChShare Bass
<BR> Voice $_Bass_Voice
<BR> Octave $_Bass_Octave
<BR> ...
<BR>
End </B>
</td></tr>
</Table>
<P>
<H1><A NAME="SECTION002130000000000000000"></A>
<A NAME="slicing"></A>
<BR>
Indexing and Slicing
</H1>
<P>
All variables can have an option <SPAN CLASS="textit">slice</SPAN> or <SPAN CLASS="textit">index</SPAN> appended
to them using ``[]'' notation. The exact syntax of the data in the
``[]''s is dependent on the underlying Python interpreter. But, as a
summary:
<P>
<DL COMPACT>
<DT></DT>
<DD><SPAN CLASS="textbf">[2]</SPAN> - selects the 3rd item in the list,
</DD>
<DT></DT>
<DD><SPAN CLASS="textbf">[1:2]</SPAN> - selects the 2nd to 3rd item (which means only the
2nd),
</DD>
<DT></DT>
<DD><SPAN CLASS="textbf">[0:2]</SPAN> - selects items 1 and 2,
</DD>
<DT></DT>
<DD><SPAN CLASS="textbf">[-1]</SPAN> - selects the last item.
</DD>
</DL>
<P>
It is possible to use the <SPAN CLASS="textit">step</SPAN> option as well, but we don't
know when you would.
<P>
When indexing or slicing a variable, the following should be kept in
mind:
<P>
<UL>
<LI>For simple variables which contain only one element
(e.g., $_Tempo) any index other than ``[0]'', ``[-1]'', etc. will
return an empty string.
<P>
</LI>
<LI>Variables containing multiple values (e.g., $_Bass_Volume) are
treated as list. Slicing and indexing is useful to extract a single
value.
<P>
</LI>
<LI>Variables created with M<SMALL>SET</SMALL> are treated a list of
lines. Slicing returns multiple (or single) lines. This can be
useful in selecting only a portion of a previously created variable.
<P>
</LI>
</UL>
The ``[]'' must follow the variable <SPAN CLASS="textit">without</SPAN> any space
characters. The expression inside the ``[]'' must not contain any
spaces.
<P>
The index or slice expression cannot be a variable.
<P>
An example:
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>Groove bossanova
<BR>
Bass Volume m mf p mp
<BR>
print $_Bass_Volume
<BR>
print $_Bass_Volume[1:3]
<BR>
print $_Bass_volume[2] </B>
</td></tr>
</Table>
<P>
will display:
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>100 110 40 70
<BR>
110 40
<BR>
40 </B>
</td></tr>
</Table>
<P>
<H1><A NAME="SECTION002140000000000000000">
Mathematical Expressions</A>
</H1>
<P>
Anywhere you can use a variable (user defined or built-in) you can
also use a mathematical expression. Expressions delimited in a
$(...) set are passed to the underlying Python interpreter, parsed
and expanded. Included in an expression can be any combination of
values, operators, and
<FONT Face="Serif" Color="Navy"><I>MMA</I></FONT> variables.
<P>
Here are a couple of examples with the
<FONT Face="Serif" Color="Navy"><I>MMA</I></FONT> generated values:
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>Print $( 123 * (4.0/5) )
<BR>
98.4 </B>
</td></tr>
</Table>
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>Tempo 100
<BR>
Set V $( $_Tempo + 44)
<BR>
Print $v
<BR>
144 </B>
</td></tr>
</Table>
<P>
How it works:
<FONT Face="Serif" Color="Navy"><I>MMA</I></FONT> first parses each line and expands any variables
it finds. In the second example this means that the $_Tempo is
converted to ``100''. After all the variable expansion is done a check
is made to find math delimiters. Anything inside these delimiters is
evaluated by Python.
<P>
You can even use this feature to modify values stored in
lists.<A NAME="tex2html82"
HREF="#foot11669"><SUP><SPAN CLASS="arabic">21</SPAN>.<SPAN CLASS="arabic">2</SPAN></SUP></A> A bit complex, but well worthwhile! In the following
example we add ``10'' to the current A<SMALL>RTICULATE</SMALL> setting. It's
split into three lines to make it clearer:
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>set a $( ' $_Chord_Articulate '.split() ) </B>
</td></tr>
</Table>
<P>
Note the use of single quotes to convert the
<FONT Face="Serif" Color="Navy"><I>MMA</I></FONT> ``string'' to
something Python can deal with. You could just as easily use double
quotes, but do note that the spaces before the ``$'' and before the
final `` ' '' are needed. The result of the above is that the variable
``$a'' now is set to something like: ``['100', '100', '90', '80']''.
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>set b $([str(int(x)+10)for x in $a ] ) </B>
</td></tr>
</Table>
<P>
Next we use a list comprehension to add ``10'' to each value in the
list. Our new list (contained in ``$b'') will be: ``['110', '110',
'100', '90']''. Notice how the strings were converted from strings to
integers (for the addition) and then back to strings.
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>set c $( ' '.join( $b ) ) </B>
</td></tr>
</Table>
<P>
The new list is now converted to a string which
<FONT Face="Serif" Color="Navy"><I>MMA</I></FONT> can deal with
and store it in ``$c''. In this case: ``110 110 100 90''.
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>Chord Articulate $c </B>
</td></tr>
</Table>
<P>
Finally, C<SMALL>HORD</SMALL> A<SMALL>RTICULATE</SMALL> is modified.
<P>
Now, that that is clear, you can easily combine the operation using no
variables at all:
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>Chord Articulate $(' '.join([str(int(x)+10)for x in'
$_Chord_Articulate '.split()])) </B>
</td></tr>
</Table>
<P>
Some additional notes:
<P>
<UL>
<LI>To keep your computer safe from malicious scripts, only the
following operators and functions are permitted.
<P>
The unary operators:
<P>
<PRE>
- + ~
</PRE>
<P>
the basic operators:
<P>
<PRE>
+ - / // % * **
</PRE>
<P>
the bitwise operators:
<P>
<PRE>
& | ^ << >>
</PRE>
<P>
the constants:
<P>
<PRE>
e pi
</PRE>
<P>
the functions:
<P>
<PRE>
ceil() fabs() floor() exp() log() log10() pow()
sqrt() acos() asin() atan() atan2() cos() hypot()
sin() tan() degrees() radians() cosh() sinh()
tanh() abs() chr() int()
</PRE>
<P>
the miscellaneous functions:<A NAME="tex2html83"
HREF="#foot11578"><SUP><SPAN CLASS="arabic">21</SPAN>.<SPAN CLASS="arabic">3</SPAN></SUP></A>
<P>
<PRE>
for, in, str(), .join(), .split()
</PRE>
<P>
and values and parentheses.
<P>
</LI>
<LI>For details on the use/format of the above please refer to the
Python documentation.
<P>
</LI>
<LI>$(...) expressions cannot be nested.
<P>
</LI>
<LI>There must be a whitespace character before the leading $.
<P>
</LI>
<LI>Any
<FONT Face="Serif" Color="Navy"><I>MMA</I></FONT> variables must be delimited with whitespace. For
example $( $_Tempo + 44) will work; however, both $($_Tempo +
44) and $( $_Tempo+ 44) will cause an error.
<P>
</LI>
<LI>The supplied file <TT><SPAN CLASS="textbf">egs/misc/math.mma</SPAN></TT> shows a number of
examples.
<P>
</LI>
</UL>
<P>
<H1><A NAME="SECTION002150000000000000000">
Conditionals</A>
</H1>
<P>
One of the most important reasons to have variables in
<FONT Face="Serif" Color="Navy"><I>MMA</I></FONT> is to use
them in conditionals. In
<FONT Face="Serif" Color="Navy"><I>MMA</I></FONT> a conditional consists of a line
starting with an I<SMALL>F</SMALL> directive, a test, a series of lines to
process (depending upon the result of the test), and a closing
E<SMALL>ND</SMALL>I<SMALL>F</SMALL> or I<SMALL>F</SMALL>E<SMALL>ND</SMALL><A NAME="tex2html84"
HREF="#foot11670"><SUP><SPAN CLASS="arabic">21</SPAN>.<SPAN CLASS="arabic">4</SPAN></SUP></A> directive. An optional E<SMALL>LSE</SMALL> statement may be included.
<P>
The first set of tests are unary (they take no arguments):
<P>
<DL>
<DT><STRONG>Def VariableName</STRONG></DT>
<DD>Returns true if the variable has been defined.
<P>
</DD>
<DT><STRONG>Ndef VariableName</STRONG></DT>
<DD>Returns true if the variable has not been
defined.
<P>
</DD>
</DL>
<P>
In the above tests you must supply the name of a variable--don't make
the mistake of including a ``$'' which will invoke expansion and
result in something you were not expecting.
<P>
A simple example:
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>If Def InCoda
<BR> 5 Cm
<BR> 6 /
<BR>
Endif </B>
</td></tr>
</Table>
<P>
The other tests are binary. Each test requires a conditional (symbolic
or mnemonic as detailed in the following table) and two arguments.
<P>
<TABLE CELLPADDING=3 BORDER="1">
<TR><TD ALIGN="CENTER">Mnemonic</TD>
<TD ALIGN="CENTER">Symbolic</TD>
<TD ALIGN="LEFT">Condition</TD>
</TR>
<TR><TD ALIGN="CENTER"> </TD>
<TD ALIGN="CENTER"> </TD>
<TD ALIGN="LEFT"> </TD>
</TR>
<TR><TH ALIGN="CENTER"><SPAN CLASS="textbf">LT</SPAN></TH>
<TD ALIGN="CENTER"><SPAN CLASS="textbf"><</SPAN></TD>
<TD ALIGN="LEFT">True if <SPAN CLASS="textit">Str1</SPAN> is less than <SPAN CLASS="textit">Str2</SPAN></TD>
</TR>
<TR><TH ALIGN="CENTER"><SPAN CLASS="textbf">LE</SPAN></TH>
<TD ALIGN="CENTER"><SPAN CLASS="textbf"><=</SPAN></TD>
<TD ALIGN="LEFT">True if <SPAN CLASS="textit">Str1</SPAN> is less than or equal to
<SPAN CLASS="textit">Str2</SPAN></TD>
</TR>
<TR><TH ALIGN="CENTER"><SPAN CLASS="textbf">EQ</SPAN></TH>
<TD ALIGN="CENTER"><SPAN CLASS="textbf">==</SPAN></TD>
<TD ALIGN="LEFT">True if <SPAN CLASS="textit">Str1</SPAN> is equal to <SPAN CLASS="textit">Str2</SPAN></TD>
</TR>
<TR><TH ALIGN="CENTER"><SPAN CLASS="textbf">NE</SPAN></TH>
<TD ALIGN="CENTER"><SPAN CLASS="textbf">!=</SPAN></TD>
<TD ALIGN="LEFT">True if <SPAN CLASS="textit">Str1</SPAN> is not equal to <SPAN CLASS="textit">Str2</SPAN></TD>
</TR>
<TR><TH ALIGN="CENTER"><SPAN CLASS="textbf">GT</SPAN></TH>
<TD ALIGN="CENTER"><SPAN CLASS="textbf">></SPAN></TD>
<TD ALIGN="LEFT">True if <SPAN CLASS="textit">Str1</SPAN> is greater than <SPAN CLASS="textit">Str2</SPAN></TD>
</TR>
<TR><TH ALIGN="CENTER"><SPAN CLASS="textbf">GE</SPAN></TH>
<TD ALIGN="CENTER"><SPAN CLASS="textbf">>=</SPAN></TD>
<TD ALIGN="LEFT">True if <SPAN CLASS="textit">Str1</SPAN> is greater than or
equal to <SPAN CLASS="textit">Str2</SPAN></TD>
</TR>
</TABLE>
<P>
In the above tests you have several choices in specifying <SPAN CLASS="textit">Str1</SPAN>
and <SPAN CLASS="textit">Str2</SPAN>. At some point, when
<FONT Face="Serif" Color="Navy"><I>MMA</I></FONT> does the actual comparison,
two strings or numeric values are expected. So, you really could do:
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>If EQ abc ABC </B>
</td></tr>
</Table>
<P>
and get a ``true'' result. The reason that ``abc'' equals ``ABC'' is
that all the comparisons in
<FONT Face="Serif" Color="Navy"><I>MMA</I></FONT> are case-insensitive.
<P>
You can also compare a variable to a string:
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>If > $foo abc </B>
</td></tr>
</Table>
<P>
will evaluate to ``true'' if the <SPAN CLASS="textit">contents</SPAN> of the variable
``foo'' evaluates to something ``greater than'' ``abc''. But, there is
a bit of a ``gotcha'' here. If you have set ``foo'' to a two word
string, then
<FONT Face="Serif" Color="Navy"><I>MMA</I></FONT> will choke on the command. In the following
example:
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>Set Foo A B
<BR>
If GT $Foo abc </B>
</td></tr>
</Table>
<P>
the comparison is passed the line:
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>If GT A B abc </B>
</td></tr>
</Table>
<P>
and
<FONT Face="Serif" Color="Navy"><I>MMA</I></FONT> seeing three arguments generates an error. If you want the
comparison done on a variable which might be more than one word, use
the ``$$'' syntax. This delays the expansion of the variable until
the I<SMALL>F</SMALL> directive is entered. So:
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>If GT $$foo abc </B>
</td></tr>
</Table>
<P>
would generate a comparison between ``A B'' and ``ABC''.
<P>
Delayed expansion can be applied to either variable. It only works in
an I<SMALL>F</SMALL> directive.
<P>
Strings and numeric values can be confusing in comparisons. For
example, if you have the strings ``22'' and ''3'' and compare them as
strings, ``3'' is greater than ``22''; however, if you compare them as
values then 3 is less than 22. The rule in
<FONT Face="Serif" Color="Navy"><I>MMA</I></FONT> is quite simple: If
both strings can be converted to a value, a numeric comparison is done;
otherwise they are compared as strings.<A NAME="tex2html85"
HREF="#foot11641"><SUP><SPAN CLASS="arabic">21</SPAN>.<SPAN CLASS="arabic">5</SPAN></SUP></A>
<P>
This lets you do consistent comparisons in situations like:
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>Set Count 1
<BR>
If LE $$Count 4
<BR> ...
<BR>
IfEnd </B>
</td></tr>
</Table>
<P>
Note that the above example could have used ``$Count'', but you
should probably always use the ``$$'' in tests.
<P>
Much like other programming languages, an optional E<SMALL>LSE</SMALL>
condition may be used:
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>If Def Coda
<BR> Groove Rhumba1
<BR>
Else
<BR> Groove Rhumba
<BR>
Endif </B>
</td></tr>
</Table>
<P>
The E<SMALL>LSE</SMALL> statement(s) are processed only if the test for the
I<SMALL>F</SMALL> test is false.
<P>
Nesting of I<SMALL>F</SMALL>s is permitted:
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>If ndef Foo
<BR> Print Foo has been defined.
<BR>
Else
<BR> If def bar
<BR> Print bar has been defined. Cool.
<BR> Else
<BR> Print no bar ...go thirsty.
<BR> Endif
<BR>
Endif </B>
</td></tr>
</Table>
<P>
works just fine. Indentation has been used in these examples to
clearly show the nesting and conditions. You should do the same.
<P>
<H1><A NAME="SECTION002160000000000000000">
Goto</A>
</H1>
<P>
The G<SMALL>OTO</SMALL> command redirects the execution order of your script
to the point at which a L<SMALL>ABEL</SMALL> or line number has been
defined. There are really two parts to this:
<P>
<OL>
<LI>A command defining a label, and,
<P>
</LI>
<LI>The G<SMALL>OTO</SMALL> command.
<P>
</LI>
</OL>
<P>
<P>
A label is set with the L<SMALL>ABEL</SMALL> directive:
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>Label Point1 </B>
</td></tr>
</Table>
<P>
The string defining the label can be any sequence of characters.
Labels are case-insensitive.
<P>
To make this look a lot more line those old BASIC programs, any lines
starting with a line number are considered to be label lines as well.
<P>
A few considerations on labels and line numbers:
<P>
<UL>
<LI>A duplicate label generated with a L<SMALL>ABEL</SMALL> command will
generate an error.
<P>
</LI>
<LI>A line number label duplicating a L<SMALL>ABEL</SMALL> is an error.
<P>
</LI>
<LI>A L<SMALL>ABEL</SMALL> duplicating a line number is an error.
<P>
</LI>
<LI>Duplicate line numbers are permitted. The last one encountered
will be the one used.
<P>
</LI>
<LI>All label points are generated when the file is opened, not as
it is parsed.
<P>
</LI>
<LI>Line numbers (really, just comments) do not need to be in any
order.
<P>
</LI>
</UL>
<P>
<P>
The command:
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>Goto Point1 </B>
</td></tr>
</Table>
<P>
causes an immediate jump to a new point in the file. If you are
currently in repeat or conditional segment of the file, the remaining
lines in that segment will be ignored.
<P>
<FONT Face="Serif" Color="Navy"><I>MMA</I></FONT> does not check to see if you are jumping into a repeat or
conditional section of code--but doing so will usually cause an
error. Jumping out of these sections is usually safe.
<P>
The following example shows the use of both types of label. In this
example only lines 2, 3, 5 and 6 will be processed.
<P>
<Table Hspace="40%" CellSpacing=0 CellPadding=10 BGColor="OldLace" Border=3>
<tr><td>
<B>Goto Foo
<BR>
1 Cm
<BR>
Label Foo
<BR>
2 Dm
<BR>
3 /
<BR>
Goto 5
<BR>
4 Am
<BR>
5 Cm
<BR>
6 Dm </B>
</td></tr>
</Table>
<P>
For an example of how to use some simple labels to simulate a ``DS al
Coda'' examine the file ``lullaby-of-Broadway'' in the sample songs
directory.
<P>
<BR><HR><H4>Footnotes</H4>
<DL>
<DT><A NAME="foot11484">... macros.</A><A
HREF="node21.html#tex2html81"><SUP><SPAN CLASS="arabic">21</SPAN>.<SPAN CLASS="arabic">1</SPAN></SUP></A></DT>
<DD>The values
are dynamically created and reflect the current settings, and may
not be exactly the same as the value you originally set due to
internal roundings, etc.
</DD>
<DT><A NAME="foot11669">...
lists.</A><A
HREF="node21.html#tex2html82"><SUP><SPAN CLASS="arabic">21</SPAN>.<SPAN CLASS="arabic">2</SPAN></SUP></A></DT>
<DD>this was written before the introduction of slices,
(<A HREF="#slicing">details here</A>). Slices make this
much easier, but lets leave the hard stuff in just to show what can
be done.
</DD>
<DT><A NAME="foot11578">... functions:</A><A
HREF="node21.html#tex2html83"><SUP><SPAN CLASS="arabic">21</SPAN>.<SPAN CLASS="arabic">3</SPAN></SUP></A></DT>
<DD>It is possible that the
following functions could be used to do ``bad'' things. If you see
code using these commands from a suspect source you should be
careful.
</DD>
<DT><A NAME="foot11670">...I<SMALL>F</SMALL>E<SMALL>ND</SMALL></A><A
HREF="node21.html#tex2html84"><SUP><SPAN CLASS="arabic">21</SPAN>.<SPAN CLASS="arabic">4</SPAN></SUP></A></DT>
<DD>
<FONT Face="Serif" Color="Navy"><I>MMA</I></FONT> 's author probably suffers
from mild dyslexia and can't remember if the command is IfEnd or
EndIf, so both are permitted. Use whichever is more comfortable for
you.
</DD>
<DT><A NAME="foot11641">... strings.</A><A
HREF="node21.html#tex2html85"><SUP><SPAN CLASS="arabic">21</SPAN>.<SPAN CLASS="arabic">5</SPAN></SUP></A></DT>
<DD>For this comparison
float values are used. Rounding errors can cause equality
comparisons to fail.
</DD>
</DL>
<DIV CLASS="navigation"><HR>
<!--Navigation Panel-->
<A NAME="tex2html788"
HREF="node22.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A>
<A NAME="tex2html786"
HREF="mma.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A>
<A NAME="tex2html780"
HREF="node20.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A>
<BR>
<B> Next:</B> <A NAME="tex2html789"
HREF="node22.html">Subroutines</A>
<B> Up:</B> <A NAME="tex2html787"
HREF="mma.html">Reference Manual</A>
<B> Previous:</B> <A NAME="tex2html781"
HREF="node20.html">Repeats</A></DIV>
<!--End of Navigation Panel-->
<ADDRESS>
Bob van der Poel
2016-06-11
</ADDRESS>
</BODY>
</HTML>
|