Skip to content

Commit 4c4745b

Browse files
author
Robot
committed
Generate sources (79beccf)
1 parent 53b0116 commit 4c4745b

File tree

22 files changed

+796
-347
lines changed

22 files changed

+796
-347
lines changed

README.md

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@
55
Documentation
66
-------------
77

8-
#### [Introduction](#introduction)
9-
#### [Installation](#installation)
10-
#### [Tutorials][]
11-
#### [API Documentation][]
12-
#### [Examples](examples) / [Demos][]
8+
- **[Installation](#installation)**
9+
10+
- **[Tutorials][]**
11+
12+
- **[API Documentation][]**
13+
14+
- **[Examples](examples)** / **[Demos][]**
1315

1416

1517
Introduction
1618
------------
1719

18-
**Note to existing users**: *CrSFML* has been recently rewritten from scratch. See the [release notes][releases] for information.
20+
**Note to existing users**: *CrSFML* has been recently rewritten from scratch. *CrSFML* releases since 2.4 have an entirely different installation procedure, and multiple important API changes.
1921

2022
*CrSFML* is a library that allows SFML to be used with the Crystal programming language. [SFML][] is a library written in C++, so *CrSFML* also needs to ship C bindings to SFML, called *VoidCSFML*.
2123

@@ -25,7 +27,7 @@ To quote the official site of SFML,
2527
2628
Indeed, SFML is most often used to make video games. It provides features such as hardware-accelerated 2D graphics, handling keyboard, mouse and gamepad input, vector and matrix manipulation, managing windows (can also be used as a base for OpenGL drawing), working with multiple image formats, audio playback and recording, basic networking... Check out some [demos][] of *CrSFML* to see what it can do.
2729

28-
*CrSFML* consists almost entirely of automatically generated code, based on SFML's header files. The *dev* git branch contains the [generator program](generate.cr) and the small manually written source files. The generated source code can be viewed at the [sources][] branch.
30+
*CrSFML* consists almost entirely of automatically generated code, based on SFML's header files. The *master* git branch contains the [generator program](generate.cr) and the small manually written source files. The generated source code can be viewed at the [sources][] branch.
2931

3032
### Differences between SFML and CrSFML
3133

@@ -49,12 +51,14 @@ The API of *CrSFML* (a library for Crystal) attempts to be similar to SFML (a C+
4951
Installation
5052
------------
5153

54+
Note that using [Shards][] is not enough to install *CrSFML*.
55+
5256
This section defines two sets of step-by-step instructions to install *CrSFML* but these are not the only ways to do it; they can even be mixed (see [VoidCSFML installation instructions](voidcsfml/README.md#installation) for an alternative look)
5357

5458
- [Approach 1](#approach-1): Generate latest *CrSFML* and *VoidCSFML* source code "from scratch"; build and use them from a local directory
5559
- Advantages:
5660
- The bindings can be fine-tuned to your system.
57-
- Should support any SFML 2.3.x, maybe even other versions.
61+
- Supports multiple recent [SFML versions](#install-sfml).
5862
- This is the right setup if you wish to contribute to *CrSFML*.
5963
- Disadvantages:
6064
- Need to always provide full path to *VoidCSFML* libraries when running a program using *CrSFML*.
@@ -63,16 +67,20 @@ This section defines two sets of step-by-step instructions to install *CrSFML* b
6367
- Advantages:
6468
- Easier installation.
6569
- Disadvantages:
66-
- Tied to a particular version of SFML.
70+
- Tied to a particular version of SFML (only SFML 2.4 right now).
6771
- Although sizes of SFML objects seem to always be of equal or smaller sizes than on Linux 64-bit with latest GCC (where the sources are generated), this is not completely guaranteed. So, in case of a mismatch, data may be written outside of the memory region allocated for an object.
6872

6973
### Install SFML
7074

7175
The first step is to install the [SFML][] library itself. There are detailed [official instructions][sfml-install] on how to install it manually, however, on many systems there are easier ways.
7276

77+
SFML versions 2.4.x and 2.3.x are supported by *CrSFML*.
78+
7379
#### Linux
7480

75-
Linux-based systems known to provide SFML 2.3.2 through their package manager: Ubuntu 16.04, Arch Linux, Fedora. Note that if you're installing an older version of SFML, it is not guaranteed to work (in fact, installation with [Approach 2](#approach-2) is almost guaranteed **not** to work).
81+
Many Linux-based systems provide SFML through their package manager. Make sure to install the *-dev* packages if there is such a separation in your Linux distribution of choice.
82+
83+
Note that most often the packages provided by Linux distributions are outdated. If you're installing an older version of SFML (not recommended), make sure that it's still [supported by *CrSFML*](#install-sfml). For installation with [Approach 2](#approach-2) getting the latest version is even more important.
7684

7785
For information on building SFML from source, check out [this article][sfml-install-linux] (but no need to install CSFML). It is as simple as downloading the source code and running:
7886

@@ -101,7 +109,7 @@ Prerequisites: [Git][], [CMake][], [Crystal][], a C++ compiler
101109
#### Download latest generator source code
102110

103111
```bash
104-
git clone -b dev https://github.com/blaxpirit/crsfml
112+
git clone https://github.com/blaxpirit/crsfml
105113
cd crsfml
106114
```
107115

@@ -152,7 +160,7 @@ Prerequisites: [CMake][], [Crystal][], a C++ compiler
152160

153161
#### Download a release of CrSFML
154162

155-
Find the release of *CrSFML* that corresponds to your installed version of *SFML* (latest is strongly recommended) at the [releases][] page.
163+
Find the release of *CrSFML* that corresponds to your installed version of *SFML* (latest is strongly recommended) at the [releases][] page. Note that only releases starting at 2.4 are applicable, and only SFML versions since 2.4 are supported in this approach. The older releases are legacy CSFML-based releases.
156164

157165
Download and extract it, and remember the version of the release (let's say v1.2.3) for later.
158166

shard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: crsfml
2-
version: 2.3.10
2+
version: 2.4.0
33

44
authors:
55
- Oleh Prypin <[email protected]>

src/audio/lib.cr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,15 @@ lib VoidCSFML
134134
fun soundrecorder_getdefaultdevice(result : LibC::Char**)
135135
fun soundrecorder_setdevice_zkC(self : Void*, name_size : LibC::SizeT, name : LibC::Char*, result : Bool*)
136136
fun soundrecorder_getdevice(self : Void*, result : LibC::Char**)
137+
fun soundrecorder_setchannelcount_emS(self : Void*, channel_count : LibC::UInt)
138+
fun soundrecorder_getchannelcount(self : Void*, result : LibC::UInt*)
137139
fun soundrecorder_isavailable(result : Bool*)
138140
fun soundrecorder_initialize(self : Void*)
139141
fun soundrecorder_setprocessinginterval_f4T(self : Void*, interval : Void*)
140142
fun soundrecorder_onstart(self : Void*, result : Bool*)
141143
fun soundrecorder_onstop(self : Void*)
142144
fun soundbufferrecorder_initialize(self : Void*)
145+
fun soundbufferrecorder_finalize(self : Void*)
143146
fun soundbufferrecorder_getbuffer(self : Void*, result : Void**)
144147
fun soundbufferrecorder_start_emS(self : Void*, sample_rate : LibC::UInt, result : Bool*)
145148
fun soundbufferrecorder_stop(self : Void*)
@@ -148,6 +151,8 @@ lib VoidCSFML
148151
fun soundbufferrecorder_getdefaultdevice(result : LibC::Char**)
149152
fun soundbufferrecorder_setdevice_zkC(self : Void*, name_size : LibC::SizeT, name : LibC::Char*, result : Bool*)
150153
fun soundbufferrecorder_getdevice(self : Void*, result : LibC::Char**)
154+
fun soundbufferrecorder_setchannelcount_emS(self : Void*, channel_count : LibC::UInt)
155+
fun soundbufferrecorder_getchannelcount(self : Void*, result : LibC::UInt*)
151156
fun soundbufferrecorder_isavailable(result : Bool*)
152157
fun sfml_audio_version(LibC::Int*, LibC::Int*, LibC::Int*)
153158
end

src/audio/obj.cr

Lines changed: 76 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ module SF
194194
#
195195
# *See also:* `SF::Sound`, `SF::SoundStream`
196196
class SoundSource
197-
@_soundsource : VoidCSFML::SoundSource_Buffer = VoidCSFML::SoundSource_Buffer.new(0u8)
197+
@_soundsource : VoidCSFML::SoundSource_Buffer
198198
# Enumeration of the sound source states
199199
enum Status
200200
# Sound is not playing
@@ -362,6 +362,13 @@ module SF
362362
VoidCSFML.soundsource_getattenuation(to_unsafe, out result)
363363
return result
364364
end
365+
# Default constructor
366+
#
367+
# This constructor is meant to be called by derived classes only.
368+
protected def initialize()
369+
@_soundsource = uninitialized VoidCSFML::SoundSource_Buffer
370+
VoidCSFML.soundsource_initialize(to_unsafe)
371+
end
365372
include AlResource
366373
# :nodoc:
367374
def to_unsafe()
@@ -457,7 +464,7 @@ module SF
457464
#
458465
# *See also:* `SF::Music`
459466
abstract class SoundStream < SoundSource
460-
@_soundstream : VoidCSFML::SoundStream_Buffer = VoidCSFML::SoundStream_Buffer.new(0u8)
467+
@_soundstream : VoidCSFML::SoundStream_Buffer
461468
# Destructor
462469
def finalize()
463470
VoidCSFML.soundstream_finalize(to_unsafe)
@@ -567,7 +574,7 @@ module SF
567574
# Default constructor
568575
#
569576
# This constructor is only meant to be called by derived classes.
570-
def initialize()
577+
protected def initialize()
571578
@_soundsource = uninitialized VoidCSFML::SoundSource_Buffer
572579
@_soundstream = uninitialized VoidCSFML::SoundStream_Buffer
573580
raise "Unexpected memory layout" if as(Void*) + sizeof(LibC::Int) != to_unsafe
@@ -727,7 +734,7 @@ module SF
727734
#
728735
# *See also:* `SF::Sound`, `SF::SoundStream`
729736
class Music < SoundStream
730-
@_music : VoidCSFML::Music_Buffer = VoidCSFML::Music_Buffer.new(0u8)
737+
@_music : VoidCSFML::Music_Buffer
731738
# Default constructor
732739
def initialize()
733740
@_soundsource = uninitialized VoidCSFML::SoundSource_Buffer
@@ -902,6 +909,11 @@ module SF
902909
end
903910
# :nodoc:
904911
def initialize(channel_count : Int, sample_rate : Int)
912+
@_soundsource = uninitialized VoidCSFML::SoundSource_Buffer
913+
@_soundstream = uninitialized VoidCSFML::SoundStream_Buffer
914+
@_music = uninitialized VoidCSFML::Music_Buffer
915+
VoidCSFML.music_initialize(to_unsafe)
916+
VoidCSFML.music_initialize_emSemS(to_unsafe, LibC::UInt.new(channel_count), LibC::UInt.new(sample_rate))
905917
end
906918
# :nodoc:
907919
def pitch=(pitch : Number)
@@ -1006,7 +1018,7 @@ module SF
10061018
#
10071019
# *See also:* `SF::SoundBuffer`, `SF::Music`
10081020
class Sound < SoundSource
1009-
@_sound : VoidCSFML::Sound_Buffer = VoidCSFML::Sound_Buffer.new(0u8)
1021+
@_sound : VoidCSFML::Sound_Buffer
10101022
# Default constructor
10111023
def initialize()
10121024
@_soundsource = uninitialized VoidCSFML::SoundSource_Buffer
@@ -1270,7 +1282,7 @@ module SF
12701282
#
12711283
# *See also:* `SF::Sound`, `SF::SoundBufferRecorder`
12721284
class SoundBuffer
1273-
@_soundbuffer : VoidCSFML::SoundBuffer_Buffer = VoidCSFML::SoundBuffer_Buffer.new(0u8)
1285+
@_soundbuffer : VoidCSFML::SoundBuffer_Buffer
12741286
# Default constructor
12751287
def initialize()
12761288
@_soundbuffer = uninitialized VoidCSFML::SoundBuffer_Buffer
@@ -1513,18 +1525,33 @@ module SF
15131525
# by calling setDevice() with the appropriate device. Otherwise
15141526
# the default capturing device will be used.
15151527
#
1528+
# By default the recording is in 16-bit mono. Using the
1529+
# setChannelCount method you can change the number of channels
1530+
# used by the audio capture device to record. Note that you
1531+
# have to decide whether you want to record in mono or stereo
1532+
# before starting the recording.
1533+
#
15161534
# It is important to note that the audio capture happens in a
15171535
# separate thread, so that it doesn't block the rest of the
15181536
# program. In particular, the onProcessSamples virtual function
15191537
# (but not onStart and not onStop) will be called
15201538
# from this separate thread. It is important to keep this in
15211539
# mind, because you may have to take care of synchronization
15221540
# issues if you share data between threads.
1541+
# Another thing to bear in mind is that you must call stop()
1542+
# in the destructor of your derived class, so that the recording
1543+
# thread finishes before your object is destroyed.
15231544
#
15241545
# Usage example:
15251546
# ```c++
15261547
# class CustomRecorder : public sf::SoundRecorder
15271548
# {
1549+
# ~CustomRecorder()
1550+
# {
1551+
# // Make sure to stop the recording thread
1552+
# stop();
1553+
# }
1554+
#
15281555
# virtual bool onStart() // optional
15291556
# {
15301557
# // Initialize whatever has to be done before the capture starts
@@ -1565,7 +1592,7 @@ module SF
15651592
#
15661593
# *See also:* `SF::SoundBufferRecorder`
15671594
abstract class SoundRecorder
1568-
@_soundrecorder : VoidCSFML::SoundRecorder_Buffer = VoidCSFML::SoundRecorder_Buffer.new(0u8)
1595+
@_soundrecorder : VoidCSFML::SoundRecorder_Buffer
15691596
# destructor
15701597
def finalize()
15711598
VoidCSFML.soundrecorder_finalize(to_unsafe)
@@ -1654,6 +1681,31 @@ module SF
16541681
VoidCSFML.soundrecorder_getdevice(to_unsafe, out result)
16551682
return String.new(result)
16561683
end
1684+
# Set the channel count of the audio capture device
1685+
#
1686+
# This method allows you to specify the number of channels
1687+
# used for recording. Currently only 16-bit mono and
1688+
# 16-bit stereo are supported.
1689+
#
1690+
# * *channel_count* - Number of channels. Currently only
1691+
# mono (1) and stereo (2) are supported.
1692+
#
1693+
# *See also:* getChannelCount
1694+
def channel_count=(channel_count : Int)
1695+
VoidCSFML.soundrecorder_setchannelcount_emS(to_unsafe, LibC::UInt.new(channel_count))
1696+
end
1697+
# Get the number of channels used by this recorder
1698+
#
1699+
# Currently only mono and stereo are supported, so the
1700+
# value is either 1 (for mono) or 2 (for stereo).
1701+
#
1702+
# *Returns:* Number of channels
1703+
#
1704+
# *See also:* setChannelCount
1705+
def channel_count() : UInt32
1706+
VoidCSFML.soundrecorder_getchannelcount(to_unsafe, out result)
1707+
return result
1708+
end
16571709
# Check if the system supports audio capture
16581710
#
16591711
# This function should always be called before using
@@ -1669,7 +1721,7 @@ module SF
16691721
# Default constructor
16701722
#
16711723
# This constructor is only meant to be called by derived classes.
1672-
def initialize()
1724+
protected def initialize()
16731725
@_soundrecorder = uninitialized VoidCSFML::SoundRecorder_Buffer
16741726
raise "Unexpected memory layout" if as(Void*) + sizeof(LibC::Int) != to_unsafe
16751727
VoidCSFML.soundrecorder_initialize(to_unsafe)
@@ -1770,12 +1822,16 @@ module SF
17701822
#
17711823
# *See also:* `SF::SoundRecorder`
17721824
class SoundBufferRecorder < SoundRecorder
1773-
@_soundbufferrecorder : VoidCSFML::SoundBufferRecorder_Buffer = VoidCSFML::SoundBufferRecorder_Buffer.new(0u8)
1825+
@_soundbufferrecorder : VoidCSFML::SoundBufferRecorder_Buffer
17741826
def initialize()
17751827
@_soundrecorder = uninitialized VoidCSFML::SoundRecorder_Buffer
17761828
@_soundbufferrecorder = uninitialized VoidCSFML::SoundBufferRecorder_Buffer
17771829
VoidCSFML.soundbufferrecorder_initialize(to_unsafe)
17781830
end
1831+
# destructor
1832+
def finalize()
1833+
VoidCSFML.soundbufferrecorder_finalize(to_unsafe)
1834+
end
17791835
# Get the sound buffer containing the captured audio data
17801836
#
17811837
# The sound buffer is valid only after the capture has ended.
@@ -1839,6 +1895,15 @@ module SF
18391895
return String.new(result)
18401896
end
18411897
# :nodoc:
1898+
def channel_count=(channel_count : Int)
1899+
VoidCSFML.soundbufferrecorder_setchannelcount_emS(to_unsafe, LibC::UInt.new(channel_count))
1900+
end
1901+
# :nodoc:
1902+
def channel_count() : UInt32
1903+
VoidCSFML.soundbufferrecorder_getchannelcount(to_unsafe, out result)
1904+
return result
1905+
end
1906+
# :nodoc:
18421907
def self.available?() : Bool
18431908
VoidCSFML.soundbufferrecorder_isavailable(out result)
18441909
return result
@@ -1855,9 +1920,10 @@ module SF
18551920
to_s(io)
18561921
end
18571922
end
1858-
#:nodoc:
1923+
# :nodoc:
18591924
class SoundBuffer::Reference < SoundBuffer
18601925
def initialize(@this : Void*, @parent : SoundBufferRecorder)
1926+
@_soundbuffer = uninitialized VoidCSFML::SoundBuffer_Buffer
18611927
end
18621928
def finalize()
18631929
end

src/common.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
require "./sizes"
22

33
module SF
4-
VERSION = "2.3.10"
5-
SFML_VERSION = "2.3.2"
4+
VERSION = "2.4.0"
5+
SFML_VERSION = "2.4.0"
66

77
# Raised in shorthand class methods if initialization or resource loading fails
88
class InitError < Exception

0 commit comments

Comments
 (0)