Skip to content
Snippets Groups Projects
Commit ac491829 authored by Axel Marmoret's avatar Axel Marmoret
Browse files

TAG: Deprecated on the "model classes" tutpo, as it's not used anymore

parent 96e742f7
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags:
# Tutorial for the model classes.
%% Cell type:markdown id: tags:
This notebook will briefly present some functionnalities implemented to cope with symbolic representation of music, as an upgrade of C. Louboutin's code.
%% Cell type:markdown id: tags:
It contains 2 files: note.py, chord.py.
All these files represent different objects, used to handle musical information at different levels.
A note is the most basic element, a chord is an aggregation of notes.
%% Cell type:markdown id: tags:
## note.py
%% Cell type:code id: tags:
``` python
from polytopes.model.note import Note
```
%% Cell type:markdown id: tags:
Let's start with the Note object, which is the lowest-level object in music.
The interest of defining such an object is that it allows us to control what is an acceptable note, and what isn't.
%% Cell type:markdown id: tags:
### Initialization
%% Cell type:markdown id: tags:
Particularily, a Note contains two attributes:
- a number: between 0 and 11, which corresponds to the pitch classe of the note. 0 represent the C pitch class, and 11 the B pitch class.
- a symbol: the classical representation of a note as a letter, with flat ("b") or sharp("#") suffixes.
%% Cell type:code id: tags:
``` python
note_a = Note('A')
repr(note_a)
```
%% Output
"<class 'polytopes.model.note.Note'>(Symbol: 'A', Number: 9)"
%% Cell type:markdown id: tags:
We can access to these attributes directly on the object:
%% Cell type:code id: tags:
``` python
note_a.symbol
```
%% Output
'A'
%% Cell type:code id: tags:
``` python
note_a.number
```
%% Output
9
%% Cell type:markdown id: tags:
A note can be defined by it's symbol or it's number.
%% Cell type:code id: tags:
``` python
Note('9')
```
%% Output
<class 'polytopes.model.note.Note'>(Symbol: 'A', Number: 9)
%% Cell type:code id: tags:
``` python
Note('A')
```
%% Output
<class 'polytopes.model.note.Note'>(Symbol: 'A', Number: 9)
%% Cell type:code id: tags:
``` python
Note('9') == Note('A')
```
%% Output
True
%% Cell type:markdown id: tags:
### Modification
%% Cell type:markdown id: tags:
A Note object can also be modified.
Modifying the number of a note will also modify it's symbol, and vice-versa, as both are linked.
%% Cell type:code id: tags:
``` python
a_note = Note('B')
print("Before modification: " + str(a_note))
a_note.symbol = 'D'
print("After modification: " + str(a_note))
a_note.number = 7
print("After modifying its number: " + str(a_note))
```
%% Output
Before modification: <class 'polytopes.model.note.Note'>(Symbol: 'B', Number: 11)
After modification: <class 'polytopes.model.note.Note'>(Symbol: 'D', Number: 2)
After modifying its number: <class 'polytopes.model.note.Note'>(Symbol: 'G', Number: 7)
%% Cell type:markdown id: tags:
Still, not every symbol or every number is acceptable. Hence, modifying or initializing a Note with a wrong number should not be tolerated.
%% Cell type:code id: tags:
``` python
a_note.number = 15
```
%% Output
---------------------------------------------------------------------------
InvalidNoteNumberException Traceback (most recent call last)
<ipython-input-10-8a3266453d6f> in <module>
----> 1 a_note.number = 15
c:\users\amarmore\desktop\projects\phd main projects\on git\code\polytopes and relation\polytopes\model\note.py in _set_number(self, number)
122 raise err.InvalidNoteNumberException("The desired new number is not an integer, and is not valid.") from None
123 except IndexError:
--> 124 raise err.InvalidNoteNumberException("The desired new number is too large to be a valid note.") from None
125
126
InvalidNoteNumberException: The desired new number is too large to be a valid note.
%% Cell type:code id: tags:
``` python
a_note.symbol = 'K'
```
%% Output
---------------------------------------------------------------------------
InvalidNoteSymbolException Traceback (most recent call last)
<ipython-input-11-20488d99cd64> in <module>
----> 1 a_note.symbol = 'K'
c:\users\amarmore\desktop\projects\phd main projects\on git\code\polytopes and relation\polytopes\model\note.py in _set_symbol(self, symbol)
87 self._number = self.number_from_symbol()
88 else:
---> 89 raise err.InvalidNoteSymbolException("This symbol is not a correct note symbol.") from None
90
91 def _get_number(self):
InvalidNoteSymbolException: This symbol is not a correct note symbol.
%% Cell type:markdown id: tags:
Finally, sharp and flat symbols should both exist but shouldn't invalid tests, as they represent the same note.
%% Cell type:code id: tags:
``` python
Note('A#') == Note("Bb")
```
%% Output
True
%% Cell type:markdown id: tags:
By default, a note symbol is set in flat convention. Still, it can be set to sharp with an argument in the constructor.
%% Cell type:code id: tags:
``` python
a_note = Note("A#")
print("Default: " + repr(a_note))
a_note = Note("A#", flat = False)
print("In sharp: " + repr(a_note))
```
%% Output
Default: <class 'polytopes.model.note.Note'>(Symbol: 'Bb', Number: 10)
In sharp: <class 'polytopes.model.note.Note'>(Symbol: 'A#', Number: 10)
%% Cell type:markdown id: tags:
Additionally, one can modify a note to be in the sharp or in the flat system.
%% Cell type:code id: tags:
``` python
a_note = Note("Bb")
print("In flat: " + repr(a_note))
a_note.to_sharp()
print("In sharp: " + repr(a_note))
```
%% Output
In flat: <class 'polytopes.model.note.Note'>(Symbol: 'Bb', Number: 10)
In sharp: <class 'polytopes.model.note.Note'>(Symbol: 'A#', Number: 10)
%% Cell type:code id: tags:
``` python
a_note = Note("A#", flat = False)
print("In sharp: " + repr(a_note))
a_note.to_flat()
print("In flat: " + repr(a_note))
```
%% Output
In sharp: <class 'polytopes.model.note.Note'>(Symbol: 'A#', Number: 10)
In flat: <class 'polytopes.model.note.Note'>(Symbol: 'Bb', Number: 10)
%% Cell type:markdown id: tags:
### chord.py
%% Cell type:code id: tags:
``` python
from polytopes.model.chord import Chord
```
%% Cell type:markdown id: tags:
A chord is a set of mulitple pitches. Hence, a chord is defined from notes.
%% Cell type:markdown id: tags:
### Initialization
%% Cell type:code id: tags:
``` python
a = Note('A')
c = Note('C')
e = Note('E')
Chord([a,c,e])
```
%% Output
<class 'polytopes.model.chord.Chord'>(Symbol: 'Am', Notes: [<class 'polytopes.model.note.Note'>(Symbol: 'A', Number: 9), <class 'polytopes.model.note.Note'>(Symbol: 'C', Number: 0), <class 'polytopes.model.note.Note'>(Symbol: 'E', Number: 4)])
%% Cell type:markdown id: tags:
A chord must contain at least one note.
%% Cell type:code id: tags:
``` python
Chord([])
```
%% Output
---------------------------------------------------------------------------
InvalidChordNotesException Traceback (most recent call last)
<ipython-input-18-bf07a16d637a> in <module>
----> 1 Chord([])
c:\users\amarmore\desktop\projects\phd main projects\on git\code\polytopes and relation\polytopes\model\chord.py in __init__(self, a_chord, redundancy)
71 self._notes = local_notes
72 if self._notes == []:
---> 73 raise err.InvalidChordNotesException("Empty list of notes: a Chord must admit notes.") from None
74 self._triad = self.triad_from_notes()
75 if self.triad != cst.AMBIGUOUS and not self._redundant: # A redundant chord shouldn't be reordered as it corresponds to permutated chord (#TODO: rename the parameter ?)
InvalidChordNotesException: Empty list of notes: a Chord must admit notes.
%% Cell type:markdown id: tags:
It can be directly defined by a list of numbers.
%% Cell type:code id: tags:
``` python
Chord([9, 0, 4])
```
%% Output
<class 'polytopes.model.chord.Chord'>(Symbol: 'Am', Notes: [<class 'polytopes.model.note.Note'>(Symbol: 'A', Number: 9), <class 'polytopes.model.note.Note'>(Symbol: 'C', Number: 0), <class 'polytopes.model.note.Note'>(Symbol: 'E', Number: 4)])
%% Cell type:markdown id: tags:
!!!!!!!!!!!! A chord **can't** be defined by a list of note symbols (at least not yet)
%% Cell type:code id: tags:
``` python
Chord(['A', 'C', 'E'])
```
%% Output
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
c:\users\amarmore\desktop\projects\phd main projects\on git\code\polytopes and relation\polytopes\model\chord.py in __init__(self, a_chord, redundancy)
67 else:
---> 68 note_obj = Note(int(a_note))
69 if not note_obj.is_in_list_of_notes(local_notes) or self._redundant:
ValueError: invalid literal for int() with base 10: 'A'
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
<ipython-input-20-6a8e4e2a89cb> in <module>
----> 1 Chord(['A', 'C', 'E'])
c:\users\amarmore\desktop\projects\phd main projects\on git\code\polytopes and relation\polytopes\model\chord.py in __init__(self, a_chord, redundancy)
80 except ValueError: # If it's a symbol
81 try:
---> 82 self._symbol = format_symbol(a_chord)
83 self._root = self.root_from_symbol()
84 self._triad = self.triad_from_symbol()
c:\users\amarmore\desktop\projects\phd main projects\on git\code\polytopes and relation\polytopes\model\chord.py in format_symbol(symbol)
693 """
694 try:
--> 695 int(symbol)
696 raise err.InvalidChordSymbolException("The symbol isn't valid.") from None
697 except ValueError:
TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'
%% Cell type:markdown id: tags:
However, a Chord can be defined by its symbol.
%% Cell type:code id: tags:
``` python
Chord('Abmin')
```
%% Output
<class 'polytopes.model.chord.Chord'>(Symbol: 'Abm', Notes: [<class 'polytopes.model.note.Note'>(Symbol: 'Ab', Number: 8), <class 'polytopes.model.note.Note'>(Symbol: 'B', Number: 11), <class 'polytopes.model.note.Note'>(Symbol: 'Eb', Number: 3)])
%% Cell type:markdown id: tags:
Defining a Chord by its symbol or by its notes doesn't change the value of its attributes.
%% Cell type:code id: tags:
``` python
Chord('Abmin') == Chord([8, 11, 3])
```
%% Output
True
%% Cell type:markdown id: tags:
When instanciated, a Chord has several attributes:
- notes: the list of notes of the Chord. These are Note objects.
- symbol: the symbol of the Chord.
- root: the root of the Chord.
- triad: the type of triad of the Chord (maj or min) if it's a triad.
%% Cell type:code id: tags:
``` python
chord = Chord('A')
chord.notes
```
%% Output
[<class 'polytopes.model.note.Note'>(Symbol: 'A', Number: 9),
<class 'polytopes.model.note.Note'>(Symbol: 'Db', Number: 1),
<class 'polytopes.model.note.Note'>(Symbol: 'E', Number: 4)]
%% Cell type:code id: tags:
``` python
chord.symbol
```
%% Output
'A'
%% Cell type:code id: tags:
``` python
chord.root
```
%% Output
<class 'polytopes.model.note.Note'>(Symbol: 'A', Number: 9)
%% Cell type:code id: tags:
``` python
chord.triad
```
%% Output
'A'
%% Cell type:markdown id: tags:
Still, defined by its notes, a chord symbol can be ambiguous (ex: A6 (A with a sixth) is also F#m7)
In that sense, a chord defined by its notes, when not a triad (perfect major or minor), will have its root and its symbol labelled as "Ambiguous"
%% Cell type:code id: tags:
``` python
Chord([9, 1, 4, 6])
```
%% Output
<class 'polytopes.model.chord.Chord'>(Symbol: 'Ambiguous', Notes: [<class 'polytopes.model.note.Note'>(Symbol: 'A', Number: 9), <class 'polytopes.model.note.Note'>(Symbol: 'Db', Number: 1), <class 'polytopes.model.note.Note'>(Symbol: 'E', Number: 4), <class 'polytopes.model.note.Note'>(Symbol: 'Gb', Number: 6)])
%% Cell type:code id: tags:
``` python
Chord([9, 1, 4, 6]).symbol, Chord([9, 1, 4, 6]).root, Chord([9, 1, 4, 6]).triad
```
%% Output
('Ambiguous', 'Ambiguous', 'Ambiguous')
%% Cell type:markdown id: tags:
### Modification
%% Cell type:markdown id: tags:
As for a Note, a Chord symbol or notes of a Chord can be directly modified.
%% Cell type:code id: tags:
``` python
a_chord = Chord('B')
print("Before modif: %r" % (a_chord))
a_chord.notes
```
%% Output
Before modif: <class 'polytopes.model.chord.Chord'>(Symbol: 'B', Notes: [<class 'polytopes.model.note.Note'>(Symbol: 'B', Number: 11), <class 'polytopes.model.note.Note'>(Symbol: 'Eb', Number: 3), <class 'polytopes.model.note.Note'>(Symbol: 'Gb', Number: 6)])
[<class 'polytopes.model.note.Note'>(Symbol: 'B', Number: 11),
<class 'polytopes.model.note.Note'>(Symbol: 'Eb', Number: 3),
<class 'polytopes.model.note.Note'>(Symbol: 'Gb', Number: 6)]
%% Cell type:code id: tags:
``` python
a_chord.notes = [8, 0, 3]
print("After modif: %r" % (a_chord))
a_chord.notes
```
%% Output
After modif: <class 'polytopes.model.chord.Chord'>(Symbol: 'Ab', Notes: [<class 'polytopes.model.note.Note'>(Symbol: 'Ab', Number: 8), <class 'polytopes.model.note.Note'>(Symbol: 'C', Number: 0), <class 'polytopes.model.note.Note'>(Symbol: 'Eb', Number: 3)])
[<class 'polytopes.model.note.Note'>(Symbol: 'Ab', Number: 8),
<class 'polytopes.model.note.Note'>(Symbol: 'C', Number: 0),
<class 'polytopes.model.note.Note'>(Symbol: 'Eb', Number: 3)]
%% Cell type:code id: tags:
``` python
a_chord.symbol = 'A7'
print("After 2nd modif: %r" % (a_chord))
a_chord.notes
```
%% Output
After 2nd modif: <class 'polytopes.model.chord.Chord'>(Symbol: 'A7', Notes: [<class 'polytopes.model.note.Note'>(Symbol: 'A', Number: 9), <class 'polytopes.model.note.Note'>(Symbol: 'Db', Number: 1), <class 'polytopes.model.note.Note'>(Symbol: 'E', Number: 4), <class 'polytopes.model.note.Note'>(Symbol: 'G', Number: 7)])
[<class 'polytopes.model.note.Note'>(Symbol: 'A', Number: 9),
<class 'polytopes.model.note.Note'>(Symbol: 'Db', Number: 1),
<class 'polytopes.model.note.Note'>(Symbol: 'E', Number: 4),
<class 'polytopes.model.note.Note'>(Symbol: 'G', Number: 7)]
%% Cell type:markdown id: tags:
Still, the other attributes can't, as they do not hold enough information on the new Chord to re-instanciate it.
%% Cell type:code id: tags:
``` python
a_chord.root = 'B'
```
%% Output
---------------------------------------------------------------------------
CantModifyAttribute Traceback (most recent call last)
<ipython-input-32-2efe97ae21f2> in <module>
----> 1 a_chord.root = 'B'
c:\users\amarmore\desktop\projects\phd main projects\on git\code\polytopes and relation\polytopes\model\chord.py in _not_on_my_watch(self, *args, **kwargs)
197 Raises an error, as these attributes must be found from either the notes or the symbol, and not set independantly (they don't contain enough information on the chord).
198 """
--> 199 raise err.CantModifyAttribute("Not on my watch: you can't modify this attribute alone, you can only modify the notes or the symbol.") from None
200
201 root = property(_get_chord_root, _not_on_my_watch)
CantModifyAttribute: Not on my watch: you can't modify this attribute alone, you can only modify the notes or the symbol.
%% Cell type:markdown id: tags:
### Adding a note
%% Cell type:markdown id: tags:
A note can be added to a Chord, which will modify all of its attributes accordingly.
%% Cell type:code id: tags:
``` python
chord = Chord('A')
chord.add_note(7)
chord.notes
```
%% Output
[<class 'polytopes.model.note.Note'>(Symbol: 'A', Number: 9),
<class 'polytopes.model.note.Note'>(Symbol: 'Db', Number: 1),
<class 'polytopes.model.note.Note'>(Symbol: 'E', Number: 4),
<class 'polytopes.model.note.Note'>(Symbol: 'G', Number: 7)]
%% Cell type:markdown id: tags:
Still, the added Note is already in the Chord, it won't be redundant.
%% Cell type:code id: tags:
``` python
chord.notes
```
%% Output
[<class 'polytopes.model.note.Note'>(Symbol: 'A', Number: 9),
<class 'polytopes.model.note.Note'>(Symbol: 'Db', Number: 1),
<class 'polytopes.model.note.Note'>(Symbol: 'E', Number: 4),
<class 'polytopes.model.note.Note'>(Symbol: 'G', Number: 7)]
%% Cell type:code id: tags:
``` python
chord.add_note(9)
chord.notes
```
%% Output
[<class 'polytopes.model.note.Note'>(Symbol: 'A', Number: 9),
<class 'polytopes.model.note.Note'>(Symbol: 'Db', Number: 1),
<class 'polytopes.model.note.Note'>(Symbol: 'E', Number: 4),
<class 'polytopes.model.note.Note'>(Symbol: 'G', Number: 7)]
%% Cell type:code id: tags:
``` python
Chord([8, 11, 3, 11]) == Chord([8, 11, 3, 11, 11, 11, 11])
```
%% Output
True
%% Cell type:markdown id: tags:
### Notes in the chord
%% Cell type:markdown id: tags:
The attributes "notes" of a chord is a list, and so, an individual Note can be retrieved from this list.
%% Cell type:code id: tags:
``` python
a_chord = Chord([8, 0, 3])
a_chord.notes[0]
```
%% Output
<class 'polytopes.model.note.Note'>(Symbol: 'Ab', Number: 8)
%% Cell type:markdown id: tags:
For convenience though, the i-th element of the .notes attribute can be accessed directly by indexing the Chord, as in:
%% Cell type:code id: tags:
``` python
a_chord[0]
```
%% Output
<class 'polytopes.model.note.Note'>(Symbol: 'Ab', Number: 8)
%% Cell type:markdown id: tags:
Inversely, the presence of a note in the chord can be tested as any element in a list:
%% Cell type:code id: tags:
``` python
Note(8) in a_chord.notes, Note(7) in a_chord.notes
```
%% Output
(True, False)
%% Cell type:markdown id: tags:
Or, more simply, by testing if the Chord contains this note:
%% Cell type:code id: tags:
``` python
Note(8) in a_chord, Note(7) in a_chord
```
%% Output
(True, False)
%% Cell type:markdown id: tags:
To know the number of notes in a chord, one can use the method get_nb_notes():
%% Cell type:code id: tags:
``` python
a_chord.get_nb_notes()
```
%% Output
3
%% Cell type:code id: tags:
``` python
a_chord.add_note(7)
a_chord.get_nb_notes()
```
%% Output
4
%% Cell type:markdown id: tags:
Finally, one can want to access to the notes as numbers, and there's a function for that:
%% Cell type:code id: tags:
``` python
a_chord.get_numbers()
```
%% Output
[8, 0, 3, 7]
%% Cell type:markdown id: tags:
### Chord with redundancy
%% Cell type:markdown id: tags:
Defined that way, chords doesn't allow repetitions in its notes (which is logical since notes are expressed in pitch classes).
This could become a problem when manipulating theoretical objects, for example in a context of optimal transport between chords.
To solve this problem, a parameter of the constructor can allow redundancy in the notes of a chord.
It is called redundancy and is a boolean.
%% Cell type:code id: tags:
``` python
Chord([8, 11, 3, 11], redundancy = True).notes
```
%% Output
[<class 'polytopes.model.note.Note'>(Symbol: 'Ab', Number: 8),
<class 'polytopes.model.note.Note'>(Symbol: 'B', Number: 11),
<class 'polytopes.model.note.Note'>(Symbol: 'Eb', Number: 3),
<class 'polytopes.model.note.Note'>(Symbol: 'B', Number: 11)]
%% Cell type:markdown id: tags:
When the object is created redundant, it remains redundant when its notes are modified.
%% Cell type:code id: tags:
``` python
redundant_chord = Chord([8, 0, 3], redundancy = True)
redundant_chord.add_note(8)
redundant_chord.get_numbers()
```
%% Output
[8, 0, 3, 8]
%% Cell type:code id: tags:
``` python
redundant_chord = Chord([8, 0, 3], redundancy = True)
redundant_chord.notes = [8, 0, 3, 4, 3]
redundant_chord.get_numbers()
```
%% Output
[8, 0, 3, 4, 3]
%% Cell type:markdown id: tags:
Conversely, a chord created without redundancy (default behavior) cannot be modified into a redundant chord.
%% Cell type:code id: tags:
``` python
default_chord = Chord([8, 0, 3], redundancy = False) # or simply Chord([8, 0, 3])
default_chord.notes = [8, 0, 3, 4, 3]
default_chord.get_numbers()
```
%% Output
[8, 0, 3, 4]
%% Cell type:markdown id: tags:
It also works when defined by its symbol.
%% Cell type:code id: tags:
``` python
default_chord = Chord('A')
default_chord.notes = [8, 0, 3, 4, 3]
default_chord.get_numbers()
```
%% Output
[8, 0, 3, 4]
%% Cell type:code id: tags:
``` python
redundant_chord = Chord('A', redundancy = True)
redundant_chord.notes = [8, 0, 3, 4, 3]
redundant_chord.get_numbers()
```
%% Output
[8, 0, 3, 4, 3]
%% Cell type:markdown id: tags:
It should be noted that the notes of a triad are ordered when the chord is not redundant, and aren't ordered when the chord is.
This is made to allow permutations when the chord is redundant, and to be more consistent with the real chord when it's not.
%% Cell type:code id: tags:
``` python
default_chord = Chord('A')
default_chord.notes = [3, 8, 0]
default_chord.get_numbers(), default_chord.root
```
%% Output
([8, 0, 3], <class 'polytopes.model.note.Note'>(Symbol: 'Ab', Number: 8))
%% Cell type:code id: tags:
``` python
redundant_chord = Chord('A', redundancy = True)
redundant_chord.notes = [3, 8, 0]
redundant_chord.get_numbers(), redundant_chord.root
```
%% Output
([3, 8, 0], <class 'polytopes.model.note.Note'>(Symbol: 'Ab', Number: 8))
%% Cell type:markdown id: tags:
## polytope.py
%% Cell type:code id: tags:
``` python
EDIT: not anymore
```
%% Output
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-1-8e7a5bdb8a47> in <module>
----> 1 EDIT: not anymore
NameError: name 'anymore' is not defined
%% Cell type:code id: tags:
``` python
from polytope import Polytope
```
%% Cell type:markdown id: tags:
A Polytope is an object defined to represent one or several musical bars, in the context of structural segmentation.
Hence, it is defined by several chords.
%% Cell type:code id: tags:
``` python
some_chords = [[8, 0, 3], [8, 0, 3], [8, 0, 3], [8, 0, 3], [7, 10, 2], [7, 10, 2], [7, 10, 2], [7, 10, 2], [8, 0, 3], [8, 0, 3], [8, 0, 3], [8, 0, 3], [10, 1, 5], [10, 1, 5], [3, 7, 10], [3, 7, 10]]
polytope = Polytope(some_chords)
polytope.chords
```
%% Output
[<class 'chord.Chord'>(Symbol: 'Ab', Notes: [<class 'note.Note'>(Symbol: 'Ab', Number: 8), <class 'note.Note'>(Symbol: 'C', Number: 0), <class 'note.Note'>(Symbol: 'Eb', Number: 3)]),
<class 'chord.Chord'>(Symbol: 'Ab', Notes: [<class 'note.Note'>(Symbol: 'Ab', Number: 8), <class 'note.Note'>(Symbol: 'C', Number: 0), <class 'note.Note'>(Symbol: 'Eb', Number: 3)]),
<class 'chord.Chord'>(Symbol: 'Ab', Notes: [<class 'note.Note'>(Symbol: 'Ab', Number: 8), <class 'note.Note'>(Symbol: 'C', Number: 0), <class 'note.Note'>(Symbol: 'Eb', Number: 3)]),
<class 'chord.Chord'>(Symbol: 'Ab', Notes: [<class 'note.Note'>(Symbol: 'Ab', Number: 8), <class 'note.Note'>(Symbol: 'C', Number: 0), <class 'note.Note'>(Symbol: 'Eb', Number: 3)]),
<class 'chord.Chord'>(Symbol: 'Gm', Notes: [<class 'note.Note'>(Symbol: 'G', Number: 7), <class 'note.Note'>(Symbol: 'Bb', Number: 10), <class 'note.Note'>(Symbol: 'D', Number: 2)]),
<class 'chord.Chord'>(Symbol: 'Gm', Notes: [<class 'note.Note'>(Symbol: 'G', Number: 7), <class 'note.Note'>(Symbol: 'Bb', Number: 10), <class 'note.Note'>(Symbol: 'D', Number: 2)]),
<class 'chord.Chord'>(Symbol: 'Gm', Notes: [<class 'note.Note'>(Symbol: 'G', Number: 7), <class 'note.Note'>(Symbol: 'Bb', Number: 10), <class 'note.Note'>(Symbol: 'D', Number: 2)]),
<class 'chord.Chord'>(Symbol: 'Gm', Notes: [<class 'note.Note'>(Symbol: 'G', Number: 7), <class 'note.Note'>(Symbol: 'Bb', Number: 10), <class 'note.Note'>(Symbol: 'D', Number: 2)]),
<class 'chord.Chord'>(Symbol: 'Ab', Notes: [<class 'note.Note'>(Symbol: 'Ab', Number: 8), <class 'note.Note'>(Symbol: 'C', Number: 0), <class 'note.Note'>(Symbol: 'Eb', Number: 3)]),
<class 'chord.Chord'>(Symbol: 'Ab', Notes: [<class 'note.Note'>(Symbol: 'Ab', Number: 8), <class 'note.Note'>(Symbol: 'C', Number: 0), <class 'note.Note'>(Symbol: 'Eb', Number: 3)]),
<class 'chord.Chord'>(Symbol: 'Ab', Notes: [<class 'note.Note'>(Symbol: 'Ab', Number: 8), <class 'note.Note'>(Symbol: 'C', Number: 0), <class 'note.Note'>(Symbol: 'Eb', Number: 3)]),
<class 'chord.Chord'>(Symbol: 'Ab', Notes: [<class 'note.Note'>(Symbol: 'Ab', Number: 8), <class 'note.Note'>(Symbol: 'C', Number: 0), <class 'note.Note'>(Symbol: 'Eb', Number: 3)]),
<class 'chord.Chord'>(Symbol: 'Bbm', Notes: [<class 'note.Note'>(Symbol: 'Bb', Number: 10), <class 'note.Note'>(Symbol: 'Db', Number: 1), <class 'note.Note'>(Symbol: 'F', Number: 5)]),
<class 'chord.Chord'>(Symbol: 'Bbm', Notes: [<class 'note.Note'>(Symbol: 'Bb', Number: 10), <class 'note.Note'>(Symbol: 'Db', Number: 1), <class 'note.Note'>(Symbol: 'F', Number: 5)]),
<class 'chord.Chord'>(Symbol: 'Eb', Notes: [<class 'note.Note'>(Symbol: 'Eb', Number: 3), <class 'note.Note'>(Symbol: 'G', Number: 7), <class 'note.Note'>(Symbol: 'Bb', Number: 10)]),
<class 'chord.Chord'>(Symbol: 'Eb', Notes: [<class 'note.Note'>(Symbol: 'Eb', Number: 3), <class 'note.Note'>(Symbol: 'G', Number: 7), <class 'note.Note'>(Symbol: 'Bb', Number: 10)])]
%% Cell type:markdown id: tags:
To facilitates the visualization of polytopes, when they contain 16 elements, a 4 by 4 visualization function has been implemented.
%% Cell type:code id: tags:
``` python
polytope.get_length()
```
%% Output
16
%% Cell type:code id: tags:
``` python
polytope.pretty_print()
```
%% Output
0 [8, 0, 3] 1 [8, 0, 3]
2 [8, 0, 3] 3 [8, 0, 3]
4 [7, 10, 2] 5 [7, 10, 2]
6 [7, 10, 2] 7 [7, 10, 2]
8 [8, 0, 3] 9 [8, 0, 3]
10 [8, 0, 3] 11 [8, 0, 3]
12 [10, 1, 5] 13 [10, 1, 5]
14 [3, 7, 10] 15 [3, 7, 10]
%% Cell type:code id: tags:
``` python
polytope.pretty_print(symbols = True)
```
%% Output
0 Ab 1 Ab
2 Ab 3 Ab
4 Gm 5 Gm
6 Gm 7 Gm
8 Ab 9 Ab
10 Ab 11 Ab
12 Bbm 13 Bbm
14 Eb 15 Eb
%% Cell type:markdown id: tags:
It is also possible to access to the chords of a polytope as a list of Chord symbols or by lists of the note numbers:
%% Cell type:code id: tags:
``` python
polytope.get_list_of_symbols()
```
%% Output
['Ab',
'Ab',
'Ab',
'Ab',
'Gm',
'Gm',
'Gm',
'Gm',
'Ab',
'Ab',
'Ab',
'Ab',
'Bbm',
'Bbm',
'Eb',
'Eb']
%% Cell type:code id: tags:
``` python
polytope.get_list_of_numbers()
```
%% Output
[[8, 0, 3],
[8, 0, 3],
[8, 0, 3],
[8, 0, 3],
[7, 10, 2],
[7, 10, 2],
[7, 10, 2],
[7, 10, 2],
[8, 0, 3],
[8, 0, 3],
[8, 0, 3],
[8, 0, 3],
[10, 1, 5],
[10, 1, 5],
[3, 7, 10],
[3, 7, 10]]
%% Cell type:markdown id: tags:
One of the interest of the polytopical paradigm is to reorder the elements in a non sequential way.
In that context, a promising framework, developed in [Louboutin 2017], is the "Primer Preseving Permutation" system, or PPP. Here, it is possible to obtain the ppp of a polytope with the methods:
%% Cell type:code id: tags:
``` python
polytope.get_ppp(1).get_list_of_numbers() # The argument is the index of the desired ppp.
```
%% Output
[[8, 0, 3],
[8, 0, 3],
[7, 10, 2],
[7, 10, 2],
[8, 0, 3],
[8, 0, 3],
[7, 10, 2],
[7, 10, 2],
[8, 0, 3],
[8, 0, 3],
[10, 1, 5],
[10, 1, 5],
[8, 0, 3],
[8, 0, 3],
[3, 7, 10],
[3, 7, 10]]
%% Cell type:code id: tags:
``` python
polytope.get_all_ppps()
```
%% Output
[<polytop.Polytop at 0x23b26514808>,
<polytop.Polytop at 0x23b26514908>,
<polytop.Polytop at 0x23b26514f08>,
<polytop.Polytop at 0x23b26514608>,
<polytop.Polytop at 0x23b26514548>,
<polytop.Polytop at 0x23b26514208>]
%% Cell type:code id: tags:
``` python
polytope.get_all_ppps()[3].get_list_of_symbols()
```
%% Output
['Ab',
'Ab',
'Ab',
'Ab',
'Ab',
'Ab',
'Ab',
'Ab',
'Gm',
'Gm',
'Bbm',
'Bbm',
'Gm',
'Gm',
'Eb',
'Eb']
%% Cell type:markdown id: tags:
Finally, it is also possible to add a Chord to a polytope.
%% Cell type:code id: tags:
``` python
polytope.add_chord('Abmin')
polytope.get_length()
```
%% Output
17
%% Cell type:code id: tags:
``` python
polytope.get_list_of_numbers()
```
%% Output
[[8, 0, 3],
[8, 0, 3],
[8, 0, 3],
[8, 0, 3],
[7, 10, 2],
[7, 10, 2],
[7, 10, 2],
[7, 10, 2],
[8, 0, 3],
[8, 0, 3],
[8, 0, 3],
[8, 0, 3],
[10, 1, 5],
[10, 1, 5],
[3, 7, 10],
[3, 7, 10],
[8, 11, 3]]
%% Cell type:code id: tags:
``` python
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment