Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Codea 1.5.2 Beta

2»

Comments

  • SimeonSimeon Admin Mod
    Posts: 5,705

    @Jmv38 is video recording broken anywhere else?

  • Jmv38Jmv38 Mod
    Posts: 3,297

    .@simeon what do you mean by 'anywhere else'? Other versions of the beta? Or sthg else? I am on ipad1 so i dont have camera or camera recording.

  • Jmv38Jmv38 Mod
    Posts: 3,297

    I tried to record some other projects: they seem to record fine.

  • SimeonSimeon Admin Mod
    edited April 2013 Posts: 5,705

    @Jmv38 I mean, are any of your other projects exhibiting odd video recording behaviour?

    Edit: thanks!

  • Jmv38Jmv38 Mod
    Posts: 3,297

    Just checked one of the variants i posted recently with the standalone library copy: the video recording is brokent too. So it seems linked to something special to this library.

  • SimeonSimeon Admin Mod
    Posts: 5,705

    Do you use clip() in your library?

  • Jmv38Jmv38 Mod
    Posts: 3,297

    Yes i do! And that is the only app where i do....

  • SimeonSimeon Admin Mod
    Posts: 5,705

    @Jmv38 sounds like this might have been a bug for a long time, I might not be able to get the fix into 1.5.2 (release version), but it's on the list for future beta versions.

  • Jmv38Jmv38 Mod
    Posts: 3,297

    Thanks!
    The positive aspect is: i have learned about the image export to twitter embedded in codea: its great! (as everything you design, actually...) :-)

  • Jmv38Jmv38 Mod
    Posts: 3,297

    Btw, it would be great to be able to export / read images in the camera roll. I am sure you plan to do it 'some day', but how far below is it on your to-do list?

  • SimeonSimeon Admin Mod
    edited April 2013 Posts: 5,705

    @Jmv38 I think I was able to fix the clip() issue. Let me know how the next build goes for you.

  • Jmv38Jmv38 Mod
    Posts: 3,297

    Great!

  • SimeonSimeon Admin Mod
    Posts: 5,705

    The priority after 1.5.2 is released will be to get custom sounds and music working (in a nice way).

    Exporting to camera roll is easier than reading, but I'm still unsure what the API will look like. Apple is fairly strict about how the camera roll must be presented (it must be inside a UIPopoverController on iPad). This means that it would have to be presented from a screen-space coordinate, and would not respect any of Codea's transformations. What we will probably end up doing is designing a modal UI from which the picker can be opened (something like the Icon selection interface in the Export Xcode feature).

  • Jmv38Jmv38 Mod
    Posts: 3,297

    Then maybe you could do a 2 steps implementation?
    1/ saving (soon).
    2/ reading (later when you have made up your mind on how to do it).
    Saving would already be great and enable all kind of apps, specially for people who have the camera.

  • SimeonSimeon Admin Mod
    Posts: 5,705

    @Reefwing here's an example of how to create a CodeaAddon

    https://gist.github.com/TwoLivesLeft/5331422

    I started tackling GameCenter and realise it's actually a little complex for an example. In this case, I've made the addon a singleton — not always necessary. It exposes one function to Codea called GameCenterStart

    While I was able to successfully test that the function was called, I wasn't able to get it to work. I assume the app ID needs to be Game Center enabled, which I didn't have time to do.

  • Posts: 563

    Thanks @Simeon - I'm not sure when you actually get a chance to sleep!

    You should be able to sign into Game Center and authenticate the player whether your app is registered or not, you will then get an alert saying "This game is not recognised by Game Center."

    I'm having a crack at iAds and your example will assist with that. I will post the results here.

    Regarding the photo picker, i think the way that icon selection works in project export is great.

    Regarding sounds and music, couldn't you use the add on functionality for this? Admittedly a native implementation would be nice.

  • Jmv38Jmv38 Mod
    edited April 2013 Posts: 3,297

    thanks for built 7 @ Simeon : problem solved!
    You know, some time i feel guilty because i paid 1.50 Euro for CODEA (in promo) and i get a support worth 25000 Euro/year (that is what it would cost me to get the same amount of support if Codea was one of the sofware i am paying external companies to developp at work...). I really appreciate. I hope you are doing (or will do) as well as you deserve to!

  • Posts: 489

    Too late for version 1.5.2 (on its way to the App Store), and perhaps already known, but the Video button does not appear to work as I would expect once the Replay button has been touched (at least, in standard screen mode and landscape orientation). The red border comes and goes, but nothing more happens.

  • SimeonSimeon Admin Mod
    Posts: 5,705

    That's a pretty significant bug. Thanks for finding it @mpilgrem. I'll resubmit if I manage to fix it today.

  • Posts: 489

    This is, I think, another bug - in the 'type a command' bar. Try entering the following sequence of commands, one after another:

    return
    return 1, 2, 3
    return
    return
    return
    return
    return
    return
    
  • Posts: 521

    Hi. Trying to use the addon system. Can I access the runtime header files somehow? I got stuck at trying to use createUIImageFromImage which is defined in image.h.

  • SimeonSimeon Admin Mod
    edited April 2013 Posts: 5,705

    Hmm you should be able to forward declare (just to let the compiler know that it exists).

    You can take some of the headers from the Codea-Runtime source and include the relevant bits in your addon. Let me know how this goes for you.

    Accessing the built in Codea types (image, vec, and so on) through your exported functions is something I'd like to add.

  • Posts: 521

    I tried to cheat using void* pointers, but I just get "Undefined symbols" errors when trying to compile it. Will try a bit more

  • SimeonSimeon Admin Mod
    edited April 2013 Posts: 5,705

    You'll need to forward declare the types as well. For example:

    struct image_type_t;
     
    typedef enum PersistenceImageAlpha
    {
        PersistenceImageAlphaPremultiply,
        PersistenceImageAlphaNoPremultiply,
    } PersistenceImageAlpha;
     
    UIImage* createUIImageFromImage(struct image_type_t* image, PersistenceImageAlpha alphaOption);
  • edited April 2013 Posts: 521

    Ah, thanks for the help, was just trying something like it, but it don't look like that in the runtime, now it seems to have a new argument. But I guess my error depends on that the createUIImageFromImage is not defined in a h-file, as in the current runtime. Or maybe I'm a newbie. :)

    Undefined symbols for architecture armv7:
      "createUIImageFromImage(image_type_t*, PersistenceImageAlpha)", referenced from:
          WriteToPhotoAlbumFunction(lua_State*) in WriteToPhotoAlbum.o
      "lua_pushcclosure(lua_State*, int (*)(lua_State*), int)", referenced from:
          -[WriteToPhotoAlbum codea:didCreateLuaState:] in WriteToPhotoAlbum.o
      "lua_setfield(lua_State*, int, char const*)", referenced from:
          -[WriteToPhotoAlbum codea:didCreateLuaState:] in WriteToPhotoAlbum.o
    ld: symbol(s) not found for architecture armv7
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    

    I'm just trying a small example of saving an image to the photo album. Here is the mm file.

    #import "WriteToPhotoAlbum.h"
    #import "lua.h"
    #import "image.h"
    
    struct image_type_t;
    
    typedef enum PersistenceImageAlpha
    {
        PersistenceImageAlphaPremultiply,
        PersistenceImageAlphaNoPremultiply,
    } PersistenceImageAlpha;
    
    UIImage* createUIImageFromImage(struct image_type_t* image, PersistenceImageAlpha alphaOption);
    
    static int WriteToPhotoAlbumFunction(struct lua_State *state);
    
    @implementation WriteToPhotoAlbum
    
    DEFINE_SHARED_INSTANCE_IMPL
    
    - (void) codea:(CodeaViewController*)controller didCreateLuaState:(struct lua_State*)L
    {
        NSLog(@"Register WriteToPhotoAlbum");
        lua_register(L, "saveToPhotoAlbum", WriteToPhotoAlbumFunction);
    }
    @end
    
    static int WriteToPhotoAlbumFunction(struct lua_State *state) {
        image_type* imageType = checkimage(state, 2);
        UIImage* image = createUIImageFromImage(imageType, PersistenceImageAlphaNoPremultiply);
        UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
        return 0;
    }
    
  • edited April 2013 Posts: 521

    Ah, guess it should be extern "C". Still have the issue with push_closure, but must have missed a h-file maybe. Edit: Got it working! Even popped up a dialog asking for access to the photo album. Was a bit confused that import only works if inside the extern statement.

    #import "WriteToPhotoAlbum.h"
    
    #ifdef __cplusplus
    extern "C" {
    #endif
    
    #import "lua.h"
    #import "lauxlib.h"
    
    struct image_type_t;
    struct image_type_t *checkimage(lua_State *L, int i);
    
    typedef enum PersistenceImageAlpha
    {
        PersistenceImageAlphaPremultiply,
        PersistenceImageAlphaNoPremultiply,
    } PersistenceImageAlpha;
    
    UIImage* createUIImageFromImage(struct image_type_t* image, PersistenceImageAlpha alphaOption);
    
    #ifdef __cplusplus
    }
    #endif
    
    static int WriteToPhotoAlbumFunction(struct lua_State *state);
    
    @implementation WriteToPhotoAlbum
    
    DEFINE_SHARED_INSTANCE_IMPL
    
    - (void) codea:(CodeaViewController*)controller didCreateLuaState:(struct lua_State*)L
    {
        NSLog(@"Register WriteToPhotoAlbum");
        lua_register(L, "saveToPhotoAlbum", WriteToPhotoAlbumFunction);
    }
    @end
    
    static int WriteToPhotoAlbumFunction(struct lua_State *state) {
        struct image_type_t* imageType = checkimage(state, 1);
        UIImage* image = createUIImageFromImage(imageType, PersistenceImageAlphaPremultiply);
        UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
        return 0;
    }
    

    Haven't figured out what the PersistenceImageAlpha does :). My transparent image gets a white background instead. Really nice to get it working :)

  • SimeonSimeon Admin Mod
    Posts: 5,705

    @tnlogy good to know you got it working!

    Sorry about the lack of headers, eventually I'd like to make this stuff a lot more developer friendly.

  • Posts: 521

    I guess it's most confusing when the old headers are not the same as the new. If they would be published somewhere it would be a bit easier. :)

    Good work with the API, will try it out a bit more.

  • Posts: 521

    I added a facebook share function as well, making the name of my addon a bit forced. Working fine!

    https://gist.github.com/tnlogy/5371725

    Would it be possible to access the camera stream? Would like to try using the CIDetector, but maybe it's about just as fast calling my function from the draw method.

    http://developer.apple.com/library/ios/#documentation/CoreImage/Reference/CIDetector_Ref/Reference/Reference.html

  • SimeonSimeon Admin Mod
    Posts: 5,705

    I'm unsure on the camera stream, basic types will probably come first.

    Note that you don't have to use the GCD singleton code — I simply used it in the GameCenter test because I needed to attach the addon as a delegate to the GKGameCenterViewController from inside the exported Lua function, this was the cleanest way I could think to have access to the specific instance of the addon. This made the code more complex than I liked.

    The singleton pattern is helpful if you need to manipulate/access the singular instance of your addon in exported Lua functions.

  • Posts: 521

    Ok, works fine anyhow. Was thinking of removing it, since I haven't read about GCD yet, but then I got use for it in the facebook share function, since I call presentViewController and need the CodeaViewController.

  • Posts: 521

    I tried using startRecording and stopRecording. It doesn't seem to work, or no video is saved anyway.

  • Posts: 563

    I got AVAudioPlayer working using the new add on functionality. The add on code is available here: https://gist.github.com/reefwing/5377746 and there is a tutorial on it here: http://codeatuts.blogspot.com.au/2013/04/tutorial-28-codea-v152-objective-c-add.html

    I like the new API. My biggest issue was trying to call an objective c method from within a c function. What I have done feels like a bit of a hack, so if there is a more elegant way then I would love to learn it.

    I didn't use @Simeon's singleton pattern for a couple of reasons:

    1. Just to see if I could; and
    2. The extra singleton code obfuscates the learning process a bit and could be intimidating for 1st time Xcoders. I wanted to show how simple it is to add functionality using this new protocol.

    As always - comments welcome.

  • Posts: 521

    Bug: The back camera seems to be mirrored horizontally. Or at least in the camera sample.

    Nice audio example!

  • Posts: 563

    Thanks @tnlogy - I just followed yours and @Simeon's lead.

  • Posts: 563

    I've updated the audio add on so that you can control the volume of the player from your Lua code and that works great. So getting values from Lua to Objective C is all good but I'm having problems going the other way.

    I'm trying to provide a dB meter as part of this audio add on. To that end I need to read an integer from my add on method within the draw loop. I'm using the Cider dial control (which looks great) like this:

    function draw()
        dial.val = peakPowerForPlayer() or 0
    end
    

    The app crashes (the old EXC_BAD_ACCESS) as soon as the mp3 starts playing. Any ideas what I am doing wrong? I think the issue is that I am not returning a valid integer in peakPowerForPlayer(). The associated Objective C method getPower seems to work ok.

    The relevant code is shown below.

    - (int)getPower
    {
        if ([self.player isPlaying])
        {
            //  Refresh the average and peak power values for all channels of our audio player.
            
            [self.player updateMeters];
            
            //  A floating-point representation, in decibels, of a given audio 
            //  channel’s current peak power.
            //  A return value of 0 dB indicates full scale, or maximum power; 
            //  a return value of -160 dB indicates
            //  minimum power (that is, near silence).
            //
            //  If the signal provided to the audio player exceeds ±full scale, 
            //  then the return value may exceed 0
            //  (that is, it may enter the positive range). For simplicity we will 
            //  only return the power from channel 0.
            
            float power = [self.player peakPowerForChannel: 0];
            
            //  Our dial is expecting a value between 0 and 100.
            
            if (power >= 0)
                return 100;
            else
            {
                power += 160.0f;    //  power is now a +ve float between 0 and 160
                power = (power / 160.0f) * 100.0f;      //  change to a percentage
                return (int)power;
            }
        }
        else
            return 0;
    }
    
    //  C Functions
    
    static int peakPowerForPlayer(struct lua_State *state)
    {
        return [audioAddOnInstance getPower];
    }
    
  • SimeonSimeon Admin Mod
    Posts: 5,705

    @Reefwing unfortunately interfacing with Lua is a bit complicated.

    Your function:

    static int peakPowerForPlayer(struct lua_State *state)
    {
        return [audioAddOnInstance getPower];
    }

    Should not be returning a value directly — the returned value from all exported Lua functions is how many values that function should return in Lua.

    For example, if you return 0 from that function, you are telling Lua that peakPowerForPlayer returns 0 values. If you return 2, you are telling Lua to expect 2 values on the stack when the function returns.

    To actually return values, you need to push them onto the Lua stack and then return the number of values you pushed on. So this should work:

    static int peakPowerForPlayer(struct lua_State *state)
    {
        //Push the integer on the stack
        lua_pushinteger(state, [audioAddOnInstance getPower]);
     
        return 1; //Our function returns 1 value
    }
  • Posts: 563

    @Simeon - that would explain it. Thanks for the info, it now works. I will post the new add on code tonight.

  • Posts: 563

    Here is a link to the updated audio framework: https://gist.github.com/reefwing/5377746

    The following functions are available in Codea once the audio add on is registered:

    playMusic()
    stopMusic()
    
    getVolume()                -- returns an integer between 0 and 100
    setVolume(setting)      -- expects setting to be between 0 and 100
    
    peakPowerForChannel(channel)
    averagePowerForChannel(channel)
    

    I used the Cider dial and donut for the left and right dB level meters, and the Cider slider for the volume control. So you will need to include these as a dependency. Thanks to @Mark for his work on these, they look great. You may have to tweak the position of the controls, for some reason they moved when I exported them from Codea into Xcode.

    Feel free to expand/modify or otherwise use the code. The meters would look better with a slow animation to zero when the mp3 is stopped. Passing in an mp3 name to play is another obvious extension.

  • Posts: 563

    @Simeon - would it be possible to expose:

    - (BOOL)shouldAutorotateToInterfaceOrientation:
    (UIInterfaceOrientation)interfaceOrientation
    

    in the CodeaViewController header file? That would simplify handling rotation in add ons.

  • SimeonSimeon Admin Mod
    Posts: 5,705

    You could subclass it and override those methods in your subclass, then instantiate that inside the AppDelegate instead.

    The CodeaViewController versions of those methods are complicated because they allow the Lua call supportedOrientations to function.

Sign In or Register to comment.