Keywords

1 Introduction

The transition to the new millennium highlights the decline of the old industrial society and the emergence of the information society [1, 2] with the new challenges proposed by artificial intelligence (AI). Even music is not immune to this change, on the contrary it was one of the first areas of experimentation and research [3]: from this perspective it is therefore evident the existence of a broad sharing of strategies and methods between musical composition and intelligence artificial. The hardware and software developments, capable of opening new possibilities to musical verifications and experiments, can be seen as multipliers of creativity (for a musician and not only: it is not strange today to find non-musicians who compose music) but at the same time they can lead to an impoverishment of musical skills and musical experience [4]. Musical composition is a complex discipline based on a series of musical grammar rules whose knowledge is essential. The acquisition and mastery of the musical grammar rules represents an obstacle for students in general but especially for dyslexic students who often find themselves in a situation of lack of autonomy and therefore of uncertainty in the carry out an exercise that leads them not to continue with the task. Therefore, the starting point of the challenges related to AI cannot and must not be technology, but a careful analysis and identification of the problems that can be faced with AI. Otherwise, any intelligent system designed without adequate problem analysis becomes useless and ineffective: the ability to carry out procedures without understanding the general concepts and connections is very limiting. There are two main dimensions that can be explored, as regards AI and teaching activity [5]:

  1. 1.

    how AI can improve teaching by helping to solve some problems in the school world,

  2. 2.

    how it is possible to educate people (teachers and students) about AI, so that they can benefit from it.

Starting from these two reflections, this research article intends to present a useful algorithm to support (dyslexic and non-dyslexic) students in the individual study, during the harmonization of a music bassline: this is the first step of the study of music composition, and aims to allow the student to know, learn and consolidate the musical grammar rules. The algorithm, through a training phase, is able to self-learn the fundamental musical grammar rules and therefore provide the student with possible solutions in case of errors made during the harmonization of the chords. The algorithm presents itself as a virtual tutor, to facilitate the learning process: the virtual tutor must support the student [6] in the creation and manipulation of musical objects [7], without replacing it by making the composition.

This paper is organized as follows.

Section 2 provides an overview of earlier automatic music composition researches. Section 3 describes the musical grammar rules as far as chords are concerned. This is followed by a description of the method used to formalize the musical grammar rules. Section 4 shows some experimental tests that illustrate the effectiveness of the proposed method. Finally, in Sect. 5 the paper ends with concluding remarks.

2 Related Works

Computer-assisted musical composition is a synthesis of the evolution of computer-music and computational-musicology. In other words, it is a phenomenon characterized by the existence of software tools that help the composer in the creation and manipulation of musical objects such as a melody, a rhythm or a musical accompaniment. Many algorithms have been designed and developed for these purposes, using different techniques: only those taken into consideration for the development of this research are illustrated below.

A Markov chain is a stochastic process, that is, a random process in which the transition probability that determines the transition to a system state depends only on the immediately preceding system state [8, 9]. Due to this characteristic, Markov chains allow the creation of a musical melody, seen as a sequence of notes [10, 11]. From the point of view of the creative process, Markov chains could create very similar melodies when the order of the chain is very high, but they can provide new combinations of smaller sections (such as a musical motif) that can be reworked with other techniques [12].

A “generative grammar” is a system of explicit and formal rules with an associated lexicon. These rules are formulated in such a way as to be able to generate a set of sentences, that is, combinations of lexical elements, which represent a language [13]. The language defined by a set of rules is made up of all the combinations of the elements that the rules can produce and only those combinations [14]. This approach can be used to chords generation but also to create variation on melodies [15].

A rules-based system uses rules to represent knowledge. Music theory traditionally describes rules that help to guide the compositional process. One way to implement rules in compositional systems is to use Constraint Programming, whose declarative nature is well fit to describe music theory rules [16]. This method can be seen as a guide for the composer and allows you to create new melodies, harmonies and rhythms, but at the same time it represents a limitation because it reduces the variety of the output [17, 18].

Most computer-assisted musical composition systems deal with the generation of a melody or the harmonization of a melody: there are few studies involving the harmonization of a bass line [19, 20].

The focus of the present research is the harmonization of a musical bassline. In this work, we introduce an algorithm able to support the student during the didactic activity in order to enhance the learning process. That’s why the primary goal of the algorithm is not to autonomously harmonizing a bassline to obtain an error-free solution, but to support (as a virtual tutor) the student during the harmonization of a bassline giving him/her advices in case of errors in the concatenation of the chords.

3 Designing the Virtual Tutor

The algorithm proposed in this article is inspired by the techniques described in the previous paragraph in order to represent and reason on about the compositional rules. The composition rules are modelled so that the algorithm defines the requirements for an advice to be musically valid. The next paragraphs present an overview of the main musical grammar rules, which are fundamental for the design of the proposed algorithm, and the methods used to formalize them.

3.1 Musical Composition Guidelines

