Examples of Piece


Examples of com.music.model.persistent.Piece

            }
        }
    }

    private Piece savePiece(ScoreContext ctx, byte[] mp3, byte[] midi) {
        Piece piece = new Piece();
        piece.setNewlyCreated(true);
        piece.setGenerationTime(new DateTime());
        piece.setTitle(ctx.getScore().getTitle());
        piece.setKeyNote(ctx.getKeyNote());
        piece.setMeasures(ctx.getMeasures());
        piece.setNormalizedMeasureSize(ctx.getNormalizedMeasureSize());
        piece.setTempo((int) ctx.getScore().getTempo());
        piece.setNoteLengthCoefficient(ctx.getNoteLengthCoefficient());
        piece.setScale(ctx.getScale());
        piece.setAlternativeScale(ctx.getAlternativeScale());
        piece.setUpBeatLength(ctx.getUpBeatLength());
        piece.setMetreNumerator(ctx.getMetre()[0]);
        piece.setMetreDenominator(ctx.getMetre()[1]);
        piece.setMainInstrument(ctx.getParts().get(PartType.MAIN).getInstrument());
        piece.setVariation(ctx.getVariation());
        piece.setParts(joiner.join(ctx.getParts().keySet()));
        piece.setAlgorithmVersion(algorithmVersion);

        piece.getIntermediateDecisions().setDullBass(ctx.isDullBass());
        piece.getIntermediateDecisions().setFourToTheFloor(ctx.isFourToTheFloor());
        piece.getIntermediateDecisions().setSimplePhrases(ctx.isSimplePhrases());
        piece.getIntermediateDecisions().setAccompaniment(ctx.getParts().containsKey(PartType.ACCOMPANIMENT));
        piece.getIntermediateDecisions().setDrums(ctx.getParts().containsKey(PartType.PERCUSSIONS));
        piece.getIntermediateDecisions().setClassical(
                ctx.getParts().get(PartType.MAIN).getInstrument() == Instruments.PIANO
                        && piece.getIntermediateDecisions().isAccompaniment());
        piece.getIntermediateDecisions().setTempoType(Tempo.forValue(piece.getTempo()));
        piece.getIntermediateDecisions().setElectronic(ctx.isElectronic());
        piece.getIntermediateDecisions().setDissonant(ctx.isDissonant());
        piece.getIntermediateDecisions().setOrnamented(ctx.isOrnamented());
        piece.getIntermediateDecisions().setVariations(StringUtils.left(joiner.join(ctx.getVariations()), 2000));

        Piece result = dao.persist(piece);

        try {
            fileStorageService.storeFile(getMp3FilePath(result.getId()), mp3);
            fileStorageService.storeFile(getMidiFilePath(result.getId()), midi);
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
        return result;
    }
View Full Code Here

Examples of com.music.model.persistent.Piece

        play.setDateTime(new DateTime());
        play.setMobileApp(mobileApp);
        if (userId != null) {
            play.setUser(dao.getById(User.class, userId));
        }
        Piece piece = dao.getById(Piece.class, pieceId);
        play.setPiece(piece);
        play.setIp(ip);
        dao.persist(play);

        if (piece.isNewlyCreated()) {
            // we don't care about isolation here - 2 or more users can get (and
            // set new=false to) the same piece and that's OK
            piece.setNewlyCreated(false);
            dao.persist(piece);
        }
    }
View Full Code Here

Examples of com.music.model.persistent.Piece

            throw new IllegalStateException(ex);
        }
    }

    public InputStream getPieceMusicXml(long id) throws IOException {
        Piece piece = dao.getById(Piece.class, id);
        try (InputStream is = fileStorageService.getFile(getMidiFilePath(id))) {
            ByteArrayOutputStream result = new ByteArrayOutputStream();
            Score score = new Score();
            SMFTools localSMF = new SMFTools();
            localSMF.read(is);
            SMFTools.SMFToScore(score, localSMF);
            score.setTitle(piece.getTitle());
            score.setNumerator(piece.getMetreNumerator());
            score.setDenominator(piece.getMetreDenominator());
            MusicXmlRenderer.render(score, result);
            return new ByteArrayInputStream(result.toByteArray());
        }
    }
