Package: crim_intervals
CRIM Intervals:  Python Tools for the Analysis of Encoded Music ScoresCurrent Version: 2.0.13CRIM Intervals on githubAbout CRIM IntervalsBased onPythonandPandas, and Mike Cuthbert's excellentmusic21(https://web.mit.edu/music21/),CRIM Intervalsis a pattern finding engine for musical scores, with an emphasis on the kinds of melodic, harmonic, and contrapuntal patterns found in Renaissance polyphony. It has been developed as a primary data analysis tool forCitations:  The Renaissance Imitation Mass(http://crimproject.organdhttps://sites.google.com/haverford.edu/crim-project/home), directed by Professor Richard Freedman (Haverford College, USA), in partnership with dozens of researchers and students around the world. Contact rfreedma at haverford.edu to learn more about the project, and how you can take part.File Formats: CRIM Intervals will analyze scores encoded in several widely-used formats:  MEI, MusicXML, and MIDI.  Results will vary according to the editorial practices used in the underlying transcriptions and editions.The CRIM Intervals Web Application:  Get started quickly with theCRIM Intervals Streamlit Application, which requires no coding sklls.  You can work with the CRIM Corpus, or import your own pieces, producing analytic tables, visualizations, and other results that you can download for use in publications and teaching.  The web app is free and requires no special account or software installation.  Tutorials are available on the site itself, with pointers back to the code and tutorials here on CRIM Intervals itself.Learn How Others are Using CRIM IntervalsviaCRIM Essays and Experiments, which assembles recent work by over two-dozen scholars and students from around the world. Find out what is possible, what others are thinking about, and how you might use their work to advance your teaching and research.Getting Started with CRIM IntervalsThis respository contains the CRIM Intervals library itself, along with tutorials that explain the various methods, and Jupyter Notebooks make them easy to use for your research and teaching.  There are various ways to get started:TheCRIM Intervals Streamlit Application, which requires no coding sklls.  You can work with the CRIM Corpus, or import your own pieces, producing analytic tables, visualizations, and other results that you can download for use in publications and teaching.Install and run CRIM Intervals (along with the Notebooks) locally withAnaconda Navigator, VS-Code, and Jupyter.  See Richard Freedman'sEncoding Music course pageto learn how.Install the latest version of CRIM Intervals library viapypi.org.Run CRIM Intervals via a freeJupyter-hub maintained by Haverford College(contact rfreedma at haverford.edu) to obtain an account.The BasicsCRIM Intervals begins by importing one (or more) MEI, MusicXML, and MIDI files, for example:piece = importScore('https://crimproject.org/mei/CRIM_Model_0008.mei')Once imported this piece object can be explored in various ways. piece.notes(), for instance, produces a dataframe in which each staff (voice part) is represented as a column of events--notes, rests, durations, lyrics, etc. Other methods (see the list below) in turn present these basic events in many different ways: as melodic intervals, harmonic intervals, n-grams, contrapuntal "modules", and so on.There are many ways to configure these basic methods. For instance intervals can be diatonic, or chromatic, or with (and without) 'quality' (such as M3 vs m3). They can also be simple or compound (a tenth in the latter would be a third in the former).Unisons can be combined (something helpful for comparing similar melodies), or events can be taken at actual durations or 'sampled' at some regular durational span.Complete documentation of each method capacities is available via doc.strings via this commandprint(model.YourMethod.__doc__), where you will replace 'YourMethod' with the name of the individual method, for exampleprint(piece.melodic.__doc__).Results are reported inPandasdataframes (and thus exportable in a variey of standard formats for further analysis), and also via several visualizations methods.Some methods inCRIM Intervalsalso work withCRIM Projectdata created by human observers.Key Methods in CRIM IntervalsMelody, Harmony, Rhythm, Lyrics and NGramspiece.notes(), which finds all the notes and rests in a score, with a tabular score-like representation of the pitches, pitch classes, and durations (expressed in music21 "offsets", in which each quarter note corresponds to the value of 1.0). It can also derminte the location of any note as a measure+beat reference with detailIndexpiece.melodic(), which finds melodic intervals in any voice part, with various options for diatonic, chromatic and zero-based distances. Intervals can be compound (distinguishing between tenths and thirds, for instance), or simple, and can include quality (distinguishing major and minor thirds, for instance), or not.piece.harmonic(), which finds harmonic intervals between every combination of two voices in a piece, with various options for diatonic and chromatic. These intervals can also be directed (as when a tenor voice sounds above the altus), or not.piece.lyrics()(for every note)piece.durations(), with quarter-note = 1.0, as per music21.piece.ngrams(), which finds n-grams of any length in each voice part. n-grams are frequently used in linguistic analysis (), and can help us find repeating patterns within and among works. The ngram tool can be used for any of the methods above: melodic, harmonic, durations, lyrics. By default it finds contrapuntal modules, which represent in numerical values a combination of the vertical intervals made between any two voices with the melodic intervals heard in the motion of the lower voice. A module of7_Held 6_-2, 8for instance, represents vertical intervals of7, 6, 8between two voices and in the lower voice a tied note followed by a descending second. Together these five events represent a typical cadence formula. Repeating modules are a key part of Renaissance contrapuntal style.It is also possible to apply variousedit distance toolsto many of these patterns, thus allowing users to findexactandclose matches.Classification of Contrapuntal TypesCRIM Intervals also include advanced methods that use combinations of the methods detailed above to predict "contrapuntal types" commonly found in Renaissance polyphony.Cadencesare one such type:piece.cadences()can find them with a high degree of accuracy.We have also developed a method that predict variousimitative textures, including Fugas, Imitative Duos, Non-Imitative Duoes, and Periodic Entries(as Peter Schubert has named them):piece.presentationTypes().It is also possible to accurately identifyhomorhythmic passages(where sets of voices move in the same durations and declaim the same lyrics):piece.homorhythm().In each case we there are various options users can select to refine the searches, including various tools that allow forsimilar no less than exact matches. Melodic and rhythmic 'flexing' are key parts of Renaissance counterpoint. These methods are too complex to summarize in a short space. But they are powerful tools for machine prospecting of musical works.Heatmaps, Graphs, and NetworksCRIM Intervals also features tools that help us visualize musical events in different ways, including:bar charts and histogramsof events (such as notes, or intervals), which are useful for understand ranges, distributions, and other large-scale distribution of categorical dataheatmaps, showing where in a piece patterns (such as repeating n-grams) occurradar plots, used to show cadences in a radial plot that reveals the tonal profile of a composition (or a corpus of works)progress charts, showing a cadences in a series (from start to finish)network diagrams, showing related patterns or piecesOne Piece, or a CorpusCRIM Intervals methods can also be applied to a corpus of pieces. We first define a corpus:corpus = CorpusBase(['https://crimproject.org/mei/CRIM_Mass_0006_1.mei', 'https://crimproject.org/mei/CRIM_Mass_0006_2.mei', 'https://crimproject.org/mei/CRIM_Mass_0006_3.mei']), then specify a method to run against each piece in the corpus:corpus.batch(func=ImportedPiece.cadences). The results are reported as a combined dataframe.Render Scores (or Excertps) with VerovioCRIM Intervals also has the capacity to render results as modern score with Laurent Pugin'sVerovio(for examplepiece.verovioCadences()), as well as reporting them as data frames and visualizations.Credits and Intellectual Property StatementCRIM Intervals is the Work of Many Hands:Andrew Janco (Haverford College/Universit of Pennsylvania)Freddie Gould (Haverford College/Audible)Trang Dang (Bryn Mawr College)Alexander Morgan (EcoRate)Daniel Russo-Batterham (Melbourne University)Richard Freedman (Haverford College)Oleh Shostak (Haverford College)Edgar Leon (Haverford College)Harrison West (Haverford College)Patty Guardiola (Haverford College)Anna Lacy (Haverford College)CRIM Intervals is made possible generous support from:Haverford CollegeThe American Council of Learned SocietiesAll CRIM intervals tools are available via aCreative Commonslicense (Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)):https://creativecommons.org/licenses/by-sa/4.0/.Sections in this guide01_Introduction_and_Corpus02_Notes_Rests03_Durations04_TimeSignatures_Beat_Strength05_Detail_Index06_Melodic_Intervals07_Harmonic_Intervals08_Contrapuntal_Modules09_Ngrams_Heat_Maps10_Lyrics_Homorhythm11_Cadences12_Presentation_Types13_Model_Finder14_Visualizations_Summary15_Network_Graphs16_Python_Basics17_Pandas_Basics18_Music21_Basics