Harmonizing a bass line is an important element of the musical language. It is a traditional system of organizing chords for 4 voices (soprano, alto, tenor and bass) characterized by two aspects [21]:

  1. 1)

    there are 4 voices and each one is singing a melody: this is called melodic movement and represents the horizontal aspect of the harmonization (see Fig. 1, green notes);

  2. 2)

    the 4 voices sing simultaneously producing 4-note chords: this is the harmonic, or “vertical”, aspect of the harmonization (see Fig. 1, orange notes). When the three upper voices (Soprano, Alto and Tenor) are within the span of one octave, they are in what is called “close position” (see Fig. 1, red notes). When the tenor and the soprano are further apart than an octave, the chord is in “open position” (see Fig. 1, red notes).

Fig. 1.
figure 1

The harmonic aspect and the melodic aspect of a musical composition.

In harmonizing a bassline, these two aspects must be considered at the same time and therefore two distinct movements can be identified: the melodic motion, when there is a passage from one sound to another in the same voice (see Fig. 1, green notes); the harmonic motion, when two or more melodic motions occur at the same time (see Fig. 1, red notes). In this context it is necessary to respect some fundamental guidelines. In the melodic motion must be avoided (see Fig. 2) [21]:

  • augmented intervals (intervals that are one half-step larger than a perfect or major interval),

  • diminished intervals (Intervals that are one half-step smaller than a perfect or minor interval),

  • the intervals of the seventh,

  • intervals larger than an octave.

Fig. 2.
figure 2

Examples of forbidden melodic intervals.

In the harmonic motion it is forbidden to proceed with two same voices at a distance of fifths and octaves (see Fig. 3) [21].

Fig. 3.
figure 3

Examples of parallel fifths and parallel octaves.

3.2 Error Recognition

In order to be able to identify one of the prohibited movements described above, it is necessary to take into account the concept of musical interval, that means, the distance in pitch between any two notes [22]. For the purpose of calculating this distance, the musical score is seen as a list of numbers each of which corresponds to a sound, based on its pitch [23]. The list can be represented in the form of a sequence Sm of N notes ni indexed according to the order of appearance i:

$$S_m = (n_i )\;_{i \in \left[ {0,N - 1} \right]}$$
(1)

The pitch of a note can be measured by following two criteria [24]. In the first case (called “real distance”), semitones are used as the unit of measurement (regardless of the key of the piece of music):

C = 0 D = 2 E = 4 F = 5 G = 7 A = 9 B = 11 etc.

In the second case (called (“tonal distance”), the key of the musical piece is considered and the pitch of a sound is measured by referring to the intervals of the musical scale of the key in question, thus measuring it in degrees:

C = 0 D = 1 E = 2 F = 3 G = 4 A = 5 B = 6 etc.

With reference to the first criteria, it is important to consider simultaneously both the distance of the interval and the type of interval (the interval quality).

The distance is calculated by counting how many names of letters of the musical alphabet there are between the two notes. For example, the notes C and E are three letter notes apart and so is an interval of a 3rd.

The type of the interval is defined by the number of tones and semi-tones between the two notes. It may be (see Fig. 4): perfect (P), major (M), minor (m), augmented (A), diminished (d).

Fig. 4.
figure 4

Types of intervals on the C major scale.

If any of the major intervals are reduced by a semitone, then they become minor intervals (see Fig. 5). By flatting any of the major or perfect interval by a semitone, they become augmented intervals (see Fig. 5). By flatting any of the three perfect intervals or a minor interval by a semitone, these become diminished intervals (see Fig. 5).

Fig. 5.
figure 5

Types of intervals on the C major scale.

In order to define the interval correctly (thus excluding forbidden intervals), and check a melodic error, it is essential to consider both the tonal distance and the real distance: considering only the number of semitones between two sounds, it is not possible to distinguish between different intervals [23]. In the example of Fig. 6 it is possible to see how between the notes F-G# and F-Ab there is an interval of 3 semitones: in the first case it is an increased interval, while in the second case a smaller interval. Considering the tonal distance first, it is possible to obtain the denomination of the interval (F-G# = second interval; F-Ab = third interval); subsequently, with the real distance the interval can be qualified (F-G# = augmented second; F-Ab = minor third).

Fig. 6.
figure 6

Example of intervals.

In the harmonic motion it is necessary to verify that in the concatenation of two chords, there is no fifth or octave interval between the same pair of voices (see Fig. 3). To do so the Markov process [24] is used: the choice was made to describe the passage from one state of the system (number of semitones of the same pair of voices in the first chord) to the next (number of semitones of the same pair of voices in the second chord) uniquely from the immediately preceding state [25, 26].

Figure 7 shows the matrix of transitions, created by the algorithm during the training phase (see paragraph 4), where in column 1 and row 1 the number of semitones between two voices is indicated, while in column 2 and row 2 it is indicated whether it is a new chord (n) or a repeated chord (r). In this way, if two voices repeat the same sounds in two consecutive chords (see Fig. 8), the algorithm does not report an error.

Fig. 7.
figure 7

Transitions matrix related to the harmonic motion.

Fig. 8.
figure 8

First 2 bars from Piano Sonata op.53 n.21 by Beethoven: example of repeated fifth (between bass and tenor) and octave (between bas and alto).

From the analysis of the transition matrix (Fig. 7) it is possible to note how the progressions of perfect fifths (7 semitones) and perfect octaves (12 semitones) have not been identified (orange cells).

4 Obtained Results

The proposed algorithm differs from most of the algorithms already developed for the automatic harmonization of the melody or bass, due to the fact that it takes into account the error as a working tool. Through a self-learning procedure, the prohibited melodic and harmonic motions are formalized, in order to identify any errors made by the student in harmonizing the sounds of the bassline, and suggest possible solutions.

To test the effectiveness of the algorithm, the following steps were followed.

1) Data collection

