Compare commits
6 Commits
add-readme
...
add-setup
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
70c7c0963b | ||
|
|
56bd6a909a | ||
|
|
25df849c19 | ||
|
|
0965ed290e | ||
|
|
8e6194071e | ||
|
|
fe6c146521 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@ __pycache__/
|
||||
*.mus
|
||||
.idea/*
|
||||
venv/
|
||||
SMNP.egg-info
|
||||
|
||||
1
Pipfile
1
Pipfile
@@ -10,7 +10,6 @@ sounddevice = "*"
|
||||
soundfile = "*"
|
||||
numpy = "*"
|
||||
matplotlib = "*"
|
||||
tkinter = "*"
|
||||
|
||||
[requires]
|
||||
python_version = "3.7"
|
||||
|
||||
34
Pipfile.lock
generated
34
Pipfile.lock
generated
@@ -106,25 +106,25 @@
|
||||
},
|
||||
"numpy": {
|
||||
"hashes": [
|
||||
"sha256:03f2ebcbffcce2dec8860633b89a93e80c6a239d21a77ae8b241450dc21e8c35",
|
||||
"sha256:078c8025da5ab9e8657edc9c2a1e9642e06e953bc7baa2e65c1aa9d9dfb7e98b",
|
||||
"sha256:0fbfa98c5d5c3c6489cc1e852ec94395d51f35d9ebe70c6850e47f465038cdf4",
|
||||
"sha256:1c841033f4fe6801648180c3033c45b3235a8bbd09bc7249010f99ea27bb6790",
|
||||
"sha256:2c0984a01ddd0aeec89f0ce46ef21d64761048cd76c0074d0658c91f9131f154",
|
||||
"sha256:4c166dcb0fff7cb3c0bbc682dfb5061852a2547efb6222e043a7932828c08fb5",
|
||||
"sha256:8c2d98d0623bd63fb883b65256c00454d5f53127a5a7bcdaa8bdc582814e8cb4",
|
||||
"sha256:8cb4b6ae45aad6d26712a1ce0a3f2556c5e1484867f9649e03496e45d6a5eba4",
|
||||
"sha256:93050e73c446c82065b7410221b07682e475ac51887cd9368227a5d944afae80",
|
||||
"sha256:a3f6b3024f8826d8b1490e6e2a9b99e841cd2c375791b1df62991bd8f4c00b89",
|
||||
"sha256:bede70fd8699695363f39e86c1e869b2c8b74fb5ef135a67b9e1eeebff50322a",
|
||||
"sha256:c304b2221f33489cd15a915237a84cdfe9420d7e4d4828c78a0820f9d990395c",
|
||||
"sha256:f11331530f0eff69a758d62c2461cd98cdc2eae0147279d8fc86e0464eb7e8ca",
|
||||
"sha256:fa5f2a8ef1e07ba258dc07d4dd246de23ef4ab920ae0f3fa2a1cc5e90f0f1888",
|
||||
"sha256:fb6178b0488b0ce6a54bc4accbdf5225e937383586555604155d64773f6beb2b",
|
||||
"sha256:fd5e830d4dc31658d61a6452cd3e842213594d8c15578cdae6829e36ad9c0930"
|
||||
"sha256:05dbfe72684cc14b92568de1bc1f41e5f62b00f714afc9adee42f6311738091f",
|
||||
"sha256:0d82cb7271a577529d07bbb05cb58675f2deb09772175fab96dc8de025d8ac05",
|
||||
"sha256:10132aa1fef99adc85a905d82e8497a580f83739837d7cbd234649f2e9b9dc58",
|
||||
"sha256:12322df2e21f033a60c80319c25011194cd2a21294cc66fee0908aeae2c27832",
|
||||
"sha256:16f19b3aa775dddc9814e02a46b8e6ae6a54ed8cf143962b4e53f0471dbd7b16",
|
||||
"sha256:3d0b0989dd2d066db006158de7220802899a1e5c8cf622abe2d0bd158fd01c2c",
|
||||
"sha256:438a3f0e7b681642898fd7993d38e2bf140a2d1eafaf3e89bb626db7f50db355",
|
||||
"sha256:5fd214f482ab53f2cea57414c5fb3e58895b17df6e6f5bca5be6a0bb6aea23bb",
|
||||
"sha256:73615d3edc84dd7c4aeb212fa3748fb83217e00d201875a47327f55363cef2df",
|
||||
"sha256:7bd355ad7496f4ce1d235e9814ec81ee3d28308d591c067ce92e49f745ba2c2f",
|
||||
"sha256:7d077f2976b8f3de08a0dcf5d72083f4af5411e8fddacd662aae27baa2601196",
|
||||
"sha256:a4092682778dc48093e8bda8d26ee8360153e2047826f95a3f5eae09f0ae3abf",
|
||||
"sha256:b458de8624c9f6034af492372eb2fee41a8e605f03f4732f43fc099e227858b2",
|
||||
"sha256:e70fc8ff03a961f13363c2c95ef8285e0cf6a720f8271836f852cc0fa64e97c8",
|
||||
"sha256:ee8e9d7cad5fe6dde50ede0d2e978d81eafeaa6233fb0b8719f60214cf226578",
|
||||
"sha256:f4a4f6aba148858a5a5d546a99280f71f5ee6ec8182a7d195af1a914195b21a2"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==1.17.1"
|
||||
"version": "==1.17.2"
|
||||
},
|
||||
"pycparser": {
|
||||
"hashes": [
|
||||
|
||||
10
README.md
10
README.md
@@ -253,7 +253,7 @@ Note literal is written with the following syntax:
|
||||
; where
|
||||
|
||||
PITCH := (c|d|e|f|g|a) [b|#] | h# | b
|
||||
| (C|D|E|F|G|A) [B|#] | H# | B
|
||||
| (C|D|E|F|G|A) [b|#] | H# | B
|
||||
OCTAVE := 1-9
|
||||
DURATION := /non-negative integer/
|
||||
```
|
||||
@@ -277,7 +277,7 @@ Examples (note that pitch is case-insensitive):
|
||||
* `@F5:2` is half note with pitch *f''*
|
||||
* `@g#3:4d` is dotted quarter note with pitch *g♯*
|
||||
* `@Ab6:16` is sixteenth note with pitch *a♭'''*
|
||||
* `@b2:1` is whole note with pitch *B* (*H♯*)
|
||||
* `@b2:1` is whole note with pitch *B* (*H♭*)
|
||||
* `@C#1:32d` is dotted thirty-second note with pitch *C♯,*
|
||||
|
||||
**Note:** note literal syntax cannot include any whitespace character.
|
||||
@@ -2364,3 +2364,9 @@ to see what is going on at each language processing stage:
|
||||
* `--ast` - *pretty-prints* abstract syntax tree as parser's output for passed code
|
||||
* `--dry-run` - runs language-processing tools without involving evaluator
|
||||
|
||||
## Installation
|
||||
To install SMNP:
|
||||
1. Make sure you have already installed *PortAudio* in your OS (it is required by Audio Module
|
||||
to send data frames to your sound device)
|
||||
2. Clone this repository
|
||||
3. Run `pip install .`
|
||||
198
examples/bach_prelude_c.mus
Normal file
198
examples/bach_prelude_c.mus
Normal file
@@ -0,0 +1,198 @@
|
||||
println("Praeludium C Major");
|
||||
println("Acht kleine Praeludien und Fugen");
|
||||
println("Johann Sebastian Bach");
|
||||
|
||||
config = {
|
||||
overtones -> flat([0.5, 0.3, 5^0.0, 0.1, 3^0.0, 0.05, 0.0, 0.03, 0.0, 0.0, 0.01, 5^0.0, 0.005, 3^0.0, 0.002, 0.0, 0.001]),
|
||||
decay -> 2,
|
||||
attack -> 0,
|
||||
tuning -> 432
|
||||
};
|
||||
|
||||
s1 = [16, @c5:16, @h:16, @c5:16, @g:16, @c5:16, @h:16, @c5:16, @e, 4];
|
||||
s2 = [16, @c5:16, @h:16, @c5:16, @g:16, @c5:16, @h:16, @c5:16, @a:16, @f:16, @e:16, @f:16, @c:16, @f:16, @e:16, @f:16];
|
||||
s3 = [@d:16, @d5:16, @c5:16, @d5:16, @a:16, @d5:16, @c5:16, @d5:16, @h:16, @g:16, @f#:16, @g:16, @d:16, @g:16, @f#:16, @g:16];
|
||||
s4 = [@e:16, @e5:16, @d5:16, @e5:16, @h:16, @e5:16, @d5:16, @e5:16, @c5:16, @a:16, @g#:16, @a:16, @e:16, @a:16, @g#:16, @a:16];
|
||||
|
||||
s5 = flat(2 ^ [@c5, @f#, @e, @f#], 2 ^ [@h, @g, @f#, @g]) as n ^ n.withDuration(16);
|
||||
s6 = flat(2 ^ [@h, @e, @d, @e], 2 ^ [@a, @f#, @e, @f#]) as n ^ n.withDuration(16);
|
||||
s7 = flat(2 ^ [@a, @d, @c, @d], 2 ^ [@g, @e, @d, @e]) as n ^ n.withDuration(16);
|
||||
s8 = flat(2 ^ [@g, @c#, @h3, @c#], 2 ^ [@f#, @d, @c#, @d]) as n ^ n.withDuration(16);
|
||||
|
||||
s9 = [@g, @f#, @g, @d, @a, @g, @a, @d, @h, @a, @h, @d, @c5, @h, @c5, @d] as n ^ n.withDuration(16);
|
||||
s10 = [@d5:4d, @d5:8, @e5:16, @g5:16, @d5:16, @g5:16, @c5:16, @g5:16, @h:16, @g5:16];
|
||||
s11 = [@a, 8, @h:8, @c5:16, @d5:16, @h:16, @c5:16, @a:8d, @g:16];
|
||||
s12 = [@g, 4, 2];
|
||||
|
||||
S1 = s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10 + s11 + s12
|
||||
|
||||
#
|
||||
a1 = [2, 16, @c5:16, @h:16, @c5:16, @g:16, @c5:16, @h:16, @c5:16];
|
||||
a2 = [@g, 8, @c5:8, @c5, 4];
|
||||
a3 = [@a, 8, @d5:8, @d5, 4];
|
||||
a4 = [@h, 8, @e5:8, @e5, 4];
|
||||
|
||||
a5 = 8 ^ @d5:8;
|
||||
a6 = 8 ^ @c5:8;
|
||||
a7 = 8 ^ @h:8;
|
||||
a8 = 8 ^ @a:8;
|
||||
a9 = [@h, @a, @g, @a];
|
||||
a10 = [@h:16, @d5:16, @e5:16, @f#5:16, @h5:8, @g5:8, @g5:2];
|
||||
a11 = [@g5:8, @f#5:16, @e5:16, @f#5:8, @g5:8, @a5:8, @g5:8, @d5];
|
||||
a12 = [@d5, 4, 2];
|
||||
|
||||
A1 = transpose(-12, a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10 + a11 + a12);
|
||||
|
||||
#
|
||||
t1 = [1];
|
||||
t2 = [@e, 8, @g:8, @a, 4];
|
||||
t3 = [@f#, 8, @a:8, @h, 4];
|
||||
t4 = [@g#, 8, @h:8, @c5, 4];
|
||||
t5 = (4 ^ @a:8) + (4 ^ @h:8);
|
||||
t6 = (4 ^ @g:8) + (4 ^ @a:8);
|
||||
t7 = (4 ^ @f#:8) + (4 ^ @g:8);
|
||||
t8 = (4 ^ @e:8) + (4 ^ @f#:8);
|
||||
t9 = [@e, @f#, @g, @f#];
|
||||
t10 = [@g, @g5:8, @h:8, @c5:8, @h:8, @a:8, @g:8];
|
||||
t11 = [@d5, 8, @d5:8, @d5:8, @d5:8, @d5];
|
||||
t12 = [@h, 4, 2];
|
||||
|
||||
T1 = transpose(-12, t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8 + t9 + t10 + t11 + t12);
|
||||
|
||||
#
|
||||
b_ = 10 ^ 1;
|
||||
b11 = [2, 8, @g3, @f#3:8];
|
||||
b12 = [16, @g3:16, @f#3:16, @g3:16, @d3:16, @g3:16, @f#3:16, @g3:16, @g2, 4];
|
||||
|
||||
B1 = b_ + b11 + b12;
|
||||
|
||||
#
|
||||
p1 = [@c:1];
|
||||
p2 = [@c, 8, @e:8, @f, 4];
|
||||
p3 = [@f#, 8, @f#:8, @g, 4];
|
||||
p4 = [@g#, 8, @g#:8, @a, 4];
|
||||
p5 = (4 ^ @d:8) + (4 ^ @g:8);
|
||||
p6 = (4 ^ @c:8) + (4 ^ @f#:8);
|
||||
p7 = (4 ^ @h3:8) + (4 ^ @e:8);
|
||||
p8 = (4 ^ @a3:8) + (4 ^ @d:8);
|
||||
p9 = [@d:1];
|
||||
p10 = [@d, 4, 2];
|
||||
p11 = [4, 8, @g:8, @f#:8, @g:8, @d];
|
||||
p12 = [@g3, 4, 16, @g:16, @f:16, @g:16, @e:16, @g:16, @d:16, @g:16];
|
||||
|
||||
P1 = transpose(-12, p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 + p12);
|
||||
|
||||
PART1 = wave(config, S1, A1, T1, B1, P1);
|
||||
|
||||
#######
|
||||
|
||||
s1 = [16, @c5:16, @h:16, @c5:16, @g:16, @c5:16, @h:16, @c5:16, @a, 4];
|
||||
s2 = [16, @h:16, @a:16, @h:16, @f:16, @h:16, @a:16, @h:16, @g#, 4];
|
||||
s3 = flat([2 ^ [@a, @e, @d, @e], 2 ^ [@g#, @d, @c, @d]]) as n ^ n.withDuration(16);
|
||||
s4 = flat([2 ^ [@a, @e, @d, @e], 2 ^ [@h, @g#, @f#, @g#]]) as n ^ n.withDuration(16);
|
||||
|
||||
s5 = [@c5, @h, @c5, @d5, @h, @a, @h, @c5] as n ^ n.withDuration(8);
|
||||
s6 = [@a:8, @g#:8, @a:8, @h:8, @g#:8, @e:8, @c5];
|
||||
s7 = [@h:8, @a:8, @g#:8d, @a:16, @a, 4];
|
||||
s8 = [16, @e5:16, @d5:16, @e5:16, @h:16, @e5:16, @d5:16, @e5:16, @c5, 4];
|
||||
s9 = [16, @g5:16, @f5:16, @g5:16, @d5:16, @g5:16, @f5:16, @g5:16, @e5:16, @c5:16, @h:16, @c5:16, @g:16, @c5:16, @h:16, @c5:16];
|
||||
|
||||
s10 = [@e, 4, 16, @c5:16, @h:16, @c5:16, @g:16, @c5:16, @h:16, @c5:16];
|
||||
s11 = flat(2 ^ [@a:16, @f:16, @e:16, @f:16], [16, @d5:16, @c5:16, @d5:16, @a:16, @d5:16, @c5:16, @d5:16]);
|
||||
s12 = flat(2 ^ [@h:16, @g:16, @f#:16, @g:16], [16, @e5:16, @d5:16, @e5:16, @h:16, @e5:16, @d5:16, @e5:16]);
|
||||
s13 = flat(2 ^ [@c5:16, @a:16, @g#:16, @a:16], [16, @g5:16, @f5:16, @g5:16, @d5:16, @g5:16, @f5:16, @g5:16]);
|
||||
|
||||
s14 = [@e, @g, @e, @g, @f, @a, @f, @a, @d, @f, @d, @f, @e, @g, @e, @g] as n ^ n.withDuration(16).withOctave(5);
|
||||
s15 = [@c5:16, @e5:16, @c5:16, @e5:16, @d5:16, @f5:16, @d5:16, @f5:16, @h:16, @g:16, @a:16, @h:16, @c5];
|
||||
s16a = [@c5, @h, @c5, 4];
|
||||
s16b = [@c5, @h, @c5:2];
|
||||
|
||||
S2 = s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10 + s11 + s12 + s13 + s14 + s15;
|
||||
|
||||
#
|
||||
a1 = [@g, 4, @f5, 4];
|
||||
a2 = [@f, 4, @e5, 4];
|
||||
a3 = flat(2 ^ [@c, @c5, @h, @c5], 2 ^ [@e, @e5, @d5, @e5]) as n ^ n.withDuration(16);
|
||||
a4 = flat(2 ^ [@c, @c5, @h, @c5], 2 ^ [@e, @e5, @d5, @e5]) as n ^ n.withDuration(16);
|
||||
|
||||
a5 = [@a, @c5, @g#, @c5, @a, @c5, @f#, @d5, @g, @d5, @f#, @d5, @g, @d5, @e, @e5] as n ^ n.withDuration(16);
|
||||
a6 = [@f:16, @c5:16, @e:16, @c5:16, @f:16, @c5:16, @d:16, @h:16, @h, 8, @a5:8];
|
||||
a7 = [@f5, @e, @e, 4];
|
||||
a8 = (4 ^ @e5:8) + [@e5, 4];
|
||||
a9 = (4 ^ @d5:8) + [@c5, 4];
|
||||
|
||||
a10 = [16, @c5:16, @h:16, @c5:16, @g:16, @c5:16, @h:16, @c5:16, @c5, 8, @c5:8];
|
||||
a11 = (4 ^ @c5:8) + [@d, 8, @d:8];
|
||||
a12 = (4 ^ @d5:8) + [@e, 8, @e:8];
|
||||
a13 = (4 ^ @e5:8) + [@g5, 8, @g5:8];
|
||||
a14 = [@c, @e, @c, @e, @c, @f, @c, @f, @h3, @d, @h3, @d, @h3, @e, @h3, @e] as n ^ n.withDuration(16).withOctave(5);
|
||||
a15 = [@a:16, @c5:16, @a:16, @c5:16, @a:16, @d5:16, @a:16, @d5:16, @g:2];
|
||||
a16a = [@g:2, @c, 4];
|
||||
a16b = [@g:2, @g:2];
|
||||
|
||||
A2 = transpose(-12, a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10 + a11 + a12 + a13 + a14 + a15);
|
||||
|
||||
#
|
||||
t1 = [@e, 4, 16, @f:16, @e:16, @f:16, @c:16, @f:16, @e:16, @f:16];
|
||||
t2 = [@d, 4, 16, @e:16, @d:16, @e:16, @h3:16, @e:16, @d:16, @e:16];
|
||||
t3 = [1];
|
||||
t4 = [1];
|
||||
|
||||
t5 = [1];
|
||||
t6 = [2, @e, 8, @e5:8];
|
||||
t7 = [2, 16, @a:16, @g#:16, @a:16, @e:16, @a:16, @g#:16, @a:16];
|
||||
t8 = (4 ^ @h:8) + [16, @h:16, @g#:16, @a:16, @e:16, @a:16, @g#:16, @a:16];
|
||||
t9 = (4 ^ @h:8) + [@g, 4];
|
||||
|
||||
t10 = [2, @g, 8, @g:8];
|
||||
t11 = (4 ^ @a:8) + [@a, 8, @a:8];
|
||||
t12 = (4 ^ @h:8) + [@h, 8, @h:8];
|
||||
t13 = (4 ^ @c5:8) + [@d5, 8, @d5:8];
|
||||
|
||||
t14 = [1];
|
||||
t15 = [2, @d5, 16, @e5:16, @d5:16, @c5:16];
|
||||
t16a = [@g5:4d, @f:8, @g ,4];
|
||||
t16b = [@g5:4d, @f:8, @e:2];
|
||||
|
||||
T2 = transpose(-12, t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8 + t9 + t10 + t11 + t12 + t13 + t14 + t15);
|
||||
|
||||
#
|
||||
b_1 = 6 ^ 1;
|
||||
b7 = [@d5:8, @c5:8, @h, @c5, 4];
|
||||
b_2 = 8 ^ 1;
|
||||
b16a = [@d:2, @e, 4];
|
||||
b16b = [@d:2, @e:2];
|
||||
|
||||
B2 = transpose(-12, b_1 + b7 + b_2);
|
||||
|
||||
#
|
||||
p1 = [@c, 4, @f, 4];
|
||||
p2 = [@h3, 4, @e, 4];
|
||||
p3 = [@c, 4, @h3, 4];
|
||||
p4 = [@c, 4, @e, 4];
|
||||
|
||||
p5 = [@a, 4, 2];
|
||||
p6 = [2, 4, 8, @a:8];
|
||||
p7 = [@d, @e, @a3, 4];
|
||||
p8 = (4 ^ @g#3:8) + [@a3, 4];
|
||||
p9 = (4 ^ @h3:8) + [@c, 4];
|
||||
|
||||
p10 = [2, @c, 8, @e:8];
|
||||
p11 = (4 ^ @f:8) + [@f#, 8, @f#:8];
|
||||
p12 = (4 ^ @g:8) + [@g#, 8, @g#:8];
|
||||
p13 = (4 ^ @a:8) + [@h, 8, @h:8];
|
||||
|
||||
p14 = [@c5, @a, @h, @g];
|
||||
p15 = [@a, @f, @g:2];
|
||||
p16a = [@g:2, 16, @c5:16, @h:16, @c5:16, @g:16, @c5:16, @e:16, @g:16];
|
||||
p16b = [@g:2, @c:2];
|
||||
|
||||
P2 = transpose(-12, p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 + p12 + p13 + p14 + p15);
|
||||
|
||||
PART2 = wave(config, S2, A2, T2, B2, P2);
|
||||
PART2a = PART2 + wave(config, s16a, a16a, t16a, b16a, p16a);
|
||||
PART2b = PART2 + wave(config, s16b, a16b, t16b, b16b, p16b);
|
||||
|
||||
MUSIC = PART1 + PART1 + PART2a + PART2b;
|
||||
|
||||
synth(MUSIC);
|
||||
45
examples/bubble_sort.mus
Normal file
45
examples/bubble_sort.mus
Normal file
@@ -0,0 +1,45 @@
|
||||
extend list as array {
|
||||
function withoutIndex(integer index) {
|
||||
return array as (i, element) ^ element % i != index;
|
||||
}
|
||||
|
||||
function push(integer index, value) {
|
||||
return (index as i ^ array.get(i)) + [value] + ((array.size-index) as i ^ array.get(i+index));
|
||||
}
|
||||
|
||||
function replace(integer index, value) {
|
||||
return array
|
||||
.withoutIndex(index)
|
||||
.push(index, value);
|
||||
}
|
||||
|
||||
function swap(integer a, integer b) {
|
||||
A = array.get(a);
|
||||
B = array.get(b);
|
||||
return array
|
||||
.replace(a, B)
|
||||
.replace(b, A);
|
||||
}
|
||||
}
|
||||
|
||||
function bubbleSort(list<integer, float> numbers) {
|
||||
sorted = numbers;
|
||||
-(numbers.size as n ^ n) as i ^ {
|
||||
i as j ^ {
|
||||
if (sorted.get(j) > sorted.get(j+1)) {
|
||||
sorted = sorted.swap(j, j+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sorted;
|
||||
}
|
||||
|
||||
min = 0;
|
||||
max = 100;
|
||||
size = 30;
|
||||
|
||||
randList = size ^ rand(min, max);
|
||||
|
||||
println(randList);
|
||||
println(bubbleSort(randList));
|
||||
36
setup.py
Normal file
36
setup.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import os
|
||||
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
|
||||
def file(file):
|
||||
return open(os.path.join(os.path.dirname(__file__), file)).read()
|
||||
|
||||
setup(
|
||||
name='SMNP',
|
||||
version=file('smnp/meta/__version__.txt'),
|
||||
packages=find_packages(),
|
||||
description=file('smnp/meta/__description__.txt'),
|
||||
author='Bartlomiej P. Pluta',
|
||||
url='https://gitlab.com/bartlomiej.pluta/smnp',
|
||||
install_requires=[
|
||||
"cffi>=1.12.3",
|
||||
"cycler>=0.10.0",
|
||||
"kiwisolver>=1.1.0",
|
||||
"matplotlib>=3.1.1",
|
||||
"numpy>=1.17.2",
|
||||
"pycparser>=2.19",
|
||||
"pyparsing>=2.4.2",
|
||||
"python-dateutil>=2.8.0",
|
||||
"six>=1.12.0",
|
||||
"sounddevice>=0.3.13",
|
||||
"soundfile>=0.10.2"
|
||||
],
|
||||
entry_points={
|
||||
'console_scripts': ['smnp=smnp.main:main']
|
||||
},
|
||||
package_data={
|
||||
'smnp.library.code': ['main.mus'],
|
||||
'smnp.meta': ['__version__.txt', '__description__.txt']
|
||||
}
|
||||
)
|
||||
66
smnp/calc.py
66
smnp/calc.py
@@ -1,66 +0,0 @@
|
||||
from smnp.ast.node.model import Node
|
||||
from smnp.ast.parser import Parser
|
||||
from smnp.token.tokenizer import tokenize
|
||||
from smnp.token.type import TokenType
|
||||
|
||||
|
||||
class Atom(Node):
|
||||
def __init__(self, value, pos):
|
||||
super().__init__(pos)
|
||||
self.children = [value]
|
||||
|
||||
@property
|
||||
def value(self):
|
||||
return self[0]
|
||||
|
||||
class Operation(Node):
|
||||
def __init__(self, left, op, right, pos):
|
||||
super().__init__(pos)
|
||||
self.children = [left, op, right]
|
||||
|
||||
@property
|
||||
def left(self):
|
||||
return self[0]
|
||||
|
||||
@property
|
||||
def operator(self):
|
||||
return self[1]
|
||||
|
||||
@property
|
||||
def right(self):
|
||||
return self[2]
|
||||
|
||||
def atom():
|
||||
return Parser.oneOfTerminals(TokenType.INTEGER, TokenType.NOTE, TokenType.STRING, createNode=lambda val, pos: Atom(val, pos))
|
||||
|
||||
def chain():
|
||||
return Parser.leftAssociativeOperatorParser(atom(), [TokenType.DOT], atom(), lambda left, op, right: Operation(left, op, right, op.pos), name="chain")
|
||||
|
||||
def factor():
|
||||
return Parser.leftAssociativeOperatorParser(chain(), [TokenType.DOUBLE_ASTERISK], chain(), lambda left, op, right: Operation(left, op, right, op.pos), name="factor")
|
||||
|
||||
def term():
|
||||
return Parser.leftAssociativeOperatorParser(factor(), [TokenType.ASTERISK, TokenType.SLASH], factor(), lambda left, op, right: Operation(left, op, right, op.pos), name="term")
|
||||
|
||||
def expr():
|
||||
return Parser.leftAssociativeOperatorParser(term(), [TokenType.PLUS, TokenType.MINUS], term(), lambda left, op, right: Operation(left, op, right, op.pos), name="expr")
|
||||
#
|
||||
def evaluate(node):
|
||||
if type(node) == Atom:
|
||||
return node.value
|
||||
lhs = evaluate(node.left)
|
||||
rhs = evaluate(node.right)
|
||||
return {
|
||||
"+": int(lhs) + int(rhs),
|
||||
"*": int(lhs) * int(rhs),
|
||||
"-": int(lhs) - int(rhs),
|
||||
"/": int(lhs) / int(rhs),
|
||||
"**": int(lhs) ** int(rhs)
|
||||
}[node.operator.value]
|
||||
|
||||
def draft():
|
||||
|
||||
tokens = tokenize(['"fesf fe" + "fsefsef" + "fsefs"'])
|
||||
e = expr()
|
||||
node = e(tokens).node
|
||||
node.print()
|
||||
@@ -1,13 +1,16 @@
|
||||
import argparse
|
||||
|
||||
VERSION = "0.1"
|
||||
DESCRIPTION = """
|
||||
Simple Music Notation Processor is a command line tool enabling you to do some music stuff using custom domain-specific language.
|
||||
"""
|
||||
from pkg_resources import resource_string
|
||||
|
||||
|
||||
def file(file):
|
||||
return resource_string('smnp.meta', file).decode("utf-8")
|
||||
|
||||
|
||||
|
||||
class CliParser(object):
|
||||
def __init__(self):
|
||||
self.parser = argparse.ArgumentParser(description=DESCRIPTION)
|
||||
self.parser = argparse.ArgumentParser(description=file("__description__.txt"))
|
||||
self.parser.add_argument('file', nargs='*', help='a file containing SMNP code')
|
||||
self.parser.add_argument('-c', '--code', action='append', default=[], type=str, help='a string with SMNP code')
|
||||
self.parser.add_argument('-m', '--mic', action='store_true', help='test microphone level')
|
||||
@@ -17,7 +20,7 @@ class CliParser(object):
|
||||
self.parser.add_argument('--tokens', action='store_true', help='print tokens of parsed code')
|
||||
self.parser.add_argument('--ast', action='store_true', help='print abstract syntax tree of parsed code')
|
||||
self.parser.add_argument('--dry-run', action='store_true', help='don\'t execute passed code')
|
||||
self.parser.version = VERSION
|
||||
self.parser.version = file("__version__.txt")
|
||||
|
||||
def parse(self):
|
||||
return self.parser.parse_args()
|
||||
1
smnp/meta/__description__.txt
Normal file
1
smnp/meta/__description__.txt
Normal file
@@ -0,0 +1 @@
|
||||
Simple Music Notation Processor is a command line tool enabling you to do some music stuff using custom domain-specific language.
|
||||
0
smnp/meta/__init__.py
Normal file
0
smnp/meta/__init__.py
Normal file
1
smnp/meta/__version__.txt
Normal file
1
smnp/meta/__version__.txt
Normal file
@@ -0,0 +1 @@
|
||||
0.1
|
||||
Reference in New Issue
Block a user