# Input: Information about the new note
# Output: the assotiated wav


# is used for piano, clarinet, flute and trumpet
extractNoteSimple=function(note.number, note.velocity, note.duration, notes.path, ctrl)
{
  path=notes.path
  # check the note.number
  if(note.number>108 | note.number<20) {
    print(sprintf("The note %i does not exist for %s", note.number, path)) 
    break()
  }
  
  # determine wether normal (NO) tones or ST (staccato, e.g., short tones) are to take
  if(note.duration <= ctrl$thresh.staccato) 
    path=sprintf("%sST",path) 
  else path=sprintf("%sNO",path)
  
  # determine wether quite (P for piano), moderate (M for mezzo) or loud (F for forte) tones are to take
  if(note.velocity<=33) 
    path=sprintf("%sP",path) 
  else {
    if (note.velocity<= 63) 
      path=sprintf("%sM",path) 
    else path=sprintf("%sF",path)
  }
  
  
  # 0-th octave
  if(note.number==21)  {p=sprintf("%s_A0.wav",path); NOTE=readWave2(Path)}
  if(note.number==22)  {p=sprintf("%s_A#0.wav",path); NOTE=readWave2(p)}
  if(note.number==23)  {p=sprintf("%s_B0.wav",path); NOTE=readWave2(p)}
  
  # 1-st octave
  if(note.number==24)  {p=sprintf("%s_C1.wav",path); NOTE=readWave2(p)}
  if(note.number==25)  {p=sprintf("%s_C#1.wav",path); NOTE=readWave2(p)}
  if(note.number==26)  {p=sprintf("%s_D1.wav",path); NOTE=readWave2(p)}
  if(note.number==27)  {p=sprintf("%s_D#1.wav",path); NOTE=readWave2(p)}
  if(note.number==28)  {p=sprintf("%s_E1.wav",path); NOTE=readWave2(p)}
  if(note.number==29)  {p=sprintf("%s_F1.wav",path); NOTE=readWave2(p)}
  if(note.number==30)  {p=sprintf("%s_F#1.wav",path); NOTE=readWave2(p)}
  if(note.number==31)  {p=sprintf("%s_G1.wav",path); NOTE=readWave2(p)}
  if(note.number==32)  {p=sprintf("%s_G#1.wav",path); NOTE=readWave2(p)}
  if(note.number==33)  {p=sprintf("%s_A1.wav",path); NOTE=readWave2(p)}
  if(note.number==34)  {p=sprintf("%s_A#1.wav",path); NOTE=readWave2(p)}
  if(note.number==35)  {p=sprintf("%s_B1.wav",path); NOTE=readWave2(p)} 
  
  # 2-nd octave
  if(note.number==36)  {p=sprintf("%s_C2.wav",path); NOTE=readWave2(p)}
  if(note.number==37)  {p=sprintf("%s_C#2.wav",path); NOTE=readWave2(p)}
  if(note.number==38)  {p=sprintf("%s_D2.wav",path); NOTE=readWave2(p)}
  if(note.number==39)  {p=sprintf("%s_D#2.wav",path); NOTE=readWave2(p)}
  if(note.number==40)  {p=sprintf("%s_E2.wav",path); NOTE=readWave2(p)}
  if(note.number==41)  {p=sprintf("%s_F2.wav",path); NOTE=readWave2(p)}
  if(note.number==42)  {p=sprintf("%s_F#2.wav",path); NOTE=readWave2(p)}
  if(note.number==43)  {p=sprintf("%s_G2.wav",path); NOTE=readWave2(p)}
  if(note.number==44)  {p=sprintf("%s_G#2.wav",path); NOTE=readWave2(p)}
  if(note.number==45)  {p=sprintf("%s_A2.wav",path); NOTE=readWave2(p)}
  if(note.number==46)  {p=sprintf("%s_A#2.wav",path); NOTE=readWave2(p)}
  if(note.number==47)  {p=sprintf("%s_B2.wav",path); NOTE=readWave2(p)}
  
  # 3-rd octave
  if(note.number==48)  {p=sprintf("%s_C3.wav",path); NOTE=readWave2(p)}
  if(note.number==49)  {p=sprintf("%s_C#3.wav",path); NOTE=readWave2(p)}
  if(note.number==50)  {p=sprintf("%s_D3.wav",path); NOTE=readWave2(p)}
  if(note.number==51)  {p=sprintf("%s_D#3.wav",path); NOTE=readWave2(p)}
  if(note.number==52)  {p=sprintf("%s_E3.wav",path); NOTE=readWave2(p)}
  if(note.number==53)  {p=sprintf("%s_F3.wav",path); NOTE=readWave2(p)}
  if(note.number==54)  {p=sprintf("%s_F#3.wav",path); NOTE=readWave2(p)}
  if(note.number==55)  {p=sprintf("%s_G3.wav",path); NOTE=readWave2(p)}
  if(note.number==56)  {p=sprintf("%s_G#3.wav",path); NOTE=readWave2(p)}
  if(note.number==57)  {p=sprintf("%s_A3.wav",path); NOTE=readWave2(p)}
  if(note.number==58)  {p=sprintf("%s_A#3.wav",path); NOTE=readWave2(p)}
  if(note.number==59)  {p=sprintf("%s_B3.wav",path); NOTE=readWave2(p)}
  
  # 4-th octave
  if(note.number==60)  {p=sprintf("%s_C4.wav",path); NOTE=readWave2(p)}
  if(note.number==61)  {p=sprintf("%s_C#4.wav",path); NOTE=readWave2(p)}
  if(note.number==62)  {p=sprintf("%s_D4.wav",path); NOTE=readWave2(p)}
  if(note.number==63)  {p=sprintf("%s_D#4.wav",path); NOTE=readWave2(p)}
  if(note.number==64)  {p=sprintf("%s_E4.wav",path); NOTE=readWave2(p)}
  if(note.number==65)  {p=sprintf("%s_F4.wav",path); NOTE=readWave2(p)}
  if(note.number==66)  {p=sprintf("%s_F#4.wav",path); NOTE=readWave2(p)}
  if(note.number==67)  {p=sprintf("%s_G4.wav",path); NOTE=readWave2(p)}
  if(note.number==68)  {p=sprintf("%s_G#4.wav",path); NOTE=readWave2(p)}
  if(note.number==69)  {p=sprintf("%s_A4.wav",path); NOTE=readWave2(p)}
  if(note.number==70)  {p=sprintf("%s_A#4.wav",path); NOTE=readWave2(p)}
  if(note.number==71)  {p=sprintf("%s_B4.wav",path); NOTE=readWave2(p)}
  
  # 5-th octave
  if(note.number==72)  {p=sprintf("%s_C5.wav",path); NOTE=readWave2(p)}
  if(note.number==73)  {p=sprintf("%s_C#5.wav",path); NOTE=readWave2(p)}
  if(note.number==74)  {p=sprintf("%s_D5.wav",path); NOTE=readWave2(p)}
  if(note.number==75)  {p=sprintf("%s_D#5.wav",path); NOTE=readWave2(p)}
  if(note.number==76)  {p=sprintf("%s_E5.wav",path); NOTE=readWave2(p)}
  if(note.number==77)  {p=sprintf("%s_F5.wav",path); NOTE=readWave2(p)}
  if(note.number==78)  {p=sprintf("%s_F#5.wav",path); NOTE=readWave2(p)}
  if(note.number==79)  {p=sprintf("%s_G5.wav",path); NOTE=readWave2(p)}
  if(note.number==80)  {p=sprintf("%s_G#5.wav",path); NOTE=readWave2(p)}
  if(note.number==81)  {p=sprintf("%s_A5.wav",path); NOTE=readWave2(p)}
  if(note.number==82)  {p=sprintf("%s_A#5.wav",path); NOTE=readWave2(p)}
  if(note.number==83)  {p=sprintf("%s_B5.wav",path); NOTE=readWave2(p)}
  
  # 6-th octave
  if(note.number==84)  {p=sprintf("%s_C6.wav",path); NOTE=readWave2(p)}
  if(note.number==85)  {p=sprintf("%s_C#6.wav",path); NOTE=readWave2(p)}
  if(note.number==86)  {p=sprintf("%s_D6.wav",path); NOTE=readWave2(p)}
  if(note.number==87)  {p=sprintf("%s_D#6.wav",path); NOTE=readWave2(p)}
  if(note.number==88)  {p=sprintf("%s_E6.wav",path); NOTE=readWave2(p)}
  if(note.number==89)  {p=sprintf("%s_F6.wav",path); NOTE=readWave2(p)}
  if(note.number==90)  {p=sprintf("%s_F#6.wav",path); NOTE=readWave2(p)}
  if(note.number==91)  {p=sprintf("%s_G6.wav",path); NOTE=readWave2(p)}
  if(note.number==92)  {p=sprintf("%s_G#6.wav",path); NOTE=readWave2(p)}
  if(note.number==93)  {p=sprintf("%s_A6.wav",path); NOTE=readWave2(p)}
  if(note.number==94)  {p=sprintf("%s_A#6.wav",path); NOTE=readWave2(p)}
  if(note.number==95)  {p=sprintf("%s_B6.wav",path); NOTE=readWave2(p)}
  
  # 7-th octave
  if(note.number==96)  {p=sprintf("%s_C7.wav",path); NOTE=readWave2(p)}
  if(note.number==97)  {p=sprintf("%s_C#7.wav",path); NOTE=readWave2(p)}
  if(note.number==98)  {p=sprintf("%s_D7.wav",path); NOTE=readWave2(p)}
  if(note.number==99)  {p=sprintf("%s_D#7.wav",path); NOTE=readWave2(p)}
  if(note.number==100)  {p=sprintf("%s_E7.wav",path); NOTE=readWave2(p)}
  if(note.number==101)  {p=sprintf("%s_F7.wav",path); NOTE=readWave2(p)}
  if(note.number==102)  {p=sprintf("%s_F#7.wav",path); NOTE=readWave2(p)}
  if(note.number==103)  {p=sprintf("%s_G7.wav",path); NOTE=readWave2(p)}
  if(note.number==104)  {p=sprintf("%s_G#7.wav",path); NOTE=readWave2(p)}
  if(note.number==105)  {p=sprintf("%s_A7.wav",path); NOTE=readWave2(p)}
  if(note.number==106)  {p=sprintf("%s_A#7.wav",path); NOTE=readWave2(p)}
  if(note.number==107)  {p=sprintf("%s_B7.wav",path); NOTE=readWave2(p)}
    
  return(list(wave=NOTE,path=p))
}