View Full Code Here

Examples of com.music.model.persistent.Piece

        return dao.getById(Piece.class, id);
    }

    @Transactional
    public long getNextPieceId(UserPreferences preferences) {
        Piece piece = dao.getNewlyCreatedPiece(preferences);
        long id = 1;
        if (piece == null && preferences.isDefault()) {
            id = getRandomPieceId();
        } else if (piece == null && !preferences.isDefault()) {
            List<Piece> pieces = dao.getByPreferences(preferences);
            if (!pieces.isEmpty()) {
                id = pieces.get(random.nextInt(pieces.size())).getId();
            } else {
                id = getRandomPieceId();
            }
        } else {
            id = piece.getId();
        }
        sharedData.getListeningRequests().incrementAndGet();
        return id;
    }
View Full Code Here

Examples of com.music.model.persistent.Piece

        sharedData.getListeningRequests().incrementAndGet();
        return id;
    }

    private long getRandomPieceId() {
        Piece piece;
        long maxId = sharedData.getMaxId();
        if (maxId == 0) {
            maxId = dao.getMaxPieceId();
        }
        long id = 0;
        int attempts = 0;
        while (attempts < 5) {
            id = (long) (1 + (Math.random() * maxId));
            piece = dao.getById(Piece.class, id);
            if (piece != null && piece.getLikes() >= -3) {
                break;
            }
            attempts++;
        }
        return id;
View Full Code Here

Examples of com.music.model.persistent.Piece

        return dao.getByIds(Piece.class, pieceIds);
    }

    @Transactional
    public void incrementDownloads(long id, boolean midi) {
        Piece piece = dao.getById(Piece.class, id);
        if (midi) {
            piece.setMidiDownloads(piece.getMidiDownloads() + 1);
        } else {
            piece.setMp3Downloads(piece.getMp3Downloads() + 1);
        }
        dao.persist(piece);
    }
View Full Code Here

Examples of com.music.model.persistent.Piece

            stop();
            return;
        }

        Long pieceId = pieceService.getNextPieceId(prefs);
        Piece piece = pieceService.getPiece(pieceId);
        pieces.add(piece);
        currentPieceId = pieceId;
        fillCurrentCorrectAnswer(piece);

        PossibleAnswers possibleAnswers = generatePossibleAnswers(piece);
View Full Code Here

Examples of com.oti.Piece

    //    System.out.println("SAM TO REMOVE createMove firstCel "+ firstCell+" otherCell "+ otherCell);
    //    System.out.println("SAM TO REMOVE createMove firstCellVal "+ firstCellVal+" otherCellVal "+ otherCellVal);
   
   
    Piece currPiece = null;
    Location  currLoc = null;
    if (firstCellVal==0) {
      currPiece = Piece.pieceForNumber(otherCellVal);
      currLoc = Location.locationFor(firstCell%4, firstCell/4, 4);
    } else {
View Full Code Here

Examples of com.oti.Piece

  private BigInteger createState(Board board) {
    BigInteger res = BigInteger.valueOf(0);
    for (int i = 0; i < 4; i++) {
      int fourth = 0;
      for (int j = 0; j < 4; j++) {       
        Piece cell = board.pieceAt(j, i);
        fourth = fourth << 4;
        fourth |= cell.getPieceNumber();
      }
      res= res.shiftLeft(16);
      res = res.add(BigInteger.valueOf(fourth));
    }
   
View Full Code Here

Examples of com.oti.Piece

    //    System.out.println("SAM TO REMOVE createMove firstCel "+ firstCell+" otherCell "+ otherCell);
    //    System.out.println("SAM TO REMOVE createMove firstCellVal "+ firstCellVal+" otherCellVal "+ otherCellVal);
   
   
    Piece currPiece = null;
    Location  currLoc = null;
    if (firstCellVal==0) {
      currPiece = Piece.pieceForNumber(otherCellVal);
      currLoc = Location.locationFor(firstCell%4, firstCell/4, 4);
    } else {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.