Skip to content

Commit

Permalink
Added basic level offset indexer (currently only working with NoteRes…
Browse files Browse the repository at this point in the history
…t indexer).
  • Loading branch information
musicus committed Nov 19, 2016
1 parent 89a22af commit c840059
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 45 deletions.
100 changes: 63 additions & 37 deletions _Index.pd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#N canvas 107 23 1115 730 10;
#N canvas 111 23 1140 710 10;
#X declare -path library;
#X obj 33 148 openfiles;
#X obj 33 103 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
Expand Down Expand Up @@ -51,38 +51,38 @@
#X obj 586 459 Ambitus, f 13;
#X obj 33 435 NoteRestIndexer;
#X obj 145 239 DataframeStartEnd;
#X obj 33 781 HintIndexer;
#X floatatom 95 569 5 0 0 0 - - -, f 5;
#X obj 137 569 DataframeStartEnd;
#X obj 137 636 IndexerPak;
#X obj 13 746 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
#X obj 33 921 HintIndexer;
#X floatatom 95 709 5 0 0 0 - - -, f 5;
#X obj 137 709 DataframeStartEnd;
#X obj 137 776 IndexerPak;
#X obj 13 886 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
-1;
#X obj 33 175 s scores;
#X obj 33 569 r scores;
#X obj 33 623 spigot;
#X obj 66 596 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
#X obj 33 709 r scores;
#X obj 33 763 spigot;
#X obj 66 736 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
1;
#X obj 33 292 spigot;
#X obj 66 266 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
1;
#X obj 33 239 r scores;
#X obj 33 808 s hint-dataframes;
#X obj 33 948 s hint-dataframes;
#X obj 33 502 s nri-dataframes;
#X obj 145 333 IndexerPak;
#X obj 355 623 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144
#X obj 355 763 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144
-1 -1;
#X msg 464 656 2;
#X msg 493 656 3;
#X msg 522 656 4;
#X msg 551 656 5;
#X msg 580 656 6;
#X floatatom 464 699 5 0 0 0 - - -, f 5;
#X obj 401 686 spigot;
#X obj 434 659 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
#X msg 464 796 2;
#X msg 493 796 3;
#X msg 522 796 4;
#X msg 551 796 5;
#X msg 580 796 6;
#X floatatom 464 839 5 0 0 0 - - -, f 5;
#X obj 401 826 spigot;
#X obj 434 799 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
1;
#X text 351 594 Horizontal NGrams;
#X obj 355 733 HorizontalNgrams;
#X obj 401 624 r hint-dataframes;
#X text 351 734 Horizontal NGrams;
#X obj 355 873 HorizontalNgrams;
#X obj 401 764 r hint-dataframes;
#X text 50 101 <= Load symbolic music scores (any format music21 can
interpret)., f 65;
#X text 31 79 1) We have to load a score first.;
Expand All @@ -94,26 +94,42 @@ interpret)., f 65;
#X text 350 241 3a) Count Pitches in a score.;
#X text 583 241 3b) Find the range of a part in a score.;
#X text 843 241 3b) Find melodic intervals in a score.;
#X text 31 545 4) We can find all melodic intervals in a score and
#X text 31 685 4) We can find all melodic intervals in a score and
index them., f 66;
#X text 611 656 <= Specify sample rate of overlapping windows.;
#X obj 137 713 IntSettings;
#X floatatom 95 879 5 0 0 0 - - -, f 5;
#X obj 137 879 DataframeStartEnd;
#X obj 137 946 IndexerPak;
#X obj 13 1056 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144
#X text 611 796 <= Specify sample rate of overlapping windows.;
#X obj 137 853 IntSettings;
#X floatatom 95 1019 5 0 0 0 - - -, f 5;
#X obj 137 1019 DataframeStartEnd;
#X obj 137 1086 IndexerPak;
#X obj 13 1196 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144
-1 -1;
#X obj 33 879 r scores;
#X obj 33 933 spigot;
#X obj 66 906 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 1
#X obj 33 1019 r scores;
#X obj 33 1073 spigot;
#X obj 66 1046 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
1;
#X obj 137 1023 IntSettings;
#X obj 33 1118 s vint-dataframes;
#X obj 33 1091 VintIndexer;
#X text 351 571 4a) With consecutive melodic intervals \, we can find
#X obj 137 1163 IntSettings;
#X obj 33 1258 s vint-dataframes;
#X obj 33 1231 VintIndexer;
#X text 351 711 4a) With consecutive melodic intervals \, we can find
melodic N-Grams., f 69;
#X text 31 855 5) We can find all vertical intervals in a score and
#X text 31 995 5) We can find all vertical intervals in a score and
index them., f 67;
#X text 31 535 3d) We can look at the DataFrame at different offsets.
;
#X obj 34 621 OffsetIndexer;
#X obj 150 562 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144
-1 -1;
#X msg 180 585 1;
#X msg 210 585 2;
#X msg 240 585 4;
#X msg 270 585 8;
#X floatatom 180 635 5 0 0 0 - - -, f 5;
#X msg 180 562 0;
#X text 212 562 <= Resets offsets.;
#X obj 34 562 r nri-dataframes;
#X obj 34 590 spigot;
#X obj 101 586 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
1;
#X connect 0 0 45 0;
#X connect 1 0 0 0;
#X connect 2 0 0 1;
Expand Down Expand Up @@ -185,3 +201,13 @@ index them., f 67;
#X connect 85 0 84 1;
#X connect 86 0 88 4;
#X connect 88 0 87 0;
#X connect 93 0 92 1;
#X connect 94 0 98 0;
#X connect 95 0 98 0;
#X connect 96 0 98 0;
#X connect 97 0 98 0;
#X connect 98 0 92 2;
#X connect 99 0 98 0;
#X connect 101 0 102 0;
#X connect 102 0 92 0;
#X connect 103 0 102 1;
20 changes: 19 additions & 1 deletion library/NoteRestIndexer.pd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#N canvas 188 106 960 590 10;
#N canvas 718 23 980 668 10;
#X msg 71 52 doc;
#X msg 71 79 doc+;
#X msg 71 106 reload;
Expand Down Expand Up @@ -56,11 +56,22 @@
#X obj 501 433 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
1;
#X obj 564 285 pyx. IndexerPak 2;
#X obj 118 611 OffsetIndexer;
#X obj 152 557 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144
-1 -1;
#X msg 270 558 1;
#X msg 300 558 2;
#X msg 330 558 4;
#X msg 360 558 8;
#X floatatom 270 608 5 0 0 0 - - -, f 5;
#X msg 270 535 0;
#X text 302 535 <= Resets offsets.;
#X connect 0 0 3 0;
#X connect 1 0 3 0;
#X connect 2 0 3 0;
#X connect 3 0 28 0;
#X connect 3 0 35 0;
#X connect 3 0 49 0;
#X connect 3 1 31 0;
#X connect 3 1 33 0;
#X connect 3 2 43 0;
Expand Down Expand Up @@ -94,3 +105,10 @@
#X connect 46 0 45 0;
#X connect 47 0 46 1;
#X connect 48 0 3 4;
#X connect 50 0 49 1;
#X connect 51 0 55 0;
#X connect 52 0 55 0;
#X connect 53 0 55 0;
#X connect 54 0 55 0;
#X connect 55 0 49 2;
#X connect 56 0 55 0;
7 changes: 2 additions & 5 deletions library/NoteRestIndexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Author: Reiner Kramer
Email: reiner@music.org
Updated: 10.13.2016
Updated: 11.18.2016
@TODO: Rather than saving dataframes as pickled files in the data folder
of the library directory, files should be cached via memoization
Expand Down Expand Up @@ -63,7 +63,7 @@ def __init__(self,
scores_mto=0,
scores_mto_frozen=0,
scores_pandas=0,
df_paths=0,
df_paths=[],
events=5,
direction='beginning',
slice_start=0,
Expand Down Expand Up @@ -119,8 +119,6 @@ def _anything_1(self, *symbolic_scores):
for x in self.scores_imported]

