Skip to content

Commit c8043d7

Browse files
committed
minim examples
1 parent a914ff1 commit c8043d7

File tree

21 files changed

+525
-77
lines changed

21 files changed

+525
-77
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# JRubyArt-examples for JRubyArt-1.7.0+
1+
# JRubyArt-examples for JRubyArt-2.2.0+
22
Replaces `AppRender` with `GfxRender`, and removal of bashisms in autorun Rakefiles
33

44
Description

external_library/gem/geomerative/hello_world.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def setup
1313
background(255)
1414
fill(255, 102, 0)
1515
stroke(0)
16-
@grp = RG.getText('Hola Mundo!', data_path('FreeSans.ttf'), 72, CENTER)
16+
@grp = RG.get_text('Hola Mundo!', data_path('FreeSans.ttf'), 72, CENTER)
1717
end
1818

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