Module: Chordsketch

Defined in:
lib/chordsketch.rb,
lib/chordsketch_uniffi.rb

Overview

Detect the platform and pre-load the correct native library before requiring the UniFFI-generated bindings.

Defined Under Namespace

Modules: ChordSketchError, NativeLoader Classes: ConversionWithWarnings, InternalError, PdfRenderWithWarnings, RustBuffer, TextRenderWithWarnings, ValidationError

Class Method Summary collapse

Class Method Details

.chord_diagram_svg(chord, instrument) ⇒ Object



1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
# File 'lib/chordsketch_uniffi.rb', line 1026

def self.chord_diagram_svg(chord, instrument)
    chord = Chordsketch::uniffi_utf8(chord)
    
    
    instrument = Chordsketch::uniffi_utf8(instrument)
    
    
  result = Chordsketch.rust_call_with_error(ChordSketchError,:uniffi_chordsketch_ffi_fn_func_chord_diagram_svg,RustBuffer.allocFromString(chord),RustBuffer.allocFromString(instrument))
  return result.consumeIntoOptionalstring
end

.convert_chordpro_to_irealb(input) ⇒ Object



1041
1042
1043
1044
1045
1046
1047
# File 'lib/chordsketch_uniffi.rb', line 1041

def self.convert_chordpro_to_irealb(input)
    input = Chordsketch::uniffi_utf8(input)
    
    
  result = Chordsketch.rust_call_with_error(ChordSketchError,:uniffi_chordsketch_ffi_fn_func_convert_chordpro_to_irealb,RustBuffer.allocFromString(input))
  return result.consumeIntoTypeConversionWithWarnings
end

.convert_irealb_to_chordpro_text(input) ⇒ Object



1053
1054
1055
1056
1057
1058
1059
# File 'lib/chordsketch_uniffi.rb', line 1053

def self.convert_irealb_to_chordpro_text(input)
    input = Chordsketch::uniffi_utf8(input)
    
    
  result = Chordsketch.rust_call_with_error(ChordSketchError,:uniffi_chordsketch_ffi_fn_func_convert_irealb_to_chordpro_text,RustBuffer.allocFromString(input))
  return result.consumeIntoTypeConversionWithWarnings
end

.parse_and_render_html(input, config_json, transpose) ⇒ Object



1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
# File 'lib/chordsketch_uniffi.rb', line 1065

def self.parse_and_render_html(input, config_json, transpose)
    input = Chordsketch::uniffi_utf8(input)
    
    
    config_json = (config_json ? Chordsketch::uniffi_utf8(config_json) : nil)
    RustBuffer.check_lower_Optionalstring(config_json)
    
    transpose = (transpose ? Chordsketch::uniffi_in_range(transpose, "i8", -2**7, 2**7) : nil)
    RustBuffer.check_lower_Optionali8(transpose)
    
  result = Chordsketch.rust_call_with_error(ChordSketchError,:uniffi_chordsketch_ffi_fn_func_parse_and_render_html,RustBuffer.allocFromString(input),RustBuffer.alloc_from_Optionalstring(config_json),RustBuffer.alloc_from_Optionali8(transpose))
  return result.consumeIntoString
end

.parse_and_render_html_body(input, config_json, transpose) ⇒ Object



1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
# File 'lib/chordsketch_uniffi.rb', line 1083

def self.parse_and_render_html_body(input, config_json, transpose)
    input = Chordsketch::uniffi_utf8(input)
    
    
    config_json = (config_json ? Chordsketch::uniffi_utf8(config_json) : nil)
    RustBuffer.check_lower_Optionalstring(config_json)
    
    transpose = (transpose ? Chordsketch::uniffi_in_range(transpose, "i8", -2**7, 2**7) : nil)
    RustBuffer.check_lower_Optionali8(transpose)
    
  result = Chordsketch.rust_call_with_error(ChordSketchError,:uniffi_chordsketch_ffi_fn_func_parse_and_render_html_body,RustBuffer.allocFromString(input),RustBuffer.alloc_from_Optionalstring(config_json),RustBuffer.alloc_from_Optionali8(transpose))
  return result.consumeIntoString
end

.parse_and_render_html_body_with_warnings(input, config_json, transpose) ⇒ Object



1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
# File 'lib/chordsketch_uniffi.rb', line 1101

