Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merging dev branch with new features #225

Merged
merged 22 commits into from
Jun 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b169547
Fixing a few inconsistencies with SPL
Bubobubobubobubo Jun 8, 2023
3956c7d
Limiting octave up and octave down operators
Bubobubobubobubo Jun 8, 2023
f144396
Adding internal variables to the Sardine Pattern Language
Bubobubobubobubo Jun 8, 2023
3fde803
Inverting . and _
Bubobubobubobubo Jun 8, 2023
647001e
Moving content in the documentation
Bubobubobubobubo Jun 8, 2023
c73dbcb
Global Scale + Scale Function
Bubobubobubobubo Jun 9, 2023
db72276
Without bugfixes
Bubobubobubobubo Jun 9, 2023
415ad2c
Scale patterning ?
Bubobubobubobubo Jun 9, 2023
f4dff06
Adding real euclidian rhythms
Bubobubobubobubo Jun 9, 2023
f4d9b88
Fixing composition bug with ultri, ulsaw and ulrect
Bubobubobubobubo Jun 10, 2023
03dfc4b
Adding a binary shift rhythm generator
Bubobubobubobubo Jun 11, 2023
baf3f9e
fix bug with unit conversion on the br algorithm
Bubobubobubobubo Jun 11, 2023
041851f
Adding the variant bl function
Bubobubobubobubo Jun 11, 2023
58fd86f
Remove "Editor" option in Sardine Config (unused)
Bubobubobubobubo Jun 11, 2023
d0d9984
Add some conditionals for color display and more
Bubobubobubobubo Jun 11, 2023
d8be7db
Refactor documentation
Bubobubobubobubo Jun 11, 2023
0fb459c
Reworking Function Library Section
Bubobubobubobubo Jun 11, 2023
3d84e07
Fixing some forgotten things with Math Functions
Bubobubobubobubo Jun 11, 2023
321d33e
The gigantic cleanup continues
Bubobubobubobubo Jun 11, 2023
88a9e81
Documentation falling from the sky
Bubobubobubobubo Jun 11, 2023
1405a13
Trying to do something with combinatorics functions
Bubobubobubobubo Jun 11, 2023
49742e1
fix rogue space
Bubobubobubobubo Jun 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fixing a few inconsistencies with SPL
- Silence is now '_'
- Repairing ' and . to their previous function
  • Loading branch information
Bubobubobubobubo committed Jun 8, 2023
commit b169547add01d96bb2a2d7996c3133bfbf011e09
41 changes: 41 additions & 0 deletions sardine_core/sequences/sardine_parser/funclib.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from math import cos, sin, tan, asin, pi, atan
from random import shuffle
from typing import Optional, Union
from time import time
import datetime

from ..sequence import euclid
from .chord import Chord
Expand Down Expand Up @@ -963,3 +965,42 @@ def lrect(self, period: int|float, pwm: int|float=0.5, **kwargs) -> list:
period, pwm = float(period[0]), float(pwm[0]) * 100
t = self.clock.time % period
return [1 if t < (period * (pwm / 100)) else -1]


def get_time(self, *args, **kwargs):
"""Return a specific time unit"""
if len(args) >= 1:
data = str(args[0][0])
else:
data = None

print(data)

if not data:
return [self.clock.time]
elif data == "year":
return [int(datetime.datetime.now().year)]
elif data == "month":
return [int(datetime.datetime.now().month)]
elif data == "day":
return [int(datetime.datetime.now().day)]
elif data == "hour":
return [int(datetime.datetime.now().hour)]
elif data == "minute":
return [int(datetime.datetime.now().minute)]
elif data == "second":
return [int(datetime.datetime.now().second)]
elif data == "micro":
return [int(datetime.datetime.now().microsecond)]

def get_bar(self, *args, **kwargs):
"""Return current measure (bar) as integer"""
return [self.clock.bar]

