Skip to content

Commit 4bf1e9a

Browse files
committed
Use generic Int and Bool alias
1 parent 2deb746 commit 4bf1e9a

File tree

9 files changed

+185
-118
lines changed

9 files changed

+185
-118
lines changed

generate/generate.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def rename_type(name, var=''):
5757
'char': 'UInt8',
5858
'int': 'Int32',
5959
'size_t': 'SizeT',
60-
'sfBool': 'Int32',
60+
'sfBool': 'CSFML::Bool',
6161
'unsigned int': 'Int32',
6262
'float': 'Float32',
6363
'sfVector2u': 'sfVector2i',
@@ -285,9 +285,6 @@ def handle_function(main, params):
285285
if nftype=='UInt32':
286286
if nfname == 'style':
287287
rtype = 'WindowStyle' if 'Window' in ofname else 'TextStyle'
288-
#elif nfname == 'attributes'
289-
#if nftype.startswith('ptr ') or nftype=='pointer':
290-
#public = False
291288

292289
aparams = []
293290
const = []
@@ -344,6 +341,9 @@ def handle_function(main, params):
344341
elif t == 'Float32':
345342
t = 'Number'
346343
conv.append('{0} = {0}.to_f32'.format(n))
344+
elif (' '+params[i][0]).endswith(' int'):
345+
t = 'Int'
346+
conv.append('{0} = {0}.to_i32'.format(n))
347347
elif t == 'SizeT':
348348
t = 'Int'
349349
conv.append('{0} = CSFML::SizeT.cast({0})'.format(n))

src/audio_lib.cr

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ lib CSFML
153153
#
154154
# * `music`: Music object
155155
# * `loop`: True to play in loop, False to play once
156-
fun music_set_loop = sfMusic_setLoop(music: Music, loop: Int32)
156+
fun music_set_loop = sfMusic_setLoop(music: Music, loop: CSFML::Bool)
157157

158158
# Tell whether or not a music is in loop mode
159159
#
@@ -162,7 +162,7 @@ lib CSFML
162162
# * `music`: Music object
163163
#
164164
# *Returns*: True if the music is looping, False otherwise
165-
fun music_get_loop = sfMusic_getLoop(music: Music): Int32
165+
fun music_get_loop = sfMusic_getLoop(music: Music): CSFML::Bool
166166

167167
# Get the total duration of a music
168168
#
@@ -297,7 +297,7 @@ lib CSFML
297297
#
298298
# * `music`: Music object
299299
# * `relative`: True to set the position relative, False to set it absolute
300-
fun music_set_relative_to_listener = sfMusic_setRelativeToListener(music: Music, relative: Int32)
300+
fun music_set_relative_to_listener = sfMusic_setRelativeToListener(music: Music, relative: CSFML::Bool)
301301

302302
# Set the minimum distance of a music
303303
#
@@ -377,7 +377,7 @@ lib CSFML
377377
# * `music`: Music object
378378
#
379379
# *Returns*: True if the position is relative, False if it's absolute
380-
fun music_is_relative_to_listener = sfMusic_isRelativeToListener(music: Music): Int32
380+
fun music_is_relative_to_listener = sfMusic_isRelativeToListener(music: Music): CSFML::Bool
381381

382382
# Get the minimum distance of a music
383383
#
@@ -484,7 +484,7 @@ lib CSFML
484484
#
485485
# * `sound`: Sound object
486486
# * `loop`: True to play in loop, False to play once
487-
fun sound_set_loop = sfSound_setLoop(sound: Sound, loop: Int32)
487+
fun sound_set_loop = sfSound_setLoop(sound: Sound, loop: CSFML::Bool)
488488

489489
# Tell whether or not a sound is in loop mode
490490
#
@@ -493,7 +493,7 @@ lib CSFML
493493
# * `sound`: Sound object
494494
#
495495
# *Returns*: True if the sound is looping, False otherwise
496-
fun sound_get_loop = sfSound_getLoop(sound: Sound): Int32
496+
fun sound_get_loop = sfSound_getLoop(sound: Sound): CSFML::Bool
497497

498498
# Get the current status of a sound (stopped, paused, playing)
499499
#
@@ -553,7 +553,7 @@ lib CSFML
553553
#
554554
# * `sound`: Sound object
555555
# * `relative`: True to set the position relative, False to set it absolute
556-
fun sound_set_relative_to_listener = sfSound_setRelativeToListener(sound: Sound, relative: Int32)
556+
fun sound_set_relative_to_listener = sfSound_setRelativeToListener(sound: Sound, relative: CSFML::Bool)
557557

