DEPARTMENT OF COMPUTING

CS 3005: Programming in C++

Musical Staves

Introduction

In this assignment you will add a collection of musical staff objects. (The plural of staff is staves.) In addition you will add commands to the score editor to add, edit, and display staves. The score reader and score writer classes will also be updated to fully support staves.

Syntax in the .score file for staff

This format was designed to be read using the C++ standard library’s >> operator. All values are whitespace delimited. By context, your code should be able to determine whether the next value is a std::string or a double.

There is no new syntax to the .score file format. We already added the STAFF in the previous assignment. This assignment will make it so the score reader actually keeps each staff it reads, and the score writer will write out all of the staves in the score.

Notes on the ScoreReader::readScore method

Notes on the ScoreWriter::writeScore method

Assignment

Here are the new commands that are required in the score editor program for this assignment. Previous commands are still required.

Command Prefixable? Function Description
score-staff-set-instrument no setStaffInstrumentUI Change instrument assigned to a staff in the score.
score-list-staves no listScoreStavesUI List staves in the score.
score-add-staff no addStaffUI Add a staff to the score.
score-show-staff no showStaffUI Display staff details.
score-staff-add-note no addStaffNoteUI Add a note to a staff.
score-render no renderScoreUI Render score to wav file.

Example Session

$ ./program-score-editor/score_editor 
Choice? score-add-waveform
Waveform name: w1
Waveform type: sine
Amplitude: 1.0
Choice? score-add-envelope
Envelope name: e1
Envelope type: AD
Maximum amplitude: 1.0
Attack seconds: 0.1
Choice? score-add-instrument
Instrument name: i1
Waveform name: w1
Envelope name: e1
Choice? score-add-staff
Staff name: s1
Instrument name: i1
Choice? score-list-staves
s1 i1
Choice? score-show-staff
Staff name: s1
s1 i1

Choice? score-staff-add-note
Staff name: s1
Start: 0.5 
Duration: q
Note: C4
Choice? score-show-staff
Staff name: s1
s1 i1
0.5 0.25 C4

Choice? score-add-staff
Staff name: s2
Instrument name: i1
Choice? score-staff-add-note
Staff name: s2
Start: 0.25
Duration: h
Note: G4
Choice? score-show-staff
Staff name: s2
s2 i1
0.25 0.5 G4

Choice? score-list-staves
s1 i1
s2 i1
Choice? score-render
Filename: foo.wav
Samples per second: 1000
Bits per sample: 16
Choice? score-add-waveform
Waveform name: w2
Waveform type: square
Amplitude: 0.9
Choice? score-add-instrument
Instrument name: i2
Waveform name: w2
Envelope name: e1
Choice? score-staff-set-instrument
Staff name: s1
Instrument name: i2
Choice? score-list-staves
s1 i2
s2 i1
Choice? score-render
Filename: bar.wav
Samples per second: 1000
Bits per sample: 16
Choice? quit

Programming Requirements

Create library-score/MusicalStaves.{h,cpp}

MusicalStaves Class

This class will represent a collection of staff objects, with the key being the name of the staff and the value being the staff.

protected Data Members:

public Methods:

Update library-score/MusicalScore.{h,cpp}

We will add to the MusicalScore class by adding the MusicalStaves collection.

MusicalScore Class

This class will store all of the information for a piece of music.

Data Members:

public Methods:

Update library-score-io/ScoreReader.{h,cpp}

We will update the ScoreReader class by adding the ability to read store staves it reads.

ScoreReader Class

This class will eventually read all of the information for a piece of music from the .score file format.

Data Members:

No data members are required.

public Methods:

Update library-score-io/ScoreWriter.{h,cpp}

We will update the ScoreWrite class by adding the ability to write all staves.

ScoreWriter Class

This class will eventually write all of the information for a piece of music from the .score file format.

Data Members:

No data members are required.

public Methods:

Create library-score-io/WavWriter.{h,cpp}

WavWriter Class

This class will render a score and save the rendered tracks to a WAV file.

protected Data Members:

None

public Methods:

Update library-commands/score_editor_aux.{h,cpp}

Commands created for the score editor program will go here. We’ll make a few more in this assignment.

Functions:

Additional Documentation

Grading Instructions

To receive credit for this assignment:

Extra Challenges (Not Required)

TBA

Last Updated 04/22/2025