def self.parse_and_render_html_body_with_warnings(input, config_json, transpose)
    input = Chordsketch::uniffi_utf8(input)
    
    
    config_json = (config_json ? Chordsketch::uniffi_utf8(config_json) : nil)
    RustBuffer.check_lower_Optionalstring(config_json)
    
    transpose = (transpose ? Chordsketch::uniffi_in_range(transpose, "i8", -2**7, 2**7) : nil)
    RustBuffer.check_lower_Optionali8(transpose)
    
  result = Chordsketch.rust_call_with_error(ChordSketchError,:uniffi_chordsketch_ffi_fn_func_parse_and_render_html_body_with_warnings,RustBuffer.allocFromString(input),RustBuffer.alloc_from_Optionalstring(config_json),RustBuffer.alloc_from_Optionali8(transpose))
  return result.consumeIntoTypeTextRenderWithWarnings
end

.parse_and_render_html_with_warnings(input, config_json, transpose) ⇒ Object



1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
# File 'lib/chordsketch_uniffi.rb', line 1119

def self.parse_and_render_html_with_warnings(input, config_json, transpose)
    input = Chordsketch::uniffi_utf8(input)
    
    
    config_json = (config_json ? Chordsketch::uniffi_utf8(config_json) : nil)
    RustBuffer.check_lower_Optionalstring(config_json)
    
    transpose = (transpose ? Chordsketch::uniffi_in_range(transpose, "i8", -2**7, 2**7) : nil)
    RustBuffer.check_lower_Optionali8(transpose)
    
  result = Chordsketch.rust_call_with_error(ChordSketchError,:uniffi_chordsketch_ffi_fn_func_parse_and_render_html_with_warnings,RustBuffer.allocFromString(input),RustBuffer.alloc_from_Optionalstring(config_json),RustBuffer.alloc_from_Optionali8(transpose))
  return result.consumeIntoTypeTextRenderWithWarnings
end

.parse_and_render_pdf(input, config_json, transpose) ⇒ Object



1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
# File 'lib/chordsketch_uniffi.rb', line 1137

def self.parse_and_render_pdf(input, config_json, transpose)
    input = Chordsketch::uniffi_utf8(input)
    
    
    config_json = (config_json ? Chordsketch::uniffi_utf8(config_json) : nil)
    RustBuffer.check_lower_Optionalstring(config_json)
    
    transpose = (transpose ? Chordsketch::uniffi_in_range(transpose, "i8", -2**7, 2**7) : nil)
    RustBuffer.check_lower_Optionali8(transpose)
    
  result = Chordsketch.rust_call_with_error(ChordSketchError,:uniffi_chordsketch_ffi_fn_func_parse_and_render_pdf,RustBuffer.allocFromString(input),RustBuffer.alloc_from_Optionalstring(config_json),RustBuffer.alloc_from_Optionali8(transpose))
  return result.consumeIntoBytes
end

.parse_and_render_pdf_with_warnings(input, config_json, transpose) ⇒ Object



1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
# File 'lib/chordsketch_uniffi.rb', line 1155

def self.parse_and_render_pdf_with_warnings(input, config_json, transpose)
    input = Chordsketch::uniffi_utf8(input)
    
    
    config_json = (config_json ? Chordsketch::uniffi_utf8(config_json) : nil)
    RustBuffer.check_lower_Optionalstring(config_json)
    
    transpose = (transpose ? Chordsketch::uniffi_in_range(transpose, "i8", -2**7, 2**7) : nil)
    RustBuffer.check_lower_Optionali8(transpose)
    
  result = Chordsketch.rust_call_with_error(ChordSketchError,:uniffi_chordsketch_ffi_fn_func_parse_and_render_pdf_with_warnings,RustBuffer.allocFromString(input),RustBuffer.alloc_from_Optionalstring(config_json),RustBuffer.alloc_from_Optionali8(transpose))
  return result.consumeIntoTypePdfRenderWithWarnings
end

.parse_and_render_text(input, config_json, transpose) ⇒ Object



1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
# File 'lib/chordsketch_uniffi.rb', line 1173

