filtermidi 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.
- checksums.yaml +7 -0
- data/bin/filtermidi +103 -0
- metadata +59 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3caff2487933e217eb302677e7a4117f616a44b3
|
4
|
+
data.tar.gz: 867142bce9862deaccad7235c4076f86fb36fd28
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 34eff7bed675c947ba8e5b9bcb72f31aeea9ca577d998fc5c1eb7fbfb16c848b5519963e45485e78c20c0fd420f5932e3ce541de04fb744409a747deb11224cb
|
7
|
+
data.tar.gz: 9f92c97cc7da245b8f9ab4ab068c11a2e8c630e438a0588faa43dbd11f4676698394fde2b21792f9ecf1f4f2482651ffca2c143fa22ff6f190c503527946a6a8
|
data/bin/filtermidi
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'optparse'
|
3
|
+
require 'midilib'
|
4
|
+
require 'midilib/io/seqreader'
|
5
|
+
require 'midilib/io/seqwriter'
|
6
|
+
|
7
|
+
options = {}
|
8
|
+
|
9
|
+
optparse = OptionParser.new do |opts|
|
10
|
+
opts.banner = "Usage: #{__FILE__} [options]"
|
11
|
+
|
12
|
+
opts.on('-i', '--input FILE_OR_DIR', 'Input file or directory (required)') do |file_or_dir|
|
13
|
+
options[:input] = file_or_dir
|
14
|
+
end
|
15
|
+
|
16
|
+
opts.on('-o', '--output FILE_OR_DIR', 'Output file or directory (required) -- dir will be created if it doesn\'t exist') do |file_or_dir|
|
17
|
+
options[:output] = file_or_dir
|
18
|
+
end
|
19
|
+
|
20
|
+
opts.on('-p', '--program-change', 'Filter Program Change (PC) events') do
|
21
|
+
options[:pc] = true
|
22
|
+
end
|
23
|
+
|
24
|
+
opts.on('-c', '--control-change', 'Filter Control Change (CC) events') do
|
25
|
+
options[:cc] = true
|
26
|
+
end
|
27
|
+
|
28
|
+
opts.on('-h', '--help', 'Display this screen') do
|
29
|
+
puts opts
|
30
|
+
exit
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
optparse.parse!
|
35
|
+
|
36
|
+
if !options[:input]
|
37
|
+
puts 'Input file or directory (-i / --input) not specified (required)'
|
38
|
+
exit 1
|
39
|
+
end
|
40
|
+
|
41
|
+
if !File.exist?(options[:input]) && !File.directory?(options[:input])
|
42
|
+
puts 'Input file or directory does not exist'
|
43
|
+
exit 1
|
44
|
+
end
|
45
|
+
|
46
|
+
if !options[:output]
|
47
|
+
puts 'Output file or directory (-o / --output) not specified (required)'
|
48
|
+
exit 1
|
49
|
+
end
|
50
|
+
|
51
|
+
if !options[:cc] && !options[:pc]
|
52
|
+
puts 'At least one of -cc / -pc is required'
|
53
|
+
exit 1
|
54
|
+
end
|
55
|
+
|
56
|
+
if File.directory?(options[:input])
|
57
|
+
input_files = Dir.glob(File.join(options[:input], '*.{mid,midi}'))
|
58
|
+
|
59
|
+
if !File.directory?(options[:output])
|
60
|
+
Dir.mkdir(options[:output])
|
61
|
+
end
|
62
|
+
|
63
|
+
output_files = input_files.map do |input_file|
|
64
|
+
File.join(options[:output], File.basename(input_file))
|
65
|
+
end
|
66
|
+
else
|
67
|
+
input_files = [options[:input]]
|
68
|
+
|
69
|
+
if File.directory?(options[:output])
|
70
|
+
output_files = [File.join(options[:output], File.basename(options[:input]))]
|
71
|
+
else
|
72
|
+
output_files = [options[:output]]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
input_files.each_with_index do |input_file, index|
|
77
|
+
output_file = output_files[index]
|
78
|
+
|
79
|
+
types_of_events = []
|
80
|
+
types_of_events << 'CC' if options[:cc]
|
81
|
+
types_of_events << 'PC' if options[:pc]
|
82
|
+
puts "Filtering #{types_of_events.join(', ')} events for #{input_file} => #{output_file}"
|
83
|
+
|
84
|
+
seq = MIDI::Sequence.new()
|
85
|
+
|
86
|
+
File.open(input_file, 'rb') do |file|
|
87
|
+
seq.read(file)
|
88
|
+
end
|
89
|
+
|
90
|
+
seq.each_with_index do |track, index|
|
91
|
+
events = track.select do |event|
|
92
|
+
!((event.kind_of?(MIDI::ProgramChange) && options[:pc]) ||
|
93
|
+
(event.kind_of?(MIDI::Controller) && options[:cc]))
|
94
|
+
end
|
95
|
+
|
96
|
+
track.events = events
|
97
|
+
track.recalc_times
|
98
|
+
end
|
99
|
+
|
100
|
+
File.open(output_file, 'wb') do |file|
|
101
|
+
seq.write(file)
|
102
|
+
end
|
103
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: filtermidi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joey Robert
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: midilib
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
description: Filter Program Change (PC) or Control Change (CC) events from MIDI files.
|
28
|
+
email: joey@joeyrobert.org
|
29
|
+
executables:
|
30
|
+
- filtermidi
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- bin/filtermidi
|
35
|
+
homepage: http://rubygems.org/gems/filtermidi
|
36
|
+
licenses:
|
37
|
+
- MIT
|
38
|
+
metadata: {}
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 2.4.8
|
56
|
+
signing_key:
|
57
|
+
specification_version: 4
|
58
|
+
summary: filtermidi
|
59
|
+
test_files: []
|