Without knowing anything about your data structure, I would offer this
comment.  It would seem that the sequence of the notes is your primary means
of accessing and referencing them.  That is, it is your primary key.  Unless
you have another means of "getting to" the notes, a dictionary will not help
much.  It will suffer from the same problem as arrays, and maybe even be
more difficult to use.

The issue is, how do you reference the "nth" note?  Does each note have some
unique identifier, apart from the array index (sequence number)?  If you
create some identifier other than sequence, then a dictionary may be the way
to go.  Otherwise, stick with arrays.

If you think of the array as a set of pointers to your note data, then the
array index provides an additional piece of information (a sequence number)
that is not stored as part of the note.  This allows you to resequence
(insert, delete, move) a note without modifying the note data, or having to
modify all the notes that follow it.  You simply manipulate the set of
pointers - your array.

To remove a pointer from the array, you copy all the subsequent pointers
down by one, and trim the last one off the array.  To insert a pointer, you
increase the array by one, find the spot to insert and copy all the
subsequent pointers into the next higher position in the array.  Moving a
note is a remove followed by an insert.

To do this with a dictionary, you would have to store the sequence number as
part of the note data, and then find and modify every subsequent note to
reflect the change in sequence.  If you use the sequence number as the
dictionary key, then you have to delete and re-add each note as you change
the sequence.

I'd stick with the array, unless you want to try your hand at a linked list
of note objects.

Now, you might be able to use a dictionary for selected notes.  Store the
index number for each selected note.  Might help...

Tim



> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] Behalf Of Philip
> Regan
> Sent: Monday, March 27, 2006 9:59 AM
> To: [email protected]
> Subject: Hobbyist's question about managing objects
>
>
> Howdy--
>
> I've been writing as my main project a simple MIDI editor off and on
> for the past year or so. As my programming skills improve, I tend to
> go back and rewrite certain parts of the editor.
>
> Right now, I'm doing a major rebuild of the editor interface (the part
> where the user adds/clicks/drags/deletes notes) and I'm coming to a
> conceptual question/problem that I'd like to ask folks on the list,
> and it regards how to manage objects whose order can be changed at the
> whim of the user.
>
> Currently, I manage notes (a custom class) in a set of arrays,
> everything from all the notes themselves, selecting, deselecting, etc.
> This is fine as long as the notes remain in their sequential order,
> and is particularly handy when it comes to playing and writing
> binaries of the song. It seems to work fine so far, but I'm hitting
> some roadblocks when it comes to selecting and deselecting multiple
> objects that I'm pretty sure are due to them being held in an array.
>
> Since the order of the notes and their selection can changed by the
> user, I'm thinking that a Dictionary might be the way to go. The only
> part that's truly fuzzy to me is how to put them all into sequential
> order when the user wants to play and save their files. Beyond that,
> the Dictionary seems to be the way to go with object management in
> this application.
>
> Before I get elbow deep into changing over my code, I thought I'd ask
> the group if that seems like the way to go, how they would approach
> it, maybe there's a more advanced approach I'm not aware of, etc.
>
> Thanks!
> --
> Philip Regan
> [EMAIL PROTECTED]
> http://homepage.mac.com/pregan
> REALBasic 2005r4, Applescript
> Mac OS 10.3.9
> _______________________________________________
> Unsubscribe or switch delivery mode:
> <http://www.realsoftware.com/support/listmanager/>
>
> Search the archives of this list here:
> <http://support.realsoftware.com/listarchives/lists.html>
>
>


_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to