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
-
.chord_diagram_svg(chord, instrument) ⇒ Object
-
.chord_diagram_svg_with_defines(chord, instrument, defines) ⇒ Object
-
.convert_chordpro_to_irealb(input) ⇒ Object
-
.convert_irealb_to_chordpro_text(input) ⇒ Object
-
.parse_and_render_html(input, config_json, transpose) ⇒ Object
-
.parse_and_render_html_body(input, config_json, transpose) ⇒ Object
-
.parse_and_render_html_body_with_warnings(input, config_json, transpose) ⇒ Object
-
.parse_and_render_html_with_warnings(input, config_json, transpose) ⇒ Object
-
.parse_and_render_pdf(input, config_json, transpose) ⇒ Object
-
.parse_and_render_pdf_with_warnings(input, config_json, transpose) ⇒ Object
-
.parse_and_render_text(input, config_json, transpose) ⇒ Object
-
.parse_and_render_text_with_warnings(input, config_json, transpose) ⇒ Object
-
.parse_irealb(input) ⇒ Object
-
.render_html_css ⇒ Object
-
.render_html_css_with_config_json(config_json) ⇒ Object
-
.render_ireal_pdf(input) ⇒ Object
-
.render_ireal_png(input) ⇒ Object
-
.render_ireal_svg(input) ⇒ Object
-
.rust_call(fn_name, *args) ⇒ Object
-
.rust_call_with_error(error_module, fn_name, *args) ⇒ Object
-
.serialize_irealb(input) ⇒ Object
-
.uniffi_bytes(v) ⇒ Object
-
.uniffi_in_range(i, type_name, min, max) ⇒ Object
-
.uniffi_utf8(v) ⇒ Object
-
.validate(input) ⇒ Object
-
.version ⇒ Object
Class Method Details
.chord_diagram_svg(chord, instrument) ⇒ Object
.chord_diagram_svg_with_defines(chord, instrument, defines) ⇒ Object
.convert_chordpro_to_irealb(input) ⇒ Object
.convert_irealb_to_chordpro_text(input) ⇒ Object
.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
.render_html_css ⇒ Object
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
.render_ireal_pdf(input) ⇒ Object
.render_ireal_png(input) ⇒ Object
.render_ireal_svg(input) ⇒ Object
.rust_call(fn_name, *args) ⇒ Object
821
822
823
824
|
# File 'lib/chordsketch_uniffi.rb', line 821
def self.rust_call(fn_name, *args)
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)
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
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
.uniffi_bytes(v) ⇒ Object
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
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
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
.version ⇒ Object
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
|