• Stars
    star
    123
  • Rank 280,958 (Top 6 %)
  • Language
    Ruby
  • License
    GNU General Publi...
  • Created about 12 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Ruby DSL for making music

Muse

Muse is a Ruby DSL for making music. Unlike MIDI, which is a specification for music in a digital form, Muse actually creates the WAV music files itself.

WARNING: This is pre-alpha software where bugs abound and snap and gnash at every mistake you make. Use at your own risk!

If you are keen on music and Ruby, and would like to help out, I'm more than glad to accept more developers! Or musicians. Or both.

Installing

To use Muse, install the gem.

gem install muse

Then write your songs, requiring the library in your song.

require 'muse'

Using Muse

Since each Muse song you write is actually a Ruby program, simply run it the way you're used to run a Ruby program, and it will generate a WAV file.

Basics of Muse

There are 3 levels to be mindful of when writing a song in Muse.

  • Song - this is the highest level and represents an entire song
  • Bar - this represents a single bar in sheet music and contains a number of notes
  • Note - this represents a single musical note

It's important to remember that when you write in Muse you're not writing sheet music. Things like clef or time signatures are no longer important. Even though Muse has a concept of bar of notes, this is merely a convenience. You don't need to have multiple bars, but it's neater to do so.

At this point there are still a number of features not available in Muse, for example you can't do slurs easily.

Song

A song is a collection of bars. You can set the name of the song, which then translates to the name of the WAV file that is created.

Song.record "this_is_my_song" do
   ...
end

The example above creates a file named this_is_my_song.wav.

Bar

A bar is a collection of notes. You can set 3 options that will be kept throughout the whole bar.

  • beat - (b) The time for each note in the bar
  • beats per minute - (bpm) The number of beats per minute. This determines how fast each beat is in actual time
  • envelope - (envelope) How the note sounds.

You can group bars together in order to play them at the same time. For example.

bar(3,b:0.25).notes   {e4 b:0.5; _ b:0.5; f4; e4; dis4; e4;}
bar(3,b:0.5).notes    {a3; c3_e3; c3_e3; c3_e3;}

To play 2 or more bars at the same time, just use the same number for the bar. In the example above, there are 2 bar 3s, so both of these bars are played together.

Notice that bars don't need to have the same beat. However, beat of all the notes in each bar summed together, must be the same. In the example above, the beats in the notes in the first bar summed must be the same as the second bar. If they don't match, the bar with the longer timing will find the notes truncated to fit the shorter bar.

Note

Each note is indicated by an alphabet from a to g. Sharps is indicated by adding a is to the end of the note. For example ais is A-sharp. There are no flats in Muse since you can always use a sharp where a flat is.

There is a number added as a suffix to each note, which indicates the octave of the note. The note c3 is the middle-C. The whole octave 3 is the default, and if you don't have a suffix for your note, it's assumed to be in octave 3.

At this point in time, Muse extends from octave 2 to 5 only. Adding more octaves is easy but I'm lazy.

There are 3 options you can use in a note.

  • beat - (b) This is the time for the note. The default is 1 if you don't specify, unless it's set at the bar level.
  • volume - (v) This is how loud the note should be. The default is 10.
  • envelope - (a) This indicates how the note should sound. The default envelope is a cosine wave (check the code please).

Use this keyboard as a reference when writing music.

Keyboard reference

Keeping time

To keep time in Muse you can use 2 options. The first is the bpm or beats per minute. This is set at the bar level and the default is 120bpm. The second is the beat duration. This can be set at the bar level or at the individual note level. A beat is equivalent to a crochet (or a quarter note) in musical notation.

To indicate a crochet or quarter note at the note level:

a b:1;

To indicate a quaver or eighth note at the bar level:

bar(1,b:0.5).notes {c; e; g;}

Each note in the bar above will be half a beat.

Playing more than one note at a time

To play double notes or chords or even more notes at the same time, you can concatenate them with underscores like this:

c_e_g; 

This plays 3 notes C, E and G at the same time. This can take in options just like any note. For example:

c_e_g b:1;

This plays the chord for 1 beat.

