Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7885929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:11:39+00:00 2026-06-03T05:11:39+00:00

I have been working with the book Practical Ruby Gems. It gave me the

  • 0

I have been working with the book Practical Ruby Gems. It gave me the code below, which I wrote in:

require 'dl/import'
class LiveMIDI
ON = 0x90
OFF = 0x80
PC = 0xC0
  def initialize
    open
  end
  def noteon(channel, note, velocity=64)
    message(ON | channel, note, velocity)
  end
  def noteoff(channel, note, velocity=64)
    message(OFF | channel, note, velocity)
  end
  def programchange(channel, preset)
    message(PC | channel, preset)
  end
  module C
    extend DL::Importer
    dlload '/System/Library/Frameworks/CoreMIDI.framework/Versions/Current/CoreMIDI'
    extern "int MIDIClientCreate(void *, void *, void *, void *)"
    extern "int MIDIClientDispose(void *)"
    extern "int MIDIGetNumberOfDestinations()"
    extern "void * MIDIGetDestination(int)"
    extern "int MIDIOutputPortCreate(void *, void *, void *)"
    extern "void * MIDIPacketListInit(void *)"
    extern "void * MIDIPacketListAdd(void *, int, void *, int, int, int, void *)"
    extern "int MIDISend(void *, void *, void *)"
  end
  module CF
    extend DL::Importer
    dlload '/System/Library/Frameworks/CoreFoundation.framework/Versions/Current/CoreFoundation'
    extern "void * CFStringCreateWithCString (void *, char *, int)"
  end
  def open
    client_name = CF.CFStringCreateWithCString(nil, "RubyMIDI", 0)
    @client = DL::PtrData.new(nil)
    C.mIDIClientCreate(client_name, nil, nil, @client.ref);

    port_name = CF.cFStringCreateWithCString(nil, "Output", 0)
    @outport = DL::PtrData.new(nil)
    C.mIDIOutputPortCreate(@client, port_name, @outport.ref);

    num = C.mIDIGetNumberOfDestinations()
    raise NoMIDIDestinations if num < 1
    @destination = C.mIDIGetDestination(0)
  end

  def close
    C.mIDIClientDispose(@client)
  end

  def message(*args)
    format = "C" * args.size
    bytes = args.pack(format).to_ptr
    packet_list = DL.malloc(256)
    packet_ptr  = C.mIDIPacketListInit(packet_list)
    # Pass in two 32 bit 0s for the 64 bit time
    packet_ptr  = C.mIDIPacketListAdd(packet_list, 256, packet_ptr, 0, 0, args.size, bytes)
    C.mIDISend(@outport, @destination, packet_list)
  end
end

When I try to run it, I get the following error, which I don’t understand, I’ve never worked with DL before.:

livemidi.rb:36:in `open': undefined method `cFStringCreateWithCString' for LiveMIDI::CF:Module (NoMethodError)
    from livemidi.rb:7:in `initialize'
    from livemidi.rb:63:in `new'
    from livemidi.rb:63:in `<main>'

Why is this???
I am using Ruby 1.9.3, on Mac OS X
Can you help me fix this bug?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T05:11:40+00:00Added an answer on June 3, 2026 at 5:11 am

    If you search the Apple Developer Documentation you will find a method called CFStringCreateWithCString. The method signature for CFStringCreateWithCString is different than what you define. The correct method definition is.

    CFStringRef CFStringCreateWithCString (
       CFAllocatorRef alloc,
       const char *cStr,
       CFStringEncoding encoding
    );
    

    That means you should change.

    extern "void * CFStringCreateWithCString (void *, char *, int)"
    

    To.

    extern "CFStringRef CFStringCreateWithCString(CFAllocatorRef, const char*, CFStringEncoding)"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working on the following problem from this book . A certain
I am new to cakephp and have been working through the Apress book Beginning
I am working through a REST services book dealing with WCF. I have been
I have recently been working on a exercise in a book I have been
I have been working with web2py following its official web2py book and got to
I have methodically been working thru the Agile Web Development with Rails book. No
I've been reading through the book Working Effectively with Legacy Code and I've been
Have been working on this question for a couple hours and have come close
I have been working with android for a little while now and feel pretty
I have been working with Objective C for a couple of months now and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.