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
-
.chord_diagram_svg(chord, instrument) ⇒ 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
.convert_chordpro_to_irealb(input) ⇒ Object
.convert_irealb_to_chordpro_text(input) ⇒ Object
.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
.render_html_css ⇒ Object
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
.render_ireal_pdf(input) ⇒ Object
.render_ireal_png(input) ⇒ Object
.render_ireal_svg(input) ⇒ Object
.rust_call(fn_name, *args) ⇒ Object
738
739
740
741
|
# File 'lib/chordsketch_uniffi.rb', line 738
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
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)
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
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
|