Ejemplo n.º 1
0
MachineLearningOutput getExhaustiveChordProgression(const std::vector<std::string>& c, unsigned size)
{
    std::vector<Chord> chords;
    for(auto it : c)
        chords.push_back(readChord(it));
    std::vector<ChordProgression> distinctChordProgressions = createAllPossibilities(chords, size);
    MachineLearningOutput res;
    for(auto& it : distinctChordProgressions)
        res.push_back(std::make_pair(it, 30));
    return res;
}
Ejemplo n.º 2
0
void ConvertGtp::readTabs()
{
	char beat_bitmask, strings, num;
	char length, volume, pan, chorus, reverb, phase, tremolo;
	int x;

	currentStage = string("readTabs");

	vector<TabTrack>::iterator trk = song->t.begin();
	for (int tr = 0; tr < numTracks; tr++) {
		trk->b.resize(numBars);
		trk->c.resize(0);
		trk++;
	}

	for (int j = 0; j < numBars; j++) {
		for (trk = song->t.begin(); trk != song->t.end(); trk++) {
			int numBeats = readDelphiInteger();
			//osg::notify(osg::INFO) << "TRACK " << tr << ", BAR " << j << ", numBeats " << numBeats << " (position: " << stream.tellg() << ")\n";

			if (numBeats < 0 || (strongChecks && numBeats > 128))  
				throw string("Track %1, bar %2, insane number of beats: %3");

			x = trk->c.size();
			trk->c.resize(trk->c.size() + numBeats);
			trk->b[j].time1 = bars[j].time1;
			trk->b[j].time2 = bars[j].time2;
			trk->b[j].keysig = bars[j].keysig;
			trk->b[j].start = x;
			trk->b[j].notes = numBeats;
			trk->b[j].tempo = -1;
			trk->b[j].begin = bars[j].begin;
			trk->b[j].end = bars[j].end;

			for (int k = 0; k < numBeats; k++) {
				trk->c[x].flags = 0;

				beat_bitmask = readChar();   // beat bitmask
				
				if (beat_bitmask & 0x01)     // dotted column
					trk->c[x].flags |= FLAG_DOT;

				if (beat_bitmask & 0x40) {
					num = readChar();        // GREYFIX: pause_kind
				}

				// Guitar Pro 4 beat lengths are as following:
				// -2 = 1    => 480     3-l = 5  2^(3-l)*15
				// -1 = 1/2  => 240           4
				//  0 = 1/4  => 120           3
				//  1 = 1/8  => 60            2
				//  2 = 1/16 => 30 ... etc    1
				//  3 = 1/32 => 15            0

				length = readChar();            // length
				//osg::notify(osg::INFO) << "beat_bitmask: " << (int) beat_bitmask << "; length: " << length << "\n";

				float len = 1.0f / (1 << (2 + length));
				trk->c[x].l = len;

				if (beat_bitmask & 0x20) {
					int tuple = readDelphiInteger();
					//osg::notify(osg::INFO) << "Tuple: " << tuple << "\n"; // GREYFIX: t for tuples
					if (!(tuple == 3 || (tuple >= 5 && tuple <= 7) || (tuple >= 9 && tuple <= 13)))  
						throw string("Insane tuple t: %1");
				}
				
				if (beat_bitmask & 0x02)     // Chord diagram
				{
					readChord(trk, x);
				}

				if (beat_bitmask & 0x04) {
					readDelphiString();
				}  

				// GREYFIX: column-wide effects
				if (beat_bitmask & 0x08)
				{
					readColumnEffects(trk, x);
				}

				if (beat_bitmask & 0x10) {     // mixer variations
					num = readChar();          // GREYFIX: new MIDI patch
					volume = readChar();       // GREYFIX: new
					pan = readChar();          // GREYFIX: new
					chorus = readChar();       // GREYFIX: new
					reverb = readChar();       // GREYFIX: new
					phase = readChar();        // GREYFIX: new
					tremolo = readChar();      // GREYFIX: new
					int tempo = readDelphiInteger(); // GREYFIX: new tempo

					trk->b[j].tempo = tempo;

					// GREYFIX: transitions
					if (volume != -1)   num = readChar();
					if (pan != -1)      num = readChar();
					if (chorus != -1)   num = readChar();
					if (reverb != -1)   num = readChar();
					if (tremolo != -1)  num = readChar();
					if (tempo != -1)    num = readChar();

					if (versionMajor >= 4) {
						num = readChar();          // bitmask: what should be applied to all tracks
					}
				}

				strings = readChar();          // used strings mask
				
				for (int y = STRING_MAX_NUMBER - 1; y >= 0; y--) {
					trk->c[x].e[y] = 0;
					trk->c[x].a[y] = NULL_NOTE;
					if (strings & (1 << (y + STRING_MAX_NUMBER - trk->strings)))
						readNote(trk, x, y);
				}
				
				// Dump column
				string tmp = "";
				for (int y = 0; y <= trk->strings; y++) {
					if (trk->c[x].a[y] == NULL_NOTE) {
						tmp += ".";
					} else {
						tmp += '0' + trk->c[x].a[y];
					}
				}
				//osg::notify(osg::INFO) << "[" << tmp << "]\n";
				
				x++;
			}
		}
	}
}
Ejemplo n.º 3
0
int GuitarPro5::readBeat(int tick, int voice, Measure* measure, int staffIdx, Tuplet** tuplets, bool /*mixChange*/)
      {
      uchar beatBits = readUChar();
      bool dotted    = beatBits & BEAT_DOTTED;

      slide = -1;
      int track = staffIdx * VOICES + voice;
      if (slides.contains(track))
            slide = slides.take(track);

      int pause = -1;
      if (beatBits & BEAT_PAUSE)
            pause = readUChar();

      // readDuration
      int len   = readChar();
      int tuple = 0;
      if (beatBits & BEAT_TUPLET)
            tuple = readInt();

      Segment* segment = measure->getSegment(Segment::Type::ChordRest, tick);
      if (beatBits & BEAT_CHORD) {
            int numStrings = score->staff(staffIdx)->part()->instr()->stringData()->strings();
            skip(17);
            QString name = readPascalString(21);
            skip(4);
            // no header to be read in the GP5 format - default to true.
            readChord(segment, staffIdx * VOICES, numStrings, name, true);
            skip(32);
            }
      Lyrics* lyrics = 0;
      if (beatBits & BEAT_LYRICS) {
            QString txt = readDelphiString();
            lyrics = new Lyrics(score);
            lyrics->setText(txt);
            }
      gpLyrics.beatCounter++;
      if (gpLyrics.beatCounter >= gpLyrics.fromBeat && gpLyrics.lyricTrack == staffIdx+1) {
            int index = gpLyrics.beatCounter - gpLyrics.fromBeat;
            if (index < gpLyrics.lyrics.size()) {
                  lyrics = new Lyrics(score);
                  lyrics->setText(gpLyrics.lyrics[index]);
                  }
            }
      int beatEffects = 0;
      if (beatBits & BEAT_EFFECTS)
            beatEffects = readBeatEffects(track, segment);

      if (beatBits & BEAT_MIX_CHANGE)
            readMixChange(measure);

      int strings = readUChar();   // used strings mask

      Fraction l    = len2fraction(len);

      // Some beat effects could add a Chord before this
      ChordRest* cr = segment->cr(track);
      if (voice != 0 && pause == 0 && strings == 0)
            cr = 0;
      else {
            if (strings == 0) {
                  if (cr) {
                        segment->remove(cr);
                        delete cr;
                        cr = 0;
                        }
                  cr = new Rest(score);
                  }
            else  {
                  if (!cr)
                        cr = new Chord(score);
                  }
            cr->setTrack(track);

            TDuration d(l);
            d.setDots(dotted ? 1 : 0);

            if (dotted)
                  l = l + (l/2);

            if (tuple) {
                  Tuplet* tuplet = tuplets[staffIdx * 2 + voice];
                  if ((tuplet == 0) || (tuplet->elementsDuration() == tuplet->baseLen().fraction() * tuplet->ratio().numerator())) {
                        tuplet = new Tuplet(score);
                        // int track = staffIdx * 2 + voice;
                        tuplets[staffIdx * 2 + voice] = tuplet;
                        tuplet->setTrack(cr->track());
                        setTuplet(tuplet, tuple);
                        tuplet->setParent(measure);
                        }
                  tuplet->setTrack(cr->track());
                  tuplet->setBaseLen(l);
                  tuplet->setDuration(l * tuplet->ratio().denominator());
                  cr->setTuplet(tuplet);
                  tuplet->add(cr);
                  }

            cr->setDuration(l);
            if (cr->type() == Element::Type::REST && (pause == 0 || l == measure->len()))
                  cr->setDurationType(TDuration::DurationType::V_MEASURE);
            else
                  cr->setDurationType(d);

            if(!segment->cr(track))
                  segment->add(cr);

            Staff* staff = cr->staff();
            int numStrings = staff->part()->instr()->stringData()->strings();
            bool hasSlur = false;
            for (int i = 6; i >= 0; --i) {
                  if (strings & (1 << i) && ((6-i) < numStrings)) {
                        Note* note = new Note(score);
                        if (dotted) {
                              // there is at most one dotted note in this guitar pro version
                              NoteDot* dot = new NoteDot(score);
                              dot->setIdx(0);
                              dot->setParent(note);
                              dot->setTrack(track);  // needed to know the staff it belongs to (and detect tablature)
                              dot->setVisible(true);
                              note->add(dot);
                              }
                        static_cast<Chord*>(cr)->add(note);

                        hasSlur = readNote(6-i, note);
                        note->setTpcFromPitch();
                        }
                  }
            createSlur(hasSlur, staffIdx, cr);
            if (lyrics)
                  cr->add(lyrics);
            }
      int rr = readChar();
      if (cr && (cr->type() == Element::Type::CHORD)) {
            Chord* chord = static_cast<Chord*>(cr);
            applyBeatEffects(chord, beatEffects);
            if (rr == ARPEGGIO_DOWN)
                  chord->setStemDirection(MScore::Direction::DOWN);
            else if (rr == ARPEGGIO_UP)
                  chord->setStemDirection(MScore::Direction::UP);
            }
      int r = readChar();
      if (r & 0x8) {
            int rrr = readChar();
qDebug("  3beat read 0x%02x", rrr);
           }
      if (cr && (cr->type() == Element::Type::CHORD) && slide > 0)
            createSlide(slide, cr, staffIdx);
      restsForEmptyBeats(segment, measure, cr, l, track, tick);
      return cr ? cr->actualTicks() : measure->ticks();
      }