Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: Representing tones visually in blocks

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Representing tones visually in blocks

    Cross-posted:http://www.java-forums.org/new-java/...tml#post310040
    Good day.

    My first post, yay!
    I'm working on a project for school, the requirements are that we must have at least 10 classes and implement the usual stuff like inheritence, overriding, ...
    I wanted to do something special, so I'm working on a visual drag'n drop program for sounds. So you can specify the frequency and duration of a tone, and add the specific block to a channel. A channel is something I created so blocks don't have to overlap. A channel is actually just an additional of blocks beneath the other one. The amount of channels is unlimited, so is the length of a Channel. Channels will be played simultaneously. Now comes the problem..

    I have a class named 'SynthBlock', which contains the starting time, duration and frequency of this tone. It is a part of my Channel class. (= arraylist)
    I wanted to represent a synthblock visually, so I made another class: ToneBox. This must be a child-class from JComponent and override the paintComponent method.

    I wanted to ask... is it wise to inherit from the JComponent class? And how would I best calculate the coordinates needed for my drawRectangle?
    Project is included if needed. I am certainly not trying to give my schoolwork away to someone else, I just want to find out the best way.
    I uploaded it here: https://rapidshare.com/files/1086823385/project.zip

    Greetings,
    Nindustries


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Representing tones visually in blocks

    Greetings and welcome Nindustries.

    I don't understand your goal. Or maybe I do but not clearly. Describe what it should look like, perhaps with an example.

    And how would I best calculate the coordinates needed for my drawRectangle?
    I don't understand what type of visual you plan to create.

    A channel is actually just an additional of blocks beneath the other one
    Is this supposed to be a description of how to draw them on screen or how they are organized for playback?

    This must be a child-class from JComponent and override the paintComponent method.
    is it wise to inherit from the JComponent class?
    Are you supposed to as in a requirement? Sure you can, do you need to? Ask yourself if what you are building is going to be a JComponent or not, and if it is, make it one.

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Representing tones visually in blocks

    prog_sample.jpg
    I don't understand what type of visual you plan to create.
    Well I want to represent each block (so each tone/sound) visually by a rectangle. (See image above)

    Is this supposed to be a description of how to draw them on screen or how they are organized for playback?
    Both, each channel will get a thread that will play the blocks in order.

    Are you supposed to as in a requirement? Sure you can, do you need to? Ask yourself if what you are building is going to be a JComponent or not, and if it is, make it one.
    I tought that if I need something visually onscreen, I needed to inherit JComponent. Maybe not, because I'm just going to draw rectangles with some text on them.

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Representing tones visually in blocks

    So It looks like starting at the left edge of the screen moving to the right, is time.
    Stacked top to bottom are channels.
    Any single channel can play one tone at a time, and to play multiple tones simultaneously you use multiple channels.
    ...
    if I understand correctly
    ...
    So the length of time the tone plays is represented by the left to right (width) of the rectangle. You will need to establish a relationship between pixels-in-width and time-the-tone-plays. Perhaps w pixels wide per ms milliseconds long or something.
    The channels are arranged channel 1 on top counting up as you move down (the same way pixels are numbered on the screen in java), nothing wrong with that.
    So the only thing missing is the frequency. How will you represent the frequency? The height of the rectangle within the channel would be one way. Change the color of the block.

    So once you determine how you will represent the frequency you finally have designed the rough draft on your plan.

    I tought that if I need something visually onscreen, I needed to inherit JComponent. Maybe not, because I'm just going to draw rectangles with some text on them.
    Do you have a window showing already? I am more trying to mention options than give suggestions.

  5. #5
    Junior Member
    Join Date
    Nov 2012
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Re: Representing tones visually in blocks

    Quote Originally Posted by jps View Post
    So It looks like starting at the left edge of the screen moving to the right, is time.
    Stacked top to bottom are channels.
    Any single channel can play one tone at a time, and to play multiple tones simultaneously you use multiple channels.
    Exactly! I think that Frequencys will just be represented by a label printed on the Box and the color of the box.
    I'll try to find a decent relation between duration and block length, and default block heights.

    Quote Originally Posted by jps View Post
    Do you have a window showing already? I am more trying to mention options than give suggestions.
    I already have a JPanel forum showing everything except the grid and the blocks :p

  6. #6
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,372
    Thanks
    183
    Thanked 836 Times in 779 Posts
    Blog Entries
    5

    Default Re: Representing tones visually in blocks

    This thread has been cross posted here:

    http://www.java-forums.org/new-java/65031-representing-classes-visually-timeline.html

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting


  7. The Following 2 Users Say Thank You to copeg For This Useful Post:

    jps (November 15th, 2012), Nindustries (November 16th, 2012)

  8. #7
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Representing tones visually in blocks

    Quote Originally Posted by Nindustries View Post
    Exactly! I think that Frequencys will just be represented by a label printed on the Box and the color of the box.
    What happens if the duration is very short and there is not enough room on the block to print the label?

    Quote Originally Posted by Nindustries View Post
    I already have a JPanel forum showing everything except the grid and the blocks :p
    I would reuse what ever I could, but also don't be afraid to write something new or add on to something old. Make it work the way you see it in your head regardless of what it takes.

  9. #8
    Junior Member
    Join Date
    Nov 2012
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Representing tones visually in blocks

    Quote Originally Posted by jps View Post
    What happens if the duration is very short and there is not enough room on the block to print the label?
    Well the user could always hover their mouse over the block, the label will be textwrapped I think.
    I already coded the 'basic' stuff like the forms, Channel classes and SynthBlock classes.

    Okay guys, so I figured:
    I will be using a Component-child class from JPanel(or JButton) where I use the GridBayLayout. I will use the dynamic aspect of the constraints of this LayoutManager.
    I will then implement drag-and-drop onto this JPanel, if it is dropped out of the constraints, the Panel will generate new and bigger constraints.
    After being dragged and dropped, the panel will paint lines to visualise the columns and rows. (Or the constraints as you can call it.)

    So first things first, how can I determine the user dropped it onto an existing 'constraint'/cell or not?

    Greetings

  10. #9
    Junior Member
    Join Date
    Nov 2012
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Representing tones visually in blocks

    To thank you for all your good support, I hereby upload my finished project.
    It's not a masterpiece, but it does the job.
    Note: It's a NetBeans project.

    Download link: http://rapidshare.com/files/817242814/VGO.zip

  11. #10
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    1,069
    Thanks
    7
    Thanked 215 Times in 191 Posts

    Default Re: Representing tones visually in blocks

    Well done! And thanks for the update.

Similar Threads

  1. Making a method to move blocks in a grid
    By geforce in forum What's Wrong With My Code?
    Replies: 60
    Last Post: May 22nd, 2012, 08:00 AM
  2. BufferedReader.read() blocks,when checking if there's any input for some URLs
    By redateksystem in forum File I/O & Other I/O Streams
    Replies: 8
    Last Post: March 27th, 2012, 10:33 AM
  3. Replies: 2
    Last Post: November 30th, 2011, 07:35 PM
  4. Nested try blocks
    By Ahmed. in forum Member Introductions
    Replies: 2
    Last Post: April 30th, 2010, 09:12 AM

Tags for this Thread