##################### Violin sample string

extractNoteViolinSample=function(note.number, note.velocity, note.duration, notes.path, ctrl)
{
  path=notes.path
  # check the note.number
  if(note.number > 100 | note.number < 55) {
    print(sprintf("The note %i does not exist for %s", note.number, path)) 
    break()
  }
  
  # determine wether normal (NO) tones or ST (staccato, e.g., short tones) are to take
  if(note.duration <= ctrl$thresh.staccato) 
    path=sprintf("%sSP",path) 
  else path=sprintf("%sNO",path)
  
  # determine wether quite (P for piano), moderate (M for mezzo) or loud (F for forte) tones are to take
  if(note.velocity<=33) 
    path=sprintf("%sP",path) 
  else {
    if (note.velocity<= 63) 
      path=sprintf("%sM",path) 
    else path=sprintf("%sF",path)
  }
  
  # 3-rd octave
  if(note.number==55)  {p=sprintf("%s_G+G3.wav",path); NOTE=readWave2(p) }
  if(note.number==56)  {p=sprintf("%s_G+G#3.wav",path); NOTE=readWave2(p)}
  if(note.number==57)  {p=sprintf("%s_G+A3.wav",path); NOTE=readWave2(p)}
  if(note.number==58)  {p=sprintf("%s_G+A#3.wav",path); NOTE=readWave2(p)}
  if(note.number==59)  {p=sprintf("%s_G+B3.wav",path); NOTE=readWave2(p)}
  
  # 4-th octave
  if(note.number==60)  {p=sprintf("%s_G+C4.wav",path); NOTE=readWave2(p)}
  if(note.number==61)  {p=sprintf("%s_G+C#4.wav",path); NOTE=readWave2(p)}
  if(note.number==62)  {p=sprintf("%s_%s+D4.wav",path,sample(c("G","D"),1)); NOTE=readWave2(p) }
  if(note.number==63)  {p=sprintf("%s_%s+D#4.wav",path,sample(c("G","D"),1)); NOTE=readWave2(p)}
  if(note.number==64)  {p=sprintf("%s_%s+E4.wav",path,sample(c("G","D"),1)); NOTE=readWave2(p)}
  if(note.number==65)  {p=sprintf("%s_%s+F4.wav",path,sample(c("G","D"),1)); NOTE=readWave2(p)}
  if(note.number==66)  {p=sprintf("%s_%s+F#4.wav",path,sample(c("G","D"),1)); NOTE=readWave2(p)}
  if(note.number==67)  {p=sprintf("%s_%s+G4.wav",path,sample(c("G","D"),1)); NOTE=readWave2(p)} #13 G
  if(note.number==68)  {p=sprintf("%s_D+G#4.wav",path); NOTE=readWave2(p)}
  if(note.number==69)  {p=sprintf("%s_%s+A4.wav",path,sample(c("A","D"),1)); NOTE=readWave2(p)}
  if(note.number==70)  {p=sprintf("%s_%s+A#4.wav",path,sample(c("A","D"),1)); NOTE=readWave2(p)}
  if(note.number==71)  {p=sprintf("%s_%s+B4.wav",path,sample(c("A","D"),1)); NOTE=readWave2(p)}
  
  # 5-th octave
  if(note.number==72)  {p=sprintf("%s_%s+C5.wav",path,sample(c("A","D"),1)); NOTE=readWave2(p)}
  if(note.number==73)  {p=sprintf("%s_%s+C#5.wav",path,sample(c("A","D"),1)); NOTE=readWave2(p)}
  if(note.number==74)  {p=sprintf("%s_%s+D5.wav",path,sample(c("A","D"),1)); NOTE=readWave2(p)} #13 D
  if(note.number==75)  {p=sprintf("%s_A+D#5.wav",path); NOTE=readWave2(p)}
  if(note.number==76)  {p=sprintf("%s_%s+E5.wav",path,sample(c("A","E"),1)); NOTE=readWave2(p)}
  if(note.number==77)  {p=sprintf("%s_%s+F5.wav",path,sample(c("A","E"),1)); NOTE=readWave2(p)}
  if(note.number==78)  {p=sprintf("%s_%s+F#5.wav",path,sample(c("A","E"),1)); NOTE=readWave2(p)}
  if(note.number==79)  {p=sprintf("%s_%s+G5.wav",path,sample(c("A","E"),1)); NOTE=readWave2(p)}
  if(note.number==80)  {p=sprintf("%s_%s+G#5.wav",path,sample(c("A","E"),1)); NOTE=readWave2(p)}
  if(note.number==81)  {p=sprintf("%s_%s+A5.wav",path,sample(c("A","E"),1)); NOTE=readWave2(p)}  #A
  if(note.number==82)  {p=sprintf("%s_E+A#5.wav",path); NOTE=readWave2(p)}
  if(note.number==83)  {p=sprintf("%s_E+B5.wav",path); NOTE=readWave2(p)}
  
  # 6-th octave
  if(note.number==84)  {p=sprintf("%s_E+C6.wav",path); NOTE=readWave2(p)}
  if(note.number==85)  {p=sprintf("%s_E+C#6.wav",path); NOTE=readWave2(p)}
  if(note.number==86)  {p=sprintf("%s_E+D6.wav",path); NOTE=readWave2(p)}
  if(note.number==87)  {p=sprintf("%s_E+D#6.wav",path); NOTE=readWave2(p)}
  if(note.number==88)  {p=sprintf("%s_E+E6.wav",path); NOTE=readWave2(p)}
  if(note.number==89)  {p=sprintf("%s_E+F6.wav",path); NOTE=readWave2(p)}
  if(note.number==90)  {p=sprintf("%s_E+F#6.wav",path); NOTE=readWave2(p)}
  if(note.number==91)  {p=sprintf("%s_E+G6.wav",path); NOTE=readWave2(p)}
  if(note.number==92)  {p=sprintf("%s_E+G#6.wav",path); NOTE=readWave2(p)}
  if(note.number==93)  {p=sprintf("%s_E+A6.wav",path); NOTE=readWave2(p)}
  if(note.number==94)  {p=sprintf("%s_E+A#6.wav",path); NOTE=readWave2(p)}
  if(note.number==95)  {p=sprintf("%s_E+B6.wav",path); NOTE=readWave2(p)}
  
  # 7-th octave
  if(note.number==96)  {p=sprintf("%s_E+C7.wav",path); NOTE=readWave2(p)}
  if(note.number==97)  {p=sprintf("%s_E+C#7.wav",path); NOTE=readWave2(p)}
  if(note.number==98)  {p=sprintf("%s_E+D7.wav",path); NOTE=readWave2(p)}
  if(note.number==99)  {p=sprintf("%s_E+D#7.wav",path); NOTE=readWave2(p)}
  if(note.number==100)  {p=sprintf("%s_E+E7.wav",path); NOTE=readWave2(p)}
  
  return(list(wav=NOTE,path=p))
}