558558
# Set the minimum distance of a sound
559559
#
@@ -633,7 +633,7 @@ lib CSFML
633633
# * `sound`: Sound object
634634
#
635635
# *Returns*: True if the position is relative, False if it's absolute
636-
fun sound_is_relative_to_listener = sfSound_isRelativeToListener(sound: Sound): Int32
636+
fun sound_is_relative_to_listener = sfSound_isRelativeToListener(sound: Sound): CSFML::Bool
637637

638638
# Get the minimum distance of a sound
639639
#
@@ -745,7 +745,7 @@ lib CSFML
745745
# * `filename`: Path of the sound file to write
746746
#
747747
# *Returns*: True if saving succeeded, False if it failed
748-
fun sound_buffer_save_to_file = sfSoundBuffer_saveToFile(sound_buffer: SoundBuffer, filename: UInt8*): Int32
748+
fun sound_buffer_save_to_file = sfSoundBuffer_saveToFile(sound_buffer: SoundBuffer, filename: UInt8*): CSFML::Bool
749749

750750
# Get the array of audio samples stored in a sound buffer
751751
#
@@ -867,8 +867,8 @@ lib CSFML
867867
# *Returns*: Read-only access to the sound buffer
868868
fun sound_buffer_recorder_get_buffer = sfSoundBufferRecorder_getBuffer(sound_buffer_recorder: SoundBufferRecorder): SoundBuffer
869869

870-
alias SoundRecorderStartCallback = (Void*) -> Int32
871-
alias SoundRecorderProcessCallback = (Int16*, SizeT, Void*) -> Int32
870+
alias SoundRecorderStartCallback = (Void*) -> CSFML::Bool
871+
alias SoundRecorderProcessCallback = (Int16*, SizeT, Void*) -> CSFML::Bool
872872
alias SoundRecorderStopCallback = (Void*) -> Void
873873
# Construct a new sound recorder from callback functions
874874
#
@@ -904,7 +904,7 @@ lib CSFML
904904
# * `sample_rate`: Desired capture rate, in number of samples per second
905905
#
906906
# *Returns*: True, if start of capture was successful
907-
fun sound_recorder_start = sfSoundRecorder_start(sound_recorder: SoundRecorder, sample_rate: Int32): Int32
907+
fun sound_recorder_start = sfSoundRecorder_start(sound_recorder: SoundRecorder, sample_rate: Int32): CSFML::Bool
908908

909909
# Stop the capture of a sound recorder
910910
#
@@ -933,7 +933,7 @@ lib CSFML
933933
# any attempt to use SoundRecorder will fail.
934934
#
935935
# *Returns*: True if audio capture is supported, False otherwise
936-
fun sound_recorder_is_available = sfSoundRecorder_isAvailable(): Int32
936+
fun sound_recorder_is_available = sfSoundRecorder_isAvailable(): CSFML::Bool
937937

938938
# Set the processing interval
939939
#
@@ -987,7 +987,7 @@ lib CSFML
987987
# * `The`: name of the audio capture device
988988
#
989989
# *Returns*: True, if it was able to set the requested device
990-
fun sound_recorder_set_device = sfSoundRecorder_setDevice(sound_recorder: SoundRecorder, name: UInt8*): Int32
990+
fun sound_recorder_set_device = sfSoundRecorder_setDevice(sound_recorder: SoundRecorder, name: UInt8*): CSFML::Bool
991991

992992
# Get the name of the current audio capture device
993993
#
@@ -1004,7 +1004,7 @@ lib CSFML
10041004
sample_count: Int32
10051005
end
10061006

1007-
alias SoundStreamGetDataCallback = (SoundStreamChunk*, Void*) -> Int32
1007+
alias SoundStreamGetDataCallback = (SoundStreamChunk*, Void*) -> CSFML::Bool
10081008
alias SoundStreamSeekCallback = (Time, Void*) -> Void
10091009
# Create a new sound stream
10101010
#
@@ -1141,7 +1141,7 @@ lib CSFML
11411141
#
11421142
# * `sound_stream`: Sound stream object
11431143
# * `relative`: True to set the position relative, False to set it absolute
1144-
fun sound_stream_set_relative_to_listener = sfSoundStream_setRelativeToListener(sound_stream: SoundStream, relative: Int32)
1144+
fun sound_stream_set_relative_to_listener = sfSoundStream_setRelativeToListener(sound_stream: SoundStream, relative: CSFML::Bool)
11451145

