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

Nobody saw anything, Sardine was never broken #226

Merged
merged 1 commit into from
Jun 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 14 additions & 9 deletions sardine/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ def set_python_process_priority() -> Tuple[int, int, bool]:


_, _, successful_patch = set_python_process_priority()
# if successful_patch:
#  print(f"Patched process", end=" | ")
# else:
#  print("Unpatched process", end=" | ")
# if successful_patch:
# print(f"Patched process", end=" | ")
# else:
# print("Unpatched process", end=" | ")

CONTEXT_SETTINGS = {
"help_option_names": ["-h", "--help"],
Expand All @@ -53,7 +53,7 @@ def set_python_process_priority() -> Tuple[int, int, bool]:
)
@click.version_option(
package_name="sardine",
# prog_name=__package__,
# prog_name=__package__,
prog_name="sardine",
message="%(prog)s for %(package)s v%(version)s",
)
Expand Down Expand Up @@ -107,32 +107,37 @@ def web(host: str, port: int, no_browser: bool):
server.open_in_browser()
consoleManager.start()


@main.command(
short_help="Starts sardine configuration tool",
help="This command starts Sardine configuration tool."
help="This command starts Sardine configuration tool.",
)
def config():
"""Start sardine.cli:main from fishery"""
from sardine_core.cli import main

main()


@main.command(
short_help="Open SuperDirt configuration file",
help="This command opens the SuperDirt configuration file with your default editor."
help="This command opens the SuperDirt configuration file with your default editor.",
)
def config_superdirt():
"""Start sardine.cli:main from fishery"""
from sardine_core.cli.main import edit_superdirt_configuration
from sardine_core.cli.main import edit_superdirt_configuration

edit_superdirt_configuration()


@main.command(
short_help="Open Python configuration file",
help="This command opens the Python configuration file with your default editor."
help="This command opens the Python configuration file with your default editor.",
)
def config_python():
"""Start sardine.cli:main from fishery"""
from sardine_core.cli.main import edit_python_configuration

edit_python_configuration()


Expand Down
11 changes: 6 additions & 5 deletions sardine/server/flask_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
APP_NAME, APP_AUTHOR = "Sardine", "Bubobubobubo"
USER_DIR = Path(user_data_dir(APP_NAME, APP_AUTHOR))
LOG_FILE = USER_DIR / "sardine.log"
FILENAMES = [f"buffer{i}.py" for i in range(1,10)]
FILENAMES = [f"buffer{i}.py" for i in range(1, 10)]

# We need to create the log file if it doesn't already exist
Path(LOG_FILE).touch(exist_ok=True)
Expand Down Expand Up @@ -137,10 +137,11 @@ def save_files_to_disk() -> str:
for key, content in data.items():
path = USER_DIR / "buffers" / f"{key}"
with open(path, "w", encoding="utf-8") as new_file:
# This is where you are supposed to do something about
# formatting.
new_file.write("\n".join(
content) if isinstance(content, list) else content)
# This is where you are supposed to do something about
# formatting.
new_file.write(
"\n".join(content) if isinstance(content, list) else content
)
return "OK"
except Exception as e:
print(e)
Expand Down
1 change: 1 addition & 0 deletions sardine_core/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ def _select_supercollider_settings(config_file: dict) -> dict:
)
return config_file


def _select_additional_options(config_file: dict) -> dict:
"""Select additionals options used by Sardine"""
print(
Expand Down
4 changes: 2 additions & 2 deletions sardine_core/io/UserConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"deferred_scheduling": True,
"editor": False,
},
"extensions": []
"extensions": [],
}


Expand Down Expand Up @@ -105,7 +105,7 @@ def to_dict(self) -> dict:
"deferred_scheduling": self.deferred_scheduling,
"editor": self.editor,
},
"extensions": self.extensions
"extensions": self.extensions,
}


Expand Down
4 changes: 1 addition & 3 deletions sardine_core/logger/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@

file_console = Console(file=report_file)

terminal_console = Console(
color_system='truecolor' if os.name != 'nt' else 'windows'
)
terminal_console = Console(color_system="truecolor" if os.name != "nt" else "windows")


