Skip to content

Commit

Permalink
apply code style
Browse files Browse the repository at this point in the history
  • Loading branch information
Dorian Eikenberg authored and rageagainsthepc committed Nov 27, 2021
1 parent 7180900 commit e108246
Show file tree
Hide file tree
Showing 24 changed files with 2,656 additions and 2,618 deletions.
115 changes: 69 additions & 46 deletions src/GuitarProToMidi.Console/GP3File.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System;
using System.Collections;
using System;
using System.Collections.Generic;

namespace GuitarProToMidi;

public class GP3File : GPFile
{

Expand Down Expand Up @@ -29,9 +30,9 @@ public class GP3File : GPFile
public int measureCount;
public int trackCount;
public string[] notice;

public RepeatGroup _currentRepeatGroup = new RepeatGroup();


public GP3File(byte[] _data)
{
Expand All @@ -43,7 +44,8 @@ public void addMeasureHeader(MeasureHeader header)
{
header.song = this;
measureHeaders.Add(header);
if (header.isRepeatOpen || (header.repeatAlternatives.Count > 0 && _currentRepeatGroup.isClosed && header.repeatAlternatives[0] <= 0)) {
if (header.isRepeatOpen || (header.repeatAlternatives.Count > 0 && _currentRepeatGroup.isClosed && header.repeatAlternatives[0] <= 0))
{
_currentRepeatGroup = new RepeatGroup();
}
_currentRepeatGroup.addMeasureHeader(header);
Expand Down Expand Up @@ -78,15 +80,16 @@ public override void readSong()
readMeasures();
}

private string readVersion(){
private string readVersion()
{
var version = GPBase.readByteSizeString(30);
return version;
}

private int[] readVersionTuple() //bl0.12
{
var tuple = version.Substring(version.Length - 4).Split('.');
return new int[] {Convert.ToInt32(tuple[0]), Convert.ToInt32(tuple[1]) };
return new int[] { Convert.ToInt32(tuple[0]), Convert.ToInt32(tuple[1]) };
}

private void readMeasures()
Expand Down Expand Up @@ -141,7 +144,7 @@ private void readVoice(int start, Voice voice)
{
//TODO: The pointer is 13 bytes too early here (when reading for measure 0xa of track 0x2, beats should return 1, not 898989)
var beats = GPBase.readInt()[0];
for (int beat =0;beat < beats; beat++)
for (int beat = 0; beat < beats; beat++)
{
start += readBeat(start, voice);
}
Expand Down Expand Up @@ -182,7 +185,8 @@ private int readBeat(int start, Voice voice)
if ((flags & 0x40) != 0)
{
beat.status = (BeatStatus)((int)GPBase.readByte()[0]);
} else
}
else
{
beat.status = BeatStatus.normal;
}
Expand All @@ -200,7 +204,7 @@ private int readBeat(int start, Voice voice)
return (!(beat.status == BeatStatus.empty)) ? duration.time() : 0;
}

private void readNotes (Track track, Beat beat, Duration duration, NoteEffect effect)
private void readNotes(Track track, Beat beat, Duration duration, NoteEffect effect)
{
/* First byte lists played strings:
Expand All @@ -214,8 +218,10 @@ private void readNotes (Track track, Beat beat, Duration duration, NoteEffect ef
- *0x80*: *blank**/

var stringFlags = GPBase.readByte()[0];
foreach (var str in track.strings){
if ((stringFlags & 1 << (7-str.number)) != 0){
foreach (var str in track.strings)
{
if ((stringFlags & 1 << (7 - str.number)) != 0)
{
var note = new Note(beat);
beat.notes.Add(note);
readNote(note, str, track);
Expand Down Expand Up @@ -286,11 +292,12 @@ read fret number.
if ((flags & 0x08) != 0)
{
note.effect = readNoteEffects(note);
if (note.effect.isHarmonic() && note.effect.harmonic is TappedHarmonic){
if (note.effect.isHarmonic() && note.effect.harmonic is TappedHarmonic)
{
note.effect.harmonic.fret = note.value + 12;
}
}

}

private NoteEffect readNoteEffects(Note note)
Expand Down Expand Up @@ -386,9 +393,9 @@ private BendEffect readBend()

private int getTiedNoteValue(int stringIndex, Track track)
{
for (int measure = track.measures.Count-1;measure >= 0; measure--)
for (int measure = track.measures.Count - 1; measure >= 0; measure--)
{
for (int voice = track.measures[measure].voices.Count-1;voice >=0; voice--)
for (int voice = track.measures[measure].voices.Count - 1; voice >= 0; voice--)
{
foreach (var beat in track.measures[measure].voices[voice].beats)
{
Expand Down Expand Up @@ -437,30 +444,40 @@ private void readMixTableChangeValues(MixTableChange tableChange, Measure measur
var phaser = GPBase.readSignedByte()[0];
var tremolo = GPBase.readSignedByte()[0];
var tempo = GPBase.readInt()[0];
if (instrument >= 0) {
if (instrument >= 0)
{
tableChange.instrument = new MixTableItem(instrument);
}
if (volume >= 0) {
if (volume >= 0)
{
tableChange.volume = new MixTableItem(volume);
}
if (balance >= 0) {
if (balance >= 0)
{
tableChange.balance = new MixTableItem(balance);
}
if (chorus >= 0) {
if (chorus >= 0)
{
tableChange.chorus = new MixTableItem(chorus);
}
if (reverb >= 0) {
if (reverb >= 0)
{
tableChange.reverb = new MixTableItem(reverb);
}
if (phaser >= 0) {
tableChange.phaser = new MixTableItem(phaser); }
if (tremolo >= 0) {
tableChange.tremolo = new MixTableItem(tremolo); }
if (tempo >= 0) {
if (phaser >= 0)
{
tableChange.phaser = new MixTableItem(phaser);
}
if (tremolo >= 0)
{
tableChange.tremolo = new MixTableItem(tremolo);
}
if (tempo >= 0)
{
tableChange.tempo = new MixTableItem(tempo);
measure.tempo().value = tempo;
}

}

private void readMixTableChangeDurations(MixTableChange tableChange)
Expand Down Expand Up @@ -514,7 +531,8 @@ tremolo bar should be read (see :meth:`readTremoloBar`). Else
if (beatEffects.slapEffect == SlapEffect.none)
{
beatEffects.tremoloBar = readTremoloBar();
} else
}
else
{
GPBase.readInt();
}
Expand All @@ -532,10 +550,11 @@ private BeatStroke readBeatStroke()
var strokeUp = GPBase.readSignedByte()[0];
if (strokeUp > 0)
{
return new BeatStroke(BeatStrokeDirection.up, toStrokeValue(strokeUp),0.0f);
} else
return new BeatStroke(BeatStrokeDirection.up, toStrokeValue(strokeUp), 0.0f);
}
else
{
return new BeatStroke(BeatStrokeDirection.down, toStrokeValue(strokeDown),0.0f);
return new BeatStroke(BeatStrokeDirection.down, toStrokeValue(strokeDown), 0.0f);
}
}

Expand Down Expand Up @@ -571,7 +590,7 @@ private BendEffect readTremoloBar()
barEffect.points = new List<BendPoint>();
barEffect.points.Add(new BendPoint(0, 0));
barEffect.points.Add(new BendPoint((int)Math.Round(BendEffect.maxPosition / 2.0f), (int)Math.Round(-barEffect.value / (double)GPBase.bendSemitone)));
barEffect.points.Add(new BendPoint(BendEffect.maxPosition,0));
barEffect.points.Add(new BendPoint(BendEffect.maxPosition, 0));

return barEffect;
}
Expand All @@ -590,15 +609,16 @@ private Chord readChord(int stringCount)
if (!chord.newFormat)
{
readOldChord(chord);
} else
}
else
{
readNewChord(chord);
}
if ((chord.notes().Length) > 0) return chord;
return null;
}



private void readOldChord(Chord chord)
{
Expand All @@ -621,7 +641,7 @@ string 6. If string is untouched then the values of fret is
chord.firstFret = GPBase.readInt()[0];
if (chord.firstFret > 0)
{
for (int i=0; i < 6; i++)
for (int i = 0; i < 6; i++)
{
var fret = GPBase.readInt()[0];
if (i < chord.strings.Length) chord.strings[i] = fret;
Expand Down Expand Up @@ -702,7 +722,7 @@ note is played in chord.
chord.ninth = (ChordAlteration)GPBase.readInt()[0];
chord.eleventh = (ChordAlteration)GPBase.readInt()[0];
chord.firstFret = GPBase.readInt()[0];
for (int i=0; i < 6; i++)
for (int i = 0; i < 6; i++)
{
var fret = GPBase.readInt()[0];
if (i < chord.strings.Length) chord.strings[i] = fret;
Expand All @@ -713,15 +733,15 @@ note is played in chord.
var barreStarts = GPBase.readInt(2);
var barreEnds = GPBase.readInt(2);

for (int x=0; x < Math.Min(2, barresCount); x++)
for (int x = 0; x < Math.Min(2, barresCount); x++)
{
var barre = new Barre(barreFrets[x], barreStarts[x], barreEnds[x]);
chord.barres.Add(barre);
}
chord.omissions = GPBase.readBool(7);
GPBase.skip(1);
}


private Duration readDuration(byte flags)
{
Expand Down Expand Up @@ -760,9 +780,9 @@ private Duration readDuration(byte flags)
return duration;
}

private Beat getBeat(Voice voice,int start)
private Beat getBeat(Voice voice, int start)
{
for (int x=voice.beats.Count-1; x>=0; x--)
for (int x = voice.beats.Count - 1; x >= 0; x--)
{
if (voice.beats[x].start == start) return voice.beats[x];
}
Expand Down Expand Up @@ -884,7 +904,7 @@ been specified previously.
:param measureCount: number of measures to expect.*/
MeasureHeader previous = null;
for (int number=1;number < measureCount + 1; number++)
for (int number = 1; number < measureCount + 1; number++)
{
var header = readMeasureHeader(number, previous);
this.addMeasureHeader(header);
Expand Down Expand Up @@ -944,14 +964,16 @@ encode a key signature change on the current piece. First byte
if ((flags & 0x01) != 0)
{
header.timeSignature.numerator = GPBase.readSignedByte()[0];
} else
}
else
{
header.timeSignature.numerator = previous.timeSignature.numerator;
}
if ((flags & 0x02) != 0)
{
header.timeSignature.denominator.value = GPBase.readSignedByte()[0];
} else
}
else
{
header.timeSignature.denominator.value = previous.timeSignature.denominator.value;
}
Expand All @@ -973,12 +995,13 @@ encode a key signature change on the current piece. First byte
sbyte root = GPBase.readSignedByte()[0];
sbyte type_ = GPBase.readSignedByte()[0];
int dir = (root < 0) ? -1 : 1;
header.keySignature = (KeySignature)((int)root*10+dir*type_);
} else if (header.number > 1)
header.keySignature = (KeySignature)((int)root * 10 + dir * type_);
}
else if (header.number > 1)
{
header.keySignature = previous.keySignature;
}
header.hasDoubleBar = ((flags&0x80)!=0);
header.hasDoubleBar = ((flags & 0x80) != 0);

return header;
}
Expand Down
Loading

0 comments on commit e108246

Please sign in to comment.