Skip to content
This repository has been archived by the owner on Sep 10, 2022. It is now read-only.

Commit

Permalink
Fixed a bug in repa(), added print command, introduced an example mel…
Browse files Browse the repository at this point in the history
…ody along with its LMMS project and ogg output
  • Loading branch information
Dave committed Sep 20, 2017
1 parent 1022e74 commit 8ff4828
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.mid
*.gem
31 changes: 31 additions & 0 deletions bin/sonic_midi
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@ def check_input(args)
return input
end

def print_sequence(title, sequence)
puts title
sequence.each do |values|
puts ' - [%s]' % values.join(', ')
end
end

def print_music(input)
require_relative '../lib/shared_functions'
load input
melody = melody()
if melody.respond_to?(:key)
melody.keys().each do |k|
print_sequence(k, melody[k])
end
elsif melody.respond_to?(:length)
print_sequence('m', melody)
end
end

def play_music(input)
melody = File.read(input)
shared_functions = File.read(local_path('shared_functions.rb'))
Expand All @@ -57,6 +77,17 @@ program :name, 'sonic_midi'
program :version, '0.1.0'
program :description, 'Sends music to Sonic Pi and convert it to Midi'

command :print do |c|
c.syntax = 'sonic_midi print <filename>'
c.summary = 'Prints the melody sequence'
c.description = 'Diagnostical print of the melody sequence'
c.example 'description', 'sonic_midi print melody.rb'
c.action do |args, options|
input = check_input(args)
print_music(input)
end
end

command :sonic do |c|
c.syntax = 'sonic_midi sonic <filename>'
c.summary = 'Send music to SonicPi'
Expand Down
2 changes: 1 addition & 1 deletion lib/shared_functions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

def repa(array, x)
result = []
(0..x).each do
(1..x).each do
result.concat(array)
end
return result
Expand Down
43 changes: 43 additions & 0 deletions melodies/run/base.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
def mybpm()
return 60
end

def mysynth()
return :piano
end

def melody()

m = []
t = []

m1 = []
t1 = []
[64, 60, 62, 59].each do |x|
m1.concat([x])
t1.concat([2*F])
end

m.concat(m1 + m1)
t.concat(t1 + t1)

m2 = [64, 66]
t2 = rep(2*F, 2)

m.concat(m2 + m2)
t.concat(t2 + t2)

m3 = []
t3 = []
m3.concat(repa([67, 71], 4))
m3.concat(repa([69, 72], 4))
t3 = rep(Q, 16)

m.concat(m3 + m3)
t.concat(t3 + t3)

m.concat(m1)
t.concat(t1)

return m, t
end
Binary file added melodies/run/run.mmpz
Binary file not shown.
Binary file added melodies/run/run.ogg
Binary file not shown.
46 changes: 46 additions & 0 deletions melodies/run/run.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
def mybpm()
return 60
end

def mysynth()
return :piano
end

def melody()

m = []
t = []

m1 = []
t1 = []
[64, 60, 62, 59].each do |x|
m1.concat(rep(x, 5))
t1.concat(rep(Q, 4) + [F])
end

m.concat(m1 + m1)
t.concat(t1 + t1)

m2 = []
t2 = []
m2.concat(repa([64, 67], 4))
m2.concat(repa([66, 69], 4))
t2 = rep(Q, 16)

m.concat(m2 + m2)
t.concat(t2 + t2)

m3 = []
t3 = []
m3.concat(repa([67, 71], 4))
m3.concat(repa([69, 72], 4))
t3 = rep(Q, 16)

m.concat(m3 + m3)
t.concat(t3 + t3)

m.concat(m1)
t.concat(t1)

return m, t
end
2 changes: 1 addition & 1 deletion sonic-midi.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'sonic-midi'
s.version = '0.2.0'
s.version = '0.2.1'
s.date = '2017-09-14'
s.summary = "Dual Sonic Pi Midi music generator"
s.description = "Command-line tool to generate Midi music also playable in Sonic Pi"
Expand Down

0 comments on commit 8ff4828

Please sign in to comment.