示例#1
0
  /** adjusts the widgets availability according to chord theory options */
  protected void adjustWidgetAvailability() {
    String chordName = ChordDatabase.get(getChordList().getSelectionIndex()).getName();
    if (chordName.equals("dim")
        || chordName.equals("dim7")
        || chordName.equals("aug")
        || chordName.equals("5")) {
      updateWidget(getAlterationList(), false);
      updateWidget(getAddCheck(), false);
      updateWidget(get_9List(), false);
      updateWidget(get_11List(), false);
      updateWidget(getPlusMinusList(), false);

      if (!chordName.equals("5")) {
        updateWidget(get_5List(), false); // disableWidget(get_5List());
      } else {
        updateWidget(get_5List(), true);
      }
    } else {
      // enable and don't change the selection index
      // getAlterationList().setEnabled(true);
      // get_5List().setEnabled(true);
      updateWidget(getAlterationList(), true);
      updateWidget(get_5List(), true);
    }

    if (this.alterationList.isEnabled()) {
      int currentIndex = this.alterationList.getSelectionIndex();
      // handle the +- list and ADD checkbox
      // handle the 9 and 11 list
      updateWidget(this.plusMinusList, (currentIndex > 0));
      updateWidget(this.addCheck, (currentIndex > 0));
      updateWidget(this._9List, (currentIndex >= 2 && !this.addCheck.getSelection()));
      updateWidget(this._11List, (currentIndex >= 3 && !this.addCheck.getSelection()));
    }
  }
