midi_create 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f073594e0455e9245c959a92d992d648854ada76fb230ac93aec66cb46f388c3
4
+ data.tar.gz: 75890c0dee74c532168692529c0f45c0ad3695ca96d6afd468ca27b6dc4421f5
5
+ SHA512:
6
+ metadata.gz: eec41bebef091eb62afbf2ef4e0fd575c8b2e497ef01875d69d6164cc61f46d30bf3cd56c09e68409cd78c4b070943fa9932ecb525be5da45963de31024ff3d5
7
+ data.tar.gz: fb3b385defc75010d408cc1356c25f2d031bb89de9b55a77ca6d1b4fdf849fb41b24114f2b7f1940678942cc94c035bc080710bc7b2a35b8406c903be4ce9c7d
data/.rubocop.yml ADDED
@@ -0,0 +1,61 @@
1
+ require:
2
+ - rubocop-md
3
+ - rubocop-performance
4
+ - rubocop-rake
5
+
6
+ AllCops:
7
+ Exclude:
8
+ - binstub/**/*
9
+ - exe/**/*
10
+ - vendor/**/*
11
+ - Gemfile*
12
+ NewCops: enable
13
+
14
+ Gemspec/DeprecatedAttributeAssignment:
15
+ Enabled: false
16
+
17
+ Gemspec/RequireMFA:
18
+ Enabled: false
19
+
20
+ Gemspec/RequiredRubyVersion:
21
+ Enabled: false
22
+
23
+ Layout/HashAlignment:
24
+ EnforcedColonStyle: table
25
+ EnforcedHashRocketStyle: table
26
+
27
+ Layout/LineLength:
28
+ Max: 150
29
+
30
+ Metrics/AbcSize:
31
+ Max: 35
32
+
33
+ Metrics/BlockLength:
34
+ Exclude:
35
+ - midi_create.gemspec
36
+ Max: 30
37
+
38
+ Metrics/CyclomaticComplexity:
39
+ Max: 15
40
+
41
+ Metrics/MethodLength:
42
+ Max: 40
43
+
44
+ Metrics/ModuleLength:
45
+ Enabled: false
46
+
47
+ Metrics/PerceivedComplexity:
48
+ Max: 15
49
+
50
+ Naming/FileName:
51
+ Exclude:
52
+ - Rakefile
53
+
54
+ Style/Documentation:
55
+ Enabled: false
56
+
57
+ Style/FrozenStringLiteralComment:
58
+ Enabled: false
59
+
60
+ Style/TrailingCommaInHashLiteral:
61
+ EnforcedStyleForMultiline: comma
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Change Log
2
+
3
+ ## 0.1.0
4
+
5
+ * Initial release.
data/README.md ADDED
@@ -0,0 +1,136 @@
1
+ # `Midi_create` [![Gem Version](https://badge.fury.io/rb/midi_create.svg)](https://badge.fury.io/rb/midi_create)
2
+
3
+ Creates a format 1 (multitrack) MIDI file with one track, defaulting to 120 BPM.
4
+ The generated MIDI file will contain 8 notes in the C major scale, starting at middle C.
5
+ Pro Tools and Ableton Live will not import a MIDI file unless it contains at least one note.
6
+
7
+
8
+ ## About Middle C
9
+
10
+ In Pro Tools and Ableton, middle C is known as C3.
11
+ [See a discussion about middle C](https://stackoverflow.com/a/69182634/553865),
12
+ [and this article](https://studiocode.dev/resources/midi-middle-c/).
13
+
14
+
15
+ ## Installation
16
+
17
+ Set up Ruby [(here is how)](https://www.mslinn.com/ruby/1000-ruby-setup.html),
18
+ then type the following at a shell prompt:
19
+
20
+ ```shell
21
+ $ gem install midi_create
22
+ ```
23
+
24
+ If you are running `rbenv` (and you should, according to the instructions mentioned above), type:
25
+
26
+ ```shell
27
+ $ rbenv rehash
28
+ ```
29
+
30
+
31
+ ## Help Message
32
+
33
+ ```text
34
+ $ midi_create -h
35
+ midi_create: Creates a MIDI file containing an 8-note scale in the key of C,
36
+ starting at middle C (C3 in Pro Tools and Ableton Live).
37
+
38
+ Syntax: midi_create [Options] PATH_TO_MIDI_FILE
39
+
40
+ Options:
41
+ -b 120 Specify beats per minute (BPM); default is 120 bpm.
42
+ Only integers can be used; a decimal point will cause an error.
43
+ -f Overwrite the output file if present
44
+ -t NAME Use this title for the track
45
+ -h Show this help message
46
+ ```
47
+
48
+
49
+ ## Sample Usage
50
+
51
+ Create a MIDI type 1 file called `filename.mid` with one track in the current directory, without a title.
52
+ Fail if the file already exists.
53
+ Include an 8-note scale in the key of C starting at middle C (C3).
54
+
55
+ ```shell
56
+ $ midi_create filename.mid
57
+ ```
58
+
59
+
60
+ Like the previous example, but overwrite `filename.mid` if it already exists.
61
+
62
+ ```shell
63
+ $ midi_create -f filename.mid
64
+ ```
65
+
66
+
67
+ Like the previous example, plus include the title `Test MIDI clip` for the track.
68
+ Ableton Live and Pro Tools ignore the MIDI track title, but Guitar Pro uses it.
69
+
70
+ ```shell
71
+ $ midi_create -ft 'Test MIDI clip' filename.mid
72
+ ```
73
+
74
+
75
+ Like the previous example, plus set BPM to 150.
76
+ BPM can only be specified as an integer; using a decimal point will cause an error.
77
+
78
+ ```shell
79
+ $ midi_create -b 150 -ft 'Test MIDI clip' filename.mid
80
+ ```
81
+
82
+
83
+ ## Development
84
+
85
+ After checking out this git repository, install dependencies by typing:
86
+
87
+ ```shell
88
+ $ bin/setup
89
+ ```
90
+
91
+ You should do the above before running Visual Studio Code.
92
+
93
+
94
+ ### Run the Tests
95
+
96
+ ```shell
97
+ $ bundle exec rake test
98
+ ```
99
+
100
+
101
+ ### Interactive Session
102
+
103
+ The following will allow you to experiment:
104
+
105
+ ```shell
106
+ $ bin/console
107
+ ```
108
+
109
+
110
+ ### Local Installation
111
+
112
+ To install this gem onto your local machine, type:
113
+
114
+ ```shell
115
+ $ bundle exec rake install
116
+ ```
117
+
118
+
119
+ ### To Release A New Version
120
+
121
+ To create a git tag for the new version, push git commits and tags,
122
+ and push the new version of the gem to https://rubygems.org, type:
123
+
124
+ ```shell
125
+ $ bundle exec rake release
126
+ ```
127
+
128
+
129
+ ## Contributing
130
+
131
+ Bug reports and pull requests are welcome at https://github.com/mslinn/midi_create.
132
+
133
+
134
+ ## License
135
+
136
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,40 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ desc 'Bump patch version'
11
+ task :patch do
12
+ system 'gem bump --tag'
13
+ end
14
+
15
+ desc 'Bump minor version'
16
+ task :minor do
17
+ system 'gem bump --version minor --tag'
18
+ end
19
+
20
+ desc 'Bump major version'
21
+ task :major do
22
+ system 'gem bump --version major --tag'
23
+ end
24
+
25
+ task publish: [:build] do
26
+ $VERBOSE = nil
27
+ load 'midi_create/version.rb'
28
+ system "gem push pkg/midi_create-#{MidiCreate::VERSION}.gem"
29
+ end
30
+
31
+ desc 'Bump patch version, create git tag, build the gem and release to geminabox (default)'
32
+ task release_patch: %i[test patch publish]
33
+
34
+ desc 'Bump minor version, create git tag, build the gem and release to geminabox'
35
+ task release_minor: %i[test minor publish]
36
+
37
+ desc 'Bump major version, create git tag, build the gem and release to geminabox'
38
+ task release_major: %i[test major publish]
39
+
40
+ task default: :test
data/exe/midi_create ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ if ENV['VO_DEBUGGING']
4
+ require_relative '../lib/midi_create'
5
+ else
6
+ require 'midi_create'
7
+ end
@@ -0,0 +1,56 @@
1
+ require 'midilib'
2
+
3
+ module MidiCreate
4
+ include MIDI
5
+
6
+ def self.main
7
+ @options = parse_options
8
+ help 'The name of the output MIDI file must be provided.' if ARGV.empty?
9
+ help "Too many parameters were specified.\n#{ARGV}" if ARGV.length > 1
10
+
11
+ @midi_out = ARGV[0]
12
+ if File.exist?(@midi_out)
13
+ if @options[:overwrite]
14
+ File.delete(@midi_out)
15
+ else
16
+ help "Error: File '#{@midi_out}' already exists and -f was not specified."
17
+ end
18
+ end
19
+ create
20
+ end
21
+
22
+ def self.create
23
+ seq = MIDI::Sequence.new # Create a new empty MIDI sequence.
24
+
25
+ # Create a first track for the MIDI sequence. This holds tempo events and other data.
26
+ track = Track.new(seq)
27
+ seq.tracks << track
28
+ track.events << Tempo.new(Tempo.bpm_to_mpq(@options[:bpm]))
29
+ track.events << MetaEvent.new(META_SEQ_NAME, @options[:title]) if @options[:title]
30
+
31
+ # Create a track to hold the notes and add it to the MIDI sequence.
32
+ track = Track.new(seq)
33
+ seq.tracks << track
34
+
35
+ # Add note events to the track, corresponding to the C major scale, from C3 to C4, inclusive.
36
+ # Arguments for note on and note off constructors are channel, note, velocity, and delta_time.
37
+ # Channel numbers start at zero.
38
+ # The Sequence#note_to_delta method returns the delta time length of a single quarter note.
39
+ track.events << ProgramChange.new(0, 1, 0)
40
+ quarter_note_length = seq.note_to_delta('quarter')
41
+
42
+ # There is probably a more elegant way of specifying middle C,
43
+ # which shows as C3 in Pro Tools and Ableton Live.
44
+ # See https://studiocode.dev/resources/midi-middle-c/
45
+ # See https://stackoverflow.com/a/69182634/553865
46
+ c3 = 60
47
+
48
+ [0, 2, 4, 5, 7, 9, 11, 12].each do |offset|
49
+ track.events << NoteOn.new(0, c3 + offset, 127, 0)
50
+ track.events << NoteOff.new(0, c3 + offset, 127, quarter_note_length)
51
+ end
52
+
53
+ # Write the sequence to a MIDI file.
54
+ File.open(@midi_out, 'wb') { |file| seq.write(file) }
55
+ end
56
+ end
@@ -0,0 +1,37 @@
1
+ require 'colorator'
2
+ require 'optparse'
3
+
4
+ def help(msg = nil)
5
+ printf "Error: #{msg}\n\n".yellow unless msg.nil?
6
+ msg = <<~END_HELP
7
+ midi_create: Creates a MIDI file containing an 8-note scale in the key of C,
8
+ starting at middle C (C3 in Pro Tools and Ableton Live).
9
+
10
+ Syntax: midi_create [Options] PATH_TO_MIDI_FILE
11
+
12
+ Options:
13
+ -b 120 Specify beats per minute (BPM); default is 120 bpm.
14
+ Only integers can be used; a decimal point will cause an error.
15
+ -f Overwrite the output file if present
16
+ -t NAME Use this title for the track
17
+ -h Show this help message
18
+ END_HELP
19
+ printf msg.cyan
20
+ exit 1
21
+ end
22
+
23
+ def parse_options
24
+ options = { bpm: 120, overwrite: false }
25
+ OptionParser.new do |parser|
26
+ parser.program_name = File.basename __FILE__
27
+ @parser = parser
28
+
29
+ parser.on('-b', '--bpm BPM', OptionParser::DecimalInteger, 'Specify BPM (default is 120 bpm)')
30
+ parser.on('-f', '--overwrite', 'Overwrite output MIDI file if present')
31
+ parser.on('-t', '--title TITLE', 'Generate title')
32
+ parser.on_tail('-h', '--help', 'Show this message') do
33
+ help
34
+ end
35
+ end.order!(into: options)
36
+ options
37
+ end
@@ -0,0 +1,3 @@
1
+ module MidiCreate
2
+ VERSION = '0.1.0'.freeze unless defined? VERSION
3
+ end
@@ -0,0 +1,8 @@
1
+ require 'colorator'
2
+
3
+ # Require all Ruby files in 'lib/', except this file
4
+ Dir[File.join("#{__dir__}/midi_create", '*.rb')].sort.each do |file|
5
+ require file
6
+ end
7
+
8
+ MidiCreate.main
@@ -0,0 +1,38 @@
1
+ require_relative 'lib/midi_create/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ host = 'https://github.com/mslinn/midi_create'
5
+
6
+ spec.authors = ['Mike Slinn']
7
+ spec.bindir = 'exe'
8
+ spec.executables = %w[midi_create]
9
+ spec.description = <<~END_DESC
10
+ Write a longer description of the gem.
11
+ Use as many lines as you like.
12
+ END_DESC
13
+ spec.email = ['mslinn@mslinn.com']
14
+ spec.files = Dir['.rubocop.yml', 'LICENSE.*', 'Rakefile', '{lib,spec}/**/*', '*.gemspec', '*.md']
15
+ spec.homepage = 'https://mslinn.com/av_studio/705-midi-create.html'
16
+ spec.license = 'MIT'
17
+ spec.metadata = {
18
+ 'allowed_push_host' => 'https://rubygems.org',
19
+ 'bug_tracker_uri' => "#{host}/issues",
20
+ 'changelog_uri' => "#{host}/CHANGELOG.md",
21
+ 'homepage_uri' => spec.homepage,
22
+ 'source_code_uri' => host,
23
+ }
24
+ spec.name = 'midi_create'
25
+ spec.post_install_message = <<~END_MESSAGE
26
+
27
+ Thanks for installing #{spec.name}!
28
+
29
+ END_MESSAGE
30
+ spec.require_paths = ['lib']
31
+ spec.required_ruby_version = '>= 2.6.0'
32
+ spec.summary = 'Creates an empty MIDI file'
33
+ spec.version = MidiCreate::VERSION
34
+
35
+ spec.add_dependency 'colorator'
36
+ spec.add_dependency 'midilib'
37
+ spec.add_dependency 'optparse'
38
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: midi_create
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mike Slinn
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-10-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorator
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: midilib
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: optparse
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: |
56
+ Write a longer description of the gem.
57
+ Use as many lines as you like.
58
+ email:
59
+ - mslinn@mslinn.com
60
+ executables:
61
+ - midi_create
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - ".rubocop.yml"
66
+ - CHANGELOG.md
67
+ - README.md
68
+ - Rakefile
69
+ - exe/midi_create
70
+ - lib/midi_create.rb
71
+ - lib/midi_create/create.rb
72
+ - lib/midi_create/options.rb
73
+ - lib/midi_create/version.rb
74
+ - midi_create.gemspec
75
+ homepage: https://mslinn.com/av_studio/705-midi-create.html
76
+ licenses:
77
+ - MIT
78
+ metadata:
79
+ allowed_push_host: https://rubygems.org
80
+ bug_tracker_uri: https://github.com/mslinn/midi_create/issues
81
+ changelog_uri: https://github.com/mslinn/midi_create/CHANGELOG.md
82
+ homepage_uri: https://mslinn.com/av_studio/705-midi-create.html
83
+ source_code_uri: https://github.com/mslinn/midi_create
84
+ post_install_message: |2+
85
+
86
+ Thanks for installing midi_create!
87
+
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: 2.6.0
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubygems_version: 3.5.17
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: Creates an empty MIDI file
106
+ test_files: []
107
+ ...