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: ChordDefine, ConversionWithWarnings, InternalError, PdfRenderWithWarnings, RustBuffer, TextRenderWithWarnings, ValidationError

Class Method Summary collapse

Class Method Details

.chord_diagram_svg(chord, instrument) ⇒ Object



1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
# File 'lib/chordsketch_uniffi.rb', line 1136

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

.chord_diagram_svg_with_defines(chord, instrument, defines) ⇒ Object



1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
# File 'lib/chordsketch_uniffi.rb', line 1151

def self.chord_diagram_svg_with_defines(chord, instrument, defines)
    chord = Chordsketch::uniffi_utf8(chord)
    
    
    instrument = Chordsketch::uniffi_utf8(instrument)
    
    
    defines = defines
    RustBuffer.check_lower_SequenceTypeChordDefine(defines)
    
  result = Chordsketch.rust_call_with_error(ChordSketchError,:uniffi_chordsketch_ffi_fn_func_chord_diagram_svg_with_defines,RustBuffer.allocFromString(chord),RustBuffer.allocFromString(instrument),RustBuffer.alloc_from_SequenceTypeChordDefine(defines))
  return result.consumeIntoOptionalstring
end

.convert_chordpro_to_irealb(input) ⇒ Object



1169
1170
1171
1172
1173
1174
1175
# File 'lib/chordsketch_uniffi.rb', line 1169

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



1181
1182
1183
1184
1185
1186
1187
# File 'lib/chordsketch_uniffi.rb', line 1181

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



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

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



1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
# File 'lib/chordsketch_uniffi.rb', line 1211

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



1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
# File 'lib/chordsketch_uniffi.rb', line 1229

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



1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
# File 'lib/chordsketch_uniffi.rb', line 1247

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



1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
# File 'lib/chordsketch_uniffi.rb', line 1265

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



1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
# File 'lib/chordsketch_uniffi.rb', line 1283

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



1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
# File 'lib/chordsketch_uniffi.rb', line 1301

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



1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
# File 'lib/chordsketch_uniffi.rb', line 1319

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



1337
1338
1339
1340
1341
1342
1343
# File 'lib/chordsketch_uniffi.rb', line 1337

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



1349
1350
1351
1352
# File 'lib/chordsketch_uniffi.rb', line 1349

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



1358
1359
1360
1361
1362
1363
1364
# File 'lib/chordsketch_uniffi.rb', line 1358

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



1370
1371
1372
1373
1374
1375
1376
# File 'lib/chordsketch_uniffi.rb', line 1370

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



1382
1383
1384
1385
1386
1387
1388
# File 'lib/chordsketch_uniffi.rb', line 1382

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



1394
1395
1396
1397
1398
1399
1400
# File 'lib/chordsketch_uniffi.rb', line 1394

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



821
822
823
824
# File 'lib/chordsketch_uniffi.rb', line 821

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



826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
# File 'lib/chordsketch_uniffi.rb', line 826

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



1406
1407
1408
1409
1410
1411
1412
# File 'lib/chordsketch_uniffi.rb', line 1406

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



1418
1419
1420
1421
1422
1423
1424
# File 'lib/chordsketch_uniffi.rb', line 1418

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



1430
1431
1432
1433
# File 'lib/chordsketch_uniffi.rb', line 1430

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