'Rewards for playing the tonic note at the right times.
Rewards for playing the tonic as the first note of the first bar, and the
first note of the final bar.
Args:
action: One-hot encoding of the chosen action.
tonic_note: The tonic/1st note of the desired key.
reward_amount: The amount the model will be awarded if it plays the
tonic note at the right time.
Returns:
Float reward value.'

def reward_tonic(self, action, tonic_note=rl_tuner_ops.C_MAJOR_TONIC, reward_amount=3.0):

    action_note = np.argmax(action)
    first_note_of_final_bar = (self.num_notes_in_melody - 4)
    if ((self.beat == 0) or (self.beat == first_note_of_final_bar)):
        if (action_note == tonic_note):
            return reward_amount
    elif (self.beat == (first_note_of_final_bar + 1)):
        if (action_note == NO_EVENT):
            return reward_amount
    elif (self.beat > (first_note_of_final_bar + 1)):
        if ((action_note == NO_EVENT) or (action_note == NOTE_OFF)):
            return reward_amount
    return 0.0
