Skip to content

Commit

Permalink
Fixes typos
Browse files Browse the repository at this point in the history
  • Loading branch information
Raymond Oung committed Apr 16, 2021
1 parent 9e454fb commit 15d1c33
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 39 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
16 changes: 8 additions & 8 deletions dancebots/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -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"):
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions dancebots/core/bitstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions dancebots/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions dancebots/core/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions dancebots/core/move.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion dancebots/core/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion dancebots/utils/inout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
)
Expand Down
9 changes: 3 additions & 6 deletions dancebots/utils/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)):
Expand All @@ -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)
)
)
Expand Down
2 changes: 1 addition & 1 deletion examples/metronome.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
filename="metronome.wav",
sample_rate=sample_rate,
)
print("Done")
print("Done!")
2 changes: 1 addition & 1 deletion setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 15d1c33

Please sign in to comment.