Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8356173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:06:16+00:00 2026-06-09T10:06:16+00:00

I have this multimap in my code: multimap<long, Note> noteList; // notes are added

  • 0

I have this multimap in my code:

multimap<long, Note> noteList;

// notes are added with this method. measureNumber is minimum `1` and doesn't go very high
void Track::addNote(Note &note) {
    long key = note.measureNumber * 1000000 + note.startTime;
    this->noteList.insert(make_pair(key, note));
}

I’m encountering problems when I try to read the notes from the last measure. In this case the song has only 8 measures and it’s measure number 8 that causes problems. If I go up to 16 measures it’s measure 16 that causes the problem and so on.

// (when adding notes I use as key the measureNumber * 1000000. This searches for notes within the same measure)
for(noteIT = trackIT->noteList.lower_bound(this->curMsr * 1000000); noteIT->first < (this->curMsr + 1) * 1000000; noteIT++){
if(this->curMsr == 8){
    cout << "_______________________________________________________" << endl;
    cout << "ID:" << noteIT->first << endl;
    noteIT->second.toString();
    int blah = 0;
}

// code left out here that processes the notes
}

I have only added one note to the 8th measure and yet this is the result I’m getting in console:

_______________________________________________________
ID:8000001
note toString()
Duration: 8
Start Time: 1
Frequency: 880
_______________________________________________________
ID:1
note toString()
Duration: 112103488
Start Time: 44
Frequency: 0    
_______________________________________________________
ID:8000001
note toString()
Duration: 8
Start Time: 1
Frequency: 880
_______________________________________________________
ID:1
note toString()
Duration: 112103488
Start Time: 44
Frequency: 0

This keeps repeating. The first result is a correct note which I’ve added myself but I have no idea where the note with ID: 1 is coming from.

Any ideas how to avoid this? This loop gets stuck repeating the same two results and I can’t get out of it. Even if there are several notes within measure 8 (so that means several values within the multimap that start with 8xxxxxx it only repeats the first note and the non-existand one.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T10:06:18+00:00Added an answer on June 9, 2026 at 10:06 am

    You aren’t checking for the end of your loop correctly. Specifically there is no guarantee that noteIT does not equal trackIT->noteList.end(). Try this instead

    for (noteIT = trackIT->noteList.lower_bound(this->curMsr * 1000000); 
        noteIT != trackIT->noteList.end() &&
        noteIT->first < (this->curMsr + 1) * 1000000;
        ++noteIT)
    {
    

    For the look of it, it might be better to use some call to upper_bound as the limit of your loop. That would handle the end case automatically.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code but it doesn't work! public class Trial { public static
I have this form: <%= form_tag posts_path, :method => :get, :class => search_nav do
I have a strongly recursive function, that creates a (very small) std::multimap locally for
I have this structure based multimap and a vector for this structure: typedef std::multimap<char,
I have a guava HashMultimap like this Multimap<String, String> multiMap = HashMultimap.create(); multiMap.put(a, x);
have this code: $products = $feed->_xpath->query( //cf:vehicle ); foreach( $products as $product ) {
Have this code: var gradient = ctx.createLinearGradient(0,0, 20, 0); gradient.addColorStop(0.8, rgb(250,250,0)); gradient.addColorStop(1, rgb(150,150,0)); ctx.fillStyle
I have a std::multimap where key is a custom class. Something like this: Class
I have written a code for finding intersection of two multimap which will compare
I'm debugging my code and at one point I have a multimap which contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.