zgomot 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. data/.document +5 -0
  2. data/LICENSE +22 -0
  3. data/README.rdoc +7 -0
  4. data/Rakefile +24 -0
  5. data/VERSION +1 -0
  6. data/bin/zgomot +2 -0
  7. data/examples/arp_chords.rb +15 -0
  8. data/examples/full_scale_notes.rb +15 -0
  9. data/examples/inv_chords.rb +15 -0
  10. data/examples/modes_notes.rb +16 -0
  11. data/examples/notes.rb +18 -0
  12. data/examples/percs.rb +20 -0
  13. data/examples/percs_multi.rb +18 -0
  14. data/examples/phase_notes.rb +20 -0
  15. data/examples/prog_chords.rb +15 -0
  16. data/examples/prog_chords_multi_vel_length.rb +15 -0
  17. data/examples/prog_chords_rest.rb +15 -0
  18. data/examples/prog_notes.rb +15 -0
  19. data/examples/prog_notes_multi_vel_length.rb +15 -0
  20. data/examples/prog_notes_rest.rb +15 -0
  21. data/examples/progressive_modes.rb +51 -0
  22. data/examples/reverse_chords.rb +15 -0
  23. data/examples/scale_chords.rb +15 -0
  24. data/examples/scale_notes.rb +15 -0
  25. data/examples/scales_notes.rb +19 -0
  26. data/examples/simple_chords.rb +15 -0
  27. data/examples/simple_markov.rb +24 -0
  28. data/examples/simple_notes.rb +15 -0
  29. data/examples/simple_notes_length.rb +17 -0
  30. data/examples/simple_notes_velocity.rb +17 -0
  31. data/examples/zgomot.yml +3 -0
  32. data/lib/zgomot/boot.rb +56 -0
  33. data/lib/zgomot/comp/chord.rb +171 -0
  34. data/lib/zgomot/comp/markov.rb +60 -0
  35. data/lib/zgomot/comp/mode.rb +66 -0
  36. data/lib/zgomot/comp/note.rb +29 -0
  37. data/lib/zgomot/comp/pattern.rb +63 -0
  38. data/lib/zgomot/comp/perc.rb +94 -0
  39. data/lib/zgomot/comp/permutation.rb +17 -0
  40. data/lib/zgomot/comp/pitch_class.rb +63 -0
  41. data/lib/zgomot/comp/progression.rb +132 -0
  42. data/lib/zgomot/comp/scale.rb +32 -0
  43. data/lib/zgomot/comp.rb +11 -0
  44. data/lib/zgomot/config.rb +51 -0
  45. data/lib/zgomot/main.rb +51 -0
  46. data/lib/zgomot/midi/channel.rb +92 -0
  47. data/lib/zgomot/midi/clock.rb +101 -0
  48. data/lib/zgomot/midi/dispatcher.rb +92 -0
  49. data/lib/zgomot/midi/interface.rb +29 -0
  50. data/lib/zgomot/midi/note.rb +104 -0
  51. data/lib/zgomot/midi/stream.rb +76 -0
  52. data/lib/zgomot/midi.rb +6 -0
  53. data/lib/zgomot/patches/object.rb +11 -0
  54. data/lib/zgomot/patches/time.rb +10 -0
  55. data/lib/zgomot/patches.rb +2 -0
  56. data/lib/zgomot.rb +14 -0
  57. data/lib/zlive.rb +7 -0
  58. metadata +178 -0