Chords

You can also play chords. The convention for a chord is to start with an underscore. The root note is capitalized. If it's a major chord an M is added as a suffix, if it's a minor chord an m is added instead and so on. Some examples of chords are:

_CM; _D7; _Fm;

Which represents the C major, D7 and F minor chords accordingly. Chords, just like multiple notes, can have the same options as notes have.

Envelopes

Envelopes defines the 'shape' of the sound. The sound wave when first generate is uniform. This means it will sound the same throughout the duration of the note. Applying an envelope creates the variation on how the note sounds.

Envelopes can be specified per note using the 'e' option, or per bar, also with the 'e' option or the entire song, with the 'envelope' option.

The default envelope, if no envelope is specified, is a cosine wave. This means, the note will sound the loudest initially, then taper off towards the end of the note.

A smoother envelope named 'sine' is also provided, which gives a smoother tone of the note as the note gradually becomes louder and is the loudest in the middle of the note, only to taper off at the end.

To add more envelopes, you can extend the Envelope module and add in your own implementation. Please refer to the code.

Harmonics

Sound is created by waves. The default sound for each note in Muse is a pure sine wave, called the fundamental harmonic. This has a very 'electronic' sound. To change how the note sounds like, you can change the harmonic being used. Each harmonic is created by adding additional 'harmonics' on top of the fundamental harmonic, changing the shape of the wave.

Harmonics can be specified per note using the 'h' option, or per bar also with the 'he' option or the entire song, with the 'harmonic' option.

The default harmonic, if none is specified, as mentioned, is a pure sine wave. You can add in your own harmonics to create different sound effects. Please refer to the code to see how this is done.

Examples

For examples look into the songs folder. This is an example of the first 9 bars of Alla Turca by Mozart.

Here's the original music score, public domain from the Mutopia Project.

First 9 bars of Alla Turca

require "muse"
include Muse

# Mozart's Piano Sonata No. 11 3rd Movement (All Turca)
# more popularly known as the 'Turkish March' or 'Turkish Rondo'
# first 9 bars only

Song.record 'turkish_march' do
  bar(1,b:0.25).notes   {b4; a4; gis4; a4;}

  bar(2,b:0.25).notes   {c5 b:0.5; _ b:0.5; d5; c5; b4; c5;}
  bar(2,b:0.5).notes    {a3;       c4_e4;   c4_e4;  c4_e4;} 

  bar(3,b:0.25).notes   {e5 b:0.5; _ b:0.5; f5; e5; dis5; e5;}
  bar(3,b:0.5).notes    {a3;       c4_e4;   c4_e4;  c4_e4;} 

  bar(4,b:0.25).notes   {b5; a5; gis5; a5; b5; a5; gis5; a5;}
  bar(4,b:0.5).notes    {a3;     c4_e4;    a3;     c4_e4;}  

  bar(5,b:0.5).notes    {c6 b:1;            a5;     c6;}
  bar(5,b:0.5).notes    {a3;       c4_e4;   c4_e4;  c4_e4;} 

  bar(6,b:0.5).notes    {b5; fis5_a5; e5_g5; fis5_a5; }
  bar(6,b:0.5).notes    {e3; b4_e4; b4_e4; b4_e4;}  

  bar(7,b:0.5).notes    {b5; fis5_a5; e5_g5; fis5_a5; }
  bar(7,b:0.5).notes    {e3; b4_e4; b4_e4; b4_e4;}  

  bar(8,b:0.5).notes    {b5; fis5_a5; e5_g5; dis5_eis5; }
  bar(8,b:0.5).notes    {e3; b4_e4; b2; b4;}  

  bar(9).notes          {e4}
  bar(9).notes          {e4}  
end

Speeding up Muse

Muse from version 0.0.5 runs 4 parallel processes when generating the music file, using the Parallel library by Michael Grosser. This runs a whole lot faster than versions prior to 0.0.5

Copyright and distribution

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

More Repositories

1

gwp

Go Web Programming code repository
JavaScript
1,596
star
2

invaders

Space Invaders in Go
Go
637
star
3

