Skip to content

Commit 5f40a08

Browse files
committed
Add minim examples
1 parent c5d8185 commit 5f40a08

File tree

26 files changed

+522
-9
lines changed

26 files changed

+522
-9
lines changed

contributed/recursive_pentagon.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def settings
3030

3131
RecursivePentagons.new
3232

33-
# Here we include Processing::Proxy to mimic vanilla processing inner class
33+
# Here we include Propane::Proxy to mimic vanilla processing inner class
3434
# access.
3535
class PentagonFractal
3636
include Propane::Proxy

external_library/java/minim/Rakefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Simple demo Rakefile to autorun samples in current directory
2+
3+
desc 'run demo'
4+
task default: [:demo]
5+
6+
desc 'demo'
7+
task :demo do
8+
samples_list.shuffle.each { |sample| run_sample sample }
9+
end
10+
11+
def samples_list
12+
Dir.glob('*.rb').map { |file| File.join(__dir__, file) }
13+
end
14+
15+
def run_sample(sample_name)
16+
puts "Running #{sample_name}...quit to run next sample"
17+
system "jruby --dev #{sample_name}"
18+
end
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env jruby
2+
# frozen_string_literal: true
3+
4+
require 'propane'
5+
6+
# ADSRExample is an example of using the ADSR envelope within an instrument.
7+
# For more information about Minim and additional features,
8+
# visit http://code.compartmental.net/minim/
9+
# author: Anderson Mills<br/>
10+
# Anderson Mills's work was supported by numediart (www.numediart.org)
11+
class ADSRExample < Propane::App
12+
load_libraries :minim, :tone_instrument
13+
java_import 'ddf.minim.Minim'
14+
15+
attr_reader :out
16+
17+
def setup
18+
sketch_title 'ADSR Example'
19+
minim = Minim.new(self)
20+
@out = minim.get_line_out(Minim::MONO, 2048)
21+
# pause time when adding a bunch of notes at once
22+
out.pause_notes
23+
# make four repetitions of the same pattern
24+
4.times do |i|
25+
# add some low notes
26+
out.play_note(1.25 + i * 2.0, 0.3, ToneInstrument.new(out, 75, 0.49))
27+
out.play_note(2.50 + i * 2.0, 0.3, ToneInstrument.new(out, 75, 0.49))
28+
29+
# add some middle notes
30+
out.play_note(1.75 + i * 2.0, 0.3, ToneInstrument.new(out, 175, 0.4))
31+
out.play_note(2.75 + i * 2.0, 0.3, ToneInstrument.new(out, 175, 0.4))
32+
33+
# add some high notes
34+
out.play_note(1.25 + i * 2.0, 0.3, ToneInstrument.new(out, 3750, 0.07))
35+
out.play_note(1.5 + i * 2.0, 0.3, ToneInstrument.new(out, 1750, 0.02))
36+
out.play_note(1.75 + i * 2.0, 0.3, ToneInstrument.new(out, 3750, 0.07))
37+
out.play_note(2.0 + i * 2.0, 0.3, ToneInstrument.new(out, 1750, 0.02))
38+
out.play_note(2.25 + i * 2.0, 0.3, ToneInstrument.new(out, 3750, 0.07))
39+
out.play_note(2.5 + i * 2.0, 0.3, ToneInstrument.new(out, 5550, 0.09))
40+
out.play_note(2.75 + i * 2.0, 0.3, ToneInstrument.new(out, 3750, 0.07))
41+
end
42+
# resume time after a bunch of notes are added at once
43+
out.resumeNotes
44+
end
45+
46+
# draw is run many times
47+
def draw
48+
# erase the window to black
49+
background(0)
50+
# draw using a white stroke
51+
stroke(255)
52+
# draw the waveforms
53+
(0...(out.bufferSize - 1)).each do |i|
54+
# find the x position of each buffer value
55+
x1 = map1d(i, 0..out.bufferSize, 0..width)
56+
x2 = map1d(i + 1, 0..out.bufferSize, 0..width)
57+
# draw a line from one buffer position to the next for both channels
58+
line(x1, 50 + out.left.get(i) * 50, x2, 50 + out.left.get(i + 1) * 50)
59+
line(x1, 150 + out.right.get(i) * 50, x2, 150 + out.right.get(i + 1) * 50)
60+
end
61+
end
62+
63+
def settings
64+
size(512, 200, P2D)
65+
end
66+
end
67+
68+
ADSRExample.new
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env jruby
2+
# frozen_string_literal: true
3+
4+
require 'propane'
5+
# This sketch demonstrates how to create synthesized sound with Minim
6+
# using an AudioOutput and an Instrument we define. By using the
7+
# playNote method you can schedule notes to played at some point in the
8+
# future, essentially allowing to you create musical scores with code.
9+
# Because they are constructed with code, they can be either
10+
# deterministic or different every time. This sketch creates a
11+
# deterministic score, meaning it is the same every time you run the
12+
# sketch. For more complex examples of using playNote check out
13+
# algorithmicCompExample and compositionExample. For more information
14+
# about Minim and additional features, visit
15+
# http://code.compartmental.net/minim/
16+
class CreateInstrument < Propane::App
17+
load_libraries :minim, :sine_instrument
18+
java_import 'ddf.minim.Minim'
19+
20+
attr_reader :out
21+
22+
def settings
23+
size(512, 200, P2D)
24+
end
25+
26+
def setup
27+
sketch_title 'Create Instrument'
28+
minim = Minim.new(self)
29+
@out = minim.getLineOut
30+
# when providing an Instrument, we always specify start time and duration
31+
out.playNote(0.0, 0.9, SineInstrument.new(out, 97.99))
32+
out.playNote(1.0, 0.9, SineInstrument.new(out, 123.47))
33+
# we can use the Frequency class to create frequencies from pitch names
34+
out.playNote(2.0, 2.9, SineInstrument.new(out, Frequency.ofPitch('C3').asHz))
35+
out.playNote(3.0, 1.9, SineInstrument.new(out, Frequency.ofPitch('E3').asHz))
36+
out.playNote(4.0, 0.9, SineInstrument.new(out, Frequency.ofPitch('G3').asHz))
37+
end
38+
39+
def draw
40+
background(0)
41+
stroke(255)
42+
# draw the waveforms
43+
(out.bufferSize - 1).times do |i|
44+
line(i, 50 + out.left.get(i) * 50, i + 1, 50 + out.left.get(i + 1) * 50)
45+
line(i, 150 + out.right.get(i) * 50, i + 1, 150 + out.right.get(i + 1) * 50)
46+
end
47+
end
48+
end
49+
50+
CreateInstrument.new
5.91 KB
Binary file not shown.
27.4 KB
Binary file not shown.
7.03 KB
Binary file not shown.
8.03 KB
Binary file not shown.
424 KB
Binary file not shown.
22 KB
Binary file not shown.

0 commit comments

Comments
 (0)