示例#2
0
  public void init() {
    Composite tonicComposite = new Composite(this, SWT.NONE);
    tonicComposite.setLayout(this.dialog.gridLayout(1, false, 0, 0));
    tonicComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    this.tonicList = new List(tonicComposite, SWT.BORDER);
    this.tonicList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    // sharp & flat buttons
    Composite buttonsComposite = new Composite(tonicComposite, SWT.NONE);
    buttonsComposite.setLayout(this.dialog.gridLayout(2, true, 0, 0));
    GridData buttonGd = new GridData(SWT.FILL, SWT.TOP, true, false);
    buttonGd.heightHint = 28;
    buttonGd.widthHint = 28;
    this.sharpButton = new Button(buttonsComposite, SWT.TOGGLE);
    this.sharpButton.setLayoutData(buttonGd);
    this.flatButton = new Button(buttonsComposite, SWT.TOGGLE);
    this.flatButton.setLayoutData(buttonGd);
    // TODO: maybe put an image instead of #,b
    this.sharpButton.setText("#");
    this.flatButton.setText("b");
    this.chordList = new List(this, SWT.BORDER);
    this.chordList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    Label separator = new Label(tonicComposite, SWT.SEPARATOR | SWT.HORIZONTAL);
    separator.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, true));
    Button customizeButton = new Button(tonicComposite, SWT.PUSH);
    customizeButton.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, false));
    customizeButton.setText(TuxGuitar.getProperty("settings"));

    customizeButton.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent arg0) {
            if (new ChordSettingsDialog().open(ChordSelector.this.getShell())) {
              new SyncThread(
                      new Runnable() {
                        @Override
                        public void run() {
                          ChordSelector.this.showChord();
                          getChordList().redraw();
                        }
                      })
                  .start();
            }
          }
        });

    initChordWidgets();

    // fill the List widgets with text
    insertTonicNames(true);

    for (int i = 0; i < ChordDatabase.length(); i++) {
      this.chordList.add(ChordDatabase.get(i).getName());
    }
    /*
    Iterator chordInfo = ChordCreatorUtil.getChordData().getChords().iterator();
    while(chordInfo.hasNext()) {
    	this.chordList.add( ((ChordDatabase.ChordInfo)chordInfo.next()).getName() );
    }
    */

    this.chordList.setSelection(0);

    String[] alterationNames = getAlterationNames();
    for (int i = 0; i < alterationNames.length; i++) {
      this.alterationList.add(alterationNames[i]);
    }
    this.alterationList.setSelection(0);

    String[] plusMinus = this.getPlusMinus("");
    for (int i = 0; i < plusMinus.length; i++) {
      this.plusMinusList.add(plusMinus[i]);
    }
    this.plusMinusList.setSelection(0);

    String[] plus5Minus = this.getPlusMinus("/5");
    for (int i = 0; i < plus5Minus.length; i++) {
      this._5List.add(plus5Minus[i]);
    }
    this._5List.setSelection(0);
    String[] plus9Minus = this.getPlusMinus("/9");
    for (int i = 0; i < plus9Minus.length; i++) {
      this._9List.add(plus9Minus[i]);
    }
    this._9List.setSelection(0);
    String[] plus11Minus = this.getPlusMinus("/11");
    for (int i = 0; i < plus11Minus.length; i++) {
      this._11List.add(plus11Minus[i]);
    }
    this._11List.setSelection(0);

    // LISTENERS

    this.tonicList.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            if (ChordSelector.this.getRefresh()) {
              if (getDialog().getEditor() != null && getDialog().getList() != null) {
                getBassCombo().select(getTonicList().getSelectionIndex());
                showChord();
              }
            }
          }
        });

    this.bassCombo.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            if (ChordSelector.this.getRefresh()) {
              if (getDialog().getEditor() != null && getDialog().getList() != null) {
                showChord();
              }
            }
          }
        });

    this.chordList.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            if (getDialog().getEditor() != null && getDialog().getList() != null) {
              adjustWidgetAvailability();
              if (ChordSelector.this.getRefresh()) {
                showChord();
              }
            }
          }
        });

    this.alterationList.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            if (getDialog().getEditor() != null && getDialog().getList() != null) {
              ChordSelector.this.adjustWidgetAvailability();
              if (ChordSelector.this.getRefresh()) {
                showChord();
              }
            }
          }
        });

    this.addCheck.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent arg0) {
            if (getDialog().getEditor() != null && getDialog().getList() != null) {

              ChordSelector.this.adjustWidgetAvailability();
              /*
              if (getAddCheck().getSelection()) {
              	updateWidget(get_9List(), false);
              	updateWidget(get_11List(), false);
              }
              */
              if (ChordSelector.this.getRefresh()) {
                showChord();
                // ChordSelector.this.dialog.getList().redraw();
              }
            }
          }
        });

    this._5List.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            if (getDialog().getEditor() != null && getDialog().getList() != null) {
              if (ChordSelector.this.getRefresh()) {
                showChord();
              }
            }
          }
        });

    this._9List.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            if (getDialog().getEditor() != null && getDialog().getList() != null) {
              if (ChordSelector.this.getRefresh()) {
                showChord();
              }
            }
          }
        });

    this._11List.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            if (getDialog().getEditor() != null && getDialog().getList() != null) {
              if (ChordSelector.this.getRefresh()) {
                showChord();
              }
            }
          }
        });

    this.plusMinusList.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            if (getDialog().getEditor() != null && getDialog().getList() != null) {
              if (ChordSelector.this.getRefresh()) {
                showChord();
                // ChordSelector.this.dialog.getList().redraw();
              }
            }
          }
        });

    this.sharpButton.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent arg0) {
            insertTonicNames(true);
          }
        });

    this.flatButton.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent arg0) {
            insertTonicNames(false);
          }
        });
    this.adjustWidgetAvailability();
  }
  /** adds points if the combination has all the notes in the basis of chord */
  private float combinationHasAllRequiredNotes(ArrayList stringValueCombination) {
    if (!isValidProcess()) {
      return 0;
    }
    Iterator it = stringValueCombination.iterator();
    int[] values = new int[this.requiredNotes.length];
    int currentIndex = 0;

    while (it.hasNext()) {
      StringValue sv = (StringValue) it.next();

      if (sv.getRequiredNoteIndex() >= 0) { // only basis tones
        boolean insert = true;

        for (int i = 0; i < currentIndex; i++)
          if (values[i] == sv.getRequiredNoteIndex() + 1) insert = false;

        // sv.requiredNoteIndex+1, because we have index 0 and we don't
        // want it inside

        if (insert) {
          values[currentIndex] = sv.getRequiredNoteIndex() + 1;
          currentIndex++;
        }
      }
    }

    if (currentIndex == this.requiredNotes.length) {
      return ChordSettings.instance().getRequiredBasicsGrade();
    }

    if (currentIndex == this.requiredNotes.length - 1) {

      boolean existsSubdominant = false;

      Iterator it2 = stringValueCombination.iterator();
      while (it2.hasNext()) {
        StringValue current = (StringValue) it2.next();
        if ((this.tuning[current.getString()] + current.getFret()) % 12
            == (this.chordTonic + 7) % 12) existsSubdominant = true;
      }

      if (!existsSubdominant && currentIndex == this.requiredNotes.length - 1) {
        // if not riff. "sus" chord, or chord with altered fifth allow chord without JUST
        // subdominant (fifth) with small penalty

        // if ( !((ChordInfo)new
        // ChordDatabase().getChords().get(this.chordIndex)).getName().contains("sus") &&
        // this.requiredNotes.length!=2 && this.add5==0) {
        // String.contains(String) is not available at JRE1.4
        // Replaced by "String.indexOf(String) >= 0"
        if (ChordDatabase.get(this.chordIndex).getName().indexOf("sus") >= 0
            && this.requiredNotes.length != 2
            && this.add5 == 0) {
          return (ChordSettings.instance().getRequiredBasicsGrade() * 4 / 5);
        }
      }
    }

    // required notes count should decrease the penalty
    int noteCount =
        (this.alteration == 0 ? 0 : 1 + this.alteration)
            + currentIndex
            + (this.bassTonic == this.chordTonic ? 0 : 1);

    // sometimes, when noteCount is bigger then tunning length, this pennalty will become positive,
    // which may help
    return -ChordSettings.instance().getRequiredBasicsGrade()
        * (this.tuning.length - noteCount)
        / this.tuning.length
        * 2;
  }
  protected void getChords(
      int[] tuning,
      int chordIndex,
      int alteration,
      int plusMinus,
      boolean add,
      int add5,
      int add9,
      int add11,
      int bassTonic,
      int chordTonic,
      boolean sharp) {

    if (!isValidProcess()) {
      return;
    }

    this.add5 = add5;

    this.tuning = tuning;

    this.chordIndex = chordIndex;

    this.chordTonic = chordTonic;

    this.bassTonic = bassTonic;

    this.alteration = alteration;

    this.chordName =
        new ChordNamingConvention()
            .createChordName(
                this.chordTonic,
                this.chordIndex,
                this.alteration,
                plusMinus,
                add,
                add5,
                add9,
                add11,
                this.bassTonic,
                sharp);

    // find the notes that expand the chord
    if (this.alteration != 0) {
      if (add) {
        this.expandingNotes = new int[1];
        this.expandingNotes[0] = getAddNote(this.alteration - 1, plusMinus);
      } else { // not just add...
        // 9+- = 7b !9(+-)    (index=1)
        // 11+- = 7b !11(+-) 9(+-)  (index=2)
        // 13+- = 7b !13(+-) 9(+-) 11(+-) (index=3)
        this.expandingNotes = new int[1 + this.alteration];
        this.expandingNotes[0] = 11; // 7b
        this.expandingNotes[1] = getAddNote(this.alteration - 1, plusMinus); // this.alteration+-

        // rest
        for (int i = 2; i <= this.alteration; i++)
          this.expandingNotes[i] =
              getAddNote(i - 2, i == 2 ? add9 : add11); // @2=add9+-, @3=add11+- tone
      }

    } else this.expandingNotes = new int[0];

    // Required notes
    // this.requiredNotes = ((ChordDatabase.ChordInfo)new
    // ChordDatabase().getChords().get(chordIndex)).cloneRequireds();
    this.requiredNotes = ChordDatabase.get(chordIndex).cloneRequireds();
    // IT DON'T BUILD UNDER JRE1.4
    // this.requiredNotes = ((ChordDatabase.ChordInfo)
    // ChordCreatorUtil.getChordData().getChords().get(chordIndex)).getRequiredNotes().clone();

    // adjust the subdominant if needed
    if (add5 != 0) {
      for (int i = 0; i < this.requiredNotes.length; i++)
        if (this.requiredNotes[i] == 8) // alternate the subdominant
        this.requiredNotes[i] += (add5 == 1 ? 1 : -1);
    }

    // first count different from -1
    int count = 0;
    for (int i = 0; i < this.requiredNotes.length; i++) {
      this.requiredNotes[i] = checkForOverlapping(this.requiredNotes[i]);
      if (this.requiredNotes[i] != -1) count++;
    }
    // then fill in the new array
    int[] tempNotes = new int[count];
    count = 0;
    for (int i = 0; i < this.requiredNotes.length; i++)
      if (this.requiredNotes[i] != -1) {
        tempNotes[count] = this.requiredNotes[i];
        count++;
      }
    // and substitute them
    this.requiredNotes = tempNotes;

    // return getChords();
    if (isValidProcess()) {
      List chords = getChords();
      if (chords != null && isValidProcess()) {
        this.listener.notifyChords(this, chords);
      }
    }
  }