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: InternalError, PdfRenderWithWarnings, RustBuffer, TextRenderWithWarnings, ValidationError
Class Method Summary
collapse
-
.chord_diagram_svg(chord, instrument) ⇒ Object
-
.parse_and_render_html(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
-
.rust_call(fn_name, *args) ⇒ Object
-
.rust_call_with_error(error_module, fn_name, *args) ⇒ 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
.parse_and_render_html(input, config_json, transpose) ⇒ Object
900
901
902
903
904
905
906
907
908
909
910
911
912
|
# File 'lib/chordsketch_uniffi.rb', line 900
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_with_warnings(input, config_json, transpose) ⇒ Object
918
919
920
921
922
923
924
925
926
927
928
929
930
|
# File 'lib/chordsketch_uniffi.rb', line 918
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
936
937
938
939
940
941
942
943
944
945
946
947
948
|
# File 'lib/chordsketch_uniffi.rb', line 936
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
954
955
956
957
958
959
960
961
962
963
964
965
966
|
# File 'lib/chordsketch_uniffi.rb', line 954
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
972
973
974
975
976
977
978
979
980
981
982
983
984
|
# File 'lib/chordsketch_uniffi.rb', line 972
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
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
|
# File 'lib/chordsketch_uniffi.rb', line 990
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
|
.rust_call(fn_name, *args) ⇒ Object
684
685
686
687
|
# File 'lib/chordsketch_uniffi.rb', line 684
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
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
|
# File 'lib/chordsketch_uniffi.rb', line 689
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
|
.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
1020
1021
1022
1023
|
# File 'lib/chordsketch_uniffi.rb', line 1020
def self.version()
result = Chordsketch.rust_call(:uniffi_chordsketch_ffi_fn_func_version,)
return result.consumeIntoString
end
|