def self.parse_and_render_text(input, config_json, transpose)
    input = Chordsketch::uniffi_utf8(input)
    
    
    config_json = (config_json ? Chordsketch::uniffi_utf8(config_json) : nil)
    RustBuffer.check_lower_Optionalstring(config_json)
    
    transpose = (transpose ? Chordsketch::uniffi_in_range(transpose, "i8", -2**7, 2**7) : nil)
    RustBuffer.check_lower_Optionali8(transpose)
    
  result = Chordsketch.rust_call_with_error(ChordSketchError,:uniffi_chordsketch_ffi_fn_func_parse_and_render_text,RustBuffer.allocFromString(input),RustBuffer.alloc_from_Optionalstring(config_json),RustBuffer.alloc_from_Optionali8(transpose))
  return result.consumeIntoString
end

.parse_and_render_text_with_warnings(input, config_json, transpose) ⇒ Object



1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
# File 'lib/chordsketch_uniffi.rb', line 1191

def self.parse_and_render_text_with_warnings(input, config_json, transpose)
    input = Chordsketch::uniffi_utf8(input)
    
    
    config_json = (config_json ? Chordsketch::uniffi_utf8(config_json) : nil)
    RustBuffer.check_lower_Optionalstring(config_json)
    
    transpose = (transpose ? Chordsketch::uniffi_in_range(transpose, "i8", -2**7, 2**7) : nil)
    RustBuffer.check_lower_Optionali8(transpose)
    
  result = Chordsketch.rust_call_with_error(ChordSketchError,:uniffi_chordsketch_ffi_fn_func_parse_and_render_text_with_warnings,RustBuffer.allocFromString(input),RustBuffer.alloc_from_Optionalstring(config_json),RustBuffer.alloc_from_Optionali8(transpose))
  return result.consumeIntoTypeTextRenderWithWarnings
end

.parse_irealb(input) ⇒ Object



1209
1210
1211
1212
1213
1214
1215
# File 'lib/chordsketch_uniffi.rb', line 1209

def self.parse_irealb(input)
    input = Chordsketch::uniffi_utf8(input)
    
    
  result = Chordsketch.rust_call_with_error(ChordSketchError,:uniffi_chordsketch_ffi_fn_func_parse_irealb,RustBuffer.allocFromString(input))
  return result.consumeIntoString
end

.render_html_cssObject



1221
1222
1223
1224
# File 'lib/chordsketch_uniffi.rb', line 1221

def self.render_html_css()
  result = Chordsketch.rust_call(:uniffi_chordsketch_ffi_fn_func_render_html_css,)
  return result.consumeIntoString
end

.render_html_css_with_config_json(config_json) ⇒ Object



1230
1231
1232
1233
1234
1235
1236
# File 'lib/chordsketch_uniffi.rb', line 1230

def self.render_html_css_with_config_json(config_json)
    config_json = (config_json ? Chordsketch::uniffi_utf8(config_json) : nil)
    RustBuffer.check_lower_Optionalstring(config_json)
    
  result = Chordsketch.rust_call_with_error(ChordSketchError,:uniffi_chordsketch_ffi_fn_func_render_html_css_with_config_json,RustBuffer.alloc_from_Optionalstring(config_json))
  return result.consumeIntoString
end

.render_ireal_pdf(input) ⇒ Object



1242
1243
1244
1245
1246
1247
1248
# File 'lib/chordsketch_uniffi.rb', line 1242

def self.render_ireal_pdf(input)
    input = Chordsketch::uniffi_utf8(input)
    
    
  result = Chordsketch.rust_call_with_error(ChordSketchError,:uniffi_chordsketch_ffi_fn_func_render_ireal_pdf,RustBuffer.allocFromString(input))
  return result.consumeIntoBytes
end

.render_ireal_png(input) ⇒ Object



1254
1255
1256
1257
1258
1259
1260
# File 'lib/chordsketch_uniffi.rb', line 1254

def self.render_ireal_png(input)
    input = Chordsketch::uniffi_utf8(input)
    
    
  result = Chordsketch.rust_call_with_error(ChordSketchError,:uniffi_chordsketch_ffi_fn_func_render_ireal_png,RustBuffer.allocFromString(input))
  return result.consumeIntoBytes
end

.render_ireal_svg(input) ⇒ Object



1266
1267
1268
1269
1270
1271
1272
# File 'lib/chordsketch_uniffi.rb', line 1266

