About Stylus detection

Discussion in 'NDS - ROM Hacking and Translations' started by Ben_j, Aug 10, 2007.

  1. Ben_j
    OP

    Ben_j GBAtemp Advanced Fan

    Member
    696
    13
    Nov 13, 2005
    France
    I'm working on a MIDI application for the DS, and a Midi CC is sent when the screen is pressed, and another one when it's released. The only problem is that it's not sent all the time when it's released... And since I have to send only one message at the moment it's released, I can't send the message anytime the stylus isn't pressed. I've tried a lot of thing and I can't figure out why it's not working. Here's what I did :

    if (Stylus.Newpress or Stylus.Held)
    Send MIDI_CC 127
    was_held = 1
    else
    if (was_held == 1 or Stylus.Released)
    Send MIDI_CC 0
    was_held = 0
     
  2. AndreXL

    AndreXL GBAtemp Advanced Fan

    Member
    514
    0
    Dec 28, 2006
    I personally have not tried coding for DS...
    Still actions under "if statement" should be contained either by brackets or indents and the "else if" statement should be on the same line, right?
     
  3. Ben_j
    OP

    Ben_j GBAtemp Advanced Fan

    Member
    696
    13
    Nov 13, 2005
    France
    duh
    I know that It was simplified code...

    If you really want C code here it is :

    Code:
    if (Stylus.Newpress || Stylus.Held)
    {
    ÂÂÂÂdsmi_write(MIDI_CC | channel, 0x00, cc_val_xy(Stylus.X, 'x'));
    ÂÂÂÂdsmi_write(MIDI_CC | channel, 0x01, cc_val_xy(Stylus.Y, 'y'));
    ÂÂÂÂdsmi_write(MIDI_CC | channel, 0x04, 127);
    ÂÂÂÂwas_held = 1;
    }
    else
    {
    ÂÂÂÂif (was_held == 1)
    ÂÂÂÂ{
    Âdsmi_write(MIDI_CC | channel, 0x04, 0);
    Âwas_held = 0;
    ÂÂÂÂ}
    }
     
  4. FAST6191

    FAST6191 Techromancer

    pip Reporter
    23,037
    8,741
    Nov 21, 2005
    I am not that familiar with midi (reading this http://www.u-he.com/vstsource/files/midiCtrl.h probably increased the knowledge I have of of it about 1000 times, can I assume your app is similar to this?).

    The DS is set to poll the touchscreen at a certain frequency (2MHz as I understand it which is faster than anything a human can do as far as touching and releasing the screen is concerned), you said you are using PaLib in the release/discussion thread which is a fine library but for me it is the equivalent of Chinese whispers as far as low level coding is concerned. Therefore gbatek specs for the touchscreen: http://nocash.emubase.de/gbatek.htm#dstouc...encontrollertsc , for something so dependent on the touchscreen it may be worthwhile writing your own I/O routine (assuming it is just for this you effectively only have to read on value (not quite that simple as that as it should require messing with the SPI bus) and see what it is (FFF hex when reading the "Y" position is unreleased, GBATek explains all though).

    I am not sure what language you are using there and I am a bit too busy to write and debug some ASM (not to mention make it compatible with what you have, nothing personal I just have a lot on right now).
    My personal suggestion for a quick fix is to read the value and write it to a a position in the memory at every poll (or every few if it hits performance as much as I think it might: rough guess says 20 times a second (20Hz) is the realistic limit for audio but you might want to up that a bit just in case.
    Now when the screen is read compare the current value to the one in the position you assigned (the nice thing about it being (0)FFF for released with all else below it is you can use a simple less than to compare).
    Now you can play "when unreleased" as it will only send on the occasion that the memory location and the current read say what you need.

    Edit: I did see your second reply, you may wish to ignore me until I revise my post.
     
  5. Ben_j
    OP

    Ben_j GBAtemp Advanced Fan

    Member
    696
    13
    Nov 13, 2005
    France
    I didn't understand everything in your post, but if you say to ignore it then I'll do for the moment [​IMG]

    Here's something else I tried. I think it seems to work a bit better...

    Code:
    if (Stylus.Held)
    {
    Â Âdsmi_write(MIDI_CC | channel, 0x00, cc_val_xy(Stylus.X, 'x'));
    Â Âdsmi_write(MIDI_CC | channel, 0x01, cc_val_xy(Stylus.Y, 'y'));
    Â Âscreen_cc = 127;
    Â Âwas_held = 1;
    }
    else
    Â Âscreen_cc = 0;
    if (!Stylus.Held && screen_cc == 127)
    Â Âscreen_cc = 0;
    if (was_held == 1)
    {
    Â Âdsmi_write(MIDI_CC | channel, 0x04, screen_cc);
       was_held = (screen_cc == 0 ? 0 : 1);
    }