def get_phase(self, *args, **kwargs):
"""Return current phase (phase) as integer"""
return [self.clock.phase]

def get_unix_time(self, *args, **kwargs):
"""Return current unix time as integer"""
return [int(time())]
58 changes: 22 additions & 36 deletions sardine_core/sequences/sardine_parser/sardine.lark
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ pattern: sum sum* -> return_pattern
| product "%" sum -> modulo

?product: atom
| product "==" atom -> is_equal
| product ">" atom -> is_greater
| product ">=" atom -> is_greater_or_equal
| product "<" atom -> is_smaller
| product ">=" atom -> is_greater_or_equal
| product "==" atom -> is_equal
| product "<=" atom -> is_smaller_or_equal
| product "*" atom -> multiplication
| product "/" atom -> division
Expand All @@ -27,33 +27,21 @@ pattern: sum sum* -> return_pattern
| product "^" atom -> chord_reverse
| product "&" atom -> get_slice

?atom: NUMBER -> number

?atom: NUMBER -> number
| function
| col
| patname
| "-" atom -> negation
| "$" -> get_time
| "$" "." "m" -> get_measure
| "$" "." "p" -> get_phase
| "rand" -> get_random_number
| "T" "." "U" -> get_unix_time
| "T" "." "Y" -> get_year
| "T" "." "M" -> get_month
| "T" "." "D" -> get_day
| "T" "." "h" -> get_hour
| "T" "." "m" -> get_minute
| "T" "." "s" -> get_second
| "T" "." "µ" -> get_microsecond // Unicode character U+00B5
| "T" "." "μ" -> get_microsecond // Unicode character U+03BC
| "[" sum ":" sum "]" -> generate_ramp
| "[" sum ":" sum "," sum "]" -> generate_ramp_with_range
| "[" sum sum* "]" -> make_list
| "[:" sum sum* ":]" -> make_list_repeat
| "{" sum sum* "}" -> make_chord
| SILENCE+ -> silence
| "-" atom -> negation
| "rand" -> get_random_number
| "[" sum ":" sum "]" -> generate_ramp
| "[" sum ":" sum "," sum "]" -> generate_ramp_with_range
| "[" sum sum* "]" -> make_list
| "[:" sum sum* ":]" -> make_list_repeat
| "{" sum sum* "}" -> make_chord
| SILENCE+ -> silence
| "(" sum ")"


///////////////////////////////////////////////////////////////////////////////

// Rules functions ////////////////////////////////////////////////////////////
Expand All @@ -66,15 +54,15 @@ pattern: sum sum* -> return_pattern
?patname: name_sum

?name_sum: name_product
| name_sum "!" sum -> extend
| name_sum "!!" sum -> extend_repeat
| name_sum "/" name_product -> specify_address
| name_sum ":" sum -> assoc_sp_number
| name_sum "!" sum -> extend
| name_sum "!!" sum -> extend_repeat
| name_sum "/" name_product -> specify_address
| name_sum ":" sum -> assoc_sp_number

?name_product: name_atom
| name_product "|" name_atom -> choice
| name_product "|" name_atom -> choice

?name_atom: NAME -> name
?name_atom: NAME -> name
| "(" name_sum ")"
| "[" name_sum name_sum* "]" -> make_list

Expand All @@ -101,10 +89,8 @@ pattern: sum sum* -> return_pattern

?note2: note1
| note1 NUMBER -> note_set_octave

// ?note3: note2
// | note3 "'" -> note_octave_up
// | note3 "." -> note_octave_down
| (note1|note2) "'" -> note_octave_up
| (note1|note2) "." -> note_octave_down

?note: note2 -> finish_note

Expand All @@ -114,11 +100,11 @@ pattern: sum sum* -> return_pattern