def print(*args, **kwargs):
Expand Down
9 changes: 6 additions & 3 deletions sardine_core/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@
ext_config = read_extension_configuration(ext_config_path)
sys.path.append(ext_config["root"])
for ext_handler in ext_config["handlers"]:
module = importlib.import_module(f'{ext_config["package"]}.{ext_handler["module"]}')
module = importlib.import_module(
f'{ext_config["package"]}.{ext_handler["module"]}'
)
cls = getattr(module, ext_handler["class"])
instance = cls(ext_handler["params"])
globals()[ext_handler["send_alias"]] = instance.send
Expand Down Expand Up @@ -674,18 +676,19 @@ def tidal_loop(p=0.05):
)
except Exception as e:
print(e)
# clock._notify_tidal_streams()
# clock._notify_tidal_streams()
again(tidal_loop, p=0.05)


#######################################################################################
# CLOCK START: THE SESSION IS NOW LIVE
bowl.start()


def spl_debug():
while True:
try:
user_input = input('> ')
user_input = input("> ")
if user_input == "exit":
break
message = bowl.parser._parse_debug(user_input)
Expand Down
101 changes: 59 additions & 42 deletions sardine_core/sequences/sardine_parser/funclib.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def set_amphibian_variable(self, *args):
def drunk(self, *args, **kwargs):
"""
Drunk walk: 50% chance +1, 50% chance -1.
The span argument will make it possible to
The span argument will make it possible to
jump from +/- the given span, randomly.
"""
span = kwargs.get("span", None)
Expand All @@ -308,9 +308,11 @@ def drunk(self, *args, **kwargs):
random_span = 1

args = list(chain(*args))

def drunk(number):
random_factor = random.random()
return number + random_span if random_factor > 0.5 else number - random_span

return map_unary_function(drunk, args)

def anti_speed(self, *args, **kwargs) -> list:
Expand Down Expand Up @@ -350,26 +352,31 @@ def scale(
)
)

def euclidian_to_number(self, pulses: list, steps: list, rotation: Optional[list] = [0]) -> list:
def euclidian_to_number(
self, pulses: list, steps: list, rotation: Optional[list] = [0]
) -> list:
"""Convert a 'binary' euclidian rhythm to a number based representation usable by patterns"""
rhythm = euclid(pulses[0], steps[0], rotation[0])

def convert(input_list):
input_list = int(''.join([str(i) for i in input_list]))
input_list = int("".join([str(i) for i in input_list]))

def convert_code(number):
count, result = 0, []
for digit in str(number):
if digit == '1':
if digit == "1":
if count > 0:
result.append(count)
count = 1
elif digit == '0':
elif digit == "0":
count += 1
if count > 0:
result.append(count)
return result

return convert_code(input_list)
return convert(rhythm)

return convert(rhythm)

