aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Cholewiński <harry666t@gmail.com>2016-10-17 11:36:10 +0200
committerKamil Cholewiński <harry666t@gmail.com>2016-10-17 11:36:10 +0200
commit9b69e0ec2dcfe37a5d83b74afc2995085f7e3718 (patch)
treefbe96cf71d6aad5b1cea15170e7caf933078a8c8
downloadeighth-9b69e0ec2dcfe37a5d83b74afc2995085f7e3718.zip
eighth-9b69e0ec2dcfe37a5d83b74afc2995085f7e3718.tar.gz
eighth-9b69e0ec2dcfe37a5d83b74afc2995085f7e3718.tar.bz2
hello
-rw-r--r--.gitignore1
-rw-r--r--player.py41
-rw-r--r--readme.md32
3 files changed, 74 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0d20b64
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+*.pyc
diff --git a/player.py b/player.py
new file mode 100644
index 0000000..5749e81
--- /dev/null
+++ b/player.py
@@ -0,0 +1,41 @@
+#!/usr/bin/env python3
+import os
+import sys
+import logging
+import time
+
+
+def start_audio():
+ return os.open(b"/dev/audio", os.O_WRONLY)
+
+
+if sys.version_info < (3, 0):
+ six_reload = reload
+else:
+ import importlib
+ def six_reload(mod):
+ return importlib.reload(mod)
+
+
+def main():
+ import sounds
+ assert sounds.step
+ fd = start_audio()
+ t = 0
+ while True:
+ try:
+ data = sounds.step(t)
+ except Exception as e:
+ logging.exception("step")
+ time.sleep(0.1)
+ else:
+ os.write(fd, data)
+ t += len(data)
+ try:
+ sounds = six_reload(sounds)
+ except Exception as e:
+ logging.exception("reload")
+
+
+if __name__ == "__main__":
+ main()
diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..e201241
--- /dev/null
+++ b/readme.md
@@ -0,0 +1,32 @@
+# Eighth
+
+Chiptune in Python
+
+## What?
+
+Chiptune: https://en.wikipedia.org/wiki/Chiptune
+
+**Eighth** allows you to easily write code that produces chiptune music,
+hot-reloads your code in real time, and plays it back without a hitch.
+All in under 100 lines of code.
+
+## How?
+
+Run `python player.py` in a terminal, it will start playback. Open
+`sounds.py` in a text editor. Edit the definition of the function
+`mksound` to get a different kind of tune. Save the file; `player.py`
+will pick up the change automatically.
+
+If your code contains a syntax error, reload will fail, print the
+exception, and use the last working version. If there's a runtime error
+in your sound-producing function (like a division by zero), the player
+will go silent.
+
+## Requirements?
+
+So far, the code has only been ported to OpenBSD, but all you need is a
+file descriptor where you can write PCM data.
+
+## Who?
+
+Author is Kamil Cholewinski <kamil@rollc.at>. Code is in public domain.