Skip to content

Instantly share code, notes, and snippets.

@interstar
Created November 26, 2023 17:43
Show Gist options
  • Save interstar/577be6d1c5aecd740763ab39bbda5e32 to your computer and use it in GitHub Desktop.
Save interstar/577be6d1c5aecd740763ab39bbda5e32 to your computer and use it in GitHub Desktop.
ByteBeats in Edison, Pyscript Edition
from enveditor import *
"""
Create bytebeats in FL Studio's Edison editor. Change the formula in generator(t) to change the actual bytebeat
This script should be called something like bytebeats.pyscript and placed in
"C:\Users\<USERNAME>\Documents\Image-Line\FL Studio\Settings\Audio scripts"
assuming C is where your user's documents live, and <USERNAME> is your user name.
"""
def generator(t):
# Translate the bitwise operations from JavaScript to Python
return (128 & t * (4 | 7 & t >> 13) >> (1 & -t >> 11)) + (127 & t * (t >> 11 & t >> 13) * (3 & -t >> 9)) % 255
def makeSample(length, srate, norm):
# Sample rate selection
if srate == 0:
EditorSample.SampleRate = 8000
elif srate == 1:
EditorSample.SampleRate = 11025
elif srate == 2:
EditorSample.SampleRate = 22050
else:
EditorSample.SampleRate = 44100
# Setting sample length
if EditorSample.Length <= 0:
EditorSample.Length = round(EditorSample.MSToSamples(length * 1000))
x1 = Editor.SelectionStartS
x2 = Editor.SelectionEndS
# Byte-beat generation
for n in range(x1, x2 + 1):
for c in range(EditorSample.NumChans):
s = generator(n)
EditorSample.SetSampleAt(n, c, s)
# Normalization
if norm == 0:
EditorSample.NormalizeFromTo(x1, x2, 0.8)
# User Interface
form = ScriptDialog('ByteBeats', 'Generate Your ByteBeats Right Now!!!')
form.AddInputKnob('Length (s)', 1, 0, 100)
form.AddInputCombo('Sample Rate', '8000,11025,22050,44100', 3)
form.AddInputCombo('Normalize?', 'Yes,No', 1)
if form.Execute():
makeSample(form.GetInputValue('Length (s)'), form.GetInputValue('Sample Rate'), form.GetInputValue('Normalize?'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment