music-performance 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f0aee433423e514dcf3e7c43cf3e41bedb419773
4
- data.tar.gz: 935623cdf53a375dbbe7931f4bbc06857144a3eb
3
+ metadata.gz: a4b9f81c3aba7e25db75da9d71fc2ba25a842599
4
+ data.tar.gz: 2c5887333f7d6fb3ede15a6813ee1f89847f9fbc
5
5
  SHA512:
6
- metadata.gz: 377e4df3573ca96e8b9307f87d8a4dc1cb5aef5bc709c841137649e7c973764b050ac3c2b0777188898c3d663305ec45cf31685a6839a0190f10ead2e9e495b4
7
- data.tar.gz: 136086c85244cbcc75168c7de393ceec0df3d1ec6266aff023b8b21876d37c9f07dbacd2cb0f0735319eb1a232139fcc5bbbe020c0156d53d44de9b409971cf0
6
+ metadata.gz: 73c9896e59861efa226a2769bd621e869bbf56ba9d3ce1c1301f621dd7d41b3c175d07571568fd55244c5bf943f3243d7c49c8d1c9a4ef785faf7561ea2c3c5f
7
+ data.tar.gz: 1b8d20d458e90a90ee7211f71963becd03ebc563a124be25822f27d92c4738fe3c5735c38d3320dbaddda9c3e6eb3fc3c2e9fee499436d73ec2920b0da7f5b50
data/bin/midify CHANGED
@@ -6,11 +6,17 @@ doc = <<DOCOPT
6
6
  Loads a music-transcription score from YAML file, and converts to MIDI file.
7
7
 
8
8
  Usage:
9
- #{exe_name} <input>
9
+ #{exe_name} <input> [PART PROGRAM] ...
10
10
  #{exe_name} <input> <output>
11
11
  #{exe_name} -h | --help
12
12
  #{exe_name} --version
13
13
 
14
+ Arguments:
15
+ input A music-transcription score file in YAML format
16
+ output Midi filename
17
+ PART name of a part in the score
18
+ PROGRAM MIDI program (instrument) number for the given part
19
+
14
20
  Options:
15
21
  -h --help Show this screen.
16
22
  --version Show version.
@@ -42,8 +48,12 @@ File.open(fin_name) do |fin|
42
48
  puts "complete"
43
49
 
44
50
  if score.valid?
51
+ part_names = args["PART"]
52
+ program_nums = args["PROGRAM"].map {|str| str.to_i }
53
+ instr_map = Hash[[part_names,program_nums].transpose]
54
+
45
55
  print "Making MIDI sequence..."
46
- seq = Performance::ScoreSequencer.new(score).make_midi_seq
56
+ seq = Performance::ScoreSequencer.new(score).make_midi_seq(instr_map)
47
57
  puts "complete"
48
58
 
49
59
  fout_name = args["<output>"]
@@ -15,8 +15,8 @@ class PartSequencer
15
15
  @events = (note_events + dynamic_events).sort
16
16
  end
17
17
 
18
- def make_midi_track midi_sequence, part_name, channel, ppqn
19
- track = begin_track(midi_sequence, part_name, channel)
18
+ def make_midi_track midi_sequence, part_name, channel, ppqn, program
19
+ track = begin_track(midi_sequence, part_name, channel, program)
20
20
 
21
21
  prev_offset = 0
22
22
  @events.each do |offset, event|
@@ -103,19 +103,19 @@ class PartSequencer
103
103
  return dynamic_events
104
104
  end
105
105
 
106
- def begin_track midi_sequence, part_name, channel
106
+ def begin_track midi_sequence, part_name, channel, program
107
107
  # Track to hold part notes
108
108
  track = MIDI::Track.new(midi_sequence)
109
109
 
110
110
  # Name the track and instrument
111
- track.name = part_name.to_s
111
+ track.name = part_name
112
112
  track.instrument = MIDI::GM_PATCH_NAMES[0]
113
113
 
114
114
  # Add a volume controller event (optional).
115
115
  track.events << MIDI::Controller.new(channel, MIDI::CC_VOLUME, 127)
116
116
 
117
117
  # Change to particular instrument sound
118
- track.events << MIDI::ProgramChange.new(channel, 1, 0)
118
+ track.events << MIDI::ProgramChange.new(channel, program)
119
119
 
120
120
  return track
121
121
  end
@@ -7,9 +7,14 @@ class ScoreSequencer
7
7
  score.start_meter.beat_duration)
8
8
  @start_usec_per_qnote = MidiUtil.usec_per_qnote(start_nps)
9
9
  @parts = ScoreCollator.new(score).collate_parts
10
+
11
+ # part names should all be strings, because 1) a midi track name needs to
12
+ # be a string and 2) the instrument map used to map part names to MIDI
13
+ # program numbers will use part name strings as keys.
14
+ @parts = Hash[ @parts.map {|k,v| [k.to_s,v] } ]
10
15
  end
11
16
 
12
- def make_midi_seq
17
+ def make_midi_seq instr_map = {}
13
18
  seq = MIDI::Sequence.new()
14
19
 
15
20
  # first track for the sequence holds time sig and tempo events
@@ -20,8 +25,13 @@ class ScoreSequencer
20
25
 
21
26
  channel = 0
22
27
  @parts.each do |part_name,part|
28
+ program = 1
29
+ if instr_map.has_key?(part_name)
30
+ program = instr_map[part_name]
31
+ end
32
+
23
33
  pseq = PartSequencer.new(part)
24
- seq.tracks << pseq.make_midi_track(seq, part_name, channel, seq.ppqn)
34
+ seq.tracks << pseq.make_midi_track(seq, part_name, channel, seq.ppqn, program)
25
35
  channel += 1
26
36
  end
27
37
 
@@ -2,6 +2,6 @@
2
2
  module Music
3
3
  module Performance
4
4
  # music-performance version
5
- VERSION = "0.3.0"
5
+ VERSION = "0.4.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: music-performance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Tunnell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-30 00:00:00.000000000 Z
11
+ date: 2014-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler