Example #1
0
int Measure::CastOffSystems( ArrayPtrVoid *params )
{
    // param 0: a pointer to the system we are taking the content from
    // param 1: a pointer the page we are adding system to
    // param 2: a pointer to the current system
    // param 3: the cummulated shift (m_drawingXRel of the first measure of the current system)
    // param 4: the system width
    // param 5: the current scoreDef width
    System *contentSystem = static_cast<System*>((*params).at(0));
    Page *page = static_cast<Page*>((*params).at(1));
    System **currentSystem = static_cast<System**>((*params).at(2));
    int *shift = static_cast<int*>((*params).at(3));
    int *systemWidth = static_cast<int*>((*params).at(4));
    int *currentScoreDefWidth = static_cast<int*>((*params).at(5));
    
    if ( ( (*currentSystem)->GetChildCount() > 0 ) && ( this->m_drawingXRel + this->GetWidth() + (*currentScoreDefWidth) - (*shift) > (*systemWidth) ) ) {
        (*currentSystem) = new System();
        page->AddSystem( *currentSystem );
        (*shift) = this->m_drawingXRel;;
    }
    
    // Special case where we use the Relinquish method.
    // We want to move the measure to the currentSystem. However, we cannot use DetachChild
    // from the content System because this screws up the iterator. Relinquish gives up
    // the ownership of the Measure - the contentSystem will be deleted afterwards.
    Measure *measure = dynamic_cast<Measure*>( contentSystem->Relinquish( this->GetIdx()) );
    assert( measure );
    (*currentSystem)->AddMeasure( measure );
    
    return FUNCTOR_SIBLINGS;
}
Example #2
0
bool DarmsInput::ImportString(std::string data_str) {
    int len, res;
    int pos = 0;
    const char *data = data_str.c_str();
    len = data_str.length();

    m_doc->Reset( Raw );
    System *system = new System();
    Page *page = new Page();
    m_staff = new Staff( 1 );
    m_measure = new Measure( true, 1 );
    m_layer = new Layer( 1 );

    m_current_tie = NULL;
    m_staff->AddLayer(m_layer);
    m_measure->AddStaff( m_staff );
    system->AddMeasure( m_measure );

    // do this the C style, char by char
    while (pos < len) {
        char c = data[pos];

        if (c == '!') {
            LogDebug("DarmsInput: Global spec. at %i", pos);
            res = do_globalSpec(pos, data);
            if (res) pos = res;
            // if notehead type was specified in the !Nx option preserve it
            m_staff->notAnc = m_antique_notation;
        } else if (isdigit(c) || c == '-' ) { // check for '-' too as note positions can be negative
            //is number followed by '!' ? it is a clef
            if (data[pos + 1] == '!') {
                res = do_Clef(pos, data);
                if (res) pos = res;
            } else { // we assume it is a note
                res = do_Note(pos, data, false);
                if (res) pos = res;
            }
        } else if (c == 'R') {
            res = do_Note(pos, data, true);
            if (res) pos = res;
        } else {
            //if (!isspace(c))
            //LogMessage("Other %c", c);
        }

        pos++;
    }

    // add miniaml scoreDef
    StaffGrp *staffGrp = new StaffGrp();
    StaffDef *staffDef = new StaffDef();
    staffDef->SetStaffNo( 1 );
    staffGrp->AddStaffDef( staffDef );
    m_doc->m_scoreDef.AddStaffGrp( staffGrp );

    page->AddSystem( system );
    m_doc->AddPage( page );

    return true;
}
Example #3
0
void Doc::LayOut( )
{
    this->SetCurrentScoreDef();
    
    Page *contentPage = this->SetDrawingPage( 0 );
    assert( contentPage );
    contentPage->LayOutHorizontally();
    
    System *contentSystem = dynamic_cast<System*>(contentPage->DetachChild( 0 ));
    assert( contentSystem );
    
    System *currentSystem = new System();
    contentPage->AddSystem( currentSystem );
    int shift = 0;
    int systemFullWidth = this->m_drawingPageWidth - this->m_drawingPageLeftMar - this->m_drawingPageRightMar
        - currentSystem->m_systemLeftMar - currentSystem->m_systemRightMar;
    ArrayPtrVoid params;
    params.push_back( contentSystem );
    params.push_back( contentPage );
    params.push_back( &currentSystem );
    params.push_back( &shift );
    params.push_back( &systemFullWidth );
    Functor castOffSystems( &Object::CastOffSystems );
    contentSystem->Process( &castOffSystems, params );
    delete contentSystem;
    
    LogDebug("Layout: %d systems", contentPage->GetSystemCount());
    
    // Reset the scoreDef at the beginning of each system
    this->SetCurrentScoreDef( true );
    contentPage->LayOutVertically( );
    
    // Detach the contentPage
    this->DetachChild( 0 );
    assert( contentPage && !contentPage->m_parent );
    
    Page *currentPage = new Page();
    this->AddPage( currentPage );
    shift = 0;
    int pageFullHeight = this->m_drawingPageHeight - this->m_drawingPageTopMar; // obviously we need a bottom margin
    params.clear();
    params.push_back( contentPage );
    params.push_back( this );
    params.push_back( &currentPage );
    params.push_back( &shift );
    params.push_back( &pageFullHeight );
    Functor castOffPages( &Object::CastOffPages );
    contentPage->Process( &castOffPages, params );
    delete contentPage;
    
    LogDebug("Layout: %d pages", this->GetChildCount());

    // We need to reset the drawing page to NULL
    // because idx will still be 0 but contentPage is dead!
    this->ResetDrawingPage( );
    this->SetCurrentScoreDef( true );
}
Example #4
0
void Doc::LayOutContinuously( )
{  
    Page *contentPage = new Page();
    System *contentSystem = new System();
    contentPage->AddSystem( contentSystem );

    ArrayPtrVoid params;
    params.push_back( contentSystem );

    Functor unCastOff( &Object::UnCastOff );
    this->Process( &unCastOff, params );
    
    this->ClearChildren();
    
    this->AddPage(contentPage);
    
    LogDebug("ContinousLayout: %d pages", this->GetChildCount());
    
    // We need to reset the drawing page to NULL
    // because idx will still be 0 but contentPage is dead!
    this->ResetDrawingPage( );
    this->SetCurrentScoreDef( true );
}
Example #5
0
void PaeInput::parsePlainAndEasy(std::istream &infile) {
    // buffers
    char c_clef[1024] = {0};
    char c_key[1024] = {0};
    char c_keysig[1024] = {0};
    char c_timesig[1024] = {0};
    char c_alttimesig[1024] = {0};
    char incipit[10001] = {0};
    int in_beam = 0;
    
    std::string s_key;
    MeasureObject current_measure;
    NoteObject current_note;
    Clef *staffDefClef = NULL;
    
    std::vector<MeasureObject> staff;
    
    // read values
    while (!infile.eof()) {
        infile.getline(data_line, 10000);
        if (infile.eof()) {
            LogDebug("Truncated file or ending tag missing");
            //exit(1);
        }
        getAtRecordKeyValue(data_key, data_value, data_line);
        if (strcmp(data_key,"end")==0) {   
            break;
        } else if (strcmp(data_key,"clef")==0) { 
            strcpy( c_clef, data_value );
        } else if (strcmp(data_key,"key")==0) { 
            strcpy( c_key, data_value );
        } else if (strcmp(data_key,"keysig")==0) { 
            strcpy( c_keysig, data_value );
        } else if (strcmp(data_key,"timesig")==0) { 
            strcpy( c_timesig, data_value );
        } else if (strcmp(data_key,"alttimesig")==0) { 
            strcpy( c_alttimesig, data_value );
        } else if (strcmp(data_key,"data")==0) { 
            strcpy( incipit, data_value );
        }
    }
    
    if (strlen(c_clef)) {
        Clef *c = new Clef;
        getClefInfo(c_clef, c );    // do we need to put a default clef?
        if (!staffDefClef) staffDefClef = c;
        else current_measure.clef = c;
    }

    if (strlen(c_keysig)) {
        KeySig *k = new KeySig();
        getKeyInfo( c_keysig, k);
        current_measure.key = k;
    }
    if (strlen(c_timesig)) {
        MeterSig *meter = new MeterSig;
        getTimeInfo( c_timesig, meter);
        // What about previous values? Potential memory leak? LP
        current_measure.meter = meter;
    }   
    
    // read the incipit string
    size_t length = strlen(incipit);
    int i = 0;
	while(i < length) {
        // eat the input...
        
		if (incipit[i] == ' ') {
            // just skip
            i++;
        }
        
        // octaves
        if ((incipit[i] == '\'') || (incipit[i] == ',')) {
            i += getOctave( incipit, &current_note.octave, i );
        }
        
        // rhythmic values
        else if (isdigit(incipit[i]) != 0) {
            i += getDurations( incipit, &current_measure, i );
        }
        
        //accidentals (1 = n; 2 = x; 3 = xx; 4 = b; 5 = bb)    
        else if (incipit[i] == 'n' || incipit[i] == 'x' || incipit[i] == 'b') {
            i += getAccidental( incipit, &current_note.accidental, i );
        }
        
        //
        // beaming starts
		else if (incipit[i] == '{') {
			//current_note.beam = 1;
            current_note.beam = BEAM_INITIAL;
            in_beam++;
        }
        
        // beaming ends
		else if (incipit[i] == '}' && in_beam > 0) {
            current_measure.notes[current_measure.notes.size() - 1].beam = BEAM_TERMINAL;
            current_note.beam = 0;
            in_beam--;
		}
		
        // slurs are read when adding the note
		else if (incipit[i] == '+') {
        }
        
		// beginning tuplets & fermatas
		else if (incipit[i] == '(') {
            i += getTupletFermata( incipit, &current_note, i );
		}
        
        // end of tuplets
		else if ((incipit[i] == ';') || (incipit[i] == ')')) {
            i += getTupletFermataEnd( incipit, &current_note, i );
		}
        
		// trills are read when adding the note
		else if (incipit[i] == 't') {
        }
        
		//grace notes
		else if ((incipit[i] == 'g') || (incipit[i] == 'q')) {
			i += getGraceNote( incipit, &current_note, i );
		}
		
        
        // end of appogiatura
		else if (incipit[i] == 'r') {
			current_note.appoggiatura = 0; // should not have to be done, but just in case
        }
        
        //note and rest
        // getNote also creates a new note object
        else if (((incipit[i]-'A'>=0) && (incipit[i]-'A'<7)) || (incipit[i]=='-')) {
            i += getNote( incipit, &current_note, &current_measure, i );
        }
        
  		// whole rest
		else if (incipit[i] == '=') {
            i += getWholeRest( incipit, &current_measure.wholerest, i );		
		} 
        
		// abbreviation
        else if (incipit[i] == '!') {
            i += getAbbreviation( incipit, &current_measure, i );
        }
        
        // measure repetition
        else if ((incipit[i] == 'i') && staff.size() > 0) {
            MeasureObject last_measure = staff[staff.size() - 1];
            current_measure.notes = last_measure.notes;
            current_measure.wholerest = last_measure.wholerest;
            
            // if old measure does not end with a tie
            // force the first note of the newly copied measure to be without tie
            // this is to prevent copying tie closes which are invalid
            if (last_measure.notes.size() > 0 && last_measure.notes[last_measure.notes.capacity() - 1].tie == 0)
                current_measure.notes[0].tie = 0;
        }
        
        //barLine
        else if ((incipit[i] == ':') || (incipit[i] == '/')) {
            i += getBarline(incipit, &current_measure.barLine, i);
            current_measure.abbreviation_offset = 0; // just in case...
            staff.push_back( current_measure );
            current_measure.reset();
        }
        
		//clef change
		else if ((incipit[i] == '%') && (i+1 < length)) {
            Clef *c = new Clef;
            i += getClefInfo(incipit, c, i + 1);
            //
            if (!staffDefClef) {
                staffDefClef = c;
            }          
            // If there are no notes yet in the measure
            // attach this clef change to the measure
            else if (current_measure.notes.size() == 0) {
                // If a clef was already assigned, remove it
                if (current_measure.clef)
                    delete current_measure.clef;
                
                current_measure.clef = c;
            } else {
                // as above
                if (current_note.clef)
                    delete current_note.clef;
                
                current_note.clef = c;
            }
        }
        
		//time signature change
		else if ((incipit[i] == '@') && (i+1 < length)) {
            MeterSig *meter = new MeterSig;
            i += getTimeInfo( incipit, meter, i + 1);
            if (current_measure.notes.size() == 0) {
                if (current_measure.meter) {
                    delete current_measure.meter;
                }
                // When will this be deleted? Potential memory leak? LP
                current_measure.meter = meter;
            } else {
                if (current_note.meter) {
                    delete current_note.meter;
                }
                current_note.meter = meter;
            }
        } 
        
  		//key signature change
		else if ((incipit[i] == '$') && (i+1 < length)) {
            KeySig *k = new KeySig;
            i += getKeyInfo( incipit, k, i + 1);
            if (current_measure.notes.size() == 0) {
                if (current_measure.key)
                    delete current_measure.key;
                
                current_measure.key = k;
            } else {
                if (current_note.key)
                    delete current_note.key;
                
                current_note.key = k;
            }
		}
            
        i++;
    }
    
    // we need to add the last measure if it has no barLine at the end
    if (current_measure.notes.size() != 0) {
        //current_measure.barLine = "=-";
        staff.push_back( current_measure );
        current_measure.notes.clear();
    }
    
    
    m_doc->Reset( Raw );
    Page *page = new Page();
    System *system = new System();
    
    int measure_count = 1;
    
    std::vector<MeasureObject>::iterator it;
    for ( it = staff.begin() ; it < staff.end(); it++ ) {
        
        m_staff = new Staff( 1 );
        m_measure = new Measure( true, measure_count );
        m_layer = new Layer( );
        m_layer->SetN( 1 );
        
        m_staff->AddLayer(m_layer);
        m_measure->AddStaff( m_staff );
        system->AddMeasure( m_measure );
        
        MeasureObject obj = *it;
        convertMeasure( &obj );
        measure_count++;
    }

    // add miniaml scoreDef
    StaffGrp *staffGrp = new StaffGrp();
    StaffDef *staffDef = new StaffDef();
    staffDef->SetN( 1 );
    staffDef->SetLines(5);
    if (staffDefClef) {
        staffDef->SetClefShape(staffDefClef->GetShape());
        staffDef->SetClefLine(staffDefClef->GetLine());
        staffDef->SetClefDis(staffDefClef->GetDis());
        staffDef->SetClefDisPlace(staffDefClef->GetDisPlace());
        delete staffDefClef;
    }
    staffGrp->AddStaffDef( staffDef );
    m_doc->m_scoreDef.AddStaffGrp( staffGrp );

    page->AddSystem( system );
    m_doc->AddPage( page );
}