In order to train and test the algorithm, around 1300 musical pieces (written in choral form) were collected (Dataset): the pieces could be both in close position or in open position. The musical scores were in MIDI format [27] or in XML format [28], and this made it possible to take advantage of the numerous archives of musical pieces (of public domain) written in choral form, present on the web.

2) Data cleaning and preparation

The musical scores were analyzed before the dataset was used for the training phase of the algorithm. The use of incorrect data can produce misleading results. This phase took a long time (due to the fact that every single score was analyzed to identify any transcription errors) but it was essential for the veracity of the results.

3) Training phase of the algorithm

The algorithm read the musical scores in order to create the table representing the correct melodic motions (see Table 1) and the matrix of transitions representing the correct harmonic motions. Both the table representing the correct melodic motions and the matrix of transitions representing the correct harmonic motions were automatically dimensioned on the basis of the characteristics of the musical piece read during this phase.

4) Model test

Two experimental tests were carried out to verify the integrity of the algorithm.

In the first test, 7 music composition teachers used the software to harmonize a musical bassline, first in close positions and then in open positions. This allowed to verify if the algorithm updated the libraries in the case of solutions other than those recognized during the training phase, or in the event of an error if the solutions proposed by the algorithm could satisfy the musical grammar rules. Subsequently, to verify the soundness of the algorithm, teachers were asked to create a choral (8 bars) without having any musical inspiration but using their own personal creativity.

In the second experiment, a group of 40 students (with different levels of preparation and different learning styles) from 2 Music High Schools and 2 Conservatories of music, was asked to harmonize a bassline under the supervision of a Composition teacher who had to note the students’ difficulties and errors and the answers of the algorithm.

After this testing phase, 3 teachers (2 from Music High Schools and 1 from Conservatory of music) were asked to permit students the use of the software for a period of 3 months (for their individual study) and to carry out a verification test every month in order to check the learning process.

The results obtained at the end of this period were satisfactory.

On the one hand, the students declared that they found no difficulty in using the software (because it was simple and intuitive), and the advices proposed in the event of an error forced them: to reflect and recognize the type of error; to consult the school book to understand the proposed solution, thus consolidating knowledge.

On the other hand, the teachers expressed their satisfaction: as regards the solutions proposed by the algorithm in the event of an error; regarding the behavior of different students, with particular attention to dyslexic students; as regards the results achieved by the students who, even if the melodic lines obtained by harmonizing the bass were less appreciable, the students had reduced the number of errors in carrying out exercises proposed and carried out independently.

Table 1. Excerpt of the allowed interval identified by the algorithm during the training phase.

5 Discussion and Conclusions

This article presented a self-adaptive learning music composition algorithm, specifically designed to enhance the educational activity, and support the student during the learning process. The algorithm presents itself as a virtual tutor able to support the student during the harmonization of the music bassline, helping him/her to consolidate the musical grammar rules. The experiments conducted show that the use of the algorithm can be beneficial: it can improve the student's ability to recognize which musical grammar rules is necessary to use during the concatenation of the chords and can help him/her to consolidate acquired skills.

An advantage of the algorithm is that there are no control parameters to be set manually. It is based on a self-learning model able to acquire on the one hand the rules relating to the movement of two sounds within the same voice (using the principles of information theory) and on the other hand the rules for the movement of the sounds of the various voices between two consecutive chords (by means of the Markov process).

Artificial intelligence is able to provide teachers with an insightful virtual tutor who is able to help students to solve the challenges and obstacles encountered during their learning path. AI can offer students explanations for a better understanding of disciplinary topics and enrich their knowledge without making them feel inferior. The virtual tutor allows learners, even when they fail, to remedy by trial and error and also to learn from mistakes. Often the fear of making a mistake, for many students (especially dyslexic students), is really limiting. If a virtual tutor is effective, this increases the probability that the student will use an application for self-study more often, improving their skills and competences.

Future research should be oriented towards the implementation of the algorithm to support the student (dyslexic and non-dyslexic) during the harmonization of a bassline in which key changes are present: these are the cause of many harmonization errors due to the change of accidents (sharps, flats).