Class: Clef::Midi::Exporter

Inherits:
Object
  • Object
show all
Includes:
MIDI
Defined in:
lib/clef/midi/exporter.rb

Constant Summary collapse

DEFAULT_VELOCITY =
90
DEFAULT_PROGRAM =
1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(score, channel_map: ChannelMap.new, ppqn: 480, instrument_map: {}, plugins: score.plugins || Clef.plugins) ⇒ Exporter

Returns a new instance of Exporter.

Parameters:

Raises:

  • (ArgumentError)


21
22
23
24
25
26
27
28
29
# File 'lib/clef/midi/exporter.rb', line 21

def initialize(score, channel_map: ChannelMap.new, ppqn: 480, instrument_map: {}, plugins: score.plugins || Clef.plugins)
  raise ArgumentError, "ppqn must be a positive Integer" unless ppqn.is_a?(Integer) && ppqn.positive?

  @score = score
  @channel_map = channel_map
  @ppqn = ppqn
  @instrument_map = instrument_map
  @plugins = plugins
end

Instance Attribute Details

#channel_mapObject (readonly)

Returns the value of attribute channel_map.



14
15
16
# File 'lib/clef/midi/exporter.rb', line 14

def channel_map
  @channel_map
end

#instrument_mapObject (readonly)

Returns the value of attribute instrument_map.



14
15
16
# File 'lib/clef/midi/exporter.rb', line 14

def instrument_map
  @instrument_map
end

#pluginsObject (readonly)

Returns the value of attribute plugins.



14
15
16
# File 'lib/clef/midi/exporter.rb', line 14

def plugins
  @plugins
end

#ppqnObject (readonly)

Returns the value of attribute ppqn.



14
15
16
# File 'lib/clef/midi/exporter.rb', line 14

def ppqn
  @ppqn
end

#scoreObject (readonly)

Returns the value of attribute score.



14
15
16
# File 'lib/clef/midi/exporter.rb', line 14

def score
  @score
end

Instance Method Details

#export(target) ⇒ String, #write

Parameters:

  • target (String, #write)

Returns:

  • (String, #write)


33
34
35
36
37
38
# File 'lib/clef/midi/exporter.rb', line 33

def export(target)
  plugins.run_hook(:on_before_midi, self)
  sequence = build_sequence
  write_sequence(sequence, target)
  target
end