Class: FlatApi::OmrInstrumentOverride

Inherits:
ApiModelBase show all
Defined in:
lib/flat_api/models/omr_instrument_override.rb

Overview

Override for a single detected part, matched by index. Omitted fields keep the detected value. To set the instrument you may use either instrumentId (Flat's instrument id) or midiProgram (a standard General MIDI program) — whichever your integration prefers; you do not need both. If both are sent, instrumentId wins; otherwise midiProgram is resolved to the matching instrument; otherwise the detected instrument is kept. transposeKey and partName apply independently on top.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApiModelBase

_deserialize, #_to_hash, #to_body, #to_s

Constructor Details

#initialize(attributes = {}) ⇒ OmrInstrumentOverride

Initializes the object

Parameters:

  • attributes (Hash) (defaults to: {})

    Model attributes in the form of hash



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/flat_api/models/omr_instrument_override.rb', line 74

def initialize(attributes = {})
  if (!attributes.is_a?(Hash))
    fail ArgumentError, "The input argument (attributes) must be a hash in `FlatApi::OmrInstrumentOverride` initialize method"
  end

  # check to see if the attribute exists and convert string to symbol for hash key
  acceptable_attribute_map = self.class.acceptable_attribute_map
  attributes = attributes.each_with_object({}) { |(k, v), h|
    if (!acceptable_attribute_map.key?(k.to_sym))
      fail ArgumentError, "`#{k}` is not a valid attribute in `FlatApi::OmrInstrumentOverride`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
    end
    h[k.to_sym] = v
  }

  if attributes.key?(:'index')
    self.index = attributes[:'index']
  else
    self.index = nil
  end

  if attributes.key?(:'instrument_id')
    self.instrument_id = attributes[:'instrument_id']
  end

  if attributes.key?(:'part_name')
    self.part_name = attributes[:'part_name']
  end

  if attributes.key?(:'transpose_key')
    self.transpose_key = attributes[:'transpose_key']
  end

  if attributes.key?(:'midi_program')
    self.midi_program = attributes[:'midi_program']
  end
end

Instance Attribute Details

#indexObject

0-based position of the part to override, matching the index of the detected part.



20
21
22
# File 'lib/flat_api/models/omr_instrument_override.rb', line 20

def index
  @index
end

#instrument_idObject

Override the resolved instrument with this Flat instrument id, for example brass.horn. See the Instrument IDs reference for valid values. Both the dotted <group>.<instrument> form (brass.horn) and the bare instrument key (horn) are accepted. Use this or midiProgram. Takes precedence over midiProgram when both are set.



23
24
25
# File 'lib/flat_api/models/omr_instrument_override.rb', line 23

def instrument_id
  @instrument_id
end

#midi_programObject

Override the instrument with a standard General MIDI program number (0-127), resolved server-side to the matching Flat instrument. Use this when you do not want to map Flat instrument ids. Ignored if instrumentId is also set.



32
33
34
# File 'lib/flat_api/models/omr_instrument_override.rb', line 32

def midi_program
  @midi_program
end

#part_nameObject

Override the part name.



26
27
28
# File 'lib/flat_api/models/omr_instrument_override.rb', line 26

def part_name
  @part_name
end

#transpose_keyObject

Override the transposition / written key: a pitch class as a letter A-G with an optional accidental. For example F for Horn in F or Bb for a B flat clarinet. The accidental may be ASCII b (flat) or # (sharp), or the Unicode music glyphs (U+266D) and (U+266F). Unicode accidentals are normalized to their ASCII equivalent, so B♭ is stored and returned as Bb.



29
30
31
# File 'lib/flat_api/models/omr_instrument_override.rb', line 29

def transpose_key
  @transpose_key
end

Class Method Details

.acceptable_attribute_mapObject

Returns attribute mapping this model knows about



46
47
48
# File 'lib/flat_api/models/omr_instrument_override.rb', line 46

def self.acceptable_attribute_map
  attribute_map
end

.acceptable_attributesObject

Returns all the JSON keys this model knows about



51
52
53
# File 'lib/flat_api/models/omr_instrument_override.rb', line 51

def self.acceptable_attributes
  acceptable_attribute_map.values
end

.attribute_mapObject

Attribute mapping from ruby-style variable name to JSON key.



35
36
37
38
39
40
41
42
43
# File 'lib/flat_api/models/omr_instrument_override.rb', line 35

def self.attribute_map
  {
    :'index' => :'index',
    :'instrument_id' => :'instrumentId',
    :'part_name' => :'partName',
    :'transpose_key' => :'transposeKey',
    :'midi_program' => :'midiProgram'
  }
end

.build_from_hash(attributes) ⇒ Object

Builds the object from hash

Parameters:

  • attributes (Hash)

    Model attributes in the form of hash

Returns:

  • (Object)

    Returns the model itself



273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'lib/flat_api/models/omr_instrument_override.rb', line 273

def self.build_from_hash(attributes)
  return nil unless attributes.is_a?(Hash)
  attributes = attributes.transform_keys(&:to_sym)
  transformed_hash = {}
  openapi_types.each_pair do |key, type|
    if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
      transformed_hash["#{key}"] = nil
    elsif type =~ /\AArray<(.*)>/i
      # check to ensure the input is an array given that the attribute
      # is documented as an array but the input is not
      if attributes[attribute_map[key]].is_a?(Array)
        transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
      end
    elsif !attributes[attribute_map[key]].nil?
      transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
    end
  end
  new(transformed_hash)
end

.openapi_nullableObject

List of attributes with nullable: true



67
68
69
70
# File 'lib/flat_api/models/omr_instrument_override.rb', line 67

def self.openapi_nullable
  Set.new([
  ])
end

.openapi_typesObject

Attribute type mapping.



56
57
58
59
60
61
62
63
64
# File 'lib/flat_api/models/omr_instrument_override.rb', line 56

def self.openapi_types
  {
    :'index' => :'Integer',
    :'instrument_id' => :'String',
    :'part_name' => :'String',
    :'transpose_key' => :'String',
    :'midi_program' => :'Integer'
  }
end

Instance Method Details

#==(o) ⇒ Object

Checks equality by comparing each attribute.

Parameters:

  • Object (Object)

    to be compared



248
249
250
251
252
253
254
255
256
# File 'lib/flat_api/models/omr_instrument_override.rb', line 248

def ==(o)
  return true if self.equal?(o)
  self.class == o.class &&
      index == o.index &&
      instrument_id == o.instrument_id &&
      part_name == o.part_name &&
      transpose_key == o.transpose_key &&
      midi_program == o.midi_program
end

#eql?(o) ⇒ Boolean

Parameters:

  • Object (Object)

    to be compared

Returns:

  • (Boolean)

See Also:

  • `==` method


260
261
262
# File 'lib/flat_api/models/omr_instrument_override.rb', line 260

def eql?(o)
  self == o
end

#hashInteger

Calculates hash code according to all attributes.

Returns:

  • (Integer)

    Hash code



266
267
268
# File 'lib/flat_api/models/omr_instrument_override.rb', line 266

def hash
  [index, instrument_id, part_name, transpose_key, midi_program].hash
end

#list_invalid_propertiesObject

Show invalid properties with the reasons. Usually used together with valid?

Returns:

  • Array for valid properties with the reasons



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/flat_api/models/omr_instrument_override.rb', line 113

def list_invalid_properties
  warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
  invalid_properties = Array.new
  if @index.nil?
    invalid_properties.push('invalid value for "index", index cannot be nil.')
  end

  if @index < 0
    invalid_properties.push('invalid value for "index", must be greater than or equal to 0.')
  end

  if !@instrument_id.nil? && @instrument_id.to_s.length > 100
    invalid_properties.push('invalid value for "instrument_id", the character length must be smaller than or equal to 100.')
  end

  if !@instrument_id.nil? && @instrument_id.to_s.length < 1
    invalid_properties.push('invalid value for "instrument_id", the character length must be greater than or equal to 1.')
  end

  if !@part_name.nil? && @part_name.to_s.length > 200
    invalid_properties.push('invalid value for "part_name", the character length must be smaller than or equal to 200.')
  end

  pattern = Regexp.new(/^[A-G][b♭#♯]?$/)
  if !@transpose_key.nil? && @transpose_key !~ pattern
    invalid_properties.push("invalid value for \"transpose_key\", must conform to the pattern #{pattern}.")
  end

  if !@midi_program.nil? && @midi_program > 127
    invalid_properties.push('invalid value for "midi_program", must be smaller than or equal to 127.')
  end

  if !@midi_program.nil? && @midi_program < 0
    invalid_properties.push('invalid value for "midi_program", must be greater than or equal to 0.')
  end

  invalid_properties
end

#to_hashHash

Returns the object in the form of hash

Returns:

  • (Hash)

    Returns the object in the form of hash



295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/flat_api/models/omr_instrument_override.rb', line 295

def to_hash
  hash = {}
  self.class.attribute_map.each_pair do |attr, param|
    value = self.send(attr)
    if value.nil?
      is_nullable = self.class.openapi_nullable.include?(attr)
      next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
    end

    hash[param] = _to_hash(value)
  end
  hash
end

#valid?Boolean

Check to see if the all the properties in the model are valid

Returns:

  • (Boolean)

    true if the model is valid



154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/flat_api/models/omr_instrument_override.rb', line 154

def valid?
  warn '[DEPRECATED] the `valid?` method is obsolete'
  return false if @index.nil?
  return false if @index < 0
  return false if !@instrument_id.nil? && @instrument_id.to_s.length > 100
  return false if !@instrument_id.nil? && @instrument_id.to_s.length < 1
  return false if !@part_name.nil? && @part_name.to_s.length > 200
  return false if !@transpose_key.nil? && @transpose_key !~ Regexp.new(/^[A-G][b♭#♯]?$/)
  return false if !@midi_program.nil? && @midi_program > 127
  return false if !@midi_program.nil? && @midi_program < 0
  true
end