DEPARTMENT OF COMPUTING

CS 3005: Programming in C++

Notes, Frequencies, Time Signatures, and Tempos

Introduction

In this assignment you will add a time signature and a tempo to the musical score, including the ability to configure them from the score editor, and read/write them in score files.

You will also add a note class and a frequency class to support music notation. These classes will be used more in future assignments.

A note represents a musical note, including its frequency and duration. We will specify the frequency by specifying the note from a keyboard, and the octave it belongs to. We will specify the duration by describing whole, half, quarter, etc. notes.

Refer to the class notes for more discussion on octaves, keys, frequency calculations, duration, etc.

Syntax in the .score file for time signature and tempo

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.

The TIME-SIGNATURE keyword must always be followed by two integers.

The TEMPO keyword must always be followed by one floating point number.

Both of these keywords will be encountered directly inside a SCORE/SCORE-END block.

Sample SCORE file

SCORE
  TIME-SIGNATURE 3 4
  TEMPO 120

SCORE-END

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-set-time-signature no setScoreTimeSignatureUI Edit the time signature of a score.
score-set-tempo no setScoreTempoUI Edit the tempo of a score.

Example Session

$ ./program-score-editor/score_editor 
Choice? menu
Options are:
  # - Skip to end of line (comment).
  comment - Skip to end of line (comment).
  echo - Echo back the arguments given.
  help - Display help message.
  menu - Display help message.
  quit - Terminate the program.
  score-add-envelope - Add envelope to the score.
  score-add-instrument - Add instrument to the score.
  score-add-waveform - Add waveform to the score.
  score-edit-envelope - Edit envelope in the score.
  score-edit-instrument - Edit instrument in the score.
  score-edit-waveform - Edit waveform in the score.
  score-list-envelopes - List envelopes in the score.
  score-list-instruments - List instruments in the score.
  score-list-waveforms - List waveforms in the score.
  score-read - Read score from file.
  score-set-tempo - Edit the tempo of a score.
  score-set-time-signature - Edit the time signature of a score.
  score-write - Write score to score file.

Choice? score-set-time-signature
Beats per bar: 6
Beat value: 8
Choice? score-set-tempo
Beats per minute: 123.4
Choice? score-write
Filename: demo.score
Choice? quit

The output file: demo.score.

Programming Requirements

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

TimeSignature Class

This class will represent a time signature. That is the number of beats in a bar and the duration of a beat.

protected Data Members:

public Methods:

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

We will add to the MusicalScore class by adding the Instrumentarium collection. Future assignments will add more to the class.

MusicalScore Class

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

Data Members:

Add these data member:

public Methods:

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

We will update the ScoreReader class by adding the ability to read time signatures and tempos.

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 time signatures and tempos.

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:

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

Commands created for the score editor program will go here. We’re adding more this assignment.

Functions:

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

Frequency Class

This class only has static methods and data members. Note that there is only 1 public method of the class. The rest of the methods are used to pre-calculate the frequencies associated with note names. The public method looks up the frequency using the name.

protected Data Members:

public Methods:

protected Methods:

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

global Constants

Note Class

Stores and manages a note’s name and duration. Names are in the format “C#5”, a key followed by the octave. Durations are stored in fractions of a whole note.

Data Members:

Data members must be protected or private. public data members are not allowed.

public Methods:

protected Methods:

Free Functions

Additional Documentation

Grading Instructions

To receive credit for this assignment:

Extra Challenges (Not Required)

TBA

Last Updated 04/15/2025