polyglot

Polyglot is a distributed web framework that allows programmers to create web applications in multiple programming languages
Go
624
star
4

gonn

Building a simple neural network in Go
Go
330
star
5

invadersapp

Space invaders in an app
Go
199
star
6

everyday

code from the book "Exploring Everyday Things with R and Ruby"
Ruby
170
star
7

saushengine.v1

Simple Ruby-based search engine
Ruby
118
star
8

ga

Simple genetic algorithms in Go
Go
111
star
9

snip

Simple TinyURL clone
Ruby
98
star
10

chirp

Simple Sinatra-based micro-blog/Twitter clone
Ruby
90
star
11

naive-bayes

Simple naive bayesian classifier implemented in Ruby
Ruby
64
star
12

tanuki

Tanuki is a polyglot web framework that allows you to develop web applications and services in multiple programming languages.
Go
62
star
13

mosaic

A photo-mosaic generating program, also showcasing Go concurrency techniques using goroutines and channels.
Go
60
star
14

talkie

A voice-based ChatGPT clone that can search on the Internet and also in local files
CSS
52
star
15

hs1xxplug

Go library for TP-Link HS100 and HS110 WiFi smart plug
Go
47
star
16

persona

Talking head video AI generator
Python
43
star
17

polyblog

How to Create A Web App In 3 Different Programming Languages
Java
41
star
18

kancil

Simple web app to showcase LlamaIndex
Python
40
star
19

chitchat

Simple forum written in Go
Go
33
star
20

goids

Flocking simulation in Go
Go
28
star
21

breeze

A simple ChatGPT clone built using Go
HTML
25
star
22

goreplicate