def self.render_ireal_svg(input)
    input = Chordsketch::uniffi_utf8(input)
    
    
  result = Chordsketch.rust_call_with_error(ChordSketchError,:uniffi_chordsketch_ffi_fn_func_render_ireal_svg,RustBuffer.allocFromString(input))
  return result.consumeIntoString
end

.rust_call(fn_name, *args) ⇒ Object



738
739
740
741
# File 'lib/chordsketch_uniffi.rb', line 738

def self.rust_call(fn_name, *args)
  # Call a rust function
  rust_call_with_error(nil, fn_name, *args)
end

.rust_call_with_error(error_module, fn_name, *args) ⇒ Object



743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
# File 'lib/chordsketch_uniffi.rb', line 743

def self.rust_call_with_error(error_module, fn_name, *args)
  # Call a rust function and handle errors
  #
  # Use this when the rust function returns a Result<>.  error_module must be the error_module that corresponds to that Result.


  # Note: RustCallStatus.new zeroes out the struct, which is exactly what we
  # want to pass to Rust (code=0, error_buf=RustBuffer(len=0, capacity=0,
  # data=NULL))
  status = RustCallStatus.new
  args << status

  result = UniFFILib.public_send(fn_name, *args)

  case status.code
  when CALL_SUCCESS
    result
  when CALL_ERROR
    if error_module.nil?
      status.error_buf.free
      raise InternalError, "CALL_ERROR with no error_module set"
    else
      raise consume_buffer_into_error(error_module, status.error_buf)
    end
  when CALL_PANIC
    # When the rust code sees a panic, it tries to construct a RustBuffer
    # with the message.  But if that code panics, then it just sends back
    # an empty buffer.
    if status.error_buf.len > 0
      raise InternalError, status.error_buf.consumeIntoString()
    else
      raise InternalError, "Rust panic"
    end
  else
    raise InternalError, "Unknown call status: #{status.code}"
  end
end

.serialize_irealb(input) ⇒ Object



1278
1279
1280
1281
1282
1283
1284
# File 'lib/chordsketch_uniffi.rb', line 1278

def self.serialize_irealb(input)
    input = Chordsketch::uniffi_utf8(input)
    
    
  result = Chordsketch.rust_call_with_error(ChordSketchError,:uniffi_chordsketch_ffi_fn_func_serialize_irealb,RustBuffer.allocFromString(input))
  return result.consumeIntoString
end

.uniffi_bytes(v) ⇒ Object

Raises:

  • (TypeError)


34
35
36
37
# File 'lib/chordsketch_uniffi.rb', line 34

def self.uniffi_bytes(v)
  raise TypeError, "no implicit conversion of #{v} into String" unless v.respond_to?(:to_str)
  v.to_str
end

.uniffi_in_range(i, type_name, min, max) ⇒ Object

Raises:

  • (TypeError)


20
21
22
23
24
25
# File 'lib/chordsketch_uniffi.rb', line 20

def self.uniffi_in_range(i, type_name, min, max)
  raise TypeError, "no implicit conversion of #{i} into Integer" unless i.respond_to?(:to_int)
  i = i.to_int
  raise RangeError, "#{type_name} requires #{min} <= value < #{max}" unless (min <= i && i < max)
  i
end

.uniffi_utf8(v) ⇒ Object

Raises:

  • (TypeError)


27
28
29
30
31
32
# File 'lib/chordsketch_uniffi.rb', line 27

def self.uniffi_utf8(v)
  raise TypeError, "no implicit conversion of #{v} into String" unless v.respond_to?(:to_str)
  v = v.to_str.encode(Encoding::UTF_8)
  raise Encoding::InvalidByteSequenceError, "not a valid UTF-8 encoded string" unless v.valid_encoding?
  v
end

.validate(input) ⇒ Object



1290
1291
1292
1293
1294
1295
1296
# File 'lib/chordsketch_uniffi.rb', line 1290

def self.validate(input)
    input = Chordsketch::uniffi_utf8(input)
    
    
  result = Chordsketch.rust_call(:uniffi_chordsketch_ffi_fn_func_validate,RustBuffer.allocFromString(input))
  return result.consumeIntoSequenceTypeValidationError
end

.versionObject



1302
1303
1304
1305
# File 'lib/chordsketch_uniffi.rb', line 1302

def self.version()
  result = Chordsketch.rust_call(:uniffi_chordsketch_ffi_fn_func_version,)
  return result.consumeIntoString
end