crystal-lang


can't use instance variables at the top level


I'm trying to get an audio player working with Crystal. The internet indicated that portaudio was the best C library for playing audio, and seeing as there are no native Crystal libraries, it seems like the best option.
Someone already put in most of the work for binding the portaudio API to Crystal, but the project is out of date and seems to have been broken by a Crystal update. I'm thinking it will be easier to fix someone else's bindings, than do the whole things from scratch.
That was an unnecessarily long introduction. When I try to compile crystal-portaudio, I get the following error:
$ crystal src/portaudio.cr ~/sw/crystal/crystal-portaudio (master)
Error in src/portaudio.cr:1: while requiring "./portaudio/*"
require "./portaudio/*"
^
in src/portaudio/device.cr:2: while requiring "./host_api"
require "./host_api"
^
in src/portaudio/host_api.cr:5: can't use instance variables at the top level
delegate :device_count, :default_input_device, :default_output_device, :type, #info
^~~~~
Link to offending line.
Here's the minimal patch to get crystal spec and crystal samples/list.cr to compile and run with Crystal 0.22, however the shard seems to need a lot more work still to be really usable.
diff --git a/spec/portaudio_spec.cr b/spec/portaudio_spec.cr
index d8171a9..049a294 100644
--- a/spec/portaudio_spec.cr
+++ b/spec/portaudio_spec.cr
## -1,6 +1,6 ##
require "./spec_helper"
-describe Portaudio do
+describe Pa do
# TODO: Write tests
it "works" do
diff --git a/src/portaudio/device.cr b/src/portaudio/device.cr
index f5ec4f3..cf999ee 100644
--- a/src/portaudio/device.cr
+++ b/src/portaudio/device.cr
## -3,13 +3,13 ## require "./host_api"
module Pa
class Device
- delegate :max_input_channels, :max_output_channels, #info
- delegate :default_low_input_latency, :default_low_output_latency, #info
- delegate :default_high_input_latency, :default_high_output_latency, #info
- delegate :default_sample_rate, #info
+ delegate :max_input_channels, :max_output_channels, to: #info
+ delegate :default_low_input_latency, :default_low_output_latency, to: #info
+ delegate :default_high_input_latency, :default_high_output_latency, to: #info
+ delegate :default_sample_rate, to: #info
getter id
- def initialize(#id, #info)
+ def initialize(#id : Pa::DeviceIndex, #info : LibPortAudio::DeviceInfo)
end
def name
diff --git a/src/portaudio/host_api.cr b/src/portaudio/host_api.cr
index de3b521..9a95ec2 100644
--- a/src/portaudio/host_api.cr
+++ b/src/portaudio/host_api.cr
## -2,9 +2,9 ## require "./lib"
module Pa
class HostApi
- delegate :device_count, :default_input_device, :default_output_device, :type, #info
+ delegate :device_count, :default_input_device, :default_output_device, :type, to: #info
- def initialize(#info)
+ def initialize(#info : LibPortAudio::HostApiInfo)
end
def name

Related Links

Crystal: a good way for method options
Crystal: abstract static method
Type checking in Crystal
Condition over object's type
Crystal C bindings: argument const unsigned char **
Crystal C bindings: return type char*
Make Class member attribute of type Array(T) accept 2D arrays of T
JSON.mapping if “root” attribute has inherit keys
Crystal C bindings: using fopen
Define Class object validations
Set attribute of type “Class” to define it as Int32, String, Float64
Set both default attribute and type of attribute
How can I test private methods?
Write binary data to stdout in Crystal
Unable to compile after upgrade from crystal 0.19.4 to 0.20
Application server for Crystal web app / Kemal

Categories

HOME
shell
sonarqube
assembly
facebook-oauth
awk
merge
zend-framework
youtube-data-api-v3
toolbox
battery
error-handling
javacc
simulink
dojo
nuget-package
angularfire2
opengl-3
special-characters
categorical-data
octave
google-chrome-app
jxl
xcodebuild
spring-social
openbugs
radgridview
selenium-ide
docx
coin3d
null-pointer
replication
question2answer
gulp-watch
syntax-highlighting
ms-access-2003
ceylon
paperjs
errbot
cognos-bi
testbed
spring-security4
vue-chartjs
python-import
arduino-ide
xajax
z-notation
linq-to-objects
plaintext
skylink
android-softkeyboard
preloader
dbnull
placeholder
snapchat
mesosphere
cnc
netbeans6.8
facebook-pixel
x-ray
boxing
opengl-4
ngmaterial
janus
atlas
redistributable
neon
swizzling
uiactionsheet
nio2
contentcontrol
terracotta
fiware-monitoring
pypiserver
jdi
coda
slash
aspectj-maven-plugin
kubuntu
zxspectrum
showdialog
mruby
appserver
cuba
kissfft
functional-java
alternate
authlogic
dsym
qscrollarea
visual-studio-express
hibernate-entitymanager
oocss
neos-server
chart-director
resource-management
booksleeve
tree-balancing
panda3d
qi4j
correlated-subquery
fusefabric
convention
entity-attribute-value
uipagecontrol
cuteeditor
appledoc
data-mapping
web-application-project
sun
windows-identity
product-management
blind
cardspace

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App