private void IndexOneObject() { long pos = Position(); _crc.Reset(); int c = ReadFromInput(); int typeCode = (c >> 4) & 7; long sz = c & 15; int shift = 4; while ((c & 0x80) != 0) { c = ReadFromInput(); sz += (c & 0x7f) << shift; shift += 7; } switch (typeCode) { case Constants.OBJ_COMMIT: case Constants.OBJ_TREE: case Constants.OBJ_BLOB: case Constants.OBJ_TAG: Whole(typeCode, pos, sz); break; case Constants.OBJ_OFS_DELTA: c = ReadFromInput(); long ofs = c & 127; while ((c & 128) != 0) { ofs += 1; c = ReadFromInput(); ofs <<= 7; ofs += (c & 127); } long pbase = pos - ofs; SkipInflateFromInput(sz); var n = new UnresolvedDelta(pos, (int)_crc.Value); n.Next = _baseByPos.put(pbase, n); _deltaCount++; break; case Constants.OBJ_REF_DELTA: c = FillFromInput(20); _crc.Update(_buffer, c, 20); ObjectId baseId = ObjectId.FromRaw(_buffer, c); Use(20); DeltaChain r = _baseById.Get(baseId); if (r == null) { r = new DeltaChain(baseId); _baseById.Add(r); } SkipInflateFromInput(sz); r.Add(new UnresolvedDelta(pos, (int)_crc.Value)); _deltaCount++; break; default: throw new IOException("Unknown object type " + typeCode + "."); } }
/// <summary> /// Read one entire object or delta from the input. /// </summary> private void IndexOneObject() { long pos = Position(); _crc.Reset(); int c = ReadFromInput(); int typeCode = (c >> 4) & 7; long sz = c & 15; int shift = 4; while ((c & 0x80) != 0) { c = ReadFromInput(); sz += (c & 0x7f) << shift; shift += 7; } switch (typeCode) { case Constants.OBJ_COMMIT: case Constants.OBJ_TREE: case Constants.OBJ_BLOB: case Constants.OBJ_TAG: Whole(typeCode, pos, sz); break; case Constants.OBJ_OFS_DELTA: c = ReadFromInput(); long ofs = c & 127; while ((c & 128) != 0) { ofs += 1; c = ReadFromInput(); ofs <<= 7; ofs += (c & 127); } long pbase = pos - ofs; SkipInflateFromInput(sz); var n = new UnresolvedDelta(pos, (int)_crc.Value); n.Next = _baseByPos.put(pbase, n); _deltaCount++; break; case Constants.OBJ_REF_DELTA: c = FillFromInput(20); _crc.Update(_buffer, c, 20); ObjectId baseId = ObjectId.FromRaw(_buffer, c); Use(20); DeltaChain r = _baseById.Get(baseId); if (r == null) { r = new DeltaChain(baseId); _baseById.Add(r); } SkipInflateFromInput(sz); r.Add(new UnresolvedDelta(pos, (int)_crc.Value)); _deltaCount++; break; default: throw new IOException("Unknown object type " + typeCode + "."); } }
public override GenericMelody GenerateMelody() { //Debug.Log("RANDOM SEED : " + Random.seed.ToString()); minduration = 0.01f; maxduration = Random.Range(0.1f, 2.0f); melodic = Random.Range(0, 4) > 0; diatonic = Random.Range(0, 6) > 0; //weight diatonic chainmemory = Random.Range(4, 11); proceedByDifferences = Random.Range(0, 2) == 0; bars = Random.Range(3, 1) > 0; barprob = Random.Range(0.75f, 1.0f); subbarprob = Random.Range(0.0f, barprob); beatcount = Random.Range(2, 7); barlength = Random.Range(1.0f, 5.0f); //Debug.Log("bar length: " + barlength.ToString()); //Debug.Log("beat count: " + beatcount.ToString()); //Debug.Log("bar prob: " + barprob.ToString()); //Debug.Log("beat prob: " + subbarprob.ToString()); if (proceedByDifferences) { //Debug.Log("differences"); } else { //Debug.Log("nondifferences"); } if (melodic) { //Debug.Log("melodic"); frequencycount = Random.Range(5, 10); MusicPlayer.mainCam.GetComponent <PP_ScreenWaves>().amplitude = frequencycount / 50f; durationcount = Random.Range(2, 3); samplecount = Random.Range(2, 4); } else { //Debug.Log("not melodic"); frequencycount = Random.Range(1, 3); durationcount = Random.Range(2, 5); samplecount = Random.Range(5, 10); } detune = Random.Range(Mathf.Pow(2.0f, -5.0f / 12.0f), Mathf.Pow(2.0f, 5.0f / 12.0f)); //Debug.Log("detune by " + detune.ToString()); if (diatonic) { //Debug.Log("diatonic"); scale = Random.Range(0, scales.GetLength(0)); transposition = Random.Range(0, 12); //Debug.Log("Scale = "+scale.ToString()); //Debug.Log("Transposition = "+transposition.ToString()); //Debug.Log(MusicPlayer.mainCam); // MusicPlayer.mainCam.GetComponent<Vortex>().radius = new Vector2(scale/3f, scale/3f); // MusicPlayer.mainCam.GetComponent<Vortex>().center = new Vector2(samplecount, samplecount/ 2f); // MusicPlayer.mainCam.GetComponent<Vortex>().angle = transposition * 30f; } else { //Debug.Log("not diatonic"); } sounds = RandomSublist(allsounds, samplecount); bool rhythmic = Random.Range(0, 3) >= 0; //weight for beats if (rhythmic) { // if (maxduration<0.5) // maxduration*=2; //Debug.Log("Beaty"); } else { //Debug.Log("Not Beaty"); } durations = new List <float>(); for (int i = 0; i < durationcount; i++) { if (rhythmic) { float r = 1.0f / Random.Range(1, 5); if (profile != 6) { r *= maxduration * Random.Range(1, 5); } durations.Add(r); } else { durations.Add(Random.Range(minduration, maxduration)); } } durations.Sort(); frequencies = new List <float>(); if (diatonic) { int range = Random.Range(0, 4); range = 1; //Debug.Log("range = " + range.ToString()); int low = 0; int high = 0; switch (range) { case 0: low = -27; high = -13; break; case 1: low = -20; high = 0; break; case 2: low = -13; high = 13; break; case 3: low = -27; high = 13; break; } for (int j = low; j < high; j++) { if (scales[scale, (j + transposition + 48) % 12] != 1) { continue; } float note = Mathf.Pow(2.0f, j / 12.0f); frequencies.Add(note * detune); } } else { for (int i = 0; i < frequencycount; i++) { float f = Random.Range(minfrequency, maxfrequency); frequencies.Add(f * detune); } } frequencies.Sort(); //for the non-diatonic case - already sorted in diatonic - for proceedByDifferences durationhistory = new List <int>(); for (int i = 0; i < leadin_durations; i++) { durationhistory.Add(Random.Range(0, durations.Count)); } frequencyhistory = new List <int>(); for (int i = 0; i < leadin_frequency; i++) { frequencyhistory.Add(Random.Range(0, frequencies.Count)); } soundhistory = new List <int>(); for (int i = 0; i < leadin_samples; i++) { soundhistory.Add(Random.Range(0, sounds.Count)); } bool modulate = Random.Range(0, 3) > 0; phraselength = Random.Range(15.0F, 35.0F); keychangehistory = new List <float>(); keychangehistory.Add(1); if (modulate) { //public float phraselength;//between 10 - 30 seconds for (int i = 0; i < 10; i++) { keychangehistory.Add(Random.Range(0.75F, 1.25F)); } } //pregenerate first ten levels, f**k it for (int level = 1; level < 10; level++) { //durations Chain <int> chain_durations = new Chain <int>(durationhistory, chainmemory); List <int> durations_adding = new List <int>(); while (durations_adding.Count < level * levelmultiplier) { durations_adding.AddRange(chain_durations.Generate(level * levelmultiplier - durations_adding.Count)); } durationhistory.AddRange(durations_adding); //frequencies if (proceedByDifferences) { DeltaChain <int> chain_frequencies = new DeltaChain <int>(frequencyhistory, chainmemory, Subtract.IntSubtract); List <int> frequencies_adding = new List <int>(); while (frequencies_adding.Count < level * levelmultiplier) { frequencies_adding.AddRange(chain_frequencies.Generate(level * levelmultiplier - frequencies_adding.Count)); } frequencyhistory.AddRange(frequencies_adding); } else { Chain <int> chain_frequencies = new Chain <int>(frequencyhistory, chainmemory); List <int> frequencies_adding = new List <int>(); while (frequencies_adding.Count < level * levelmultiplier) { frequencies_adding.AddRange(chain_frequencies.Generate(level * levelmultiplier - frequencies_adding.Count)); } frequencyhistory.AddRange(frequencies_adding); } //samples Chain <int> chain_sounds = new Chain <int>(soundhistory, chainmemory); List <int> sounds_adding = new List <int>(); while (sounds_adding.Count < level * levelmultiplier) { sounds_adding.AddRange(chain_sounds.Generate(level * levelmultiplier - sounds_adding.Count)); } soundhistory.AddRange(sounds_adding); } hasleadinstrument = Random.Range(0, 4) > 0; leadreplaceprob = Random.Range(0.6f, 1.0f); leadinstrument = Random.Range(0, sounds.Count); leadspread = Random.Range(1, 5); leadpasses = Random.Range(1, 4); //Debug.Log("leadspread " + leadspread.ToString()); //Debug.Log("leadpasses " + leadpasses.ToString()); //Debug.Log("leadreplaceprob " + leadreplaceprob.ToString()); if (hasleadinstrument && (frequencies.Count > 2)) { for (int t = 0; t < leadpasses; t++) { for (int i = 0; i < Mathf.Min(new int[] { soundhistory.Count, frequencyhistory.Count, durationhistory.Count }); i++) { if (soundhistory[i] == leadinstrument && durationhistory[i] > 0 && Random.value < leadreplaceprob) { durationhistory[i]--; durationhistory.Insert(i + 1, durationhistory[i]); soundhistory.Insert(i + 1, leadinstrument); frequencyhistory.Insert(i + 1, frequencyhistory[i]); frequencyhistory[i + 1] = Mathf.Clamp(frequencyhistory[i + 1] + (Random.value < 0.5f ? 1 : -1) * Random.Range(0, leadspread), 0, frequencies.Count - 1); i++; } } } } //Debug.Log("history lengths : " + soundhistory.Count.ToString() + " , " + durationhistory.Count.ToString()); soundlocation = 0; frequencylocation = 0; durationlocation = 0; melody = new GenericMelody(); melody.durations = new List <float>(); melody.frequencies = new List <float>(); melody.sounds = new List <AudioClip>(); melody.volumes = new List <float>(); ProcessMusic(); return(melody); }
private UnresolvedDelta RemoveBaseById(AnyObjectId id) { DeltaChain d = _baseById.Get(id); return(d != null?d.Remove() : null); }