# Violin fix string

extractNoteViolinFix=function(note.number, note.velocity, note.duration, notes.path, ctrl)
{
  path=notes.path
  # check the note.number
  if(note.number > 100 | note.number < 55) {
    print(sprintf("The note %i does not exist for %s", note.number, path)) 
    break()
  }
  
  # determine wether normal (NO) tones or ST (staccato, e.g., short tones) are to take
  if(note.duration <= ctrl$thresh.staccato) 
    path=sprintf("%sSP",path) 
  else path=sprintf("%sNO",path)
  
  # determine wether quite (P for piano), moderate (M for mezzo) or loud (F for forte) tones are to take
  if(note.velocity<=33) 
    path=sprintf("%sP",path) 
  else {
    if (note.velocity<= 63) 
      path=sprintf("%sM",path) 
    else path=sprintf("%sF",path)
  }
  

  # 3-th octave
  if(note.number==55)  {p=sprintf("%s_G+G3.wav",path); NOTE=readWave2(p)}
  if(note.number==56)  {p=sprintf("%s_G+G#3.wav",path); NOTE=readWave2(p)}
  if(note.number==57)  {p=sprintf("%s_G+A3.wav",path); NOTE=readWave2(p)}
  if(note.number==58)  {p=sprintf("%s_G+A#3.wav",path); NOTE=readWave2(p)}
  if(note.number==59)  {p=sprintf("%s_G+B3.wav",path); NOTE=readWave2(p)}
  
  # 4-th octave
  if(note.number==60)  {p=sprintf("%s_%s+C4.wav",path,"G"); NOTE=readWave2(p)}
  if(note.number==61)  {p=sprintf("%s_G+C#4.wav",path); NOTE=readWave2(p)}
  if(note.number==62)  {p=sprintf("%s_D+D4.wav",path); NOTE=readWave2(p)}
  if(note.number==63)  {p=sprintf("%s_D+D#4.wav",path); NOTE=readWave2(p)}
  if(note.number==64)  {p=sprintf("%s_D+E4.wav",path); NOTE=readWave2(p)}
  if(note.number==65)  {p=sprintf("%s_D+F4.wav",path); NOTE=readWave2(p)}
  if(note.number==66)  {p=sprintf("%s_D+F#4.wav",path); NOTE=readWave2(p)}
  if(note.number==67)  {p=sprintf("%s_D+G4.wav",path); NOTE=readWave2(p)}
  if(note.number==68)  {p=sprintf("%s_D+G#4.wav",path); NOTE=readWave2(p)}
  if(note.number==69)  {p=sprintf("%s_A+A4.wav",path); NOTE=readWave2(p)}
  if(note.number==70)  {p=sprintf("%s_A+A#4.wav",path); NOTE=readWave2(p)}
  if(note.number==71)  {p=sprintf("%s_A+B4.wav",path); NOTE=readWave2(p)}
  
  # 5-th octave
  if(note.number==72)  {p=sprintf("%s_A+C5.wav",path); NOTE=readWave2(p)}
  if(note.number==73)  {p=sprintf("%s_A+C#5.wav",path); NOTE=readWave2(p)}
  if(note.number==74)  {p=sprintf("%s_A+D5.wav",path); NOTE=readWave2(p)}
  if(note.number==75)  {p=sprintf("%s_A+D#5.wav",path); NOTE=readWave2(p)}
  if(note.number==76)  {p=sprintf("%s_A+E5.wav",path); NOTE=readWave2(p)}
  if(note.number==77)  {p=sprintf("%s_E+F5.wav",path); NOTE=readWave2(p)}
  if(note.number==78)  {p=sprintf("%s_E+F#5.wav",path); NOTE=readWave2(p)}
  if(note.number==79)  {p=sprintf("%s_E+G5.wav",path); NOTE=readWave2(p)}
  if(note.number==80)  {p=sprintf("%s_E+G#5.wav",path); NOTE=readWave2(p)}
  if(note.number==81)  {p=sprintf("%s_E+A5.wav",path); NOTE=readWave2(p)}
  if(note.number==82)  {p=sprintf("%s_E+A#5.wav",path); NOTE=readWave2(p)}
  if(note.number==83)  {p=sprintf("%s_E+B5.wav",path); NOTE=readWave2(p)}
 
  # 6-th octave
  if(note.number==84)  {p=sprintf("%s_E+C6.wav",path); NOTE=readWave2(p)}
  if(note.number==85)  {p=sprintf("%s_E+C#6.wav",path); NOTE=readWave2(p)}
  if(note.number==86)  {p=sprintf("%s_E+D6.wav",path); NOTE=readWave2(p)}
  if(note.number==87)  {p=sprintf("%s_E+D#6.wav",path); NOTE=readWave2(p)}
  if(note.number==88)  {p=sprintf("%s_E+E6.wav",path); NOTE=readWave2(p)}
  if(note.number==89)  {p=sprintf("%s_E+F6.wav",path); NOTE=readWave2(p)}
  if(note.number==90)  {p=sprintf("%s_E+F#6.wav",path); NOTE=readWave2(p)}
  if(note.number==91)  {p=sprintf("%s_E+G6.wav",path); NOTE=readWave2(p)}
  if(note.number==92)  {p=sprintf("%s_E+G#6.wav",path); NOTE=readWave2(p)}
  if(note.number==93)  {p=sprintf("%s_E+A6.wav",path); NOTE=readWave2(p)}
  if(note.number==94)  {p=sprintf("%s_E+A#6.wav",path); NOTE=readWave2(p)}
  if(note.number==95)  {p=sprintf("%s_E+B6.wav",path); NOTE=readWave2(p)}
  
  # 7-th octave
  if(note.number==96)  {p=sprintf("%s_E+C7.wav",path); NOTE=readWave2(p)}
  if(note.number==97)  {p=sprintf("%s_E+C#7.wav",path); NOTE=readWave2(p)}
  if(note.number==98)  {p=sprintf("%s_E+D7.wav",path); NOTE=readWave2(p)}
  if(note.number==99)  {p=sprintf("%s_E+D#7.wav",path); NOTE=readWave2(p)}
  if(note.number==100)  {p=sprintf("%s_E+E7.wav",path); NOTE=readWave2(p)}
  
  return(list(wav=NOTE,path=p))
}