// Notes start with an uppercase letter, other names start with a lower case letter.
// This helps disambiguating the syntax.
NOTE: "A"|"La"|"B"|"Si"|"Ti"|"D"|"Re"|"Ré"|"C"|"Do"|"E"|"Mi"|"F"|"Fa"|"G"|"Sol"
NOTE: "A"|"La"|"B"|"Si"|"D"|"Re"|"Ré"|"C"|"Do"|"E"|"Mi"|"F"|"Fa"|"G"|"Sol"
| "Cb"|"Db"|"Eb"|"Fb"|"Gb"|"Ab"|"Bb"
NAME: LCASE_LETTER (LETTER|DIGIT+)*

SILENCE: "."
SILENCE: "_"

SPACE: /[\s\t\f\r\n]/
%ignore SPACE
Expand Down
72 changes: 22 additions & 50 deletions sardine_core/sequences/sardine_parser/tree_calc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import datetime
import random
from itertools import count, takewhile, chain
import random
from time import time

from lark import Transformer, v_args
Expand Down Expand Up @@ -45,6 +44,14 @@ def silence(self, *args):
"""
return [None] * len(args)

def numbered_silence(self, duration):
"""
Variant of a silence with a numeric value indicating silence length
"""
print(duration)
return [None] * duration


# ---------------------------------------------------------------------- #
# Notes: methods used by the note-specific parser
# ---------------------------------------------------------------------- #
Expand Down Expand Up @@ -197,50 +204,6 @@ def make_list_repeat(self, *args):
"""
return sum(args, start=[]) * 2

def get_time(self):
"""Return current clock time (tick) as integer"""
return [self.clock.time]

def get_year(self):
"""Return current clock time (tick) as integer"""
return [int(datetime.datetime.now().year)]

def get_month(self):
"""Return current clock time (tick) as integer"""
return [int(datetime.datetime.now().month)]

def get_day(self):
"""Return current clock time (tick) as integer"""
return [int(datetime.datetime.now().day)]

def get_hour(self):
"""Return current clock time (tick) as integer"""
return [int(datetime.datetime.now().hour)]

def get_minute(self):
"""Return current clock time (tick) as integer"""
return [int(datetime.datetime.now().minute)]

def get_second(self):
"""Return current clock time (tick) as integer"""
return [int(datetime.datetime.now().second)]

def get_microsecond(self):
"""Return current clock time (tick) as integer"""
return [int(datetime.datetime.now().microsecond)]

def get_measure(self):
"""Return current measure (bar) as integer"""
return [self.clock.bar]

def get_phase(self):
"""Return current phase (phase) as integer"""
return [self.clock.phase]

def get_unix_time(self):
"""Return current unix time as integer"""
return [int(time())]

def get_random_number(self):
"""Return a random number (alias used by parser)

Expand Down Expand Up @@ -489,8 +452,8 @@ def function_call(self, func_name, *args):
"aspeed": self.library.anti_speed,
# Boolean mask operations
"euclid": self.library.euclidian_rhythm,
"eu": self.library.euclidian_rhythm,
"negative_euclid": self.library.negative_euclidian_rhythm,
"eu": self.library.euclidian_rhythm,
"neu": self.library.negative_euclidian_rhythm,
"mask": self.library.mask,
"vanish": self.library.remove_x,
Expand Down Expand Up @@ -528,9 +491,18 @@ def function_call(self, func_name, *args):
"ltri": self.library.ltri,
"lsaw": self.library.lsaw,
"lrect": self.library.lrect,
"alsin": self.library.alsin,
"altri": self.library.altri,
"alsaw": self.library.alsaw,
"ulsin": self.library.alsin,
"ultri": self.library.altri,
"ulsaw": self.library.alsaw,
# Time information
"time": self.library.get_time,
"t": self.library.get_time,
"bar": self.library.get_bar,
"b": self.library.get_bar,
"phase": self.library.get_phase,
"p": self.library.get_phase,
"unix": self.library.get_unix_time,
"u": self.library.get_unix_time,
}
try:
if kwarguments.get("cond", [1]) >= [1] or not "cond" in kwarguments.keys():
Expand Down