Skip to content

Commit

Permalink
Globally more stable.. Needs to fix that little interruption at patte…
Browse files Browse the repository at this point in the history
…rn update!
  • Loading branch information
Bubobubobubobubo committed Jul 18, 2024
1 parent 5253fa5 commit 13afb5c
Show file tree
Hide file tree
Showing 18 changed files with 4,011 additions and 295 deletions.
8 changes: 0 additions & 8 deletions devlog.md

This file was deleted.

14 changes: 9 additions & 5 deletions src/shrimp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
)
env.add_clock(clock)
pattern = Player.initialize_patterns(clock)
for pattern in pattern.values():
# Registering the pattern to the global environment
env.subscribe(pattern)

# Opening MIDI output ports based on user configuration
for all_output_midi_ports in CONFIGURATION["midi"]["out_ports"]:
Expand Down Expand Up @@ -127,9 +130,7 @@ def exit():


clock._start()
clock.add(
func=lambda: clock.play(now=True), time=clock.next_bar - clock.now, passthrough=True, once=True
)
clock.add(func=lambda: clock.play(), time=clock.next_bar - clock.now, passthrough=True, once=True)

# == TEST AREA FOR THE PATTERN SYSTEM ======================================================

Expand Down Expand Up @@ -212,14 +213,17 @@ def kabelsalat(*args, **kwargs):


# Adding all patterns to the global scope
for key, value in pattern.items():
patterns = Player.initialize_patterns(clock)
for pattern in patterns.values():
env.subscribe(pattern)
for key, value in patterns.items():
globals()[key] = value


def silence(*args):
if len(args) == 0:
env.dispatch("main", "silence", {})
for key in pattern.keys():
for key in patterns.keys():
globals()[key].stop()
if "graph" in globals():
graph.clear()
Expand Down
9 changes: 4 additions & 5 deletions src/shrimp/io/midi.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ def _note_on(self, note: int = 60, velocity: int = 100, channel: int = 1) -> Non
"""
# Send note_off if the note is already pressed
if self.pressed_notes[channel].get(note, False):
self._note_off(note=note, channel=channel)
self._note_off(note=note, channel=channel, velocity=0)
self.pressed_notes[channel][note] = True
midi_message = mido.Message("note_on", note=note, velocity=velocity, channel=channel)
self._midi_out.send(midi_message)
self.pressed_notes[channel][note] = True # Mark note as pressed

def _note_off(self, note: int = 60, velocity: int = 0, channel: int = 1) -> None:
"""Send a MIDI note off message.
Expand All @@ -169,9 +169,9 @@ def _note_off(self, note: int = 60, velocity: int = 0, channel: int = 1) -> None
velocity (int): The velocity of the note.
channel (int): The MIDI channel.
"""
self.pressed_notes[channel][note] = False
midi_message = mido.Message("note_off", note=note, velocity=velocity, channel=channel)
self._midi_out.send(midi_message)
self.pressed_notes[channel][note] = False # Mark note as released

def note(
self,
Expand Down Expand Up @@ -204,7 +204,6 @@ def note(
self.note(note=int(n), velocity=velocity, channel=channel, length=length)
return

epsilon = length / 100
self.clock.add(
func=lambda: self._note_on(
note=int(note), velocity=int(velocity), channel=int(channel) - 1
Expand All @@ -214,7 +213,7 @@ def note(
)
self.clock.add(
func=lambda: self._note_off(note=int(note), velocity=0, channel=int(channel) - 1),
time=time + (length - epsilon),
time=(time + length) - 0.020,
once=True,
)

Expand Down
Loading

0 comments on commit 13afb5c

Please sign in to comment.