// // Programmer: Craig Stuart Sapp // Creation Date: Mon Jun 24 20:05:15 PDT 2002 // Last Modified: Thu Jul 11 14:48:23 2002 // Filename: ...sig/examples/all/chordset.cpp // Web Address: http://sig.sapp.org/examples/museinfo/humdrum/chordset.cpp // Syntax: C++; museinfo // // Description: Count and collect chords from **kern data using a // **root interpretation indicating the segmentation of // the chords. // #include "humdrum.h" #include #include #include template int arrayEqual(Array& a, Array& b); class ChordEntry { public: ChordEntry(void) { clear(); } ~ChordEntry() { clear(); } void clear(void) { count = root = 0; pitches.setSize(0); } int count; int root; Array pitches; }; class ChordData : public SigCollection { public: ChordData(void) { clear(); } ~ChordData() { clear(); } void clear(void) { setSize(10000); setGrowth(10000); setSize(0); } void addData(int root, Array& pitches); void addDataNoRoot(Array& pitches); }; void ChordData::addData(int root, Array& pitches) { ChordData& data = *this; int i; for (i=0; i& pitches) { ChordData& data = *this; int i; for (i=0; i absbeat; Array pitches; Array durations; Array levels; infile.getNoteArray(absbeat, pitches, durations, levels, startline, stopline); // extract just pitch class info, and ignore rests Array npitches; npitches.setSize(pitches.getSize()); npitches.setSize(0); int value = 0; int i; for (i=0; i nnpitches(npitches.getSize()); if (uniqQ == 0) { if (rootlessQ) { chordData.addDataNoRoot(npitches); } else { chordData.addData(root, npitches); } nnpitches = npitches; } else { nnpitches.setSize(0); nnpitches.append(npitches[0]); for (i=1; i int arrayEqual(Array& a, Array& b) { if (a.getSize() != b.getSize()) { return 0; } int i; for (i=0; i B.root) { return 1; } else { return 0; } } ////////////////////////////// // // countcompare -- // int countcompare(const void* a, const void* b) { ChordEntry& A = *((ChordEntry*)a); ChordEntry& B = *((ChordEntry*)b); if (A.count < B.count) { return 1; } else if (A.count > B.count) { return -1; } else { return 0; } } ////////////////////////////// // // picthcompare -- // int pitchcompare(const void* a, const void* b) { ChordEntry& A = *((ChordEntry*)a); ChordEntry& B = *((ChordEntry*)b); Array x(A.pitches.getSize()); Array y(A.pitches.getSize()); x.setSize(0); y.setSize(0); int i; x.append(A.pitches[0]); for (i=1; i y[i]) { return 1; } } if (x.getSize() < y.getSize()) { return -1; } else if (x.getSize() > y.getSize()) { return 1; } else { return 0; } } ////////////////////////////// // // rootcompare -- compare two roots for ordering // int rootcompare(const void* a, const void* b) { if (*((int*)a) < *((int*)b)) { return -1; } else if (*((int*)a) > *((int*)b)) { return 1; } else { return 0; } } // md5sum: 5c38e99551dcb6feab923332279bcdc0 chordset.cpp [20160320]