@@ -0,0 +1,104 @@
1
+ ##############################################################################################################
2
+ module Zgomot::Midi
3
+
4
+ #####-------------------------------------------------------------------------------------------------------
5
+ class Note
6
+
7
+ #.........................................................................................................
8
+ PITCH_CLASS = {
9
+ :C => 0, :Bs => 0,
10
+ :Cs => 1, :Db => 1,
11
+ :D => 2,
12
+ :Ds => 3, :Ed => 3,
13
+ :E => 4, :Fd => 4,
14
+ :F => 5, :Es => 5,
15
+ :Fs => 6, :Gb => 6,
16
+ :G => 7,
17
+ :Gs => 8, :Ab => 8,
18
+ :A => 9,
19
+ :As => 10, :Bb => 10,
20
+ :B => 11, :Cb => 11,
21
+ :R => -1,
22
+ }
23
+
24
+ #.........................................................................................................
25
+ LENGTH = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024].select{|d| d <= Clock.resolution}
26
+
27
+ #.........................................................................................................
28
+ OCTAVE = (-1..9).to_a
29
+
30
+ #####-------------------------------------------------------------------------------------------------------
31
+ class << self
32
+
33
+ #### self
34
+ end
35
+
36
+ #.........................................................................................................
37
+ attr_reader :pitch_class, :octave, :midi, :time_scale
38
+ attr_accessor :time, :offset_time, :channel, :velocity, :length
39
+
40
+ #.........................................................................................................
41
+ def initialize(args)
42
+ @pitch_class, @octave = case args[:pitch]
43
+ when Array then args[:pitch]
44
+ when Symbol then [args[:pitch], 4]
45
+ else raise(Zgomot::Error, "#{args[:pitch].inspect} is invalid pitch")
46
+ end
47
+ @length, @velocity = args[:length], args[:velocity]
48
+ @midi = pitch_to_midi(pitch_class, octave)
49
+ @time_scale = 1.0
50
+ raise(Zgomot::Error, "#{octave} is invalid octave") unless OCTAVE.include?(octave)
51
+ raise(Zgomot::Error, "#{length} is invalid duration") unless LENGTH.include?(length)
52
+ raise(Zgomot::Error, "#{args[:pitch].inspect} is invalid") if midi.nil?
53
+ raise(Zgomot::Error, "#{velocity} is invalid velocity") unless velocity < 1.0
54
+ end
55
+
56
+ #.........................................................................................................
57
+ def to_s
58
+ "[#{pitch_class.to_s},#{octave}].#{length}.#{midi}.#{velocity}"
59
+ end
60
+
61
+ #.........................................................................................................
62
+ # transforms
63
+ #.........................................................................................................
64
+ def bpm!(bpm)
65
+ @time_scale = 1.0/bpm.to_f; self
66
+ end
67
+
68
+ #.........................................................................................................
69
+ def octave!(oct)
70
+ @octave = oct; self
71
+ end
72
+
73
+ #.........................................................................................................
74
+ # channel and dispatch interface
75
+ #.........................................................................................................
76
+ def play_at
77
+ time.to_f + offset_time.to_f
78
+ end
79
+
80
+ #.........................................................................................................
81
+ def length_to_sec
82
+ time_scale*Clock.whole_note_sec/length
83
+ end
84
+
85
+ #.........................................................................................................
86
+ def to_midi
87
+ self
88
+ end
89
+
90
+ #.........................................................................................................
91
+ def pitch_to_midi(pitch_class, octave)
92
+ if PITCH_CLASS[pitch_class]
93
+ (midi = 12*(octave+1)+PITCH_CLASS[pitch_class]) <= 127 ? midi : nil
94
+ end
95
+ end
96
+
97
+ #.........................................................................................................
98
+ private :pitch_to_midi
99
+
100
+ #### Note
101
+ end
102
+
103
+ #### Zgomot::Midi
104
+ end
@@ -0,0 +1,76 @@
1
+ ##############################################################################################################
2
+ module Zgomot::Midi
3
+
4
+ #####-------------------------------------------------------------------------------------------------------
5
+ class Stream
6
+
7
+ #.........................................................................................................
8
+ @streams = []
9
+
10
+ #####-------------------------------------------------------------------------------------------------------
11
+ class << self
12
+
13
+ #.........................................................................................................
14
+ attr_reader :streams
15
+
16
+ #.........................................................................................................
17
+ def str(name, pattern=nil, opts={}, &blk)
18
+ strm = new(name, blk.arity, pattern, opts[:lim])
19
+ strm.define_meta_class_method(:play, &blk)
20
+ @streams << strm
21
+ end
22
+
23
+ #.........................................................................................................
24
+ def play
25
+ streams.each{|s| s.dispatch(::Time.now.truncate_to(Clock.tick_sec) + Zgomot::PLAY_DELAY) if s.status.eql?(:new)}
26
+ end
27
+
28
+ #### self
29
+ end
30
+
31
+ #####-------------------------------------------------------------------------------------------------------
32
+ attr_reader :patterns, :times, :status, :count, :thread, :limit, :name, :play_meth
33
+
34
+ #.........................................................................................................
35
+ def initialize(name, arity, pattern, limit)
36
+ @patterns, @times = [Zgomot::Comp::Pattern.new(pattern)], [Time.new]
37
+ @limit, @name, @count, @thread, @status = limit || :inf, name, 0, nil, :new
38
+ @play_meth = "play#{arity.eql?(-1) ? 0 : arity}".to_sym
39
+ end
40
+
41
+ #.........................................................................................................
42
+ def dispatch(start_time)
43
+ ch_time, @status = 0.0, :playing
44
+ @thread = Thread.new do
45
+ loop do
46
+ @count += 1
47
+ break if not limit.eql?(:inf) and count > limit
48
+ if self.respond_to?(play_meth, true)
49
+ if (chan = self.send(play_meth)).kind_of?(Zgomot::Midi::Channel)
50
+ Dispatcher.enqueue(chan.time_shift(start_time+ch_time))
51
+ else; break; end
52
+ else
53
+ raise(Zgomot::Error, 'str block arity not supported')
54
+ end
55
+ Zgomot.logger.info "STREAM:#{count}:#{name}"
56
+ patterns << Zgomot::Comp::Pattern.new(chan.pattern)
57
+ ch_time += chan.length_to_sec; times << Time.new(ch_time)
58
+ sleep(0.80*(start_time+ch_time-::Time.now.truncate_to(Clock.tick_sec)))
59
+ end
60
+ Zgomot.logger.info "STREAM FINISHED:#{name}"
61
+ @status = :finished
62
+ end
63
+ end
64
+
65
+ #.........................................................................................................
66
+ def play0;play;end
67
+ def play1;play(Marshal.load(Marshal.dump(patterns.last)));end
68
+
69
+ #.........................................................................................................
70
+ private :play0, :play1
71
+
72
+ #### Stream
73
+ end
74
+
75
+ #### Zgomot::Midi
76
+ end
@@ -0,0 +1,6 @@
1
+ require 'zgomot/midi/clock'
2
+ require 'zgomot/midi/note'
3
+ require 'zgomot/midi/channel'
4
+ require 'zgomot/midi/stream'
5
+ require 'zgomot/midi/interface'
6
+ require 'zgomot/midi/dispatcher'
@@ -0,0 +1,11 @@
1
+ ##############################################################################################################
2
+ class Object
3
+
4
+ #.......................................................................................................
5
+ def define_meta_class_method(name, &blk)
6
+ (class << self; self; end).instance_eval {define_method(name, &blk)}
7
+ end
8
+
9
+ #### Object
10
+ end
11
+
@@ -0,0 +1,10 @@
1
+ ##############################################################################################################
2
+ class Time
3
+
4
+ #.......................................................................................................
5
+ def truncate_to(tick_sec)
6
+ tick_sec*(to_f/tick_sec).to_i
7
+ end
8
+
9
+ #### Time
10
+ end
@@ -0,0 +1,2 @@
1
+ require 'zgomot/patches/object'
2
+ require 'zgomot/patches/time'
data/lib/zgomot.rb ADDED
@@ -0,0 +1,14 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+
3
+ require 'optparse'
4
+ require 'logger'
5
+ require 'monitor'
6
+
7
+ require 'midiator'
8
+
9
+ require 'zgomot/config'
10
+ require 'zgomot/boot'
11
+ require 'zgomot/patches'
12
+ require 'zgomot/comp'
13
+ require 'zgomot/midi'
14
+ require 'zgomot/main'
data/lib/zlive.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'zgomot'
3
+ Zgomot.live = true
4
+ begin
5
+ load ENV['HOME'] + '/.zgomot'
6
+ rescue LoadError; end
7
+ Zgomot::Boot.boot
metadata ADDED
@@ -0,0 +1,178 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zgomot
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Troy Stribling
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-23 00:00:00 -05:00
19
+ default_executable: zgomot
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rake
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 57
30
+ segments:
31
+ - 0
32
+ - 8
33
+ - 3
34
+ version: 0.8.3
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: midiator
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 21
46
+ segments:
47
+ - 0
48
+ - 3
49
+ - 3
50
+ version: 0.3.3
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ description:
54
+ email: troy.stribling@gmail.com
55
+ executables:
56
+ - zgomot
57
+ extensions: []
58
+
59
+ extra_rdoc_files:
60
+ - LICENSE
61
+ - README.rdoc
62
+ files:
63
+ - .document
64
+ - LICENSE
65
+ - README.rdoc
66
+ - Rakefile
67
+ - VERSION
68
+ - bin/zgomot
69
+ - examples/arp_chords.rb
70
+ - examples/full_scale_notes.rb
71
+ - examples/inv_chords.rb
72
+ - examples/modes_notes.rb
73
+ - examples/notes.rb
74
+ - examples/percs.rb
75
+ - examples/percs_multi.rb
76
+ - examples/phase_notes.rb
77
+ - examples/prog_chords.rb
78
+ - examples/prog_chords_multi_vel_length.rb
79
+ - examples/prog_chords_rest.rb
80
+ - examples/prog_notes.rb
81
+ - examples/prog_notes_multi_vel_length.rb
82
+ - examples/prog_notes_rest.rb
83
+ - examples/progressive_modes.rb
84
+ - examples/reverse_chords.rb
85
+ - examples/scale_chords.rb
86
+ - examples/scale_notes.rb
87
+ - examples/scales_notes.rb
88
+ - examples/simple_chords.rb
89
+ - examples/simple_markov.rb
90
+ - examples/simple_notes.rb
91
+ - examples/simple_notes_length.rb
92
+ - examples/simple_notes_velocity.rb
93
+ - examples/zgomot.yml
94
+ - lib/zgomot.rb
95
+ - lib/zgomot/boot.rb
96
+ - lib/zgomot/comp.rb
97
+ - lib/zgomot/comp/chord.rb
98
+ - lib/zgomot/comp/markov.rb
99
+ - lib/zgomot/comp/mode.rb
100
+ - lib/zgomot/comp/note.rb
101
+ - lib/zgomot/comp/pattern.rb
102
+ - lib/zgomot/comp/perc.rb
103
+ - lib/zgomot/comp/permutation.rb
104
+ - lib/zgomot/comp/pitch_class.rb
105
+ - lib/zgomot/comp/progression.rb
106
+ - lib/zgomot/comp/scale.rb
107
+ - lib/zgomot/config.rb
108
+ - lib/zgomot/main.rb
109
+ - lib/zgomot/midi.rb
110
+ - lib/zgomot/midi/channel.rb
111
+ - lib/zgomot/midi/clock.rb
112
+ - lib/zgomot/midi/dispatcher.rb
113
+ - lib/zgomot/midi/interface.rb
114
+ - lib/zgomot/midi/note.rb
115
+ - lib/zgomot/midi/stream.rb
116
+ - lib/zgomot/patches.rb
117
+ - lib/zgomot/patches/object.rb
118
+ - lib/zgomot/patches/time.rb
119
+ - lib/zlive.rb
120
+ has_rdoc: true
121
+ homepage: http://github.com/troystribling/zgomot
122
+ licenses: []
123
+
124
+ post_install_message:
125
+ rdoc_options: []
126
+
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ hash: 3
135
+ segments:
136
+ - 0
137
+ version: "0"
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ hash: 3
144
+ segments:
145
+ - 0
146
+ version: "0"
147
+ requirements: []
148
+
149
+ rubyforge_project:
150
+ rubygems_version: 1.3.7
151
+ signing_key:
152
+ specification_version: 3
153
+ summary: zgomot is a simple DSL for writting MIDI music.
154
+ test_files:
155
+ - examples/arp_chords.rb
156
+ - examples/full_scale_notes.rb
157
+ - examples/inv_chords.rb
158
+ - examples/modes_notes.rb
159
+ - examples/notes.rb
160
+ - examples/percs.rb
161
+ - examples/percs_multi.rb
162
+ - examples/phase_notes.rb
163
+ - examples/prog_chords.rb
164
+ - examples/prog_chords_multi_vel_length.rb
165
+ - examples/prog_chords_rest.rb
166
+ - examples/prog_notes.rb
167
+ - examples/prog_notes_multi_vel_length.rb
168
+ - examples/prog_notes_rest.rb
169
+ - examples/progressive_modes.rb
170
+ - examples/reverse_chords.rb
171
+ - examples/scale_chords.rb
172
+ - examples/scale_notes.rb
173
+ - examples/scales_notes.rb
174
+ - examples/simple_chords.rb
175
+ - examples/simple_markov.rb
176
+ - examples/simple_notes.rb
177
+ - examples/simple_notes_length.rb
178
+ - examples/simple_notes_velocity.rb