def euclidian_rhythm(
self,
Expand Down Expand Up @@ -858,79 +865,81 @@ def absolute(
x = list(chain(*x))
return map_unary_function(abs, x)

def lsin(self, period: int|float, **kwargs) -> list:
def lsin(self, period: int | float, **kwargs) -> list:
"""Basic sinusoïdal low frequency oscillator
Args:
period (int|float): LFO period (duration in beats)
period (int|float): LFO period (duration in beats)
Returns:
list: lfo value (-1 -> 1)
"""
period = float(period[0])
return [sin(2*pi*self.clock.time/period)]
return [sin(2 * pi * self.clock.time / period)]

def ltri(self, period: int|float, **kwargs) -> list:
def ltri(self, period: int | float, **kwargs) -> list:
"""Basic triangular low frequency oscillator
Args:
period (int|float): LFO period (duration in beats)
period (int|float): LFO period (duration in beats)
Returns:
list: lfo value (-1 -> 1)
"""
period = float(period[0])
t = self.clock.time % period

def inner_func():
if t < period / 4:
return 4 * t / period
elif t > 3 * period / 4:
return 4 * t / period - 4
else:
return -4 * t / period + 2

return [inner_func()]

def lsaw(self, period: int|float, **kwargs) -> list:
def lsaw(self, period: int | float, **kwargs) -> list:
"""Basic sawtooth low frequency oscillator
Args:
period (int|float): LFO period (duration in beats)
period (int|float): LFO period (duration in beats)
Returns:
list: lfo value (-1 -> 1)
"""
period = float(period[0])
t = self.clock.time % period
return [((2 * t if t < period / 2 else (2 * t)) / 2) - 1]

def lrect(self, period: int|float, pwm: int|float=0.5, **kwargs) -> list:
def lrect(self, period: int | float, pwm: int | float = 0.5, **kwargs) -> list:
"""Basic square low frequency oscillator
Args:
period (int|float): LFO period (duration in beats)
period (int|float): LFO period (duration in beats)
Returns:
list: lfo value (-1 -> 1)
"""
period, pwm = float(period[0]), float(pwm[0]) * 100
t = self.clock.time % period
return [1 if t < (period * (pwm / 100)) else -1]

def ulsin(self, period: int|float, **kwargs) -> list:
def ulsin(self, period: int | float, **kwargs) -> list:
"""Basic unipolar sinusoïdal low frequency oscillator
Args:
period (int|float): LFO period (duration in beats)
period (int|float): LFO period (duration in beats)
Returns:
list: lfo value (0 -> 1)
"""
# period = float(period[0])
return self.absolute(*[self.lsin(period)])

def ultri(self, period: int|float, **kwargs) -> list:
def ultri(self, period: int | float, **kwargs) -> list:
"""Basic unipolar triangular low frequency oscillator
Args:
period (int|float): LFO period (duration in beats)
period (int|float): LFO period (duration in beats)
Returns:
list: lfo value (0 -> 1)
"""
return self.absolute(*[self.ltri(period=period)])

def ulsaw(self, period: int|float, **kwargs) -> list:
def ulsaw(self, period: int | float, **kwargs) -> list:
"""Basic unipolar sawtooth low frequency oscillator
Args:
period (int|float): LFO period (duration in beats)
period (int|float): LFO period (duration in beats)
Returns:
list: lfo value (0 -> 1)
"""
Expand Down Expand Up @@ -990,54 +999,62 @@ def get_scale_note(self, *args, **kwargs):
def note_computer(note) -> int:
"""Internal function to calculate the current note"""
octave, note = divmod(note, len(selected_scale) - 1)
return (12*octave) + selected_scale[note]
return map_unary_function(note_computer, x)
return 48 + (12 * octave) + selected_scale[note]

return map_unary_function(note_computer, x)

def set_scale(self, *args, **kwargs):
"""
Set the current global scale. If the name is
Set the current global scale. If the name is
unknown, will continue on the current scale.
"""
args = list(chain(*args))

def internal_scale_changer(scale_name):
new_scale = str(scale_name)
if new_scale in self.qualifiers.keys():
self.global_scale = new_scale

return map_unary_function(internal_scale_changer, args)

def binary_rhythm_generator(self, input_number: int|float, rotation: int|float = [0]):
def binary_rhythm_generator(
self, input_number: int | float, rotation: int | float = [0]
):
"""
Generate rhythms by converting an integer to binary representation.
Everything is then converted in a rhythm using the same technique
as the euclidian rhythm generator
"""
rotation = int(rotation[0])
number_as_list = [int(x) for x in list('{0:0b}'.format(int(input_number[0])))]
number_as_list = [int(x) for x in list("{0:0b}".format(int(input_number[0])))]
if rotation != 0:
number_as_list = number_as_list[-rotation:] + number_as_list[:-rotation]

def convert(input_list):
input_list = int(''.join([str(i) for i in input_list]))
def convert_code(number):
count, result = 0, []
for digit in str(number):
if digit == '1':
if count > 0:
result.append(count)
count = 1
elif digit == '0':
count += 1
if count > 0:
result.append(count)
return result
return convert_code(input_list)
input_list = int("".join([str(i) for i in input_list]))

def convert_code(number):
count, result = 0, []
for digit in str(number):
if digit == "1":
if count > 0:
result.append(count)
count = 1
elif digit == "0":
count += 1
if count > 0:
result.append(count)
return result

return convert_code(input_list)

result = convert(number_as_list)
return result

def binary_list(self, number: int|float, rotation: int|float = [0]):
def binary_list(self, number: int | float, rotation: int | float = [0]):
"""Generate a binary list with optional rotation"""
rotation = int(rotation[0])
number_as_list = [int(x) for x in list('{0:0b}'.format(int(number[0])))]
number_as_list = [int(x) for x in list("{0:0b}".format(int(number[0])))]
if rotation != 0:
number_as_list = number_as_list[-rotation:] + number_as_list[:-rotation]
return number_as_list
Loading