This is a simple Go package for interacting with the Replicate (https://replicate.com) HTTP APIs. Replicate is an API service that allows developers to use machine learning models easily through calling APIs.
Go
25
star
23

blueblue

Bluetooth LE scanner and spelunking tool
Go
24
star
24

exblog

A blogging web application written with Elixir and Dynamo.
Elixir
21
star
25

modular

Examples uses to illustrate how to write modular Rack-based web applications
Ruby
21
star
26

tinyclone

TinyURL clone
Ruby
20
star
27

carpark-cgpt

ChatGPT plugin for Singapore HDB car park availability
Go
17
star
28

ruby-gpio

A Ruby DSL to interface with the Raspberry Pi GPIO.
Ruby
17
star
29

saushengine

Ruby
16
star
30

tanks

Tanks! is a Gosu-based simple, real-time online multiplayer game, based on the popular retro game, Tank Battalion.
Ruby
14
star
31

Colony

Facebook clone project for the Cloning Internet Applications with Ruby book
JavaScript
14
star
32

rbase

A minimalist NoSQL database written in pure Ruby.
Ruby
13
star
33

petri

Go framework for building simulations based on cellular automation
Go
13
star
34

netnet

Discover Wi-Fi clients using Raspberry Pi Zero W, airodump-ng and Go
Go
12
star
35

gocookbook

Code repository for the Go Cookbook
Go
12
star
36

utopia

Pure Ruby version of 'Money, Sex and Evolution' agent-based modeling simulations
Ruby
11
star
37

gonb

Go
11
star
38

Wavform

Generate MP3 waveforms using Ruby and R
Ruby
11
star
39

epidemic-sim

Epidemic simulation using Go and Python
Jupyter Notebook
10
star
40

auth

Examples of third-party authentication, using Sinatra and Shoes, with RPX, OpenID etc
Ruby
10
star
41

easyblog

A minimalist blog web app
Ruby
9
star
42

ghost

"What if a cyber brain could possibly generate its own ghost, create a soul all by itself?"
Python
9
star
43

snip-appengine

Snip! deployment on Google AppEngine
Ruby
9
star
44

gwp2

Code for Go Web Programming 2nd edition
Go
9
star
45

squall

Squall is a Question Answering chatbot that runs entirely on a laptop, using Llama-2 and a downloaded HuggingFace embedding model.
Python
9
star
46

monsoon

Monsoon is a simple ChatGPT clone built with Go. It uses Llama-compatible LLMs, through llama.cpp.
CSS
8
star
47

pynn

Building simple artificial neural networks with TensorFlow, Keras, PyTorch and MXNet/Gluon
Python
8
star
48

gost

Gost is a native Go data store for storing data in S3 compatible object storage services.
Go
8
star
49

maiad

My AI Assistant for Microsoft Word
HTML
7
star
50

merkato

E-Commerce application with Go
Go
7
star
51

sghazeserv

Singapore Haze Watch server
Go
7
star
52

ruby_complexity_simulations

Source code for Programming Complexity (Ruby version) talk
JavaScript
7
star
53

promptscript

PromptScript is an experimental prompting language created by GPT-4
Python
7
star
54

founders

Algorithms for Startup Founders
Jupyter Notebook
7
star
55

gomuse

Creating music with Go
JavaScript
7
star
56

house

House is a debate simulation between multiple participants, which can be represented by different large language models (LLMs). House is an experiment to use LLMs to debate and discuss a topic and get views from multiple perspectives.
Python
7
star
57

chirpy

Simple Twitter clone
Ruby
6
star
58

easyforum

A minimalist forum web application for Rubyists
Ruby
6
star
59

gotext

Random Text Generator written in Go
Go
6
star
60

tanksworld

Web-based Tanks game server management
Ruby
6
star
61

anthill

Simple workload distribution system
JavaScript
6
star
62

bookspeak

Create audio books in any language using Python
Python
5
star
63

complexity_simulations

Code repository for 'Programming Complexity' talk
Go
5
star
64

Utopia2

Sugarscape JRuby simulation clone
Ruby
5
star
65

qard

Qard is a simple QR Code business card generator.
HTML
4
star
66

pompoko

Pom Poko is a sample blog web app written using the Tanuki web framework.
Ruby
4
star
67

mosaicgo

Docker-deployed version of the concurrent mosaic web application
Go
4
star
68

sausheong.github.com

Saush's GitHub Homepage
4
star
69

bots

Simple library for controlling robots using Ruby
Ruby
3
star
70

complexity

Programming Complexity
3
star
71

newspaper

Faster way to read print newspapers
Go
3
star
72

easywiki

An all-in-a-file wiki web app
Ruby
3
star
73

goauthserv

A REST-based authentication service written in Go.
Go
3
star
74

myhaze

Haze monitoring for Malaysia
JavaScript
3
star
75

go-recipes

Code for the Go Recipes publication site
Go
3
star
76

gosearch

A simple search engine in Go
Go
3
star
77

pixelate

Simple Go web application that pixelates a given JPEG file
Go
3
star
78

vdb

Sample code to show how to create an in-memory RAG
Go
3
star
79

culture_sim

Model and simulate cultural dissemination with Go and Python
Jupyter Notebook
2
star
80

todayreader

An alternative reader for the Today newspaper
CSS
2
star
81

hist

Simple Go web app to create histograms
HTML
2
star
82

sausheong.github.io

HTML
2
star
83

mst

Code repository for the minimum spanning tree algorithms post
Go
2
star
84

server-frameworks

Ruby
2
star
85

simplerd

Server for the Simpler Chrome extension
Go
2
star
86

waldo

Waldo is a command-line AI assistant that wraps around local LLMs, Google's Gemini models and OpenAI's GPT models
Go
2
star
87

gale

Gale is an AI chatbot used for question & answering over documents, built with Go
HTML
1
star
88

sghaze

Singapore Haze alert
JavaScript
1
star
89

perf-go

Testing the performance of the basic go web application
Ruby
1
star
90

tweetclone

Twitter clone
1
star
91

shado

Camera-based motion detector
Go
1
star
92

red

Go
1
star
93

minstrel

Using LLM to create stories
HTML
1
star
94

loca

Simple chatbot wrapping around a LLM.
Python
1
star
95

multipage-pdf

Sample code to show how to convert multi-page PDFs to a sequence of PNG images using RMagick
Ruby
1
star
96

openai

Go package that wraps around OpenAI HTTP APIs
Go
1
star