# Save NoteRestIndexed DataFrames:
self.df_paths = []

for i in range(len(self.scores_pandas)):

# Build the path names, and save into a list.
Expand All @@ -140,7 +138,6 @@ def _anything_1(self, *symbolic_scores):
# Renaming the columns to a more user friendly format:
for x, y in zip(self.df_paths,self.scores_pandas):
self._generate_name(x)

y.columns.set_levels(['Part'], level=0, inplace=True)
y.columns.set_names(['Score','Events'], inplace=True)
print(y.head(self.events).to_csv(
Expand Down
37 changes: 36 additions & 1 deletion library/OffsetIndexer.pd
Original file line number Diff line number Diff line change
@@ -1 +1,36 @@
#N canvas 0 22 450 300 10;
#N canvas 266 40 527 284 10;
#X obj 182 29 inlet;
#X obj 115 187 pyext OffsetIndexer Set;
#X msg 61 92 doc;
#X msg 61 119 doc+;
#X msg 61 146 reload;
#X msg 300 108 1;
#X msg 330 108 2;
#X msg 360 108 4;
#X msg 390 108 8;
#X floatatom 270 158 5 0 0 0 - - -, f 5;
#X obj 270 59 inlet;
#X obj 182 124 bng 20 250 50 0 empty empty empty 17 7 0 10 -262144
-1 -1;
#X obj 182 154 list;
#X obj 182 64 t b l;
#X obj 241 30 inlet;
#X text 282 30 <= Recall previously loaded files.;
#X msg 300 85 0;
#X text 332 85 <= Resets offsets.;
#X connect 0 0 13 0;
#X connect 2 0 1 0;
#X connect 3 0 1 0;
#X connect 4 0 1 0;
#X connect 5 0 9 0;
#X connect 6 0 9 0;
#X connect 7 0 9 0;
#X connect 8 0 9 0;
#X connect 9 0 1 2;
#X connect 10 0 9 0;
#X connect 11 0 12 0;
#X connect 12 0 1 1;
#X connect 13 0 11 0;
#X connect 13 1 12 1;
#X connect 14 0 11 0;
#X connect 16 0 9 0;
87 changes: 86 additions & 1 deletion library/OffsetIndexer.py
Original file line number Diff line number Diff line change
@@ -1 +1,86 @@
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-

import sys, os, music21, pandas, requests, vis, pyext
from vis.models.indexed_piece import Importer

try:
print("OffIndexer.py was loaded.")
except:
print("Loading OffIndexer.py failed.")


class Set(pyext._class):

_inlets = 2
_outlets = 2

def __init__(self,
symbolic_scores=0,
scores_paths=0,
scores_imported=[],
events=5,
df_offset=0):
self.symbolic_scores = symbolic_scores
self.scores_paths = scores_paths
self.scores_imported = scores_imported
self.events = events
self.df_offset = df_offset


def _anything_1(self, *symbolic_scores):


if(len(symbolic_scores) >= 1):

try:

self.scores_paths = [str(x) for x in symbolic_scores]

for i in range(len(self.scores_paths)):
self.scores_imported.append(
pandas.read_pickle(self.scores_paths[i]))

# Convert score paths from symbols to strings:
#self.scores_paths = [str(x) for x in symbolic_scores]

# Create Music21 streams and index them with VIS:
#self.scores_imported = [Importer(x) for x in self.scores_paths]

#print(self.scores_imported)

for x, y in zip(self.scores_paths,self.scores_imported):
#self._generate_name(x)
y.columns.set_levels(['Part'], level=0, inplace=True)
y.columns.set_names(['Score','Events'], inplace=True)
print(y.head(self.events).to_csv(
sep='\t',
na_rep='^'))

except Exception as e:

print(e)
#self._print_output('not_indexed')

else:

#self._print_output('no_scores')
print("...there were no scores...")

def _anything_2(self, offset):

self.df_offset = offset

for x, y in zip(self.scores_paths,self.scores_imported):
#self._generate_name(x)
y.columns.set_levels(['Part'], level=0, inplace=True)
y.columns.set_names(['Score','Events'], inplace=True)

if(self.df_offset == 0):
print(y.head(self.events).to_csv(
sep='\t',
na_rep='^'))
else:
print(y[::self.df_offset].head(self.events).to_csv(
sep='\t',
na_rep='^'))

0 comments on commit c840059

Please sign in to comment.