#### Guitar Sample
# No stacatto hier
extractNoteGuitarSample=function(note.number, note.velocity, note.duration, notes.path, ctrl)
{
  path=notes.path
  # check the note.number
  if(note.number > 76 | note.number < 40) {
    print(sprintf("The note %i does not exist for %s", note.number, path)) 
    break()
  }

  # determine wether quite (P for piano), moderate (M for mezzo) or loud (F for forte) tones are to take
  if(note.velocity<=33) 
    path=sprintf("%sP",path) 
  else {
    if (note.velocity<= 63) 
      path=sprintf("%sM",path) 
    else path=sprintf("%sF",path)
  }
  
  # 2-nd octave
  if(note.number==40)  {p=sprintf("%s_E+E2.wav",path); NOTE=readWave2(p)}
  if(note.number==41)  {p=sprintf("%s_E+F2.wav",path); NOTE=readWave2(p)}
  if(note.number==42)  {p=sprintf("%s_E+F#2.wav",path); NOTE=readWave2(p)}
  if(note.number==43)  {p=sprintf("%s_E+G2.wav",path); NOTE=readWave2(p)}
  if(note.number==44)  {p=sprintf("%s_E+G#2.wav",path); NOTE=readWave2(p)}
  if(note.number==45)  {p=sprintf("%s_%s+A2.wav",path, sample(c("E","A"),1)); NOTE=readWave2(p)}
  if(note.number==46)  {p=sprintf("%s_%s+A#2.wav",path, sample(c("E","A"),1)); NOTE=readWave2(p)}
  if(note.number==47)  {p=sprintf("%s_%s+B2.wav",path, sample(c("E","A"),1)); NOTE=readWave2(p)}
  
  
  # 3-th octave
  if(note.number==48)  {p=sprintf("%s_%s+C3.wav",path,sample(c("E","A"),1)); NOTE=readWave2(p)}
  if(note.number==49) {p=sprintf("%s_%s+C#3.wav",path,sample(c("E","A"),1)); NOTE=readWave2(p)}
  if(note.number==50)  {p=sprintf("%s_%s+D3.wav",path,sample(c("E","A","D"),1)); NOTE=readWave2(p)}
  if(note.number==51)  {p=sprintf("%s_%s+D#3.wav",path,sample(c("E","A","D"),1)); NOTE=readWave2(p)}
  if(note.number==52)  {p=sprintf("%s_%s+E3.wav",path,sample(c("E","A","D"),1)); NOTE=readWave2(p)}  # e13
  if(note.number==53)  {p=sprintf("%s_%s+F3.wav",path,sample(c("A","D"),1)); NOTE=readWave2(p)}
  if(note.number==54)  {p=sprintf("%s_%s+F#3.wav",path,sample(c("A","D"),1)); NOTE=readWave2(p)}
  if(note.number==55)  {p=sprintf("%s_%s+G3.wav",path,sample(c("A","D","G"),1)); NOTE=readWave2(p)}
  if(note.number==56)  {p=sprintf("%s_%s+G#3.wav",path,sample(c("A","D","G"),1)); NOTE=readWave2(p)}
  if(note.number==57)  {p=sprintf("%s_%s+A3.wav",path,sample(c("A","D","G"),1)); NOTE=readWave2(p)} #A13
  if(note.number==58)  {p=sprintf("%s_%s+A#3.wav",path,sample(c("D","G"),1)); NOTE=readWave2(p)}
  if(note.number==59)  {p=sprintf("%s_%s+B3.wav",path,sample(c("D","G","B"),1)); NOTE=readWave2(p)}
  
  # 4-th octave
  if(note.number==60)  {p=sprintf("%s_%s+C4.wav",path,sample(c("D","G","B"),1)); NOTE=readWave2(p)}
  if(note.number==61)  {p=sprintf("%s_%s+C#4.wav",path,sample(c("D","G","B"),1)); NOTE=readWave2(p)}
  if(note.number==62)  {p=sprintf("%s_%s+D4.wav",path,sample(c("D","G","B"),1)); NOTE=readWave2(p)} #D13
  if(note.number==63)  {p=sprintf("%s_%s+D#4.wav",path,sample(c("G","B"),1)); NOTE=readWave2(p)}
  if(note.number==64)  {p=sprintf("%s_%s+E4.wav",path,sample(c("G","B","E"),1)); NOTE=readWave2(p)}
  if(note.number==65)  {p=sprintf("%s_%s+F4.wav",path,sample(c("G","B","E"),1)); NOTE=readWave2(p)}
  if(note.number==66)  {p=sprintf("%s_%s+F#4.wav",path,sample(c("G","B","E"),1)); NOTE=readWave2(p)}
  if(note.number==67)  {p=sprintf("%s_%s+G4.wav",path,sample(c("G","B","E"),1)); NOTE=readWave2(p)} #G13
  if(note.number==68)  {p=sprintf("%s_%s+G#4.wav",path,sample(c("B","E"),1)); NOTE=readWave2(p)} 
  if(note.number==69)  {p=sprintf("%s_%s+A4.wav",path,sample(c("B","E"),1)); NOTE=readWave2(p)}
  if(note.number==70)  {p=sprintf("%s_%s+A#4.wav",path,sample(c("B","E"),1)); NOTE=readWave2(p)}
  if(note.number==71)  {p=sprintf("%s_%s+B4.wav",path,sample(c("B","E"),1)); NOTE=readWave2(p)} #B3
  
  # 5-th octave
  if(note.number==72)  {p=sprintf("%s_E+C5.wav",path); NOTE=readWave2(p)}
  if(note.number==73)  {p=sprintf("%s_E+C#5.wav",path); NOTE=readWave2(p)}
  if(note.number==74)  {p=sprintf("%s_E+D5.wav",path); NOTE=readWave2(p)} # 11E
  if(note.number==75)  {p=sprintf("%s_E+D#5.wav",path); NOTE=readWave2(p)}
  if(note.number==76)  {p=sprintf("%s_E+E5.wav",path); NOTE=readWave2(p)} #13E
  
  return(list(wav=NOTE,path=p))
}


# Guitar Fix
extractNoteGuitarFix=function(note.number, note.velocity, note.duration, notes.path, ctrl)
{
  path=notes.path
  # check the note.number
  if(note.number > 76 | note.number < 40) {
    print(sprintf("The note %i does not exist for %s", note.number, path)) 
    break()
  }
  
  # determine wether quite (P for piano), moderate (M for mezzo) or loud (F for forte) tones are to take
  if(note.velocity<=33) 
    path=sprintf("%sP",path) 
  else {
    if (note.velocity<= 63) 
      path=sprintf("%sM",path) 
    else path=sprintf("%sF",path)
  }
  # 2-nd octave
  if(note.number==40)  {p=sprintf("%s_E+E2.wav",path); NOTE=readWave2(p)}
  if(note.number==41)  {p=sprintf("%s_E+F2.wav",path); NOTE=readWave2(p)}
  if(note.number==42)  {p=sprintf("%s_E+F#2.wav",path); NOTE=readWave2(p)}
  if(note.number==43)  {p=sprintf("%s_E+G2.wav",path); NOTE=readWave2(p)}
  if(note.number==44)  {p=sprintf("%s_E+G#2.wav",path); NOTE=readWave2(p)}
  if(note.number==45)  {p=sprintf("%s_A+A2.wav",path); NOTE=readWave2(p)}
  if(note.number==46)  {p=sprintf("%s_A+A#2.wav",path); NOTE=readWave2(p)}
  if(note.number==47)  {p=sprintf("%s_A+B2.wav",path); NOTE=readWave2(p)}
  
  # 3-rd octave
  if(note.number==48)  {p=sprintf("%s_A+C3.wav",path); NOTE=readWave2(p)}
  if(note.number==49) {p=sprintf("%s_A+C#3.wav",path); NOTE=readWave2(p)}
  if(note.number==50)  {p=sprintf("%s_D+D3.wav",path); NOTE=readWave2(p)}
  if(note.number==51)  {p=sprintf("%s_D+D#3.wav",path); NOTE=readWave2(p)}
  if(note.number==52)  {p=sprintf("%s_D+E3.wav",path); NOTE=readWave2(p)}  # e13
  if(note.number==53)  {p=sprintf("%s_D+F3.wav",path); NOTE=readWave2(p)}
  if(note.number==54)  {p=sprintf("%s_D+F#3.wav",path); NOTE=readWave2(p)}
  if(note.number==55)  {p=sprintf("%s_G+G3.wav",path); NOTE=readWave2(p)}
  if(note.number==56)  {p=sprintf("%s_G+G#3.wav",path); NOTE=readWave2(p)}
  if(note.number==57)  {p=sprintf("%s_G+A3.wav",path); NOTE=readWave2(p)} #A13
  if(note.number==58)  {p=sprintf("%s_G+A#3.wav",path); NOTE=readWave2(p)}
  if(note.number==59)  {p=sprintf("%s_B+B3.wav",path); NOTE=readWave2(p)}
  
  # 4-th octave
  if(note.number==60)  {p=sprintf("%s_B+C4.wav",path); NOTE=readWave2(p)}
  if(note.number==61)  {p=sprintf("%s_B+C#4.wav",path); NOTE=readWave2(p)}
  if(note.number==62)  {p=sprintf("%s_B+D4.wav",path); NOTE=readWave2(p)} #D13
  if(note.number==63)  {p=sprintf("%s_B+D#4.wav",path); NOTE=readWave2(p)}
  if(note.number==64)  {p=sprintf("%s_E+E4.wav",path); NOTE=readWave2(p)}
  if(note.number==65)  {p=sprintf("%s_E+F4.wav",path); NOTE=readWave2(p)}
  if(note.number==66)  {p=sprintf("%s_E+F#4.wav",path); NOTE=readWave2(p)}
  if(note.number==67)  {p=sprintf("%s_E+G4.wav",path); NOTE=readWave2(p)} #G13
  if(note.number==68)  {p=sprintf("%s_E+G#4.wav",path); NOTE=readWave2(p)}
  if(note.number==69)  {p=sprintf("%s_E+A4.wav",path); NOTE=readWave2(p)}
  if(note.number==70)  {p=sprintf("%s_E+A#4.wav",path); NOTE=readWave2(p)}
  if(note.number==71)  {p=sprintf("%s_E+B4.wav",path); NOTE=readWave2(p)} #B3
  
  # 5-te octave
  if(note.number==72)  {p=sprintf("%s_E+C5.wav",path); NOTE=readWave2(p)}
  if(note.number==73)  {p=sprintf("%s_E+C#5.wav",path); NOTE=readWave2(p)}
  if(note.number==74)  {p=sprintf("%s_E+D5.wav",path); NOTE=readWave2(p)} # 11E
  if(note.number==75)  {p=sprintf("%s_E+D#5.wav",path); NOTE=readWave2(p)}
  if(note.number==76)  {p=sprintf("%s_E+E5.wav",path); NOTE=readWave2(p)} #13E
  
  return(list(wav=NOTE,path=p))
}
