From 15d1c3385010990815601cdcb1df365e970fd4ba Mon Sep 17 00:00:00 2001 From: Raymond Oung Date: Fri, 16 Apr 2021 23:08:31 +0900 Subject: [PATCH] Fixes typos --- README.md | 5 +++-- dancebots/__init__.py | 16 ++++++++-------- dancebots/core/bitstream.py | 10 +++++----- dancebots/core/frame.py | 12 ++++++------ dancebots/core/light.py | 10 +++++----- dancebots/core/move.py | 6 +++--- dancebots/core/step.py | 2 +- dancebots/utils/inout.py | 2 +- dancebots/utils/plot.py | 9 +++------ examples/metronome.py | 2 +- setup.sh | 2 +- 11 files changed, 37 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index d1d0bb6..6981db7 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) # Dancebots Python -A Python 3 package for [Dancebots](https://www.dancebots.ch/) πŸ€–. +A Python 3 package for [Dancebots](https://www.dancebots.ch/) πŸ•ΊπŸ’ƒπŸ€–.πŸŽ‰βœ¨ ## Installation @@ -24,10 +24,11 @@ git clone https://github.com/r-oung/dancebots-python.git pip install -e dancebots-python/ ``` + ### Dependencies The package uses [librosa](https://github.com/librosa/librosa) for reading MP3 files and beat detection, which means: - If you don't plan to synchronize your compositions with music, then there shouldn't be any problem. -- If you are going to synchronize your compomsition with music, then you'll need to install [ffmpeg](https://www.ffmpeg.org/) or [gstreamer](https://gstreamer.freedesktop.org/). Refer to [this link](https://github.com/librosa/librosa#hints-for-the-installation) for installation hints. +- If you're going to synchronize your composition with music, then you'll need to install [ffmpeg](https://www.ffmpeg.org/) or [gstreamer](https://gstreamer.freedesktop.org/). Refer to [this link](https://github.com/librosa/librosa#hints-for-the-installation) for installation hints. ## Example diff --git a/dancebots/__init__.py b/dancebots/__init__.py index 1497642..2589172 100644 --- a/dancebots/__init__.py +++ b/dancebots/__init__.py @@ -37,7 +37,7 @@ def load(filename): audio, sample_rate = utils.load(filename) # Extract beats - print("Extracting beats...(be patient)") + print("Extracting beats...(be patient ⏳)") bpm, beat_times = utils.get_beats(audio, sample_rate) print("Estimated tempo: {:.2f} BPM ({:.2f} Hz)".format(bpm, bpm / 60)) @@ -59,7 +59,7 @@ def add(obj): elif isinstance(obj, Light): lights.append(obj) else: - raise ValueError("Invalid argument") + raise ValueError("πŸ‘Ž Invalid argument") def save(filename="output.wav", audio_channel="left"): @@ -73,7 +73,7 @@ def save(filename="output.wav", audio_channel="left"): global channel_l, channel_r global beat_times - print("Composing choreography") + print("Creating composition... πŸ•ΊπŸ’ƒ") composition = core.Compose(moves, lights) bitstream = utils.convert.steps_to_bitstream( composition.steps, beat_times, sample_rate @@ -88,7 +88,7 @@ def save(filename="output.wav", audio_channel="left"): channel_l = bitstream channel_r = [0] * len(bitstream) else: - raise ValueError("Invalid audio channel") + raise ValueError("πŸ‘Ž Invalid audio channel") else: # Audio data exists # Make composition-bitstream the same length as the audio channel @@ -107,16 +107,16 @@ def save(filename="output.wav", audio_channel="left"): channel_l = bitstream channel_r = audio[1] else: - raise ValueError("Invalid audio channel") + raise ValueError("πŸ‘Ž Invalid audio channel") - print("Building audio file...") + print("Building audio file... 🎢") utils.create_wav( channel_l=channel_l, channel_r=channel_r, filename=filename, sample_rate=sample_rate, ) - print("Done") + print("Done! πŸŽ‰βœ¨") return { "channel_l": channel_l, @@ -130,7 +130,7 @@ def plot(): global beat_times if len(channel_l) == 0 or len(channel_r) == 0: - raise ValueError("You must first load and/or save an audio file") + raise ValueError("πŸ‘Ž You must first load and/or save an audio file") if beat_times is None: utils.plot(channel_l=channel_l, channel_r=channel_r, sample_rate=sample_rate) diff --git a/dancebots/core/bitstream.py b/dancebots/core/bitstream.py index 8817b01..502f1a3 100644 --- a/dancebots/core/bitstream.py +++ b/dancebots/core/bitstream.py @@ -22,14 +22,14 @@ def __init__(self, frames=None, sample_rate=44100): if frames is not None: for frame in frames: if not isinstance(frame, Frame): - raise TypeError("Must be of type Frame") + raise TypeError("πŸ‘Ž Must be of type Frame") self._frames = frames else: self._frames = [] if sample_rate <= 0 or not isinstance(sample_rate, int): - raise ValueError("Sample rate must be a positive integer") + raise ValueError("πŸ‘Ž Sample rate must be a positive integer") self._sample_rate = sample_rate self._last_value = 1 @@ -54,14 +54,14 @@ def _convert_frames_to_bits(self, frames): elif bit == 1: self._append(self._ONE) else: - raise ValueError("Frame must contain binary values, i.e. 0 or 1") + raise ValueError("πŸ‘Ž Frame must contain binary values, i.e. 0 or 1") def __len__(self): return len(self._bits) def __add__(self, other): if self._sample_rate != other.sample_rate: - raise ValueError("Sampling rates are different") + raise ValueError("πŸ‘Ž Sampling rates are different") new_frames = self._frames.copy() new_frames = new_frames + other.frames @@ -75,7 +75,7 @@ def __radd__(self, other): def __iadd__(self, other): if self._sample_rate != other.sample_rate: - raise ValueError("Sampling rates are different") + raise ValueError("πŸ‘Ž Sampling rates are different") self._frames += other.frames self._convert_frames_to_bits(other.frames) diff --git a/dancebots/core/frame.py b/dancebots/core/frame.py index 2043228..1bdc2e0 100644 --- a/dancebots/core/frame.py +++ b/dancebots/core/frame.py @@ -15,25 +15,25 @@ class Frame: def __init__(self, motor_l, motor_r, leds): if len(motor_l) != 8: - raise ValueError("Left motor must contain 8 values") + raise ValueError("πŸ‘Ž Left motor must contain 8 values") if len(motor_r) != 8: - raise ValueError("Right motor must contain 8 values") + raise ValueError("πŸ‘Ž Right motor must contain 8 values") if len(leds) != 8: - raise ValueError("LEDs must contain 8 values") + raise ValueError("πŸ‘Ž LEDs must contain 8 values") for bit in motor_l: if bit not in (0, 1): - raise ValueError("motor_l must be either 0 or 1") + raise ValueError("πŸ‘Ž motor_l must be either 0 or 1") for bit in motor_r: if bit not in (0, 1): - raise ValueError("motor_r must be either 0 or 1") + raise ValueError("πŸ‘Ž motor_r must be either 0 or 1") for bit in leds: if bit not in (0, 1): - raise ValueError("leds must be either 0 or 1") + raise ValueError("πŸ‘Ž leds must be either 0 or 1") self._motor_l = motor_l self._motor_r = motor_r diff --git a/dancebots/core/light.py b/dancebots/core/light.py index dbfafee..58d2a09 100644 --- a/dancebots/core/light.py +++ b/dancebots/core/light.py @@ -18,14 +18,14 @@ def __init__(self): def _append_step(self, num_units, leds): if num_units < 0: - raise ValueError("num_units must be a positive value") + raise ValueError("πŸ‘Ž num_units must be a positive value") if len(leds) != 8: - raise ValueError("led list must contain 8 values") + raise ValueError("πŸ‘Ž led list must contain 8 values") for led in leds: if led not in (0, 1): - raise ValueError("led value must be either 0 or 1") + raise ValueError("πŸ‘Ž led value must be either 0 or 1") self._steps.append(Step([0] * 8, [0] * 8, leds, num_units)) @@ -37,10 +37,10 @@ def blink(self, leds, num_units, freq=1): freq: Blink/toggling frequency (per unit) """ if num_units < 1 or not isinstance(num_units, int): - raise ValueError("num_units must be a positive integer") + raise ValueError("πŸ‘Ž num_units must be a positive integer") if freq < 1 or not isinstance(freq, int): - raise ValueError("freq must be a positive integer") + raise ValueError("πŸ‘Ž freq must be a positive integer") num_steps = num_units * freq for _ in range(num_steps): diff --git a/dancebots/core/move.py b/dancebots/core/move.py index 936c900..921f87e 100644 --- a/dancebots/core/move.py +++ b/dancebots/core/move.py @@ -23,17 +23,17 @@ def __init__(self): def _append_step(self, num_units, motor_l, motor_r): if num_units < 1 or not isinstance(num_units, int): - raise ValueError("num_units must be a positive integer") + raise ValueError("πŸ‘Ž num_units must be a positive integer") self._steps.append(Step(motor_l, motor_r, [0] * 8, num_units)) def _motor(self, speed, direction): """Convert speed and direction to binary list""" if speed > self._SPEED_MAX or speed < self._SPEED_MIN: - raise ValueError("Speed must be a value between 0 and 100") + raise ValueError("πŸ‘Ž Speed must be a value between 0 and 100") if direction not in (self._FORWARD, self._BACKWARD): - raise ValueError("Direction must be either 0 or 1") + raise ValueError("πŸ‘Ž Direction must be either 0 or 1") # Convert decimal to binary list, with LSB first binary_list = [0] * 8 diff --git a/dancebots/core/step.py b/dancebots/core/step.py index 35a4880..9a0cdd1 100644 --- a/dancebots/core/step.py +++ b/dancebots/core/step.py @@ -22,7 +22,7 @@ def __init__(self, motor_l, motor_r, leds, num_units=1): self._num_units = num_units # number of units if num_units < 0: - raise ValueError("num_units must be a positive value") + raise ValueError("πŸ‘Ž num_units must be a positive value") @property def motor_l(self): diff --git a/dancebots/utils/inout.py b/dancebots/utils/inout.py index d79efa7..02966c7 100644 --- a/dancebots/utils/inout.py +++ b/dancebots/utils/inout.py @@ -37,7 +37,7 @@ def create_wav(channel_l, channel_r, filename="output.wav", sample_rate=44100): """ if len(channel_l) != len(channel_r): raise ValueError( - "Left and right channel lists must be of equal length: ({}, {})".format( + "πŸ‘Ž Left and right channel lists must be of equal length: ({}, {})".format( len(channel_l), len(channel_r) ) ) diff --git a/dancebots/utils/plot.py b/dancebots/utils/plot.py index a60da8a..848d8cf 100644 --- a/dancebots/utils/plot.py +++ b/dancebots/utils/plot.py @@ -17,22 +17,19 @@ def plot1ch(data, sample_rate=44100, xlim=None): """ bits = [] if isinstance(data, Frame): - print("Printing Frames") bits = Bitstream([data], sample_rate).bits elif isinstance(data, Bitstream): - print("Printing Bitstream") bits = data.bits sample_rate = data.sample_rate elif isinstance(data, list): if isinstance(data[0], Frame): bits = Bitstream(data, sample_rate).bits elif isinstance(data[0], int): - print("Printing List") bits = data else: - raise ValueError("Unsupported data type") + raise ValueError("πŸ‘Ž Unsupported data type") else: - raise ValueError("Unsupported data type") + raise ValueError("πŸ‘Ž Unsupported data type") time = [] for sample in range(len(bits)): @@ -58,7 +55,7 @@ def plot2ch(channel_l, channel_r=None, beat_times=None, sample_rate=44100, xlim= """ if len(channel_l) != len(channel_r): raise ValueError( - "Left and right channel lists must be of equal length: ({}, {})".format( + "πŸ‘Ž Left and right channel lists must be of equal length: ({}, {})".format( len(channel_l), len(channel_r) ) ) diff --git a/examples/metronome.py b/examples/metronome.py index d0214d6..6a32b22 100644 --- a/examples/metronome.py +++ b/examples/metronome.py @@ -25,4 +25,4 @@ filename="metronome.wav", sample_rate=sample_rate, ) -print("Done") +print("Done!") diff --git a/setup.sh b/setup.sh index d8f2d4a..05f81e3 100755 --- a/setup.sh +++ b/setup.sh @@ -15,7 +15,7 @@ if [ ! -d "${VENV_PATH}" ]; then if [ ! -f "${PYTHON}" ]; then echo "Could not find Python" fi - virtualenv -p "${PYTHON}" "${VENV_PATH}" + python3 -m venv venv/ fi # Activate the virtual environment