• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

finding out difference in time?

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to implement recording, this will include timing between notes.

I want to time between two presses of any one of 8 keys and then store the result in an array.

i have tried using getTime, but do not understand how to use it really, it would only compile if i put it in it's own method? then calling the method does not seem to work when i try and add this long to a long array.
[ April 25, 2006: Message edited by: Andrew Brown ]
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
System.currentTimeMillis() is handy for this kind of thing. You might have an algorithm like:

Does this seem to answer the right question? If so, some further thoughts ...

You'd have to write the Note class. If you're not comfortable doing that just ask for more hints.

You'll also have to wire this method to the keyboard somehow. Is this a Swing application?

This makes each note play until you hit the next key; you might want to make an onKeyUp() method to stop notes.

I didn't handle the "stop recording" event to put the last Note into the list, but it would be a lot like onKeyPressed.

Look into the Midi Sequencer APIs for inspiration. They are kinda tricky but might give you some ideas on how to structure this stuff.
[ April 25, 2006: Message edited by: Stan James ]
 
Andrew Brown
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you for you help but it's not really what i'm looking for, i'm looking to find the differences in time from when a key is pressed until another key is pressed.

The system that i am writing is not a keyboard, so it isn't about how long the note plays for, but about the difference in time because i want to play the notes back with the same gap as when i've played them.

The System.getCurrentTimeMillis(), what does this do? not sure how to use it.

Other things are that i have implemented it in such a way that it compiles, but then simply doesn't work. not sure why because in my opinion it should be working.

any further help will be greatly received.
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
System.getCurrentTimeMillis() returns "the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC."

All you need to so is get the current time using the above method whenever a note is pressed. Store them however you want, either group the note and timestamp together in an object, or store them in seperate arrays with identical indexes.

If you want to go back and compare the differences in time, use simple subtraction.
 
Stan James
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

thank you for you help but it's not really what i'm looking for, i'm looking to find the differences in time from when a key is pressed until another key is pressed.



I think that's precisely what I outlined. System currentTimeInMillis gives you the current time (!) to millisecond precision. Getting the time between two events is as simple as saving the current time before and subtracting it from the current time after. The result is in milliseconds. If you have a playback routine, you can make it sleep the same number of milliseconds to reproduce your timing.

The kind of keyboard will make a lot of difference in how you get key down and key up events. Is it a standard computer? A MIDI controller? Something else? Are you able to capture these events and just display them as they happen? I know that's not part of the problem, but it's a step in figuring out a solution.

Look back through my earlier post and imagine what it would do if something as yet unknown called onKeyDown every time you hit a key. Look up the JavaDoc for anything that's not familiar. Except Note. I made that up.

If that doesn't help, keep asking! We might want to break this down into smaller problems so we don't get confused about what's needed and what's working.
 
Andrew Brown
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does anyone know if i have to imprt a package to use the System.getCurrentTimeMillis() method? it keeps telling me that it wont compile.
 
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Andrew Brown:
Does anyone know if i have to imprt a package to use the System.getCurrentTimeMillis() method? it keeps telling me that it wont compile.



Try... System.currentTimeMillis()

Henry
 
Stan James
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's a secret ... how we make ourselves look smarter than we really are ... bookmark this: http://java.sun.com/j2se/1.5.0/docs/api/
 
Andrew Brown
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it works now, although couldn't find the System.currentTimeMillis() method in the API. I did try that one first, and thought that the get time method would be sufficient, but thanks for pointing me in the right direction. You've all been very helpful.

My recording works a treat now.

Cheers
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
System is in the java.lang package. The reason you can use it without importing it is that all classes in the java.lang package are imported automatically (because you need them all the time).
 
Bras cause cancer. And tiny ads:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic