Note pitches

Discussion in 'Plugin Development' started by Forseth11, Dec 18, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Forseth11

    I am trying to make a plugin that uses notes in it.
    I am using this for playing the sound:
    Code:java
    1. public void playSound(int ins, int type, int tone, int octave){
    2. plugin.logger.info("NUM: " + ins + " " + type +" "+ tone + " "+ octave);
    3. List<String> worlds = main.GetConfig.getStringList("worlds");
    4. float pitch = getPitch(tone);
    5.  
    6.  
    7.  
    8. for(Player p : plugin.getServer().getOnlinePlayers()){
    9. if(worlds.contains(p.getWorld().getName())){
    10. if(ins == 0){
    11. p.playSound(p.getLocation(), Sound.NOTE_PIANO, octave, pitch);
    12. }
    13. if(ins == 1){
    14. p.playSound(p.getLocation(), Sound.NOTE_BASS, octave, pitch); }
    15. if(ins == 2){
    16. p.playSound(p.getLocation(), Sound.NOTE_BASS_DRUM, octave, pitch); }
    17. if(ins == 3){
    18. p.playSound(p.getLocation(), Sound.NOTE_BASS_GUITAR, octave, pitch); }
    19. if(ins == 4){
    20. p.playSound(p.getLocation(), Sound.NOTE_PLING, octave, pitch); }
    21. if(ins == 5){
    22. p.playSound(p.getLocation(), Sound.NOTE_SNARE_DRUM, octave, pitch); }
    23. if(ins == 6){
    24. p.playSound(p.getLocation(), Sound.NOTE_STICKS, octave, pitch); }
    25. }
    26. }
    27. }


    Now my problem is the pitches. I want to have A-G on different octaves and I also want flats and sharps.

    This is what I am using and I am petty sure that this is wrong:
    Code:java
    1. private static float getPitch(int id) {
    2. switch (id) {
    3. case 0: return 0.5F;
    4. case 1: return 0.53F;
    5. case 2: return 0.56F;
    6. case 3: return 0.6F;
    7. case 4: return 0.63F;
    8. case 5: return 0.67F;
    9. case 6: return 0.7F;
    10. case 7: return 0.76F;
    11. case 8: return 0.8F;
    12. case 9: return 0.84F;
    13. case 10: return 0.9F;
    14. case 11: return 0.94F;
    15. case 12: return 1.0F;
    16. case 13: return 1.06F;
    17. case 14: return 1.12F;
    18. case 15: return 1.18F;
    19. case 16: return 1.26F;
    20. case 17: return 1.34F;
    21. case 18: return 1.42F;
    22. case 19: return 1.5F;
    23. case 20: return 1.6F;
    24. case 21: return 1.68F;
    25. case 22: return 1.78F;
    26. case 23: return 1.88F;
    27. case 24: return 2.0F;
    28. default: return 0.0F;
    29. }
    30. }

    Does anyone know the correct pitches?
     
  2. Offline

    blablubbabc

    I think I am using those values as well and they worked fine so far.
     
  3. Offline

    Forseth11

    blablubbabc Well if they work I would like to know which ones are A, B, C, D, E, F, G and find out how to convert it to a flat or sharp.
     
  4. Offline

    blablubbabc

  5. Offline

    Forseth11

    blablubbabc So it would be like this:
    Code:java
    1. private static float getPitch(int id) {
    2. switch (id) {
    3. case 0: return 0.5F; //F#
    4. case 1: return 0.53F;//G
    5. case 2: return 0.56F;//G#
    6. case 3: return 0.6F;//A
    7. case 4: return 0.63F;//A#
    8. case 5: return 0.67F;//B
    9. case 6: return 0.7F;//C
    10. case 7: return 0.76F;//C#
    11. case 8: return 0.8F;//D
    12. case 9: return 0.84F;//D#
    13. case 10: return 0.9F;//E
    14. case 11: return 0.94F;//F
    15. case 12: return 1.0F;//F#
    16. case 13: return 1.06F;//G
    17. case 14: return 1.12F;//G#
    18. case 15: return 1.18F;//A
    19. case 16: return 1.26F;//A#
    20. case 17: return 1.34F;//B
    21. case 18: return 1.42F;//C
    22. case 19: return 1.5F;//C#
    23. case 20: return 1.6F;//D
    24. case 21: return 1.68F;//D#
    25. case 22: return 1.78F;//E
    26. case 23: return 1.88F;//F
    27. case 24: return 2.0F;//F#
    28. default: return 0.0F;
    29. }
    30. }


    Edit: If it is that way how do I get flats? Do I just subtract a certain amount? If so what amount?
     
  6. Offline

    blablubbabc

    Forseth11 I have no clue about notes, but isn't for example C# the same as flat D (and so on)? At least on a keyboard they are played with the same button, no?
     
  7. Offline

    Forseth11

    blablubbabc I tested it. It sounds fine. Thank you.
     
Thread Status:
Not open for further replies.

Share This Page