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

How to parse data from POST request
Read a single char from stdin without pressing enter
What object receives #puts in my Crystal programs?
Avoid repeating variable name in assignation
Sharing variables between different macros
passing json to a superclass using .from_json
execution of command failed with code: 1: `cc -o "/root/.cache/crystal/var-app-staging-new-http.cr
How to use union in “if” statement [Crystal]
How to convert a hex string to bytes array in Crystal?
is INSTANCE = new in class is run after compilation automatically or the first time it is accessed?
Crystal lang: understanding method return type of Void
Crystal-lang httpget basic_auth
How to control using CPU cores [Crystal]
How can I read a slice with other size in crystal?
Unix-style password readline
Cannot find -lxml2 when trying to run crystal spec

Categories

HOME
batch-file
asp.net-web-api
eclipse
paraview
jax-rs
angular-formly
yahoo-finance
camera
javacc
yandex
gembox-spreadsheet
limit
x264
crystal-lang
opengl-3
minecraft-forge
watson-conversation
filechannel
spring-social
code-generation
intershop
gmm
visual-studio-extensions
exploit
froala
windows-server-2003
appirater
delimiter
inversion-of-control
carrierwave
zend-debugger
memory-address
gojs
biztalk-rule-engine
indy10
jwplayer6
sql-delete
searchkit
python-pptx
watchman
nohup
watchface
naming
logback-groovy
oracle-service-bus
httrack
term
datamaps
manova
filehandle
seq
bootstrap-tags-input
rxtx
juice-ui
model-associations
avspeechsynthesizer
simevents
observablecollection
nss
project-organization
html-to-pdf
concurrentmodification
themoviedb-api
lazybones
poppler
doctype
ember-cli-rails
typemock
amiga
wso2greg
dronekit-android
baasbox
diff3
gamekit
apache-spark-1.3
showdialog
mruby
browserify-shim
sip-server
device-tree
gae-quotas
bin
hibernate-entitymanager
inappsettingskit
beaker-testing
kogrid
cmmi
dolby-audio-api
pclzip
server-administration
android-loadermanager
monotouch.dialog
dajaxice
failing-tests
ikimagebrowserview
xcelsius
commerceserver2007
eclipse-marketplace
wysiwym
entitykey
xslcompiledtransform

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App