mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-28 17:20:22 +00:00
Add Csound languages (#3005)
* Add Csound languages * Remove Csound Document alias * Remove Csound Score alias * Replace sample files * Update language-csound grammar * Update language-csound * Update language-csound * Add Makefile.sco to Makefile filenames * Add makefile.sco sample * Fix case of filename makefile.sco
This commit is contained in:
committed by
Arfon Smith
parent
28af996bf9
commit
e70f3f595a
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -728,3 +728,6 @@
|
||||
[submodule "vendor/grammars/creole"]
|
||||
path = vendor/grammars/creole
|
||||
url = https://github.com/Siddley/Creole
|
||||
[submodule "vendor/grammars/language-csound"]
|
||||
path = vendor/grammars/language-csound
|
||||
url = https://github.com/nwhetsell/language-csound
|
||||
|
||||
@@ -345,6 +345,10 @@ vendor/grammars/language-csharp:
|
||||
- source.cs
|
||||
- source.csx
|
||||
- source.nant-build
|
||||
vendor/grammars/language-csound:
|
||||
- source.csound
|
||||
- source.csound-document
|
||||
- source.csound-score
|
||||
vendor/grammars/language-gfm:
|
||||
- source.gfm
|
||||
vendor/grammars/language-graphql:
|
||||
|
||||
@@ -722,6 +722,34 @@ Crystal:
|
||||
interpreters:
|
||||
- crystal
|
||||
|
||||
Csound:
|
||||
type: programming
|
||||
aliases:
|
||||
- csound-orc
|
||||
extensions:
|
||||
- .orc
|
||||
- .udo
|
||||
tm_scope: source.csound
|
||||
ace_mode: text
|
||||
|
||||
Csound Document:
|
||||
type: programming
|
||||
aliases:
|
||||
- csound-csd
|
||||
extensions:
|
||||
- .csd
|
||||
tm_scope: source.csound-document
|
||||
ace_mode: text
|
||||
|
||||
Csound Score:
|
||||
type: programming
|
||||
aliases:
|
||||
- csound-sco
|
||||
extensions:
|
||||
- .sco
|
||||
tm_scope: source.csound-score
|
||||
ace_mode: text
|
||||
|
||||
Cucumber:
|
||||
type: programming
|
||||
extensions:
|
||||
@@ -2131,6 +2159,7 @@ Makefile:
|
||||
- Makefile.in
|
||||
- Makefile.inc
|
||||
- makefile
|
||||
- makefile.sco
|
||||
- mkfile
|
||||
interpreters:
|
||||
- make
|
||||
|
||||
21
samples/Csound Document/allglass.csd
Executable file
21
samples/Csound Document/allglass.csd
Executable file
@@ -0,0 +1,21 @@
|
||||
<CsoundSynthesizer>
|
||||
<CsInstruments>
|
||||
sr = 44100
|
||||
kr = 44100
|
||||
ksmps = 1
|
||||
nchnls = 2
|
||||
|
||||
; pvanal -n 512 -w 8 allglass1-L.wav allglass1-L.pvc
|
||||
; pvanal -n 512 -w 8 allglass1-R.wav allglass1-R.pvc
|
||||
instr 1
|
||||
ktime line 0, p3, 17.5018
|
||||
arL pvoc ktime, 1, "allglass1-L.pvc"
|
||||
arR pvoc ktime, 1, "allglass1-R.pvc"
|
||||
out arL, arR
|
||||
endin
|
||||
</CsInstruments>
|
||||
<CsScore>
|
||||
i 1 0 70.0073
|
||||
e
|
||||
</CsScore>
|
||||
</CsoundSynthesizer>
|
||||
34
samples/Csound Document/interp.csd
Executable file
34
samples/Csound Document/interp.csd
Executable file
@@ -0,0 +1,34 @@
|
||||
<CsoundSynthesizer>
|
||||
<CsInstruments>
|
||||
sr = 44100
|
||||
kr = 44100
|
||||
ksmps = 1
|
||||
nchnls = 2
|
||||
|
||||
; pvanal -n 1024 -w 2 partA-L.wav partA-L.pvc
|
||||
; pvanal -n 1024 -w 2 partA-R.wav partA-R.pvc
|
||||
; pvanal -n 1024 -w 2 partB.wav partB.pvc
|
||||
instr 1
|
||||
iscale = 1
|
||||
|
||||
ktimpnt1 line 0, iscale*(82196/44100), 82196/44100
|
||||
ktimpnt2 linseg 0, iscale*1.25, 0, iscale*(103518/44100), 103518/44100
|
||||
kfreqscale linseg 1, iscale*0.5, 1, iscale*1.6, 0.8
|
||||
kfreqinterpL linseg 0, iscale*0.25, 0, iscale*1.6, 1
|
||||
kampinterpL linseg 0, iscale*0.25, 0, iscale*1.6, 1
|
||||
kfreqinterpR linseg 0, iscale*0.5, 0, iscale*1.2, 1
|
||||
kampinterpR linseg 0, iscale*0.5, 0, iscale*1.2, 1
|
||||
|
||||
pvbufread ktimpnt1, "partB.pvc"
|
||||
apvcL pvinterp ktimpnt2, 1, "partA-L.pvc", kfreqscale, 1, 1, 1, 1-kfreqinterpL, 1-kampinterpL
|
||||
pvbufread ktimpnt1, "partB.pvc"
|
||||
apvcR pvinterp ktimpnt2, 1, "partA-R.pvc", kfreqscale, 1, 1, 1, 1-kfreqinterpR, 1-kampinterpR
|
||||
|
||||
outs apvcL*0.8, apvcR*0.8
|
||||
endin
|
||||
</CsInstruments>
|
||||
<CsScore>
|
||||
i 1 0 7
|
||||
e
|
||||
</CsScore>
|
||||
</CsoundSynthesizer>
|
||||
253
samples/Csound Document/test.csd
Normal file
253
samples/Csound Document/test.csd
Normal file
@@ -0,0 +1,253 @@
|
||||
<CsoundSynthesizer>
|
||||
<CsInstruments>
|
||||
// Csound single-line comments can be preceded by a pair of forward slashes...
|
||||
; ...or a semicolon.
|
||||
|
||||
/* Block comments begin with /* and end with */
|
||||
|
||||
// Orchestras begin with a header of audio parameters.
|
||||
nchnls = 1
|
||||
nchnls_i = 1
|
||||
sr = 44100
|
||||
0dbfs = 1
|
||||
ksmps = 10
|
||||
|
||||
// The control rate kr = sr / ksmps can be omitted when the number of audio
|
||||
// samples in a control period (ksmps) is set, but kr may appear in older
|
||||
// orchestras.
|
||||
kr = 4410
|
||||
|
||||
// Orchestras contain instruments. These begin with the keyword instr followed
|
||||
// by a comma-separated list of numbers or names of the instrument. Instruments
|
||||
// end at the endin keyword and cannot be nested.
|
||||
instr 1, N_a_M_e_, +Name
|
||||
// Instruments contain statements. Here is a typical statement:
|
||||
aSignal oscil 0dbfs, 440, 1
|
||||
// Statements are terminated with a newline (possibly preceded by a comment).
|
||||
// To write a statement on several lines, precede the newline with a
|
||||
// backslash.
|
||||
prints \
|
||||
"hello, world\n";comment
|
||||
|
||||
// Csound 6 introduced function syntax for opcodes with one or zero outputs.
|
||||
// The oscil statement above is the same as
|
||||
aSignal = oscil(0dbfs, 440, 1)
|
||||
|
||||
// Instruments can contain control structures.
|
||||
kNote = p3
|
||||
if (kNote == 0) then
|
||||
kFrequency = 220
|
||||
elseif kNote == 1 then // Parentheses around binary expressions are optional.
|
||||
kFrequency = 440
|
||||
endif
|
||||
|
||||
// Csound 6 introduced looping structures.
|
||||
iIndex = 0
|
||||
while iIndex < 5 do
|
||||
print iIndex
|
||||
iIndex += 1
|
||||
od
|
||||
iIndex = 0
|
||||
until iIndex >= 5 do
|
||||
print iIndex
|
||||
iIndex += 1
|
||||
enduntil
|
||||
// Both kinds of loops can be terminated by either od or enduntil.
|
||||
|
||||
// Single-line strings are enclosed in double-quotes.
|
||||
prints "string\\\r\n\t\""
|
||||
// Multi-line strings are enclosed in pairs of curly braces.
|
||||
prints {{
|
||||
hello,
|
||||
|
||||
world
|
||||
}}
|
||||
|
||||
// Instruments often end with a statement containing an output opcode.
|
||||
outc aSignal
|
||||
endin
|
||||
|
||||
// Orchestras can also contain user-defined opcodes (UDOs). Here is an
|
||||
// oscillator with one audio-rate output and two control-rate inputs:
|
||||
opcode anOscillator, a, kk
|
||||
kAmplitude, kFrequency xin
|
||||
aSignal vco2 kAmplitude, kFrequency
|
||||
xout aSignal
|
||||
endop
|
||||
instr TestOscillator
|
||||
outc(anOscillator(0dbfs, 110))
|
||||
endin
|
||||
|
||||
// Python can be executed in Csound
|
||||
// <https://csound.github.io/docs/manual/pyrun.html>. So can Lua
|
||||
// <https://csound.github.io/docs/manual/lua.html>.
|
||||
pyruni {{
|
||||
import random
|
||||
|
||||
pool = [(1 + i / 10.0) ** 1.2 for i in range(100)]
|
||||
|
||||
def get_number_from_pool(n, p):
|
||||
if random.random() < p:
|
||||
i = int(random.random() * len(pool))
|
||||
pool[i] = n;
|
||||
return random.choice(pool)
|
||||
}}
|
||||
|
||||
// The Csound preprocessor supports conditional compilation and including files.
|
||||
#ifdef DEBUG
|
||||
#undef DEBUG
|
||||
#include "filename.orc"
|
||||
#endif
|
||||
|
||||
// The preprocessor also supports object- and function-like macros. This is an
|
||||
// object-like macro that defines a number:
|
||||
#define A_HZ #440#
|
||||
|
||||
// This is a function-like macro:
|
||||
#define OSCIL_MACRO(VOLUME'FREQUENCY'TABLE) #oscil $VOLUME, $FREQUENCY, $TABLE#
|
||||
|
||||
// Bodies of macros are enclosed in # and can contain newlines. The arguments of
|
||||
// function-like macros are separated by single-quotes. Uses of macros are
|
||||
// prefixed with a dollar sign.
|
||||
instr TestMacro
|
||||
aSignal $OSCIL_MACRO(1'$A_HZ'1)
|
||||
// Not unlike PHP, macros expand in double-quoted strings.
|
||||
prints "The frequency of the oscillator is $A_HZ Hz.\n"
|
||||
out aSignal
|
||||
endin
|
||||
|
||||
// Here are other things to note about Csound.
|
||||
|
||||
// There are two bitwise NOT operators, ~ and ¬ (U+00AC). The latter is common
|
||||
// on keyboards in the United Kingdom
|
||||
// <https://en.wikipedia.org/wiki/British_and_American_keyboards>.
|
||||
instr TestBitwiseNOT
|
||||
print ~42
|
||||
print ¬42
|
||||
endin
|
||||
|
||||
// Csound uses # for bitwise XOR, which the Csound manual calls bitwise
|
||||
// non-equivalence <https://csound.github.io/docs/manual/opnonequiv.html>.
|
||||
instr TestBitwiseXOR
|
||||
print 0 # 0
|
||||
print 0 # 1
|
||||
print 1 # 0
|
||||
print 1 # 1
|
||||
endin
|
||||
|
||||
// Loops and if-then statements are relatively recent additions to Csound. There
|
||||
// are many flow-control opcodes that involve goto and labels.
|
||||
instr TestGoto
|
||||
// This...
|
||||
if p3 > 0 goto if_label
|
||||
goto else_label
|
||||
if_label:
|
||||
prints "if branch\n"
|
||||
goto endif_label
|
||||
else_label:
|
||||
prints "else branch\n"
|
||||
endif_label:
|
||||
|
||||
// ...is the same as this.
|
||||
if p3 > 0 then
|
||||
prints "if branch\n"
|
||||
else
|
||||
prints "else branch\n"
|
||||
endif
|
||||
|
||||
// This...
|
||||
iIndex = 0
|
||||
loop_label:
|
||||
print iIndex
|
||||
iIndex += 1
|
||||
if iIndex < 10 goto loop_label
|
||||
|
||||
// ...is the same as this...
|
||||
iIndex = 0
|
||||
loop_lt_label:
|
||||
print iIndex
|
||||
loop_lt iIndex, 1, 10, loop_lt_label
|
||||
|
||||
// ...and this.
|
||||
iIndex = 0
|
||||
while iIndex < 10 do
|
||||
print iIndex
|
||||
iIndex += 1
|
||||
od
|
||||
endin
|
||||
|
||||
// The prints and printks opcodes
|
||||
// <https://github.com/csound/csound/blob/develop/OOps/ugrw1.c#L831>, arguably
|
||||
// the primary methods of logging output, treat certain sequences of characters
|
||||
// different from printf in C.
|
||||
instr TestPrints
|
||||
// ^ prints an ESCAPE character (U+001B), not a CIRCUMFLEX ACCENT character
|
||||
// (U+005E). ^^ prints a CIRCUMFLEX ACCENT.
|
||||
prints "^^\n"
|
||||
// ~ prints an ESCAPE character (U+001B) followed by a [, not a TILDE
|
||||
// character (U+007E). ~~ prints a TILDE.
|
||||
prints "~~\n"
|
||||
// \A, \B, \N, \R, and \T correspond to the escaped lowercase characters (that
|
||||
// is, BELL (U+0007), BACKSPACE (U+0008), new line (U+000A), CARRIAGE RETURN
|
||||
// (U+000D), and tab (U+0009)).
|
||||
prints "\T\R\N"
|
||||
// %n, %r, and %t are the same as \n, \r, and \t, as are %N, %R, and %T.
|
||||
prints "%t%r%n"
|
||||
// %! prints a semicolon. This is a hold-over from old versions of Csound that
|
||||
// allowed comments to begin in strings.
|
||||
prints "; %!\n"
|
||||
endin
|
||||
|
||||
// The arguments of function-like macros can be separated by # instead of '.
|
||||
// These two lines define the same macro.
|
||||
#define OSCIL_MACRO(VOLUME'FREQUENCY'TABLE) #oscil $VOLUME, $FREQUENCY, $TABLE#
|
||||
#define OSCIL_MACRO(VOLUME#FREQUENCY#TABLE) #oscil $VOLUME, $FREQUENCY, $TABLE#
|
||||
|
||||
// Uses of macros can optionally be suffixed with a period.
|
||||
instr TestMacroPeriodSuffix
|
||||
aSignal $OSCIL_MACRO.(1'$A_HZ'1)
|
||||
prints "The frequency of the oscillator is $A_HZ.Hz.\n"
|
||||
out aSignal
|
||||
endin
|
||||
|
||||
// Csound has @ and @@ operator-like macros that, when followed by a literal
|
||||
// non-negative integer, expand to the next power of 2 and the next power of 2
|
||||
// plus 1:
|
||||
// @x = 2^(ceil(log2(x + 1))), x >= 0
|
||||
// @@0 = 2
|
||||
// @@x = 2^(ceil(log2(x))) + 1, x > 0
|
||||
instr TestAt
|
||||
prints "%d %2d %2d\n", 0, @0, @@0
|
||||
prints "%d %2d %2d\n", 1, @1, @@1
|
||||
prints "%d %2d %2d\n", 2, @2, @@2
|
||||
prints "%d %2d %2d\n", 3, @3, @@3
|
||||
prints "%d %2d %2d\n", 4, @4, @@4
|
||||
prints "%d %2d %2d\n", 5, @5, @@5
|
||||
prints "%d %2d %2d\n", 6, @6, @@6
|
||||
prints "%d %2d %2d\n", 7, @7, @@7
|
||||
prints "%d %2d %2d\n", 8, @8, @@8
|
||||
prints "%d %2d %2d\n", 9, @9, @@9
|
||||
endin
|
||||
|
||||
// Including newlines in macros can lead to confusing code.
|
||||
instr MacroAbuse
|
||||
if 1 == 1 then
|
||||
prints "on\n"
|
||||
#define FOO#
|
||||
BAR
|
||||
#endif // This ends the if block. It is not a preprocessor directive.
|
||||
endin
|
||||
</CsInstruments>
|
||||
<CsScore>
|
||||
f 1 0 16384 10 1
|
||||
i "N_a_M_e_" 0 2
|
||||
i "TestOscillator" 2 2
|
||||
i "TestBitwiseNOT" 0 1
|
||||
i "TestBitwiseXOR" 0 1
|
||||
i "TestGoto" 0 1
|
||||
i "TestMacroPeriodSuffix" 4 1
|
||||
i "TestAt" 0 1
|
||||
i "MacroAbuse" 0 1
|
||||
e
|
||||
</CsScore>
|
||||
</CsoundSynthesizer>
|
||||
2
samples/Csound Score/allglass.sco
Executable file
2
samples/Csound Score/allglass.sco
Executable file
@@ -0,0 +1,2 @@
|
||||
i 1 0 70.0073
|
||||
e
|
||||
2
samples/Csound Score/interp.sco
Executable file
2
samples/Csound Score/interp.sco
Executable file
@@ -0,0 +1,2 @@
|
||||
i 1 0 7
|
||||
e
|
||||
10
samples/Csound Score/test.sco
Normal file
10
samples/Csound Score/test.sco
Normal file
@@ -0,0 +1,10 @@
|
||||
f 1 0 16384 10 1
|
||||
i "N_a_M_e_" 0 2
|
||||
i "TestOscillator" 2 2
|
||||
i "TestBitwiseNOT" 0 1
|
||||
i "TestBitwiseXOR" 0 1
|
||||
i "TestGoto" 0 1
|
||||
i "TestMacroPeriodSuffix" 4 1
|
||||
i "TestAt" 0 1
|
||||
i "MacroAbuse" 0 1
|
||||
e
|
||||
13
samples/Csound/allglass.orc
Executable file
13
samples/Csound/allglass.orc
Executable file
@@ -0,0 +1,13 @@
|
||||
sr = 44100
|
||||
kr = 44100
|
||||
ksmps = 1
|
||||
nchnls = 2
|
||||
|
||||
; pvanal -n 512 -w 8 allglass1-L.wav allglass1-L.pvc
|
||||
; pvanal -n 512 -w 8 allglass1-R.wav allglass1-R.pvc
|
||||
instr 1
|
||||
ktime line 0, p3, 17.5018
|
||||
arL pvoc ktime, 1, "allglass1-L.pvc"
|
||||
arR pvoc ktime, 1, "allglass1-R.pvc"
|
||||
out arL, arR
|
||||
endin
|
||||
26
samples/Csound/interp.orc
Executable file
26
samples/Csound/interp.orc
Executable file
@@ -0,0 +1,26 @@
|
||||
sr = 44100
|
||||
kr = 44100
|
||||
ksmps = 1
|
||||
nchnls = 2
|
||||
|
||||
; pvanal -n 1024 -w 2 partA-L.wav partA-L.pvc
|
||||
; pvanal -n 1024 -w 2 partA-R.wav partA-R.pvc
|
||||
; pvanal -n 1024 -w 2 partB.wav partB.pvc
|
||||
instr 1
|
||||
iscale = 1
|
||||
|
||||
ktimpnt1 line 0, iscale*(82196/44100), 82196/44100
|
||||
ktimpnt2 linseg 0, iscale*1.25, 0, iscale*(103518/44100), 103518/44100
|
||||
kfreqscale linseg 1, iscale*0.5, 1, iscale*1.6, 0.8
|
||||
kfreqinterpL linseg 0, iscale*0.25, 0, iscale*1.6, 1
|
||||
kampinterpL linseg 0, iscale*0.25, 0, iscale*1.6, 1
|
||||
kfreqinterpR linseg 0, iscale*0.5, 0, iscale*1.2, 1
|
||||
kampinterpR linseg 0, iscale*0.5, 0, iscale*1.2, 1
|
||||
|
||||
pvbufread ktimpnt1, "partB.pvc"
|
||||
apvcL pvinterp ktimpnt2, 1, "partA-L.pvc", kfreqscale, 1, 1, 1, 1-kfreqinterpL, 1-kampinterpL
|
||||
pvbufread ktimpnt1, "partB.pvc"
|
||||
apvcR pvinterp ktimpnt2, 1, "partA-R.pvc", kfreqscale, 1, 1, 1, 1-kfreqinterpR, 1-kampinterpR
|
||||
|
||||
outs apvcL*0.8, apvcR*0.8
|
||||
endin
|
||||
250
samples/Csound/test.orc
Normal file
250
samples/Csound/test.orc
Normal file
@@ -0,0 +1,250 @@
|
||||
// Csound single-line comments can be preceded by a pair of forward slashes...
|
||||
; ...or a semicolon.
|
||||
|
||||
/* Block comments begin with /* and end with */
|
||||
|
||||
// Orchestras begin with a header of audio parameters.
|
||||
nchnls = 1
|
||||
nchnls_i = 1
|
||||
sr = 44100
|
||||
0dbfs = 1
|
||||
ksmps = 10
|
||||
|
||||
// The control rate kr = sr / ksmps can be omitted when the number of audio
|
||||
// samples in a control period (ksmps) is set, but kr may appear in older
|
||||
// orchestras.
|
||||
kr = 4410
|
||||
|
||||
// Orchestras contain instruments. These begin with the keyword instr followed
|
||||
// by a comma-separated list of numbers or names of the instrument. Instruments
|
||||
// end at the endin keyword and cannot be nested.
|
||||
instr 1, N_a_M_e_, +Name
|
||||
// Instruments contain statements. Here is a typical statement:
|
||||
aSignal oscil 0dbfs, 440, 1
|
||||
// Statements are terminated with a newline (possibly preceded by a comment).
|
||||
// To write a statement on several lines, precede the newline with a
|
||||
// backslash.
|
||||
prints \
|
||||
"hello, world\n";comment
|
||||
|
||||
// Csound 6 introduced function syntax for opcodes with one or zero outputs.
|
||||
// The oscil statement above is the same as
|
||||
aSignal = oscil(0dbfs, 440, 1)
|
||||
|
||||
// Instruments can contain control structures.
|
||||
kNote = p3
|
||||
if (kNote == 0) then
|
||||
kFrequency = 220
|
||||
elseif kNote == 1 then // Parentheses around binary expressions are optional.
|
||||
kFrequency = 440
|
||||
endif
|
||||
|
||||
// Csound 6 introduced looping structures.
|
||||
iIndex = 0
|
||||
while iIndex < 5 do
|
||||
print iIndex
|
||||
iIndex += 1
|
||||
od
|
||||
iIndex = 0
|
||||
until iIndex >= 5 do
|
||||
print iIndex
|
||||
iIndex += 1
|
||||
enduntil
|
||||
// Both kinds of loops can be terminated by either od or enduntil.
|
||||
|
||||
// Single-line strings are enclosed in double-quotes.
|
||||
prints "string\\\r\n\t\""
|
||||
// Multi-line strings are enclosed in pairs of curly braces.
|
||||
prints {{
|
||||
hello,
|
||||
|
||||
world
|
||||
}}
|
||||
|
||||
// Instruments often end with a statement containing an output opcode.
|
||||
outc aSignal
|
||||
endin
|
||||
|
||||
// Orchestras can also contain user-defined opcodes (UDOs). Here is an
|
||||
// oscillator with one audio-rate output and two control-rate inputs:
|
||||
opcode anOscillator, a, kk
|
||||
kAmplitude, kFrequency xin
|
||||
aSignal vco2 kAmplitude, kFrequency
|
||||
xout aSignal
|
||||
endop
|
||||
instr TestOscillator
|
||||
outc(anOscillator(0dbfs, 110))
|
||||
endin
|
||||
|
||||
// Python can be executed in Csound
|
||||
// <https://csound.github.io/docs/manual/pyrun.html>. So can Lua
|
||||
// <https://csound.github.io/docs/manual/lua.html>.
|
||||
pyruni {{
|
||||
import random
|
||||
|
||||
pool = [(1 + i / 10.0) ** 1.2 for i in range(100)]
|
||||
|
||||
def get_number_from_pool(n, p):
|
||||
if random.random() < p:
|
||||
i = int(random.random() * len(pool))
|
||||
pool[i] = n;
|
||||
return random.choice(pool)
|
||||
}}
|
||||
|
||||
// The Csound preprocessor supports conditional compilation and including files.
|
||||
#ifdef DEBUG
|
||||
#undef DEBUG
|
||||
#include "filename.orc"
|
||||
#endif
|
||||
|
||||
// The preprocessor also supports object- and function-like macros. This is an
|
||||
// object-like macro that defines a number:
|
||||
#define A_HZ #440#
|
||||
|
||||
// This is a function-like macro:
|
||||
#define OSCIL_MACRO(VOLUME'FREQUENCY'TABLE) #oscil $VOLUME, $FREQUENCY, $TABLE#
|
||||
|
||||
// Bodies of macros are enclosed in # and can contain newlines. The arguments of
|
||||
// function-like macros are separated by single-quotes. Uses of macros are
|
||||
// prefixed with a dollar sign.
|
||||
instr TestMacro
|
||||
aSignal $OSCIL_MACRO(1'$A_HZ'1)
|
||||
// Not unlike PHP, macros expand in double-quoted strings.
|
||||
prints "The frequency of the oscillator is $A_HZ Hz.\n"
|
||||
out aSignal
|
||||
endin
|
||||
|
||||
// Here are other things to note about Csound.
|
||||
|
||||
// There are two bitwise NOT operators, ~ and ¬ (U+00AC). The latter is common
|
||||
// on keyboards in the United Kingdom
|
||||
// <https://en.wikipedia.org/wiki/British_and_American_keyboards>.
|
||||
instr TestBitwiseNOT
|
||||
print ~42
|
||||
print ¬42
|
||||
endin
|
||||
|
||||
// Csound uses # for bitwise XOR, which the Csound manual calls bitwise
|
||||
// non-equivalence <https://csound.github.io/docs/manual/opnonequiv.html>.
|
||||
instr TestBitwiseXOR
|
||||
print 0 # 0
|
||||
print 0 # 1
|
||||
print 1 # 0
|
||||
print 1 # 1
|
||||
endin
|
||||
|
||||
// Loops and if-then statements are relatively recent additions to Csound. There
|
||||
// are many flow-control opcodes that involve goto and labels.
|
||||
instr TestGoto
|
||||
// This...
|
||||
if p3 > 0 goto if_label
|
||||
goto else_label
|
||||
if_label:
|
||||
prints "if branch\n"
|
||||
goto endif_label
|
||||
else_label:
|
||||
prints "else branch\n"
|
||||
endif_label:
|
||||
|
||||
// ...is the same as this.
|
||||
if p3 > 0 then
|
||||
prints "if branch\n"
|
||||
else
|
||||
prints "else branch\n"
|
||||
endif
|
||||
|
||||
// This...
|
||||
iIndex = 0
|
||||
loop_label:
|
||||
print iIndex
|
||||
iIndex += 1
|
||||
if iIndex < 10 goto loop_label
|
||||
|
||||
// ...is the same as this...
|
||||
iIndex = 0
|
||||
loop_lt_label:
|
||||
print iIndex
|
||||
loop_lt iIndex, 1, 10, loop_lt_label
|
||||
|
||||
// ...and this.
|
||||
iIndex = 0
|
||||
while iIndex < 10 do
|
||||
print iIndex
|
||||
iIndex += 1
|
||||
od
|
||||
endin
|
||||
|
||||
// The prints and printks opcodes
|
||||
// <https://github.com/csound/csound/blob/develop/OOps/ugrw1.c#L831>, arguably
|
||||
// the primary methods of logging output, treat certain sequences of characters
|
||||
// different from printf in C.
|
||||
instr TestPrints
|
||||
// ^ prints an ESCAPE character (U+001B), not a CIRCUMFLEX ACCENT character
|
||||
// (U+005E). ^^ prints a CIRCUMFLEX ACCENT.
|
||||
prints "^^\n"
|
||||
// ~ prints an ESCAPE character (U+001B) followed by a [, not a TILDE
|
||||
// character (U+007E). ~~ prints a TILDE.
|
||||
prints "~~\n"
|
||||
// \A, \B, \N, \R, and \T correspond to the escaped lowercase characters (that
|
||||
// is, BELL (U+0007), BACKSPACE (U+0008), new line (U+000A), CARRIAGE RETURN
|
||||
// (U+000D), and tab (U+0009)).
|
||||
prints "\T\R\N"
|
||||
// %n, %r, and %t are the same as \n, \r, and \t, as are %N, %R, and %T.
|
||||
prints "%t%r%n"
|
||||
// %! prints a semicolon. This is a hold-over from old versions of Csound that
|
||||
// allowed comments to begin in strings.
|
||||
prints "; %!\n"
|
||||
endin
|
||||
|
||||
// The arguments of function-like macros can be separated by # instead of '.
|
||||
// These two lines define the same macro.
|
||||
#define OSCIL_MACRO(VOLUME'FREQUENCY'TABLE) #oscil $VOLUME, $FREQUENCY, $TABLE#
|
||||
#define OSCIL_MACRO(VOLUME#FREQUENCY#TABLE) #oscil $VOLUME, $FREQUENCY, $TABLE#
|
||||
|
||||
// Uses of macros can optionally be suffixed with a period.
|
||||
instr TestMacroPeriodSuffix
|
||||
aSignal $OSCIL_MACRO.(1'$A_HZ'1)
|
||||
prints "The frequency of the oscillator is $A_HZ.Hz.\n"
|
||||
out aSignal
|
||||
endin
|
||||
|
||||
// Csound has @ and @@ operator-like macros that, when followed by a literal
|
||||
// non-negative integer, expand to the next power of 2 and the next power of 2
|
||||
// plus 1:
|
||||
// @x = 2^(ceil(log2(x + 1))), x >= 0
|
||||
// @@0 = 2
|
||||
// @@x = 2^(ceil(log2(x))) + 1, x > 0
|
||||
instr TestAt
|
||||
prints "%d %2d %2d\n", 0, @0, @@0
|
||||
prints "%d %2d %2d\n", 1, @1, @@1
|
||||
prints "%d %2d %2d\n", 2, @2, @@2
|
||||
prints "%d %2d %2d\n", 3, @3, @@3
|
||||
prints "%d %2d %2d\n", 4, @4, @@4
|
||||
prints "%d %2d %2d\n", 5, @5, @@5
|
||||
prints "%d %2d %2d\n", 6, @6, @@6
|
||||
prints "%d %2d %2d\n", 7, @7, @@7
|
||||
prints "%d %2d %2d\n", 8, @8, @@8
|
||||
prints "%d %2d %2d\n", 9, @9, @@9
|
||||
endin
|
||||
|
||||
// Including newlines in macros can lead to confusing code.
|
||||
instr MacroAbuse
|
||||
if 1 == 1 then
|
||||
prints "on\n"
|
||||
#define FOO#
|
||||
BAR
|
||||
#endif // This ends the if block. It is not a preprocessor directive.
|
||||
endin
|
||||
|
||||
scoreline_i {{
|
||||
f 1 0 16384 10 1
|
||||
i "N_a_M_e_" 0 2
|
||||
i "TestOscillator" 2 2
|
||||
i "TestBitwiseNOT" 0 1
|
||||
i "TestBitwiseXOR" 0 1
|
||||
i "TestGoto" 0 1
|
||||
i "TestMacroPeriodSuffix" 4 1
|
||||
i "TestAt" 0 1
|
||||
i "MacroAbuse" 0 1
|
||||
e
|
||||
}}
|
||||
226
samples/Makefile/filenames/makefile.sco
Normal file
226
samples/Makefile/filenames/makefile.sco
Normal file
@@ -0,0 +1,226 @@
|
||||
# makefile for SCO OSr5 ELF and Unixware 7 with Native cc
|
||||
# Contributed by Mike Hopkirk (hops@sco.com) modified from Makefile.lnx
|
||||
# force ELF build dynamic linking, SONAME setting in lib and RPATH in app
|
||||
# Copyright (C) 2002, 2006, 2010-2014 Glenn Randers-Pehrson
|
||||
# Copyright (C) 1998 Greg Roelofs
|
||||
# Copyright (C) 1996, 1997 Andreas Dilger
|
||||
#
|
||||
# This code is released under the libpng license.
|
||||
# For conditions of distribution and use, see the disclaimer
|
||||
# and license in png.h
|
||||
|
||||
# Library name:
|
||||
LIBNAME = libpng16
|
||||
PNGMAJ = 16
|
||||
|
||||
# Shared library names:
|
||||
LIBSO=$(LIBNAME).so
|
||||
LIBSOMAJ=$(LIBNAME).so.$(PNGMAJ)
|
||||
LIBSOREL=$(LIBSOMAJ).$(RELEASE)
|
||||
OLDSO=libpng.so
|
||||
|
||||
# Utilities:
|
||||
CC=cc
|
||||
AR_RC=ar rc
|
||||
MKDIR_P=mkdir
|
||||
LN_SF=ln -f -s
|
||||
RANLIB=echo
|
||||
CP=cp
|
||||
RM_F=/bin/rm -f
|
||||
|
||||
# where make install puts libpng.a, $(OLDSO)*, and png.h
|
||||
prefix=/usr/local
|
||||
exec_prefix=$(prefix)
|
||||
|
||||
# Where the zlib library and include files are located
|
||||
#ZLIBLIB=/usr/local/lib
|
||||
#ZLIBINC=/usr/local/include
|
||||
ZLIBLIB=../zlib
|
||||
ZLIBINC=../zlib
|
||||
|
||||
CPPFLAGS=-I$(ZLIBINC)
|
||||
CFLAGS= -dy -belf -O3
|
||||
LDFLAGS=-L. -L$(ZLIBLIB) -lpng16 -lz -lm
|
||||
|
||||
INCPATH=$(prefix)/include
|
||||
LIBPATH=$(exec_prefix)/lib
|
||||
MANPATH=$(prefix)/man
|
||||
BINPATH=$(exec_prefix)/bin
|
||||
|
||||
# override DESTDIR= on the make install command line to easily support
|
||||
# installing into a temporary location. Example:
|
||||
#
|
||||
# make install DESTDIR=/tmp/build/libpng
|
||||
#
|
||||
# If you're going to install into a temporary location
|
||||
# via DESTDIR, $(DESTDIR)$(prefix) must already exist before
|
||||
# you execute make install.
|
||||
DESTDIR=
|
||||
|
||||
DB=$(DESTDIR)$(BINPATH)
|
||||
DI=$(DESTDIR)$(INCPATH)
|
||||
DL=$(DESTDIR)$(LIBPATH)
|
||||
DM=$(DESTDIR)$(MANPATH)
|
||||
|
||||
# Pre-built configuration
|
||||
# See scripts/pnglibconf.mak for more options
|
||||
PNGLIBCONF_H_PREBUILT = scripts/pnglibconf.h.prebuilt
|
||||
|
||||
OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
|
||||
pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
|
||||
pngwtran.o pngmem.o pngerror.o pngpread.o
|
||||
|
||||
OBJSDLL = $(OBJS:.o=.pic.o)
|
||||
|
||||
.SUFFIXES: .c .o .pic.o
|
||||
|
||||
.c.o:
|
||||
$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<
|
||||
|
||||
.c.pic.o:
|
||||
$(CC) -c $(CPPFLAGS) $(CFLAGS) -KPIC -o $@ $*.c
|
||||
|
||||
all: libpng.a $(LIBSO) pngtest libpng.pc libpng-config
|
||||
|
||||
pnglibconf.h: $(PNGLIBCONF_H_PREBUILT)
|
||||
$(CP) $(PNGLIBCONF_H_PREBUILT) $@
|
||||
|
||||
libpng.a: $(OBJS)
|
||||
$(AR_RC) $@ $(OBJS)
|
||||
$(RANLIB) $@
|
||||
|
||||
libpng.pc:
|
||||
cat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \
|
||||
-e s!@exec_prefix@!$(exec_prefix)! \
|
||||
-e s!@libdir@!$(LIBPATH)! \
|
||||
-e s!@includedir@!$(INCPATH)! \
|
||||
-e s!-lpng16!-lpng16\ -lz\ -lm! > libpng.pc
|
||||
|
||||
libpng-config:
|
||||
( cat scripts/libpng-config-head.in; \
|
||||
echo prefix=\"$(prefix)\"; \
|
||||
echo I_opts=\"-I$(INCPATH)/$(LIBNAME)\"; \
|
||||
echo ccopts=\"-belf\"; \
|
||||
echo L_opts=\"-L$(LIBPATH)\"; \
|
||||
echo libs=\"-lpng16 -lz -lm\"; \
|
||||
cat scripts/libpng-config-body.in ) > libpng-config
|
||||
chmod +x libpng-config
|
||||
|
||||
$(LIBSO): $(LIBSOMAJ)
|
||||
$(LN_SF) $(LIBSOMAJ) $(LIBSO)
|
||||
|
||||
$(LIBSOMAJ): $(OBJSDLL)
|
||||
$(CC) -G -Wl,-h,$(LIBSOMAJ) -o $(LIBSOMAJ) \
|
||||
$(OBJSDLL)
|
||||
|
||||
pngtest: pngtest.o $(LIBSO)
|
||||
LD_RUN_PATH=.:$(ZLIBLIB) $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)
|
||||
|
||||
test: pngtest
|
||||
./pngtest
|
||||
|
||||
install-headers: png.h pngconf.h pnglibconf.h
|
||||
-@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi
|
||||
-@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi
|
||||
-@$(RM_F) $(DI)/png.h
|
||||
-@$(RM_F) $(DI)/pngconf.h
|
||||
-@$(RM_F) $(DI)/pnglibconf.h
|
||||
cp png.h pngconf.h pnglibconf.h $(DI)/$(LIBNAME)
|
||||
chmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h $(DI)/$(LIBNAME)/pnglibconf.h
|
||||
-@$(RM_F) $(DI)/png.h $(DI)/pngconf.h $(DI)/pnglibconf.h
|
||||
-@$(RM_F) $(DI)/libpng
|
||||
(cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .)
|
||||
|
||||
install-static: install-headers libpng.a
|
||||
-@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
|
||||
cp libpng.a $(DL)/$(LIBNAME).a
|
||||
chmod 644 $(DL)/$(LIBNAME).a
|
||||
-@$(RM_F) $(DL)/libpng.a
|
||||
(cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a)
|
||||
|
||||
install-shared: install-headers $(LIBSOMAJ) libpng.pc
|
||||
-@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
|
||||
-@$(RM_F) $(DL)/$(LIBSO)
|
||||
-@$(RM_F) $(DL)/$(LIBSOREL)
|
||||
-@$(RM_F) $(DL)/$(OLDSO)
|
||||
cp $(LIBSOMAJ) $(DL)/$(LIBSOREL)
|
||||
chmod 755 $(DL)/$(LIBSOREL)
|
||||
(cd $(DL); \
|
||||
$(LN_SF) $(LIBSOREL) $(LIBSO); \
|
||||
$(LN_SF) $(LIBSO) $(OLDSO))
|
||||
-@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi
|
||||
-@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc
|
||||
-@$(RM_F) $(DL)/pkgconfig/libpng.pc
|
||||
cp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc
|
||||
chmod 644 $(DL)/pkgconfig/$(LIBNAME).pc
|
||||
(cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc)
|
||||
|
||||
install-man: libpng.3 libpngpf.3 png.5
|
||||
-@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi
|
||||
-@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi
|
||||
-@$(RM_F) $(DM)/man3/libpng.3
|
||||
-@$(RM_F) $(DM)/man3/libpngpf.3
|
||||
cp libpng.3 $(DM)/man3
|
||||
cp libpngpf.3 $(DM)/man3
|
||||
-@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi
|
||||
-@$(RM_F) $(DM)/man5/png.5
|
||||
cp png.5 $(DM)/man5
|
||||
|
||||
install-config: libpng-config
|
||||
-@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi
|
||||
-@$(RM_F) $(DB)/libpng-config
|
||||
-@$(RM_F) $(DB)/$(LIBNAME)-config
|
||||
cp libpng-config $(DB)/$(LIBNAME)-config
|
||||
chmod 755 $(DB)/$(LIBNAME)-config
|
||||
(cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config)
|
||||
|
||||
install: install-static install-shared install-man install-config
|
||||
|
||||
# If you installed in $(DESTDIR), test-installed won't work until you
|
||||
# move the library to its final location. Use test-dd to test it
|
||||
# before then.
|
||||
|
||||
test-dd:
|
||||
echo
|
||||
echo Testing installed dynamic shared library in $(DL).
|
||||
$(CC) -I$(DI) $(CPPFLAGS) \
|
||||
`$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \
|
||||
-L$(DL) -L$(ZLIBLIB) \
|
||||
-o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags`
|
||||
./pngtestd pngtest.png
|
||||
|
||||
test-installed:
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) \
|
||||
`$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \
|
||||
-L$(ZLIBLIB) \
|
||||
-o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags`
|
||||
./pngtesti pngtest.png
|
||||
|
||||
clean:
|
||||
$(RM_F) *.o libpng.a pngtest pngout.png libpng-config \
|
||||
$(LIBSO) $(LIBSOMAJ)* pngtest-static pngtesti \
|
||||
pnglibconf.h libpng.pc
|
||||
|
||||
DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO
|
||||
writelock:
|
||||
chmod a-w *.[ch35] $(DOCS) scripts/*
|
||||
|
||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
||||
|
||||
png.o png.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
|
||||
pngerror.o pngerror.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
|
||||
pngrio.o pngrio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
|
||||
pngwio.o pngwio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
|
||||
pngmem.o pngmem.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
|
||||
pngset.o pngset.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
|
||||
pngget.o pngget.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
|
||||
pngread.o pngread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
|
||||
pngrtran.o pngrtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
|
||||
pngrutil.o pngrutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
|
||||
pngtrans.o pngtrans.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
|
||||
pngwrite.o pngwrite.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
|
||||
pngwtran.o pngwtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
|
||||
pngwutil.o pngwutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
|
||||
pngpread.o pngpread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
|
||||
|
||||
pngtest.o: png.h pngconf.h pnglibconf.h
|
||||
1
vendor/grammars/language-csound
vendored
Submodule
1
vendor/grammars/language-csound
vendored
Submodule
Submodule vendor/grammars/language-csound added at c303b56a44
12
vendor/licenses/grammar/language-csound.txt
vendored
Normal file
12
vendor/licenses/grammar/language-csound.txt
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
---
|
||||
type: grammar
|
||||
name: language-csound
|
||||
license: mit
|
||||
---
|
||||
Copyright © 2015–2016 Nathan Whetsell
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
Reference in New Issue
Block a user