11461146
# Set the minimum distance of a sound stream
11471147
#
@@ -1197,7 +1197,7 @@ lib CSFML
11971197
#
11981198
# * `sound_stream`: Sound stream object
11991199
# * `loop`: True to play in loop, False to play once
1200-
fun sound_stream_set_loop = sfSoundStream_setLoop(sound_stream: SoundStream, loop: Int32)
1200+
fun sound_stream_set_loop = sfSoundStream_setLoop(sound_stream: SoundStream, loop: CSFML::Bool)
12011201

12021202
# Get the pitch of a sound stream
12031203
#
@@ -1234,7 +1234,7 @@ lib CSFML
12341234
# * `sound_stream`: Sound stream object
12351235
#
12361236
# *Returns*: True if the position is relative, False if it's absolute
1237-
fun sound_stream_is_relative_to_listener = sfSoundStream_isRelativeToListener(sound_stream: SoundStream): Int32
1237+
fun sound_stream_is_relative_to_listener = sfSoundStream_isRelativeToListener(sound_stream: SoundStream): CSFML::Bool
12381238

12391239
# Get the minimum distance of a sound stream
12401240
#
@@ -1261,7 +1261,7 @@ lib CSFML
12611261
# * `sound_stream`: Sound stream object
12621262
#
12631263
# *Returns*: True if the music is looping, False otherwise
1264-
fun sound_stream_get_loop = sfSoundStream_getLoop(sound_stream: SoundStream): Int32
1264+
fun sound_stream_get_loop = sfSoundStream_getLoop(sound_stream: SoundStream): CSFML::Bool
12651265

12661266
# Get the current playing position of a sound stream
12671267
#

src/audio_obj.cr

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ module SF
869869
# * `sample_rate`: Sample rate (number of samples to play per second)
870870
#
871871
# *Returns*: A new SoundBuffer object (NULL if failed)
872-
def self.from_samples(samples, sample_count: Int, channel_count: Int32, sample_rate: Int32)
872+
def self.from_samples(samples, sample_count: Int, channel_count: Int, sample_rate: Int)
873873
if samples
874874
if samples.responds_to?(:to_unsafe)
875875
psamples = samples.to_unsafe
@@ -880,6 +880,8 @@ module SF
880880
psamples = nil
881881
end
882882
sample_count = sample_count.to_u64
883+
channel_count = channel_count.to_i32
884+
sample_rate = sample_rate.to_i32
883885
SoundBuffer.transfer_ptr(CSFML.sound_buffer_create_from_samples(psamples, sample_count, channel_count, sample_rate))
884886
end
885887

@@ -1023,7 +1025,8 @@ module SF
10231025
#
10241026
# * `sound_buffer_recorder`: Sound buffer recorder object
10251027
# * `sample_rate`: Desired capture rate, in number of samples per second
1026-
def start(sample_rate: Int32)
1028+
def start(sample_rate: Int)
1029+
sample_rate = sample_rate.to_i32
10271030
CSFML.sound_buffer_recorder_start(@this, sample_rate)
10281031
end
10291032

@@ -1111,7 +1114,8 @@ module SF
11111114
# * `sample_rate`: Desired capture rate, in number of samples per second
11121115
#
11131116
# *Returns*: True, if start of capture was successful
1114-
def start(sample_rate: Int32)
1117+
def start(sample_rate: Int)
1118+
sample_rate = sample_rate.to_i32
11151119
CSFML.sound_recorder_start(@this, sample_rate) != 0
11161120
end
11171121

@@ -1239,7 +1243,9 @@ module SF
12391243
# * `user_data`: Data to pass to the callback functions
12401244
#
12411245
# *Returns*: A new SoundStream object
1242-
def initialize(on_get_data: SoundStreamGetDataCallback, on_seek: SoundStreamSeekCallback, channel_count: Int32, sample_rate: Int32, user_data: Void*)
1246+
def initialize(on_get_data: SoundStreamGetDataCallback, on_seek: SoundStreamSeekCallback, channel_count: Int, sample_rate: Int, user_data: Void*)
1247+
channel_count = channel_count.to_i32
1248+
sample_rate = sample_rate.to_i32
12431249
@owned = true
12441250
@this = CSFML.sound_stream_create(on_get_data, on_seek, channel_count, sample_rate, user_data)
12451251
end

src/common_lib.cr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
lib CSFML
2323
alias SizeT = LibC::SizeT
2424

25+
alias Bool = Int32
26+
2527
ifdef windows || macosx
2628
alias WindowHandle = Void*
2729
else

0 commit comments

Comments
 (0)